|
Agent System POND 1.2 (28.2.2002) | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--FIM.Util.WWW.Form.HTMLForm
Models a HTML form. The internal support of HTMLDocument
ONLY works when using a GUI, so
we cannot use it for handling it directly. Builds up on HTMLDocument
.
Sample code for parsing a certain form and submitting it:
StringReader in=new StringReader(srcPageAsString); HTMLEditorKit editorKit=new HTMLEditorKit(); HTMLDocument doc=(HTMLDocument)editorKit.createDefaultDocument(); doc.putProperty("IgnoreCharsetDirective",new Boolean(true)); editorKit.read(in,doc,0); HTMLForm form=new HTMLForm(doc,nameOfTheFormToParse); form.setBaseURL(baseURLOfTheForm); ...... // Modify the contained elements ...... String resultPage=form.doSubmit(null);
The elements of the form are stored in a flat structure and groups (e. g. radiobuttons or checkboxes with the same name) are stored separartely.
>See the HTML 4.01 specification
Field Summary | |
protected MutableAttributeSet |
formAttributes
Attributes of the form. |
protected Vector |
formElements
The elements of the form. |
protected String |
formName
The name of the form. |
protected Hashtable |
groups
The groups of elements within the form. |
Constructor Summary | |
HTMLForm(HTMLDocument doc,
int nthForm)
Parses a certain form from a document by its position number (first form=1). |
|
HTMLForm(HTMLDocument doc,
String formName)
Creates a new HTML form by extracting the information from a document. |
Method Summary | |
String |
doSubmit(ActionElement submitter)
Submits the form. |
String |
doSubmit(ActionElement submitter,
CookieStore store,
URL referer)
Submits the form. |
URL |
getActionURL()
Retrieve the URL where the form is submitted to. |
AttributeSet |
getAttributes()
Fetches the collection of attributes this element contains. |
URL |
getBaseURL()
Retrieve the base URL of the form. |
Document |
getDocument()
Fetches the document associated with this element. |
Element |
getElement(int index)
Fetches the child element at the given index. |
int |
getElementCount()
Gets the number of child elements contained by this element. |
int |
getElementIndex(int offset)
Gets the child element index closest to the given offset. |
FormElement[] |
getElements(String name)
Fetches the child elements (=form element) with the given name. |
int |
getEndOffset()
Fetches the offset from the beginning of the document that this element ends at. |
static HTMLForm |
getForm(String formPage,
int nthForm)
Creates a new HTML form by extracting the information from a document by its position number (first form=1). |
static HTMLForm |
getForm(String formPage,
String formName)
Creates a new HTML form by extracting the information from a document. |
static HTMLForm[] |
getForms(HTMLDocument doc)
Parses all forms in the document and returns them as an array. |
static HTMLForm[] |
getForms(String formsPage)
Parses all forms in the document and returns them as an array. |
ElementGroup |
getGroup(String groupName)
Retrieve the group object for a certain name. |
String |
getMethod()
Retrieve the method for submitting the form. |
String |
getName()
Fetches the name of the form. |
Element |
getParentElement()
Fetches the parent element, which is always null , as forms have no parent. |
String |
getPostText(FormElement elem,
int length)
Retrieve the text visible immediately after an element. |
String |
getPreText(FormElement elem,
int length)
Retrieve the text visible immediately before an element (50 characters). |
int |
getStartOffset()
Fetches the offset from the beginning of the document that this form begins at. |
boolean |
isDocumentLocalSubmit()
Check whether this dorm will be submitted to the same host this document is from. |
boolean |
isLeaf()
Is this element a leaf element? |
ElementGroup |
newGroup(HTMLDocument doc,
String groupName,
boolean singleSelectionOnly)
Creates a new group element and adds it to the list of groups. |
protected void |
parseForm(HTMLDocument.Iterator iter)
Parses a single form. |
void |
resetForm()
Resets the form to its initial state. |
void |
setBaseURL(URL baseURL)
Sets the base URL of the form. |
String |
toString()
Returns a string representation of the form |
Methods inherited from class java.lang.Object |
|
Field Detail |
protected String formName
protected Vector formElements
protected MutableAttributeSet formAttributes
protected Hashtable groups
Constructor Detail |
public HTMLForm(HTMLDocument doc, String formName) throws ParseException
doc
- the document in which the form is containedformName
- the value of the "name" attribute of the desired form. If null
, the first form encountered is parsedParseException
- if an error occured during parsing (wrong element names, ...)public HTMLForm(HTMLDocument doc, int nthForm) throws ParseException
doc
- the HTML document to extract the form fromnthForm
- number of the form to return from the documentParseException
- if an error occured during parsing (wrong element names, ...)Method Detail |
protected void parseForm(HTMLDocument.Iterator iter) throws ParseException
iter
- the form to parse (in HTMLDocument
style)ParseException
- if an error occured during parsing (wrong element names, ...)public static HTMLForm getForm(String formPage, String formName) throws ParseException
formPage
- the String of the age in which the form is containedformName
- the value of the "name" attribute of the desired form. If null
, the first form encountered is parsedParseException
- if an error occured during parsing (wrong element names, ...)public static HTMLForm getForm(String formPage, int nthForm) throws ParseException
formPage
- the String of the age in which the form is containednthForm
- number of the form to return from the documentParseException
- if an error occured during parsing (wrong element names, ...)public static HTMLForm[] getForms(String formsPage) throws ParseException
formspage
- the page with the forms to parseParseException
- if an error occured during parsing (wrong element names, ...)public static HTMLForm[] getForms(HTMLDocument doc) throws ParseException
doc
- the document to parseParseException
- if an error occured during parsing (wrong element names, ...)public String getMethod()
public void setBaseURL(URL baseURL)
URL
of the form.baseURL
- the new base URL
for the formpublic URL getBaseURL()
URL
of the form. Returns null
if none specified in the document or explicitely set.URL
of the form or null
public boolean isDocumentLocalSubmit()
true
if the form is sent to the same host it is frompublic URL getActionURL()
URL
where the form is submitted to. Does NOT include the parameters
if the method for submitting is GET.URl
for sending the form topublic void resetForm()
public String doSubmit(ActionElement submitter) throws IOException
CookieStore
and no referer.submitter
- the element causing the form to submit or null
IOException
- if an error occured during submitting the form or receiving the responsepublic String doSubmit(ActionElement submitter, CookieStore store, URL referer) throws IOException
submitter
- the element causing the form to submit or null
store
- the cookies to send/receivereferer
- the referer for this formIOException
- if an error occured during submitting the form or receiving the responsepublic String getPreText(FormElement elem, int length)
elem
- the element to get the surrounding text forlength
- the length of the text to getpublic String getPostText(FormElement elem, int length)
elem
- the element to get the surrounding text forlength
- the length of the text to getpublic Document getDocument()
getDocument
in interface Element
public Element getParentElement()
null
, as forms have no parent.getParentElement
in interface Element
null
public String getName()
getName
in interface Element
public AttributeSet getAttributes()
getAttributes
in interface Element
public int getStartOffset()
getStartOffset
in interface Element
public int getEndOffset()
getEndOffset
in interface Element
public int getElementIndex(int offset)
getElementIndex
in interface Element
offset
- the specified offset >= 0public int getElementCount()
getElementCount
in interface Element
public Element getElement(int index)
getElement
in interface Element
index
- the specified index >= 0public FormElement[] getElements(String name)
name
- the specified name (if null
all elements are returned)public boolean isLeaf()
isLeaf
in interface Element
true
if a leaf element (no elements in the form) else false
public ElementGroup getGroup(String groupName)
groupName
- the name of the grouppublic ElementGroup newGroup(HTMLDocument doc, String groupName, boolean singleSelectionOnly)
SelectableElement
doc
- the document this group belongs togroupName
- the name of the groupsingleSelectionOnly
- if true
, only one element of the group may be selected at any time.SelectableElement
public String toString()
toString
in class Object
|
Agent System POND 1.2 (28.2.2002) | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |