Package org.xmpp.forms
Class DataForm
- java.lang.Object
-
- org.xmpp.packet.PacketExtension
-
- org.xmpp.forms.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 usingaddItemFields(Map).- Author:
- Gaston Dombiak
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDataForm.TypeType-safe enumeration to represent the type of the Data forms.
-
Field Summary
Fields Modifier and Type Field Description static StringELEMENT_NAMEElement name of the packet extension.static StringNAMESPACENamespace of the packet extension.-
Fields inherited from class org.xmpp.packet.PacketExtension
docFactory, element, registeredExtensions
-
-
Constructor Summary
Constructors Constructor Description DataForm(org.dom4j.Element element)DataForm(DataForm.Type type)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description FormFieldaddField()Adds a new field as part of the form.FormFieldaddField(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.voidclearInstructions()Clears all the stored instructions in this packet extension.DataFormcreateCopy()Creates a deep copy of this packet extension.FormFieldgetField(String variable)Returns the field whose variable matches the specified variable.List<FormField>getFields()Returns the fields that are part of the form.List<String>getInstructions()Returns an unmodifiable list of instructions that explain how to fill out the form and what the form is about.StringgetTitle()Returns the description of the data form.DataForm.TypegetType()Returns the type of this data form.static booleanparseBoolean(String booleanString)static DateparseDate(String date)Returns the Date obtained by parsing the specified date representation.booleanremoveField(String variable)Removes the field whose variable matches the specified variable.voidsetTitle(String title)Sets the description of the data.-
Methods inherited from class org.xmpp.packet.PacketExtension
getElement, getExtensionClass
-
-
-
-
Field Detail
-
ELEMENT_NAME
public static final String ELEMENT_NAME
Element name of the packet extension.- See Also:
- Constant Field Values
-
NAMESPACE
public static final String NAMESPACE
Namespace of the packet extension.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DataForm
public DataForm(DataForm.Type type)
-
DataForm
public DataForm(org.dom4j.Element element)
-
-
Method Detail
-
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:
DataForm.Type
-
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
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
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 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
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 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
public void addItemFields(Map<String,Object> fields)
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
public DataForm createCopy()
Description copied from class:PacketExtensionCreates a deep copy of this packet extension.- Overrides:
createCopyin classPacketExtension- Returns:
- a deep copy of this packet extension.
-
-