doc.api.au.id.jericho.lib.html.FormFields.html Maven / Gradle / Ivy
FormFields (Jericho HTML Parser 1.5-dev1)
Package
Class
Tree
Deprecated
Index
Help
PREV CLASS
NEXT CLASS
FRAMES
NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
au.id.jericho.lib.html
Class FormFields
java.lang.Object
java.util.AbstractCollection
au.id.jericho.lib.html.FormFields
- All Implemented Interfaces:
- java.util.Collection
- public final class FormFields
- extends java.util.AbstractCollection
Represents a collection of FormField
objects.
FormFields
objects are created using the FormFields(Collection formControls)
constructor
or by calling the Segment.findFormFields()
method.
See the documentation of the FormField
class for a description of the relationship between
fields and controls.
The case sensitivity of form field names is determined by the static FieldNameCaseSensitive
property.
Examples:
-
Output the data received from in the current
ServletRequest
(submitted from the form in the source document) to a .CSV
file:
(See also the sample program FormFieldCSVOutput)
Source source=new Source(htmlText);
FormFields formFields=source.findFormFields();
Writer writer=new FileWriter("FormData.csv");
Util.outputCSVLine(writer,formFields.getColumnHeadings());
Util.outputCSVLine(writer,formFields.getColumnValues(servletRequest.getParameterMap()));
writer.close();
- Output the form in the source document populated with the values received in the current
ServletRequest
:
Source source=new Source(htmlText);
FormFields formFields=source.findFormFields();
formFields.setValuesMap(servletRequest.getParameterMap());
OutputDocument outputDocument=new OutputDocument(source);
outputDocument.add(formFields);
outputDocument.output(servletResponse.getWriter());
- Create a new document and set the values in the form named "MyForm" to new values:
(See also the sample program FormFieldSetValues)
Source source=new Source(htmlText);
Element myForm=null;
List formElements=source.findAllElements(Tag.FORM);
for (Iterator i=formElements.iterator(); i.hasNext();) {
Element formElement=(Element)i.next();
String formName=formElement.getAttributes().getValue("name");
if ("MyForm".equals(formName)) {
myForm=form;
break;
}
}
FormFields formFields=myForm.findFormFields();
formFields.clearValues(); // clear any values that might be set in the source document
formFields.addValue("Name","Humphrey Bear");
formFields.addValue("MailingList","A");
formFields.addValue("MailingList","B");
formFields.addValue("FavouriteFair","honey");
OutputDocument outputDocument=new OutputDocument(source);
outputDocument.add(formFields);
String newHtmlText=outputDocument.toString();
- See Also:
FormField
Field Summary
static java.lang.String
ColumnFalse
static java.lang.String
ColumnMultipleValueSeparator
static java.lang.String
ColumnTrue
static boolean
FieldNameCaseSensitive
Determines whether field names are treated as case sensitive.
Constructor Summary
FormFields(java.util.Collection formControls)
Constructs a new FormFields
object based on the specified form controls.
Method Summary
boolean
addValue(java.lang.String name,
java.lang.CharSequence value)
****
void
clearValues()
****
FormField
get(java.lang.String name)
Returns the FormField with the specified name.
java.lang.String[]
getColumnHeadings()
****
java.lang.String[]
getColumnValues()
****
java.lang.String[]
getColumnValues(java.util.Map valuesMap)
****
int
getCount()
Returns the number of FormField
objects.
java.lang.String
getDebugInfo()
Returns a string representation of this object useful for debugging purposes.
java.util.List
getFormControls()
****
java.util.Map
getValuesMap()
**** Returns a map of name to String[], similar to
javax.servlet.ServletRequest.getParameterMap()
java.util.Iterator
iterator()
Returns an iterator over the FormField
objects in the collection.
void
merge(FormFields formFields)
Merges the specified FormFields
into this FormFields
collection.
boolean
setValue(java.lang.String name,
java.lang.CharSequence value)
****
void
setValuesMap(java.util.Map valuesMap)
**** Sets the values using a map of name to string[], compatible with result from
javax.servlet.ServletRequest.getParameterMap()
int
size()
Returns the number of FormField
objects.
java.lang.String
toString()
Returns a string representation of this object useful for debugging purposes.
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
equals, hashCode
Field Detail
ColumnMultipleValueSeparator
public static java.lang.String ColumnMultipleValueSeparator
ColumnTrue
public static java.lang.String ColumnTrue
ColumnFalse
public static java.lang.String ColumnFalse
FieldNameCaseSensitive
public static boolean FieldNameCaseSensitive
- Determines whether field names are treated as case sensitive.
Microsoft Internet Explorer treats field names as case insensitive,
while Mozilla treats them as case sensitive.
The default value is false
, consistent with the interpretation of IE.
This is a global setting which affects all instances of the FormFields class.
It should be set to the desired configuration before any instances are created.
Constructor Detail
FormFields
public FormFields(java.util.Collection formControls)
- Constructs a new
FormFields
object based on the specified form controls.
- Parameters:
formControls
- a collection of FormControl
objects.- See Also:
Segment.findFormFields()
Method Detail
getCount
public int getCount()
- Returns the number of
FormField
objects.
- Returns:
- the number of
FormField
objects.
size
public int size()
- Returns the number of
FormField
objects.
This is equivalent to getCount()
,
and is necessary to for the implementation of the java.util.Collection
interface.
- Returns:
- the number of
FormField
objects.
get
public FormField get(java.lang.String name)
- Returns the FormField with the specified name.
The case sensitivity of the name argument is determined by the static FieldNameCaseSensitive
property.
- Parameters:
name
- the name of the FormField to get.
- Returns:
- the FormField with the specified name, or
null
if no FormField with the specified name exists.
iterator
public java.util.Iterator iterator()
- Returns an iterator over the
FormField
objects in the collection.
The order in which the form fields are iterated corresponds to the order of appearance
of each form field's first FormControl
in the source document.
If this FormFields
object has been merged with another,
the ordering is no longer guaranteed.
- Returns:
- an iterator over the
FormField
objects in the collection.
clearValues
public void clearValues()
- ****
getValuesMap
public java.util.Map getValuesMap()
- **** Returns a map of name to String[], similar to
javax.servlet.ServletRequest.getParameterMap()
setValuesMap
public void setValuesMap(java.util.Map valuesMap)
- **** Sets the values using a map of name to string[], compatible with result from
javax.servlet.ServletRequest.getParameterMap()
setValue
public boolean setValue(java.lang.String name,
java.lang.CharSequence value)
- ****
addValue
public boolean addValue(java.lang.String name,
java.lang.CharSequence value)
- ****
getColumnHeadings
public java.lang.String[] getColumnHeadings()
- ****
getColumnValues
public java.lang.String[] getColumnValues(java.util.Map valuesMap)
- ****
getColumnValues
public java.lang.String[] getColumnValues()
- ****
getFormControls
public java.util.List getFormControls()
- ****
merge
public void merge(FormFields formFields)
- Merges the specified
FormFields
into this FormFields
collection.
This is useful if a full collection of possible form fields is required from multiple Source
documents.
If both collections contain a FormField
with the same name,
the resulting FormField
will have the following properties:
getUserValueCount()
: the maximum user value count from both form fields
allowsMultipleValues()
: true
if either form field allows multiple values
getPredefinedValues()
: the union of predefined values in both form fields
getFormControls()
: the union of form controls from both form fields
NOTE: Some underlying data structures may end up being shared between the two merged FormFields
collections.
getDebugInfo
public java.lang.String getDebugInfo()
- Returns a string representation of this object useful for debugging purposes.
- Returns:
- a string representation of this object useful for debugging purposes.
toString
public java.lang.String toString()
- Returns a string representation of this object useful for debugging purposes.
This is equivalent to getDebugInfo()
.
- Returns:
- a string representation of this object useful for debugging purposes.
Package
Class
Tree
Deprecated
Index
Help
PREV CLASS
NEXT CLASS
FRAMES
NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD