Package org.xmpp.forms
Class DataForm
java.lang.Object
org.xmpp.packet.PacketExtension
org.xmpp.forms.DataForm
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumType-safe enumeration to represent the type of the Data forms. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringElement name of the packet extension.static final StringNamespace of the packet extension.Fields inherited from class org.xmpp.packet.PacketExtension
docFactory, element, registeredExtensions -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddField()Adds a new field as part of the form.addField(String variable, String label, FormField.Type type) Adds a new field as part of the form.voidaddInstruction(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.voidaddItemFields(Map<String, Object> fields) Adds a new row of items of reported data.voidaddReportedField(String variable, String label, FormField.Type type) Adds a field to the list of fields that will be returned from a search.voidClears all the stored instructions in this packet extension.Creates a deep copy of this packet extension.Returns the field whose variable matches the specified variable.Returns the fields that are part of the form.Returns an unmodifiable list of instructions that explain how to fill out the form and what the form is about.getTitle()Returns the description of the data form.getType()Returns the type of this data form.static booleanparseBoolean(String booleanString) static DateReturns the Date obtained by parsing the specified date representation.booleanremoveField(String variable) Removes the field whose variable matches the specified variable.voidSets the description of the data.Methods inherited from class org.xmpp.packet.PacketExtension
getElement, getExtensionClass
-
Field Details
-
ELEMENT_NAME
Element name of the packet extension.- See Also:
-
NAMESPACE
Namespace of the packet extension.- See Also:
-
-
Constructor Details
-
DataForm
-
DataForm
public DataForm(org.dom4j.Element element)
-
-
Method Details
-
parseDate
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
- Throws:
ParseException
-
getType
Returns the type of this data form.- Returns:
- the data form type.
- See Also:
-
setTitle
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
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
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
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
nullor 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
Adds a new field as part of the form.- Returns:
- the newly created field.
-
addField
Adds a new field as part of the form. The provided arguments are optional (they are allowed to benull).- 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
Returns the fields that are part of the form.- Returns:
- fields that are part of the form.
-
getField
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
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
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 inaddItemFields(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
Adds a new row of items of reported data. For each entry in thefieldsparameter afieldelement will be added to the <item> element. The variable of the newfieldwill be the key of the entry. The newfieldwill have several values if the entry's value is aCollection. Since the value is of typeObjectit is possible to include any type of object as a value. The actual value to include in the data form is the result of theencode(Object)method.- Parameters:
fields- list of <variable,value> to be added as a new item.
-
createCopy
Description copied from class:PacketExtensionCreates a deep copy of this packet extension.- Overrides:
createCopyin classPacketExtension- Returns:
- a deep copy of this packet extension.
-