Java Doc for FormFields.java in  » HTML-Parser » jericho-html » au » id » jericho » lib » html » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » HTML Parser » jericho html » au.id.jericho.lib.html 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   java.util.AbstractCollection
      au.id.jericho.lib.html.FormFields

FormFields
final public class FormFields extends AbstractCollection (Code)
Represents a collection of FormField objects.

This class provides the main interface for the analysis and manipulation of . A FormFields object is a collection of FormField objects, with each form field consisting of a group of having the same .

The functionality provided by this class can be used to accomplish two main tasks:

  1. Modify the submission values of the constituent form controls for subsequent output in an OutputDocument .

    The methods available for this purpose are:
    FormFields.getValues(String) Collection getValues(String fieldName)
    FormFields.getDataSet() Map getDataSet()
    FormFields.clearValues() void clearValues()
    FormFields.setDataSet(Map) void setDataSet(Map)
    FormFields.setValue(String,CharSequence) boolean setValue(String fieldName, CharSequence value)
    FormFields.addValue(String,CharSequence) boolean addValue(String fieldName, CharSequence value)

    Although the FormField and FormControl classes provide methods for directly modifying the submission values of individual form fields and controls, it is generally recommended to use the interface provided by this (the FormFields) class unless there is a specific requirement for the lower level functionality.

    The display characteristics of individual controls, such as whether the control is , replaced with a simple , or altogether, can only be set on the individual FormControl objects. See below for information about retrieving a specific FormControl object from the FormFields object.

  2. Convert data from a form data set (represented as a field data set) into a simple array format, suitable for storage in a tabular format such as a database table or .CSV file.

    The methods available for this purpose are:
    FormFields.getColumnLabels() String[] getColumnLabels()
    FormFields.getColumnValues(Map) String[] getColumnValues(Map)
    FormFields.getColumnValues() String[] getColumnValues()

    The Util class contains a method called Util.outputCSVLine(WriterString[]) outputCSVLine(Writer,String[]) which writes the String[] output of these methods to the specified Writer in .CSV format.

    The implementation of these methods makes use of certain properties in the FormField class that describe the structure of the data in each field. These properties can be utilised directly in the event that a form data set is to be converted from its normal format into some other type of data structure.

To access a specific FormControl from a FormFields object, use:

The term field data set is used in this library to refer to a data structure consisting of a set of names (in lower case), each mapped to one or more values. Generally, this is represented by a java.util.Map with the keys (names) being of type String and the values represented by either an array or collection containing one or more items of type CharSequence. A field data set can be used to represent the data in an HTML form data set.

FormFields instances are obtained using the FormFields.FormFields(Collection formControls) constructor or by calling the Segment.findFormFields method.

The case sensitivity of form field names is determined by the Config.CurrentCompatibilityMode . Config.CompatibilityMode.isFormFieldNameCaseInsensitive FormFieldNameCaseInsensitive property.

Examples:

  1. Write the data received from in the current ServletRequest to a .CSV file, and then display the form populated with this data:

     Source source=new Source(htmlTextOfOriginatingForm);
     FormFields formFields=source.findFormFields();
     File csvOutputFile=new File("FormData.csv");
     boolean outputHeadings=!csvOutputFile.exists();
     Writer writer=new FileWriter(csvOutputFile,true);
     if (outputHeadings) Util.outputCSVLine(writer,formFields.getColumnLabels());
     Util.outputCSVLine(writer,formFields.getColumnValues(servletRequest.getParameterMap()));
     writer.close();
     formFields.setDataSet(servletRequest.getParameterMap());
     OutputDocument outputDocument=new OutputDocument(source);
     outputDocument.replace(formFields);
     outputDocument.writeTo(servletResponse.getWriter());

    See also the sample program FormFieldCSVOutput.

  2. Replace the initial values of controls in the form named "MyForm" with new values:

     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("FavouriteFare","honey");
     OutputDocument outputDocument=new OutputDocument(source);
     outputDocument.replace(formFields);
     String newHtmlText=outputDocument.toString();

    See also the sample program FormFieldSetValues.

  3. Change the display characteristics of individual controls:

     Source source=new Source(htmlText);
     FormFields formFields=source.findFormFields();
     // disable some controls:
     formFields.get("Password").getFormControl().setDisabled(true);
     FormField mailingListFormField=formFields.get("MailingList");
     mailingListFormField.setValue("C");
     mailingListFormField.getFormControl("C").setDisabled(true);
     mailingListFormField.getFormControl("D").setDisabled(true);
     // remove some controls:
     formFields.get("button1").getFormControl().setOutputStyle(FormControlOutputStyle.REMOVE);
     FormControl rhubarbFormControl=formFields.get("FavouriteFare").getFormControl("rhubarb");
     rhubarbFormControl.setOutputStyle(FormControlOutputStyle.REMOVE);
     // set some controls to display value:
     formFields.setValue("Address","The Lodge\nDeakin  ACT  2600\nAustralia");
     formFields.get("Address").getFormControl().setOutputStyle(FormControlOutputStyle.DISPLAY_VALUE);
     FormField favouriteSportsFormField=formFields.get("FavouriteSports");
     favouriteSportsFormField.setValue("BB");
     favouriteSportsFormField.addValue("AFL");
     favouriteSportsFormField.getFormControl().setOutputStyle(FormControlOutputStyle.DISPLAY_VALUE);
     OutputDocument outputDocument=new OutputDocument(source);
     outputDocument.replace(formFields); // adds all segments necessary to effect changes
     String newHtmlText=outputDocument.toString();

    See also the sample program FormControlDisplayCharacteristics.


See Also:   FormField
See Also:   FormControl



Constructor Summary
public  FormFields(Collection formControls)
     Constructs a new FormFields object consisting of the specified .

Method Summary
 voidadd(FormControl formControl)
    
 voidadd(FormControl formControl, String predefinedValue)
    
 voidadd(FormControl formControl, String predefinedValue, String fieldName)
    
 voidaddName(FormControl formControl, String fieldName)
    
public  booleanaddValue(String fieldName, CharSequence value)
     Adds the specified value to the field submission values of the constituent with the specified .

This is equivalent to FormFields.get(String) get(fieldName) . FormField.addValue(CharSequence) addValue(value) , assuming that a field with the specified name exists in this collection.

The return value indicates whether the specified form field "accepted" the value. A return value of false implies an error condition as either no field with the specified name exists, or the specified value is not compatible with the specified field.
Parameters:
  fieldName - the of the form field.
Parameters:
  value - the new field submission value to add to the specified field, must not be null.

public  voidclearValues()
     Clears the submission values of all the constituent .
public  FormFieldget(String fieldName)
     Returns the FormField with the specified .

The case sensitivity of the fieldName argument is determined by the Config.CurrentCompatibilityMode . Config.CompatibilityMode.isFormFieldNameCaseInsensitive FormFieldNameCaseInsensitive property.
Parameters:
  fieldName - the name of the FormField to get.

public  String[]getColumnLabels()
     Returns a string array containing the column labels corresponding to the values from the FormFields.getColumnValues(Map) method.
public  String[]getColumnValues(Map dataSet)
     Converts the data values in the specified field data set into a simple string array, suitable for storage in a tabular format such as a database table or .CSV file.

The conversion is performed in a way that allows the multiple values of certain fields to be stored in separate columns, by analysing the possible form data sets that can be generated from the constituent .

The column labels and values are determined as follows:

  • For each in this collection (taken in order):
    • If the form field has no , such as a single , then:
      • Add a single column:
        :the of the form field in original case
        Value:the single value mapped to this field in the specified field data set.
        In the unlikely event that this field contains more than one value, all values are included in this one column and separated by the text defined in the Config.ColumnMultipleValueSeparator property.
    • Otherwise, if the form field does have , but does not , then:
      • If the form field has only one , such as a single , then:
        • Add a single boolean column:
          :the of the form field in original case
          Value:the currently configured string representation for if a value mapped to this field in the specified field data set matches the , otherwise
      • Otherwise, if the form field has more than one , such as a set of , then:
        • Add a single column:
          :the of the form field in original case
          Value:the single value mapped to this field in the specified field data set, which in the case of a set of radio buttons should be the of the radio button.
    • Otherwise, if the form field has and , such as a set of , then:
      • For each in the form field:
        • Add a boolean column:
          :"FieldName.PredefinedValue", where FieldName is the of the form field in original case, and PredefinedValue is the .
          Value:the currently configured string representation for if a value mapped to this field in the specified field data set matches the , otherwise
      • In addition, if the form field can also contain user values ( FormField.getUserValueCount >0), then:
        • Add another column:
          :the of the form field in original case
          Value:all values mapped to this field in the specified field data set that do not match any of the , separated by the text defined in the Config.ColumnMultipleValueSeparator property.

The sample program FormFieldCSVOutput demonstrates the use of this method and its output.
Parameters:
  dataSet - a field data set containing the data to convert.

public  String[]getColumnValues()
     Converts all the of the constituent form fields into a simple string array, suitable for storage in a tabular format such as a database table or .CSV file.
public  intgetCount()
     Returns the number of FormField objects.
public  MapgetDataSet()
     Returns the entire field data set represented by the of the constituent form fields.
public  StringgetDebugInfo()
     Returns a string representation of this object useful for debugging purposes.
public  ListgetFormControls()
     Returns a list of all the from all the in this collection.
public  CollectiongetValues(String fieldName)
     Returns a collection of the field submission values of all the specified constituent with the specified .

All objects in the returned collection are of type CharSequence, with no null entries.

This is equivalent to FormFields.get(String) get(fieldName) . FormField.getValues getValues() , assuming that a field with the specified name exists in this collection.
Parameters:
  fieldName - the of the form field.

public  Iteratoriterator()
     Returns an iterator over the FormField objects in the collection.
public  voidmerge(FormFields formFields)
     Merges the specified FormFields into this FormFields collection.
 voidreplaceInOutputDocument(OutputDocument outputDocument)
    
public  voidsetDataSet(Map dataSet)
     Sets the submission values of all the constituent to match the data in the specified field data set.
public  booleansetValue(String fieldName, CharSequence value)
     Sets the field submission values of the constituent with the specified to the single specified value.

This is equivalent to FormFields.get(String) get(fieldName) . FormField.setValue(CharSequence) setValue(value) , assuming that a field with the specified name exists in this collection.

The return value indicates whether the specified form field "accepted" the value. A return value of false implies an error condition as either no field with the specified name exists, or the specified value is not compatible with the specified field.
Parameters:
  fieldName - the of the form field.
Parameters:
  value - the new field submission value of the specified field, or null to the field of all submission values.

public  intsize()
     Returns the number of FormField objects.
public  StringtoString()
     Returns a string representation of this object useful for debugging purposes.


Constructor Detail
FormFields
public FormFields(Collection formControls)(Code)
Constructs a new FormFields object consisting of the specified .
Parameters:
  formControls - a collection of FormControl objects.
See Also:   Segment.findFormFields




Method Detail
add
void add(FormControl formControl)(Code)



add
void add(FormControl formControl, String predefinedValue)(Code)



add
void add(FormControl formControl, String predefinedValue, String fieldName)(Code)



addName
void addName(FormControl formControl, String fieldName)(Code)



addValue
public boolean addValue(String fieldName, CharSequence value)(Code)
Adds the specified value to the field submission values of the constituent with the specified .

This is equivalent to FormFields.get(String) get(fieldName) . FormField.addValue(CharSequence) addValue(value) , assuming that a field with the specified name exists in this collection.

The return value indicates whether the specified form field "accepted" the value. A return value of false implies an error condition as either no field with the specified name exists, or the specified value is not compatible with the specified field.
Parameters:
  fieldName - the of the form field.
Parameters:
  value - the new field submission value to add to the specified field, must not be null. true if a field of the specified name exists in this collection and it accepts the specified value, otherwise false.




clearValues
public void clearValues()(Code)
Clears the submission values of all the constituent .
See Also:   FormControl.clearValues



get
public FormField get(String fieldName)(Code)
Returns the FormField with the specified .

The case sensitivity of the fieldName argument is determined by the Config.CurrentCompatibilityMode . Config.CompatibilityMode.isFormFieldNameCaseInsensitive FormFieldNameCaseInsensitive property.
Parameters:
  fieldName - the name of the FormField to get. the FormField with the specified , or null if no FormField with the specified name exists.




getColumnLabels
public String[] getColumnLabels()(Code)
Returns a string array containing the column labels corresponding to the values from the FormFields.getColumnValues(Map) method.

Instead of using the of each constituent form field to construct the labels, the of the first from each form field is used. This allows the labels to be constructed using the names with the original case from the source document rather than unsing the all lower case names of the form fields.

See the documentation of the FormFields.getColumnValues(Map) method for more details. a string array containing the column labels corresponding to the values from the FormFields.getColumnValues(Map) method.
See Also:   Util.outputCSVLine(WriterString[])




getColumnValues
public String[] getColumnValues(Map dataSet)(Code)
Converts the data values in the specified field data set into a simple string array, suitable for storage in a tabular format such as a database table or .CSV file.

The conversion is performed in a way that allows the multiple values of certain fields to be stored in separate columns, by analysing the possible form data sets that can be generated from the constituent .

The column labels and values are determined as follows:

  • For each in this collection (taken in order):
    • If the form field has no , such as a single , then:
      • Add a single column:
        :the of the form field in original case
        Value:the single value mapped to this field in the specified field data set.
        In the unlikely event that this field contains more than one value, all values are included in this one column and separated by the text defined in the Config.ColumnMultipleValueSeparator property.
    • Otherwise, if the form field does have , but does not , then:
      • If the form field has only one , such as a single , then:
        • Add a single boolean column:
          :the of the form field in original case
          Value:the currently configured string representation for if a value mapped to this field in the specified field data set matches the , otherwise
      • Otherwise, if the form field has more than one , such as a set of , then:
        • Add a single column:
          :the of the form field in original case
          Value:the single value mapped to this field in the specified field data set, which in the case of a set of radio buttons should be the of the radio button.
    • Otherwise, if the form field has and , such as a set of , then:
      • For each in the form field:
        • Add a boolean column:
          :"FieldName.PredefinedValue", where FieldName is the of the form field in original case, and PredefinedValue is the .
          Value:the currently configured string representation for if a value mapped to this field in the specified field data set matches the , otherwise
      • In addition, if the form field can also contain user values ( FormField.getUserValueCount >0), then:
        • Add another column:
          :the of the form field in original case
          Value:all values mapped to this field in the specified field data set that do not match any of the , separated by the text defined in the Config.ColumnMultipleValueSeparator property.

The sample program FormFieldCSVOutput demonstrates the use of this method and its output.
Parameters:
  dataSet - a field data set containing the data to convert. the data values in the specified field data set in the form of a simple string array.
See Also:   Util.outputCSVLine(WriterString[])
See Also:   FormFields.getColumnLabels()
See Also:   FormFields.getColumnValues()




getColumnValues
public String[] getColumnValues()(Code)
Converts all the of the constituent form fields into a simple string array, suitable for storage in a tabular format such as a database table or .CSV file.

This is equivalent to FormFields.getColumnValues(Map) getColumnValues ( FormFields.getDataSet() ). all the of the constituent form fields in the form of a simple string array.




getCount
public int getCount()(Code)
Returns the number of FormField objects. the number of FormField objects.



getDataSet
public Map getDataSet()(Code)
Returns the entire field data set represented by the of the constituent form fields.

The values in the map returned by this method are represented as a string array, giving the map a format consistent with the javax.servlet.ServletRequest.getParameterMap() method.

Only the of form fields with at least one are included in the map, meaning every String[] is guaranteed to have at least one entry. the entire field data set represented by the of the constituent form fields.
See Also:   FormFields.setDataSet(Map)




getDebugInfo
public String getDebugInfo()(Code)
Returns a string representation of this object useful for debugging purposes. a string representation of this object useful for debugging purposes.



getFormControls
public List getFormControls()(Code)
Returns a list of all the from all the in this collection. a list of all the from all the in this collection.



getValues
public Collection getValues(String fieldName)(Code)
Returns a collection of the field submission values of all the specified constituent with the specified .

All objects in the returned collection are of type CharSequence, with no null entries.

This is equivalent to FormFields.get(String) get(fieldName) . FormField.getValues getValues() , assuming that a field with the specified name exists in this collection.
Parameters:
  fieldName - the of the form field. a collection of the field submission values of all the specified constituent with the specified , or null if no form field with this name exists.
See Also:   FormField.getValues




iterator
public Iterator iterator()(Code)
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 with another, the ordering is no longer defined. an iterator over the FormField objects in the collection.




merge
public void merge(FormFields formFields)(Code)
Merges the specified FormFields into this FormFields collection. This is useful if a full collection of possible form fields is required from multiple documents.

If both collections contain a FormField with the same , the resulting FormField has the following properties:

NOTE: Some underlying data structures may end up being shared between the two merged FormFields collections.




replaceInOutputDocument
void replaceInOutputDocument(OutputDocument outputDocument)(Code)



setDataSet
public void setDataSet(Map dataSet)(Code)
Sets the submission values of all the constituent to match the data in the specified field data set.

The map keys must be String , with each map value either an array or Collection of CharSequence objects containing the field's new .

The map returned by the javax.servlet.ServletRequest.getParameterMap() method has a suitable format for use with this method.

All existing values are before the values from the field data set are added.

Any map entries with a null value are ignored.
Parameters:
  dataSet - the field data set containing the new of the constituent form fields.
See Also:   FormFields.getDataSet()




setValue
public boolean setValue(String fieldName, CharSequence value)(Code)
Sets the field submission values of the constituent with the specified to the single specified value.

This is equivalent to FormFields.get(String) get(fieldName) . FormField.setValue(CharSequence) setValue(value) , assuming that a field with the specified name exists in this collection.

The return value indicates whether the specified form field "accepted" the value. A return value of false implies an error condition as either no field with the specified name exists, or the specified value is not compatible with the specified field.
Parameters:
  fieldName - the of the form field.
Parameters:
  value - the new field submission value of the specified field, or null to the field of all submission values. true if a field of the specified name exists in this collection and it accepts the specified value, otherwise false.




size
public int size()(Code)
Returns the number of FormField objects.

This is equivalent to FormFields.getCount() , and is necessary to for the implementation of the java.util.Collection interface. the number of FormField objects.




toString
public String toString()(Code)
Returns a string representation of this object useful for debugging purposes.

This is equivalent to FormFields.getDebugInfo() . a string representation of this object useful for debugging purposes.




Methods inherited from java.util.AbstractCollection
public boolean add(E e)(Code)(Java Doc)
public boolean addAll(Collection<? extends E> c)(Code)(Java Doc)
public void clear()(Code)(Java Doc)
public boolean contains(Object o)(Code)(Java Doc)
public boolean containsAll(Collection c)(Code)(Java Doc)
public boolean isEmpty()(Code)(Java Doc)
abstract public Iterator<E> iterator()(Code)(Java Doc)
public boolean remove(Object o)(Code)(Java Doc)
public boolean removeAll(Collection c)(Code)(Java Doc)
public boolean retainAll(Collection c)(Code)(Java Doc)
abstract public int size()(Code)(Java Doc)
public Object[] toArray()(Code)(Java Doc)
public T[] toArray(T[] a)(Code)(Java Doc)
public String toString()(Code)(Java Doc)

Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.