com.cometway.httpd
Class HTMLFormWriter

java.lang.Object
  extended by com.cometway.httpd.HTMLFormWriter
Direct Known Subclasses:
XHTMLFormWriter

public class HTMLFormWriter
extends java.lang.Object

HTMLFormWriter is a tool for writing simple HTML-based forms to a StringBuffer or AgentRequest output stream. Using this class it is relatively simple to create generic forms without worrying about the HTML code.


Constructor Summary
HTMLFormWriter(AgentRequest agentRequest)
          Use this constructor to write HTML forms directly to an AgentRequest.
HTMLFormWriter(java.lang.StringBuffer b)
          Use this constructor to write HTML forms to a StringBuffer.
 
Method Summary
protected  java.lang.String encode(java.lang.String in)
           
 void print(int i)
          Converts the integer to a String and writes it to the output.
 void print(java.lang.String s)
          Prints the String to the output.
 void println(int i)
          Converts the integer to a String and writes it to the output followed by a carriage return.
 void println(java.lang.String s)
          Prints the String to the output followed by a carriage return.
 void writeCaption(java.lang.String caption)
          Adds a centered caption to the form output.
 void writeCheckbox(java.lang.String label, java.lang.String name, boolean checked)
          Writes a checkbox to the form output.
 void writeCheckbox(java.lang.String label, java.lang.String name, boolean checked, java.lang.String title)
          Writes a checkbox to the form output and includes a title attribute.
 void writeField(java.lang.String label, java.lang.String name, int size)
          Writes a standard input field to the form output.
 void writeField(java.lang.String label, java.lang.String name, Props p, int size)
          Writes a standard input field to the form output displaying the value as retrieved from the Props using the specified name as the Props key.
 void writeField(java.lang.String label, java.lang.String name, java.lang.String value, int size)
          Writes a standard input field to the form output displaying the specified value.
 void writeFooter()
          Writes the form footer to the output.
 void writeHeader(java.lang.String submitURL)
          Writes the form header to the output.
 void writeHeader(java.lang.String submitURL, Props userProps)
          Writes the form header to the output.
 void writeHelp(java.lang.String message)
          Adds a help description over the fields.
 void writeHiddenField(java.lang.String name, Props p)
          Writes a hidden input parameter to the form output as retrieved from the Props using the specified name as the Props key.
 void writeHiddenField(java.lang.String name, java.lang.String value)
          Writes a hidden input parameter to the form output.
 void writeLoginFields(Props p)
          Hidden "login_name" and "login_hash" parameters are added to the form output using the "name" and "password" values of the specified Props.
 void writeLoginFields(java.lang.String name, java.lang.String password)
          Hidden "login_name" and "login_hash" parameters are added to the form output using the specified name and password.
 void writeMultilineField(java.lang.String label, java.lang.String name, int columns, int rows)
          Writes a multiline field (TEXTAREA) to the form output.
 void writeMultilineField(java.lang.String label, java.lang.String name, Props p, int columns, int rows)
          Writes a multiline field (TEXTAREA) to the form output displaying the specified value as retrieved from the Props using the specified name as a key.
 void writeMultilineField(java.lang.String label, java.lang.String name, java.lang.String value, int columns, int rows)
          Writes a multiline field (TEXTAREA) to the form output displaying the specified value.
 void writePassword(java.lang.String label, java.lang.String name, int size)
          Writes a password input field to the form output.
 void writePassword(java.lang.String label, java.lang.String name, java.lang.String value, int size)
          Writes a password input field to the form output containing the specified value.
 void writeProps(Props p)
          Writes a table containing the Props keys and associated values to the output.
 void writeResetButton(java.lang.String title, java.lang.String description)
          Writes a reset button and description to the form output that resets changes to the form when pressed.
 void writeSelectFooter()
          Writes the footer HTML for a SELECT to the form output.
 void writeSelectHeader(java.lang.String label, java.lang.String name, boolean multiple)
          Writes the header HTML for a SELECT to the form output to display a popup menu or selection list.
 void writeSelectItem(java.lang.String name, java.lang.String value, boolean selected)
          Writes a SELECT OPTION to the form output.
 void writeSelectItem(java.lang.String name, java.lang.String value, java.lang.String currentSelection)
          Writes a SELECT OPTION to the form output.
 void writeSpace()
          Writes appropriate HTML to the output to add vertical space between form items.
 void writeStaticField(java.lang.String label, java.lang.String value)
          Writes a static text field to the form output.
 void writeSubmitButton(java.lang.String title, java.lang.String name, java.lang.String description)
          Writes a submit button and description to the form output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HTMLFormWriter

public HTMLFormWriter(AgentRequest agentRequest)
Use this constructor to write HTML forms directly to an AgentRequest.


HTMLFormWriter

public HTMLFormWriter(java.lang.StringBuffer b)
Use this constructor to write HTML forms to a StringBuffer.

Method Detail

print

public void print(int i)
           throws java.io.IOException
Converts the integer to a String and writes it to the output.

Throws:
java.io.IOException

print

public void print(java.lang.String s)
           throws java.io.IOException
Prints the String to the output.

Throws:
java.io.IOException

println

public void println(int i)
             throws java.io.IOException
Converts the integer to a String and writes it to the output followed by a carriage return.

Throws:
java.io.IOException

println

public void println(java.lang.String s)
             throws java.io.IOException
Prints the String to the output followed by a carriage return.

Throws:
java.io.IOException

writeCaption

public void writeCaption(java.lang.String caption)
                  throws java.io.IOException
Adds a centered caption to the form output.

Throws:
java.io.IOException

writeCheckbox

public void writeCheckbox(java.lang.String label,
                          java.lang.String name,
                          boolean checked)
                   throws java.io.IOException
Writes a checkbox to the form output.

Throws:
java.io.IOException

writeCheckbox

public void writeCheckbox(java.lang.String label,
                          java.lang.String name,
                          boolean checked,
                          java.lang.String title)
                   throws java.io.IOException
Writes a checkbox to the form output and includes a title attribute.

Throws:
java.io.IOException

writeFooter

public void writeFooter()
                 throws java.io.IOException
Writes the form footer to the output. Call this method last to properly terminate the form HTML.

Throws:
java.io.IOException

writeHeader

public void writeHeader(java.lang.String submitURL)
                 throws java.io.IOException
Writes the form header to the output. Call this method first to properly begin the form HTML. This creates a POST type request to the specified submitURL.

Throws:
java.io.IOException

writeHeader

public void writeHeader(java.lang.String submitURL,
                        Props userProps)
                 throws java.io.IOException
Writes the form header to the output. Call this method first to properly begin the form HTML. This creates a POST type request to the specified submitURL. Hidden "login_name" and "login_hash" parameters are added to the form for the specified userProps.

Throws:
java.io.IOException

writeHelp

public void writeHelp(java.lang.String message)
               throws java.io.IOException
Adds a help description over the fields.

Throws:
java.io.IOException

writeSpace

public void writeSpace()
                throws java.io.IOException
Writes appropriate HTML to the output to add vertical space between form items.

Throws:
java.io.IOException

writeField

public void writeField(java.lang.String label,
                       java.lang.String name,
                       int size)
                throws java.io.IOException
Writes a standard input field to the form output.

Throws:
java.io.IOException

writeField

public void writeField(java.lang.String label,
                       java.lang.String name,
                       java.lang.String value,
                       int size)
                throws java.io.IOException
Writes a standard input field to the form output displaying the specified value.

Throws:
java.io.IOException

writeField

public void writeField(java.lang.String label,
                       java.lang.String name,
                       Props p,
                       int size)
                throws java.io.IOException
Writes a standard input field to the form output displaying the value as retrieved from the Props using the specified name as the Props key.

Throws:
java.io.IOException

writeHiddenField

public void writeHiddenField(java.lang.String name,
                             java.lang.String value)
                      throws java.io.IOException
Writes a hidden input parameter to the form output.

Throws:
java.io.IOException

writeHiddenField

public void writeHiddenField(java.lang.String name,
                             Props p)
                      throws java.io.IOException
Writes a hidden input parameter to the form output as retrieved from the Props using the specified name as the Props key.

Throws:
java.io.IOException

writeLoginFields

public void writeLoginFields(java.lang.String name,
                             java.lang.String password)
                      throws java.io.IOException
Hidden "login_name" and "login_hash" parameters are added to the form output using the specified name and password.

Throws:
java.io.IOException

writeLoginFields

public void writeLoginFields(Props p)
                      throws java.io.IOException
Hidden "login_name" and "login_hash" parameters are added to the form output using the "name" and "password" values of the specified Props.

Throws:
java.io.IOException

writeMultilineField

public void writeMultilineField(java.lang.String label,
                                java.lang.String name,
                                int columns,
                                int rows)
                         throws java.io.IOException
Writes a multiline field (TEXTAREA) to the form output.

Throws:
java.io.IOException

writeMultilineField

public void writeMultilineField(java.lang.String label,
                                java.lang.String name,
                                java.lang.String value,
                                int columns,
                                int rows)
                         throws java.io.IOException
Writes a multiline field (TEXTAREA) to the form output displaying the specified value.

Throws:
java.io.IOException

writeMultilineField

public void writeMultilineField(java.lang.String label,
                                java.lang.String name,
                                Props p,
                                int columns,
                                int rows)
                         throws java.io.IOException
Writes a multiline field (TEXTAREA) to the form output displaying the specified value as retrieved from the Props using the specified name as a key.

Throws:
java.io.IOException

writePassword

public void writePassword(java.lang.String label,
                          java.lang.String name,
                          int size)
                   throws java.io.IOException
Writes a password input field to the form output.

Throws:
java.io.IOException

writePassword

public void writePassword(java.lang.String label,
                          java.lang.String name,
                          java.lang.String value,
                          int size)
                   throws java.io.IOException
Writes a password input field to the form output containing the specified value.

Throws:
java.io.IOException

writeProps

public void writeProps(Props p)
                throws java.io.IOException
Writes a table containing the Props keys and associated values to the output. This is useful for debugging the contents of AgentRequest Props.

Throws:
java.io.IOException

writeResetButton

public void writeResetButton(java.lang.String title,
                             java.lang.String description)
                      throws java.io.IOException
Writes a reset button and description to the form output that resets changes to the form when pressed.

Throws:
java.io.IOException

writeSelectFooter

public void writeSelectFooter()
                       throws java.io.IOException
Writes the footer HTML for a SELECT to the form output.

Throws:
java.io.IOException

writeSelectHeader

public void writeSelectHeader(java.lang.String label,
                              java.lang.String name,
                              boolean multiple)
                       throws java.io.IOException
Writes the header HTML for a SELECT to the form output to display a popup menu or selection list. The multiple parameter should be set to false for a popup; set it to true to create a selection list. A call to this method is typically followed by multiple calls to writeSelectItem followed by a call to writeSelectFooter to terminate the SELECT.

Throws:
java.io.IOException

writeSelectItem

public void writeSelectItem(java.lang.String name,
                            java.lang.String value,
                            boolean selected)
                     throws java.io.IOException
Writes a SELECT OPTION to the form output. Calls to this method must be surrounded by calls to writeSelectHeader and writeSelectFooter.

Throws:
java.io.IOException

writeSelectItem

public void writeSelectItem(java.lang.String name,
                            java.lang.String value,
                            java.lang.String currentSelection)
                     throws java.io.IOException
Writes a SELECT OPTION to the form output. If the name is equal to the currentSelection the item is selected; otherwise it is not selected. Calls to this method must be surrounded by calls to writeSelectHeader and writeSelectFooter.

Throws:
java.io.IOException

writeStaticField

public void writeStaticField(java.lang.String label,
                             java.lang.String value)
                      throws java.io.IOException
Writes a static text field to the form output.

Throws:
java.io.IOException

writeSubmitButton

public void writeSubmitButton(java.lang.String title,
                              java.lang.String name,
                              java.lang.String description)
                       throws java.io.IOException
Writes a submit button and description to the form output.

Throws:
java.io.IOException

encode

protected java.lang.String encode(java.lang.String in)