Class DataForm
- java.lang.Object
-
- org.jivesoftware.smackx.xdata.packet.DataForm
-
- All Implemented Interfaces:
Element
,ExtensionElement
,FullyQualifiedElement
,NamedElement
,XmlLangElement
public final class DataForm extends Object implements ExtensionElement
Represents a form that could be use for gathering data as well as for reporting data returned from a search.Note that unlike many other things in XMPP, the order of the form fields is actually Important in data forms.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DataForm.Builder
static class
DataForm.Item
Represents items of reported data.static class
DataForm.ReportedData
Represents the fields that will be returned from a search.static class
DataForm.Type
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description DataForm.Builder
asBuilder()
static DataForm.Builder
builder()
Get a new data form builder with the form type set toDataForm.Type.submit
.static DataForm.Builder
builder(DataForm.Type type)
static DataForm
from(Collection<DataForm> dataForms, String formType)
Return the first matching data form with the given form type from the given collection of data forms.static DataForm
from(StanzaView stanzaView)
Get data form from a stanza.static DataForm
from(StanzaView stanzaView, String formType)
Get the data form with the given form type from a stanza view.String
getElementName()
Returns the root element name.List<Element>
getExtensionElements()
FormField
getField(String fieldName)
Return the form field with the given variable name or null.List<FormField>
getFields()
Returns a List of the fields that are part of the form.String
getFormType()
Return the form type from the hidden form type field.TextSingleFormField
getHiddenFormTypeField()
Returns the hidden FORM_TYPE field or null if this data form has none.List<String>
getInstructions()
Returns a List of the list of instructions that explain how to fill out the form and what the form is about.List<DataForm.Item>
getItems()
Returns a List of the items returned from a search.String
getNamespace()
Returns the root element XML namespace.DataForm.ReportedData
getReportedData()
Returns the fields that will be returned from a search.String
getTitle()
Returns the description of the data.DataForm.Type
getType()
Returns the meaning of the data within the context.boolean
hasField(String fieldName)
Check if a form field with the given variable name exists.boolean
hasHiddenFormTypeField()
Returns true if this DataForm has at least one FORM_TYPE field which is hidden.static DataForm
remove(Collection<DataForm> dataForms, String formType)
Remove the first matching data form with the given form type from the given collection.XmlStringBuilder
toXML(XmlEnvironment xmlEnvironment)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jivesoftware.smack.packet.FullyQualifiedElement
getLanguage, getQName
-
-
-
-
Field Detail
-
NAMESPACE
public static final String NAMESPACE
- See Also:
- Constant Field Values
-
ELEMENT
public static final String ELEMENT
- See Also:
- Constant Field Values
-
-
Method Detail
-
getType
public DataForm.Type getType()
Returns the meaning of the data within the context. The data could be part of a form to fill out, a form submission or data results.- Returns:
- the form's type.
-
getTitle
public String getTitle()
Returns 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.- Returns:
- description of the data.
-
getInstructions
public List<String> getInstructions()
Returns a List of 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. Join the instructions together in order to show them to the user.- Returns:
- a List of the list of instructions that explain how to fill out the form.
-
getReportedData
public DataForm.ReportedData getReportedData()
Returns the fields that will be returned from a search.- Returns:
- fields that will be returned from a search.
-
getItems
public List<DataForm.Item> getItems()
Returns a List of the items returned from a search.- Returns:
- a List of the items returned from a search.
-
getFields
public List<FormField> getFields()
Returns a List of the fields that are part of the form.- Returns:
- a List of the fields that are part of the form.
-
getField
public FormField getField(String fieldName)
Return the form field with the given variable name or null.- Parameters:
fieldName
- the name of the field (the value of the 'var' (variable) attribute)- Returns:
- the form field or null.
- Since:
- 4.1
-
hasField
public boolean hasField(String fieldName)
Check if a form field with the given variable name exists.- Parameters:
fieldName
- the name of the field.- Returns:
- true if a form field with the variable name exists, false otherwise.
- Since:
- 4.2
-
getElementName
public String getElementName()
Description copied from interface:NamedElement
Returns the root element name.- Specified by:
getElementName
in interfaceNamedElement
- Returns:
- the element name.
-
getNamespace
public String getNamespace()
Description copied from interface:FullyQualifiedElement
Returns the root element XML namespace.- Specified by:
getNamespace
in interfaceFullyQualifiedElement
- Returns:
- the namespace.
-
getExtensionElements
public List<Element> getExtensionElements()
-
getFormType
public String getFormType()
Return the form type from the hidden form type field.- Returns:
- the form type or
null
if this form has none set. - Since:
- 4.4.0
-
getHiddenFormTypeField
public TextSingleFormField getHiddenFormTypeField()
Returns the hidden FORM_TYPE field or null if this data form has none.- Returns:
- the hidden FORM_TYPE field or null.
- Since:
- 4.1
-
hasHiddenFormTypeField
public boolean hasHiddenFormTypeField()
Returns true if this DataForm has at least one FORM_TYPE field which is hidden. This method is used for sanity checks.- Returns:
- true if there is at least one field which is hidden.
-
toXML
public XmlStringBuilder toXML(XmlEnvironment xmlEnvironment)
-
asBuilder
public DataForm.Builder asBuilder()
-
from
public static DataForm from(StanzaView stanzaView)
Get data form from a stanza.- Parameters:
stanzaView
- the stanza to get data form from.- Returns:
- the DataForm or null
-
from
public static DataForm from(StanzaView stanzaView, String formType)
Get the data form with the given form type from a stanza view.- Parameters:
stanzaView
- the stanza view to retrieve the data form fromformType
- the form type- Returns:
- the retrieved data form or
null
if there is no matching one - Since:
- 4.4.0
-
from
public static DataForm from(Collection<DataForm> dataForms, String formType)
Return the first matching data form with the given form type from the given collection of data forms.- Parameters:
dataForms
- the collection of data formsformType
- the form type to match for- Returns:
- the first matching data form or
null
if there is none - Since:
- 4.4.0
-
remove
public static DataForm remove(Collection<DataForm> dataForms, String formType)
Remove the first matching data form with the given form type from the given collection.- Parameters:
dataForms
- the collection of data formsformType
- the form type to match for- Returns:
- the removed data form or
null
if there was none removed - Since:
- 4.4.0
-
builder
public static DataForm.Builder builder()
Get a new data form builder with the form type set toDataForm.Type.submit
.- Returns:
- a new data form builder.
-
builder
public static DataForm.Builder builder(DataForm.Type type)
-
-