Class DataForm


@NotThreadSafe public class DataForm extends PacketExtension
Represents a form that could be use for gathering data as well as for reporting data returned from a search.

The form could be of the following types:

  • form -> Indicates a form to fill out.
  • submit -> The form is filled out, and this is the data that is being returned from the form.
  • cancel -> The form was cancelled. Tell the asker that piece of information.
  • result -> Data results being returned from a search, or some other query.

In case the form represents a search, the report will be structured in columns and rows. Use addReportedField(String, String, FormField.Type) to set the columns of the report whilst the report's rows can be configured using addItemFields(Map).

Author:
Gaston Dombiak
  • Field Details

  • Constructor Details

    • DataForm

      public DataForm(DataForm.Type type)
    • DataForm

      public DataForm(org.dom4j.Element element)
  • Method Details

    • parseDate

      public static Date parseDate(String date) throws ParseException
      Returns the Date obtained by parsing the specified date representation. The date representation is expected to be in the UTC GMT+0 format.
      Parameters:
      date - date representation in the UTC GMT+0 format.
      Returns:
      the Date obtained by parsing the specified date representation.
      Throws:
      ParseException - if an error occurs while parsing the date representation.
    • parseBoolean

      public static boolean parseBoolean(String booleanString) throws ParseException
      Throws:
      ParseException
    • getType

      public DataForm.Type getType()
      Returns the type of this data form.
      Returns:
      the data form type.
      See Also:
    • setTitle

      public void setTitle(String title)
      Sets the description of the data. It is similar to the title on a web page or an X window. You can put a <title/> on either a form to fill out, or a set of data results.
      Parameters:
      title - description of the data.
    • getTitle

      public String getTitle()
      Returns the description of the data form. It is similar to the title on a web page or an X window. You can put a <title/> on either a form to fill out, or a set of data results.
      Returns:
      description of the data.
    • getInstructions

      public List<String> getInstructions()
      Returns an unmodifiable list of instructions that explain how to fill out the form and what the form is about. The dataform could include multiple instructions since each instruction could not contain newlines characters.
      Returns:
      an unmodifiable list of instructions that explain how to fill out the form.
    • addInstruction

      public void addInstruction(String instruction)
      Adds a new instruction to the list of instructions that explain how to fill out the form and what the form is about. The dataform could include multiple instructions since each instruction could not contain newlines characters.

      Nothing will be set, if the provided argument is null or an empty String.

      Parameters:
      instruction - the new instruction that explain how to fill out the form.
    • clearInstructions

      public void clearInstructions()
      Clears all the stored instructions in this packet extension.
    • addField

      public FormField addField()
      Adds a new field as part of the form.
      Returns:
      the newly created field.
    • addField

      public FormField addField(String variable, String label, FormField.Type type)
      Adds a new field as part of the form. The provided arguments are optional (they are allowed to be null).
      Parameters:
      variable - the unique identifier of the field in the context of the form. Optional parameter.
      type - an indicative of the format for the data. Optional parameter.
      label - the label of the question. Optional parameter.
      Returns:
      the newly created field.
    • getFields

      public List<FormField> getFields()
      Returns the fields that are part of the form.
      Returns:
      fields that are part of the form.
    • getField

      public FormField getField(String variable)
      Returns the field whose variable matches the specified variable.
      Parameters:
      variable - the variable name of the field to search.
      Returns:
      the field whose variable matches the specified variable
    • removeField

      public boolean removeField(String variable)
      Removes the field whose variable matches the specified variable.
      Parameters:
      variable - the variable name of the field to remove.
      Returns:
      true if the field was removed.
    • addReportedField

      public void addReportedField(String variable, String label, FormField.Type type)
      Adds a field to the list of fields that will be returned from a search. Each field represents a column in the report. The order of the columns in the report will honor the sequence in which they were added.
      Parameters:
      variable - variable name of the new column. This value will be used in addItemFields(java.util.Map<java.lang.String, java.lang.Object>) when adding reported items.
      label - label that corresponds to the new column. Optional parameter.
      type - indicates the type of field of the new column. Optional parameter.
    • addItemFields

      public void addItemFields(Map<String,Object> fields)
      Adds a new row of items of reported data. For each entry in the fields parameter a field element will be added to the <item> element. The variable of the new field will be the key of the entry. The new field will have several values if the entry's value is a Collection. Since the value is of type Object it is possible to include any type of object as a value. The actual value to include in the data form is the result of the encode(Object) method.
      Parameters:
      fields - list of <variable,value> to be added as a new item.
    • createCopy

      public DataForm createCopy()
      Description copied from class: PacketExtension
      Creates a deep copy of this packet extension.
      Overrides:
      createCopy in class PacketExtension
      Returns:
      a deep copy of this packet extension.