|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractCollection
au.id.jericho.lib.html.FormFields
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:
ServletRequest
(submitted from the form in the source document) to a .CSV
file:
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();
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());
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();
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 |
public static java.lang.String ColumnMultipleValueSeparator
public static java.lang.String ColumnTrue
public static java.lang.String ColumnFalse
public static boolean FieldNameCaseSensitive
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 |
public FormFields(java.util.Collection formControls)
FormFields
object based on the specified form controls.
formControls
- a collection of FormControl
objects.Segment.findFormFields()
Method Detail |
public int getCount()
FormField
objects.
FormField
objects.public int size()
FormField
objects.
This is equivalent to getCount()
,
and is necessary to for the implementation of the java.util.Collection
interface.
FormField
objects.public FormField get(java.lang.String name)
The case sensitivity of the name argument is determined by the static FieldNameCaseSensitive
property.
name
- the name of the FormField to get.
null
if no FormField with the specified name exists.public java.util.Iterator iterator()
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.
FormField
objects in the collection.public void clearValues()
public java.util.Map getValuesMap()
javax.servlet.ServletRequest.getParameterMap()
public void setValuesMap(java.util.Map valuesMap)
javax.servlet.ServletRequest.getParameterMap()
public boolean setValue(java.lang.String name, java.lang.CharSequence value)
public boolean addValue(java.lang.String name, java.lang.CharSequence value)
public java.lang.String[] getColumnHeadings()
public java.lang.String[] getColumnValues(java.util.Map valuesMap)
public java.lang.String[] getColumnValues()
public java.util.List getFormControls()
public void merge(FormFields formFields)
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 fieldsallowsMultipleValues()
: true
if either form field allows multiple valuesgetPredefinedValues()
: the union of predefined values in both form fieldsgetFormControls()
: 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.
public java.lang.String getDebugInfo()
public java.lang.String toString()
This is equivalent to getDebugInfo()
.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |