The Encog Project

org.encog.bot.html
Class FormUtility

java.lang.Object
  extended by org.encog.bot.html.FormUtility

public class FormUtility
extends java.lang.Object

The Heaton Research Spider Copyright 2007 by Heaton Research, Inc. HTTP Programming Recipes for Java ISBN: 0-9773206-6-9 http://www.heatonresearch.com/articles/series/16/ FormUtility: This class is used to construct responses to HTML forms. The class supports both standard HTML forms, as well as multipart forms. This class is released under the: GNU Lesser General Public License (LGPL) http://www.gnu.org/copyleft/lesser.html


Field Summary
static int BUFFER_SIZE
          The size of the read buffer.
static java.lang.String ENCODE
          The charset to use for URL encoding.
static int RANDOM_LENGTH
          The length of random string to create for multipart.
 
Constructor Summary
FormUtility(java.io.OutputStream os, java.lang.String boundary)
          Prepare to access either a regular, or multipart, form.
 
Method Summary
 void add(java.lang.String name, java.io.File file)
          Add a file to a multipart form.
 void add(java.lang.String name, java.lang.String value)
          Add a regular text field to either a regular or multipart form.
 void complete()
          Complete the building of the form.
static java.lang.String getBoundary()
          Generate a boundary for a multipart form.
static java.util.Map<java.lang.String,java.lang.String> parse(java.lang.String form)
          Parse a URL query string.
protected static java.lang.String randomString()
          Generate a random string, of a specified length.
protected  void writeln(java.lang.String str)
          Write a string, with a carriage return and linefeed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENCODE

public static final java.lang.String ENCODE
The charset to use for URL encoding. Per URL coding spec, this value should always be UTF-8.

See Also:
Constant Field Values

BUFFER_SIZE

public static final int BUFFER_SIZE
The size of the read buffer.

See Also:
Constant Field Values

RANDOM_LENGTH

public static final int RANDOM_LENGTH
The length of random string to create for multipart.

See Also:
Constant Field Values
Constructor Detail

FormUtility

public FormUtility(java.io.OutputStream os,
                   java.lang.String boundary)
Prepare to access either a regular, or multipart, form.

Parameters:
os - The stream to output to.
boundary - The boundary to be used, or null if this is not a multipart form.
Method Detail

getBoundary

public static java.lang.String getBoundary()
Generate a boundary for a multipart form.

Returns:
The boundary.

parse

public static java.util.Map<java.lang.String,java.lang.String> parse(java.lang.String form)
Parse a URL query string. Return a map of all of the name value pairs.

Parameters:
form - The query string to parse.
Returns:
A map of name-value pairs.

randomString

protected static java.lang.String randomString()
Generate a random string, of a specified length. This is used to generate the multipart boundary.

Returns:
A random string.

add

public void add(java.lang.String name,
                java.io.File file)
         throws java.io.IOException
Add a file to a multipart form.

Parameters:
name - The field name.
file - The file to attach.
Throws:
java.io.IOException - If any error occurs while writing.

add

public void add(java.lang.String name,
                java.lang.String value)
         throws java.io.IOException
Add a regular text field to either a regular or multipart form.

Parameters:
name - The name of the field.
value - The value of the field.
Throws:
java.io.IOException - If any error occurs while writing.

complete

public void complete()
              throws java.io.IOException
Complete the building of the form.

Throws:
java.io.IOException - If any error occurs while writing.

writeln

protected void writeln(java.lang.String str)
                throws java.io.IOException
Write a string, with a carriage return and linefeed.

Parameters:
str - The string to write.
Throws:
java.io.IOException - If any error occurs while writing.

The Encog Project