Package org.jivesoftware.smackx.xdata
Class FormField
- java.lang.Object
-
- org.jivesoftware.smackx.xdata.FormField
-
- All Implemented Interfaces:
Element,FullyQualifiedElement,NamedElement,XmlLangElement
- Direct Known Subclasses:
AbstractMultiFormField,JidMultiFormField,SingleValueFormField
public abstract class FormField extends java.lang.Object implements FullyQualifiedElement
Represents a field of a form. The field could be used to represent a question to complete, a completed question or a data returned from a search. The exact interpretation of the field depends on the context where the field is used.Fields have a name, which is stored in the 'var' attribute of the field's XML representation. Field instances of all types, except of type "fixed" must have a name.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFormField.Builder<F extends FormField,B extends FormField.Builder<?,?>>static classFormField.Descriptionstatic classFormField.OptionRepresents the available options of aListSingleFormFieldandListMultiFormField.static classFormField.Requiredstatic classFormField.TypeForm Field Types as defined in XEP-4 § 3.3.static classFormField.Value
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringELEMENTprotected java.util.List<FullyQualifiedElement>extraXmlChildElementsstatic java.lang.StringFORM_TYPEThe constant String "FORM_TYPE".static java.lang.StringNAMESPACEstatic javax.xml.namespace.QNameQNAME
-
Constructor Summary
Constructors Modifier Constructor Description protectedFormField(FormField.Builder<?,?> builder)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description TextSingleFormFieldasHiddenFormTypeFieldIfPossible()static BooleanFormField.BuilderbooleanBuilder(java.lang.String fieldName)static TextSingleFormField.Builderbuilder(java.lang.String fieldName)static TextSingleFormFieldbuildHiddenFormType(java.lang.String formType)booleanequals(java.lang.Object obj)static TextSingleFormField.BuilderfixedBuilder()static TextSingleFormField.BuilderfixedBuilder(java.lang.String fieldName)java.lang.StringgetDescription()Returns a description that provides extra clarification about the question.java.lang.StringgetElementName()Returns the root element name.java.lang.StringgetFieldName()Returns the field's name, also known as the variable name in case this is an filled out answer form.java.lang.StringgetFirstValue()Returns the first value of this form field ornull.java.util.DategetFirstValueAsDate()Parses the first value of this form field as XEP-0082 date/time format and returns a date instance ornull.FormFieldChildElementgetFormFieldChildElement(javax.xml.namespace.QName qname)java.util.List<FormFieldChildElement>getFormFieldChildElements()java.util.List<FormFieldChildElement>getFormFieldChildElements(javax.xml.namespace.QName qname)java.lang.StringgetLabel()Returns the label of the question which should give enough information to the user to fill out the form.java.lang.StringgetNamespace()Returns the root element XML namespace.javax.xml.namespace.QNamegetQName()java.util.List<java.lang.CharSequence>getRawValueCharSequences()abstract java.util.List<FormField.Value>getRawValues()FormField.TypegetType()Returns an indicative of the format for the data to answer.java.util.List<? extends java.lang.CharSequence>getValues()Returns a List of the default values of the question if the question is part of a form to fill out.java.util.List<java.lang.String>getValuesAsString()Returns the values a String.java.lang.StringgetVariable()Deprecated.usegetFieldName()instead.inthashCode()booleanhasValueSet()static TextSingleFormField.BuilderhiddenBuilder(java.lang.String fieldName)<F extends FormField>
FifPossibleAs(java.lang.Class<F> formFieldClass)<F extends FormField>
FifPossibleAsOrThrow(java.lang.Class<F> formFieldClass)booleanisRequired()Returns true if the question must be answered in order to complete the questionnaire.static JidMultiFormField.BuilderjidMultiBuilder(java.lang.String fieldName)static JidSingleFormField.BuilderjidSingleBuilder(java.lang.String fieldName)static ListMultiFormField.BuilderlistMultiBuilder(java.lang.String fieldName)static ListSingleFormField.BuilderlistSingleBuilder(java.lang.String fieldName)protected voidpopulateExtraXmlChildElements()Populate @{linkextraXmlChildElements}.static TextMultiFormField.BuildertextMultiBuilder(java.lang.String fieldName)static TextSingleFormField.BuildertextPrivateBuilder(java.lang.String fieldName)static TextSingleFormField.BuildertextSingleBuilder(java.lang.String fieldName)XmlStringBuildertoXML(XmlEnvironment enclosingNamespace)XmlStringBuildertoXML(XmlEnvironment enclosingNamespace, boolean includeType)-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jivesoftware.smack.packet.FullyQualifiedElement
getLanguage
-
-
-
-
Field Detail
-
ELEMENT
public static final java.lang.String ELEMENT
- See Also:
- Constant Field Values
-
NAMESPACE
public static final java.lang.String NAMESPACE
- See Also:
- Constant Field Values
-
QNAME
public static final javax.xml.namespace.QName QNAME
-
FORM_TYPE
public static final java.lang.String FORM_TYPE
The constant String "FORM_TYPE".- See Also:
- Constant Field Values
-
extraXmlChildElements
protected transient java.util.List<FullyQualifiedElement> extraXmlChildElements
-
-
Constructor Detail
-
FormField
protected FormField(FormField.Builder<?,?> builder)
-
-
Method Detail
-
getDescription
public java.lang.String getDescription()
Returns a description that provides extra clarification about the question. This information could be presented to the user either in tool-tip, help button, or as a section of text before the question.If the question is of type FIXED then the description should remain empty.
- Returns:
- description that provides extra clarification about the question.
-
getLabel
public java.lang.String getLabel()
Returns the label of the question which should give enough information to the user to fill out the form.- Returns:
- label of the question.
-
isRequired
public boolean isRequired()
Returns true if the question must be answered in order to complete the questionnaire.- Returns:
- true if the question must be answered in order to complete the questionnaire.
-
getType
public FormField.Type getType()
Returns an indicative of the format for the data to answer.- Returns:
- format for the data to answer.
- See Also:
FormField.Type
-
getValues
public java.util.List<? extends java.lang.CharSequence> getValues()
Returns a List of the default values of the question if the question is part of a form to fill out. Otherwise, returns a List of the answered values of the question.- Returns:
- a List of the default values or answered values of the question.
-
getRawValues
public abstract java.util.List<FormField.Value> getRawValues()
-
getRawValueCharSequences
public final java.util.List<java.lang.CharSequence> getRawValueCharSequences()
-
hasValueSet
public boolean hasValueSet()
-
getValuesAsString
public java.util.List<java.lang.String> getValuesAsString()
Returns the values a String. Note that you should usegetValues()whenever possible instead of this method.- Returns:
- a list of Strings representing the values
- Since:
- 4.3
- See Also:
getValues()
-
getFirstValue
public java.lang.String getFirstValue()
Returns the first value of this form field ornull.- Returns:
- the first value or
null - Since:
- 4.3
-
getFirstValueAsDate
public java.util.Date getFirstValueAsDate() throws java.text.ParseException
Parses the first value of this form field as XEP-0082 date/time format and returns a date instance ornull.- Returns:
- a Date instance representing the date/time information of the first value of this field.
- Throws:
java.text.ParseException- if parsing fails.- Since:
- 4.3.0
-
getVariable
@Deprecated public java.lang.String getVariable()
Deprecated.usegetFieldName()instead.Returns the field's name, also known as the variable name in case this is an filled out answer form.According to XEP-4 § 3.2 the variable name (the 'var' attribute) "uniquely identifies the field in the context of the form" (if the field is not of type 'fixed', in which case the field "MAY possess a 'var' attribute")
- Returns:
- the field's name.
-
getFieldName
public java.lang.String getFieldName()
Returns the field's name, also known as the variable name in case this is an filled out answer form.According to XEP-4 § 3.2 the variable name (the 'var' attribute) "uniquely identifies the field in the context of the form" (if the field is not of type 'fixed', in which case the field "MAY possess a 'var' attribute")
- Returns:
- the field's name.
-
getFormFieldChildElement
public FormFieldChildElement getFormFieldChildElement(javax.xml.namespace.QName qname)
-
getFormFieldChildElements
public java.util.List<FormFieldChildElement> getFormFieldChildElements(javax.xml.namespace.QName qname)
-
getFormFieldChildElements
public java.util.List<FormFieldChildElement> getFormFieldChildElements()
-
getElementName
public java.lang.String getElementName()
Description copied from interface:NamedElementReturns the root element name.- Specified by:
getElementNamein interfaceNamedElement- Returns:
- the element name.
-
getNamespace
public java.lang.String getNamespace()
Description copied from interface:FullyQualifiedElementReturns the root element XML namespace.- Specified by:
getNamespacein interfaceFullyQualifiedElement- Returns:
- the namespace.
-
getQName
public javax.xml.namespace.QName getQName()
- Specified by:
getQNamein interfaceFullyQualifiedElement
-
populateExtraXmlChildElements
protected void populateExtraXmlChildElements()
Populate @{linkextraXmlChildElements}. Note that this method may be overridden by subclasses.
-
toXML
public final XmlStringBuilder toXML(XmlEnvironment enclosingNamespace)
-
toXML
public final XmlStringBuilder toXML(XmlEnvironment enclosingNamespace, boolean includeType)
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
booleanBuilder
public static BooleanFormField.Builder booleanBuilder(java.lang.String fieldName)
-
fixedBuilder
public static TextSingleFormField.Builder fixedBuilder()
-
fixedBuilder
public static TextSingleFormField.Builder fixedBuilder(java.lang.String fieldName)
-
hiddenBuilder
public static TextSingleFormField.Builder hiddenBuilder(java.lang.String fieldName)
-
jidMultiBuilder
public static JidMultiFormField.Builder jidMultiBuilder(java.lang.String fieldName)
-
jidSingleBuilder
public static JidSingleFormField.Builder jidSingleBuilder(java.lang.String fieldName)
-
listMultiBuilder
public static ListMultiFormField.Builder listMultiBuilder(java.lang.String fieldName)
-
listSingleBuilder
public static ListSingleFormField.Builder listSingleBuilder(java.lang.String fieldName)
-
textMultiBuilder
public static TextMultiFormField.Builder textMultiBuilder(java.lang.String fieldName)
-
textPrivateBuilder
public static TextSingleFormField.Builder textPrivateBuilder(java.lang.String fieldName)
-
textSingleBuilder
public static TextSingleFormField.Builder textSingleBuilder(java.lang.String fieldName)
-
builder
public static TextSingleFormField.Builder builder(java.lang.String fieldName)
-
buildHiddenFormType
public static TextSingleFormField buildHiddenFormType(java.lang.String formType)
-
ifPossibleAs
public <F extends FormField> F ifPossibleAs(java.lang.Class<F> formFieldClass)
-
ifPossibleAsOrThrow
public <F extends FormField> F ifPossibleAsOrThrow(java.lang.Class<F> formFieldClass)
-
asHiddenFormTypeFieldIfPossible
public TextSingleFormField asHiddenFormTypeFieldIfPossible()
-
-