Groovy Documentation

org.jdesktop.html.form
[Java] Class Forms

java.lang.Object
  org.jdesktop.html.form.Forms

public final class Forms
extends Object

Utility class used for automatically creating a Form instance directly from an HTTP Response. Also contains utility methods for encoding form bodies for transmission, and other Form related functions.

Because HTML is not always well formed, this utility class does not support parsing HTML directly. Rather, it supports parsing HTML documents which have been previously made well-formed. It is then parsed just as any XML document.

Those methods which take a Response directly will take the response text and pass it through some routines to attempt to clean the HTML. If this fails, parsing will fail.

If you want to run your own cleanup routines, do so prior to calling one of the methods which take a SimpleDocument.

Authors:
rbair


Constructor Summary
private Forms()

 
Method Summary
static Form getForm(SimpleDocument dom, String baseUrl, String expression)

Gets a Form from the given DOM Document, based on the given XPath expression.

static Form getFormById(SimpleDocument dom, String baseUrl, String formId)

Gets a Form from the given DOM Document by finding the Form in the document which has an id attribute equal to the given id parameter.

static Form getFormByIndex(SimpleDocument dom, String baseUrl, int index)

Gets a Form from the given DOM Document by finding the index'th Form in the document.

static Form getFormByName(SimpleDocument dom, String baseUrl, String name)

Gets a Form from the given DOM Document by finding the Form in the document which has a name attribute equal to the given name parameter.

static Parameter[] getParameters(Form f)

Given a Form, return the Parameters that would be used to construct an HTTP request for this form.

private static boolean isValidUrl(String url)

static Response submit(Form f, Session session)

Submits this form using the given Session.

 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Constructor Detail

Forms

private Forms()


 
Method Detail

getForm

public static Form getForm(SimpleDocument dom, String baseUrl, String expression)
Gets a Form from the given DOM Document, based on the given XPath expression.
Parameters:
dom - the DOM Document to parse the HTML Form from.
baseUrl - the baseUrl which generated this DOM document. This is required if you later want to submit the HTML Form, since url's in the Form may be relative.
expression - the XPath expression to use to find the Form tag to be parsed.


getFormById

public static Form getFormById(SimpleDocument dom, String baseUrl, String formId)
Gets a Form from the given DOM Document by finding the Form in the document which has an id attribute equal to the given id parameter.
Parameters:
dom - the DOM Document to parse the HTML Form from.
baseUrl - the baseUrl which generated this DOM document. This is required if you later want to submit the HTML Form, since url's in the Form may be relative.
id - the id of the Form element within the DOM which should be parsed


getFormByIndex

public static Form getFormByIndex(SimpleDocument dom, String baseUrl, int index)
Gets a Form from the given DOM Document by finding the index'th Form in the document.
Parameters:
dom - the DOM Document to parse the HTML Form from.
baseUrl - the baseUrl which generated this DOM document. This is required if you later want to submit the HTML Form, since url's in the Form may be relative.
index - the index of the Form to parse. For example, if there are 3 <form> tags in the document, and index is 2, then the second form will be selected. index is 1 based.


getFormByName

public static Form getFormByName(SimpleDocument dom, String baseUrl, String name)
Gets a Form from the given DOM Document by finding the Form in the document which has a name attribute equal to the given name parameter.
Parameters:
dom - the DOM Document to parse the HTML Form from.
baseUrl - the baseUrl which generated this DOM document. This is required if you later want to submit the HTML Form, since url's in the Form may be relative.
name - the name of the Form element within the DOM which should be parsed


getParameters

public static Parameter[] getParameters(Form f)
Given a Form, return the Parameters that would be used to construct an HTTP request for this form.
Parameters:
f - the Form to use. If null, an empty parameter array is returned.
Returns:
the array of Parameters needed to construct an HTTP request for this form


isValidUrl

private static boolean isValidUrl(String url)


submit

public static Response submit(Form f, Session session)
Submits this form using the given Session. This method blocks.
throws:
Exception if some client error occurs while processing the submition.
Parameters:
session - the Session to execute this form through. This must not be null.
Returns:
The Response for this form submition.


 

Groovy Documentation