2004-03-29 23:29:55 +02:00
|
|
|
/**
|
2004-11-03 00:37:00 +01:00
|
|
|
*
|
2007-02-12 01:59:05 +01:00
|
|
|
* Copyright 2003-2007 Jive Software.
|
2004-11-03 00:37:00 +01:00
|
|
|
*
|
2014-02-17 18:57:38 +01:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
2004-11-03 00:37:00 +01:00
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2004-03-29 23:29:55 +02:00
|
|
|
|
2014-02-15 11:35:08 +01:00
|
|
|
package org.jivesoftware.smackx.xdata;
|
2004-03-29 23:29:55 +02:00
|
|
|
|
2006-07-18 07:14:33 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
2004-03-29 23:29:55 +02:00
|
|
|
|
2015-01-21 09:49:57 +01:00
|
|
|
import org.jivesoftware.smack.packet.NamedElement;
|
2014-11-22 23:16:45 +01:00
|
|
|
import org.jivesoftware.smack.util.XmlStringBuilder;
|
|
|
|
import org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement;
|
|
|
|
|
2004-03-29 23:29:55 +02:00
|
|
|
/**
|
|
|
|
* 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.
|
2006-09-16 00:42:06 +02:00
|
|
|
*
|
2004-03-29 23:29:55 +02:00
|
|
|
* @author Gaston Dombiak
|
|
|
|
*/
|
2015-01-21 09:49:57 +01:00
|
|
|
public class FormField implements NamedElement {
|
2006-10-17 15:15:35 +02:00
|
|
|
|
2014-06-19 11:48:01 +02:00
|
|
|
public static final String ELEMENT = "field";
|
|
|
|
|
2015-01-10 18:01:07 +01:00
|
|
|
/**
|
2015-03-29 12:15:32 +02:00
|
|
|
* The constant String "FORM_TYPE".
|
2015-01-10 18:01:07 +01:00
|
|
|
*/
|
|
|
|
public static final String FORM_TYPE = "FORM_TYPE";
|
|
|
|
|
2014-12-27 20:47:57 +01:00
|
|
|
/**
|
|
|
|
* Form Field Types as defined in XEP-4 § 3.3.
|
|
|
|
*
|
|
|
|
* @see <a href="http://xmpp.org/extensions/xep-0004.html#protocol-fieldtypes">XEP-4 § 3.3 Field Types</a>
|
|
|
|
*/
|
|
|
|
public enum Type {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Boolean type. Can be 0 or 1, true or false, yes or no. Default value is 0.
|
|
|
|
* <p>
|
|
|
|
* Note that in XEP-4 this type is called 'boolean', but since that String is a restricted keyword in Java, it
|
|
|
|
* is named 'bool' in Smack.
|
|
|
|
* </p>
|
|
|
|
*/
|
|
|
|
bool,
|
|
|
|
|
|
|
|
/**
|
2015-03-29 12:15:32 +02:00
|
|
|
* Fixed for putting in text to show sections, or just advertise your web site in the middle of the form.
|
2014-12-27 20:47:57 +01:00
|
|
|
*/
|
|
|
|
fixed,
|
|
|
|
|
|
|
|
/**
|
2015-03-29 12:15:32 +02:00
|
|
|
* Is not given to the user at all, but returned with the questionnaire.
|
2014-12-27 20:47:57 +01:00
|
|
|
*/
|
|
|
|
hidden,
|
|
|
|
|
|
|
|
/**
|
2015-03-29 12:15:32 +02:00
|
|
|
* multiple entries for JIDs.
|
2014-12-27 20:47:57 +01:00
|
|
|
*/
|
|
|
|
jid_multi,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Jabber ID - choosing a JID from your roster, and entering one based on the rules for a JID.
|
|
|
|
*/
|
|
|
|
jid_single,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a list of choices, pick one or more.
|
|
|
|
*/
|
|
|
|
list_multi,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a list of choices, pick one.
|
|
|
|
*/
|
|
|
|
list_single,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Multiple lines of text entry.
|
|
|
|
*/
|
|
|
|
text_multi,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instead of showing the user what they typed, you show ***** to protect it.
|
|
|
|
*/
|
|
|
|
text_private,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Single line or word of text.
|
|
|
|
*/
|
|
|
|
text_single,
|
|
|
|
;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
switch (this) {
|
|
|
|
case bool:
|
|
|
|
return "boolean";
|
|
|
|
default:
|
|
|
|
return this.name().replace('_', '-');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-25 15:45:56 +01:00
|
|
|
/**
|
|
|
|
* Get a form field type from the given string. If <code>string</code> is null, then null will be returned.
|
|
|
|
*
|
|
|
|
* @param string the string to transform or null.
|
|
|
|
* @return the type or null.
|
|
|
|
*/
|
2014-12-27 20:47:57 +01:00
|
|
|
public static Type fromString(String string) {
|
2015-01-25 15:45:56 +01:00
|
|
|
if (string == null) {
|
|
|
|
return null;
|
|
|
|
}
|
2014-12-27 20:47:57 +01:00
|
|
|
switch (string) {
|
|
|
|
case "boolean":
|
|
|
|
return bool;
|
|
|
|
default:
|
|
|
|
string = string.replace('-', '_');
|
|
|
|
return Type.valueOf(string);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-03-29 23:29:55 +02:00
|
|
|
|
2015-01-10 18:01:07 +01:00
|
|
|
private final String variable;
|
|
|
|
|
2004-03-29 23:29:55 +02:00
|
|
|
private String description;
|
|
|
|
private boolean required = false;
|
|
|
|
private String label;
|
2014-12-27 20:47:57 +01:00
|
|
|
private Type type;
|
2006-07-18 07:14:33 +02:00
|
|
|
private final List<Option> options = new ArrayList<Option>();
|
|
|
|
private final List<String> values = new ArrayList<String>();
|
2014-11-22 23:16:45 +01:00
|
|
|
private ValidateElement validateElement;
|
2004-03-29 23:29:55 +02:00
|
|
|
|
2004-04-05 18:27:40 +02:00
|
|
|
/**
|
2006-09-16 00:42:06 +02:00
|
|
|
* Creates a new FormField with the variable name that uniquely identifies the field
|
|
|
|
* in the context of the form.
|
|
|
|
*
|
2004-04-05 18:27:40 +02:00
|
|
|
* @param variable the variable name of the question.
|
|
|
|
*/
|
|
|
|
public FormField(String variable) {
|
|
|
|
this.variable = variable;
|
|
|
|
}
|
2006-09-16 00:42:06 +02:00
|
|
|
|
2004-04-26 04:34:29 +02:00
|
|
|
/**
|
2006-09-16 00:42:06 +02:00
|
|
|
* Creates a new FormField of type FIXED. The fields of type FIXED do not define a variable
|
|
|
|
* name.
|
2004-04-26 04:34:29 +02:00
|
|
|
*/
|
|
|
|
public FormField() {
|
2015-01-10 18:01:07 +01:00
|
|
|
this(null);
|
2014-12-27 20:47:57 +01:00
|
|
|
this.type = Type.fixed;
|
2004-04-26 04:34:29 +02:00
|
|
|
}
|
2006-09-16 00:42:06 +02:00
|
|
|
|
2004-03-29 23:29:55 +02:00
|
|
|
/**
|
|
|
|
* Returns a description that provides extra clarification about the question. This information
|
2006-09-16 00:42:06 +02:00
|
|
|
* could be presented to the user either in tool-tip, help button, or as a section of text
|
2015-04-03 19:15:35 +02:00
|
|
|
* before the question.
|
|
|
|
* <p>
|
2004-03-29 23:29:55 +02:00
|
|
|
* If the question is of type FIXED then the description should remain empty.
|
2015-04-03 19:15:35 +02:00
|
|
|
* </p>
|
2006-09-16 00:42:06 +02:00
|
|
|
*
|
2004-03-29 23:29:55 +02:00
|
|
|
* @return description that provides extra clarification about the question.
|
|
|
|
*/
|
|
|
|
public String getDescription() {
|
|
|
|
return description;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-09-16 00:42:06 +02:00
|
|
|
* Returns the label of the question which should give enough information to the user to
|
2004-03-29 23:29:55 +02:00
|
|
|
* fill out the form.
|
2006-09-16 00:42:06 +02:00
|
|
|
*
|
2004-03-29 23:29:55 +02:00
|
|
|
* @return label of the question.
|
|
|
|
*/
|
|
|
|
public String getLabel() {
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-04-09 08:26:28 +02:00
|
|
|
* Returns a List of the available options that the user has in order to answer
|
2006-09-16 00:42:06 +02:00
|
|
|
* the question.
|
|
|
|
*
|
2014-04-09 08:26:28 +02:00
|
|
|
* @return List of the available options.
|
2004-03-29 23:29:55 +02:00
|
|
|
*/
|
2014-04-09 08:26:28 +02:00
|
|
|
public List<Option> getOptions() {
|
2004-03-29 23:29:55 +02:00
|
|
|
synchronized (options) {
|
2014-04-09 08:26:28 +02:00
|
|
|
return Collections.unmodifiableList(new ArrayList<Option>(options));
|
2004-03-29 23:29:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the question must be answered in order to complete the questionnaire.
|
2006-09-16 00:42:06 +02:00
|
|
|
*
|
2004-03-29 23:29:55 +02:00
|
|
|
* @return true if the question must be answered in order to complete the questionnaire.
|
|
|
|
*/
|
|
|
|
public boolean isRequired() {
|
|
|
|
return required;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-12-27 20:47:57 +01:00
|
|
|
* Returns an indicative of the format for the data to answer.
|
2006-09-16 00:42:06 +02:00
|
|
|
*
|
2004-03-29 23:29:55 +02:00
|
|
|
* @return format for the data to answer.
|
2014-12-27 20:47:57 +01:00
|
|
|
* @see Type
|
2004-03-29 23:29:55 +02:00
|
|
|
*/
|
2014-12-27 20:47:57 +01:00
|
|
|
public Type getType() {
|
2004-03-29 23:29:55 +02:00
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-04-09 08:26:28 +02:00
|
|
|
* 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
|
2006-09-16 00:42:06 +02:00
|
|
|
* the question.
|
|
|
|
*
|
2014-04-09 08:26:28 +02:00
|
|
|
* @return a List of the default values or answered values of the question.
|
2004-03-29 23:29:55 +02:00
|
|
|
*/
|
2014-04-09 08:26:28 +02:00
|
|
|
public List<String> getValues() {
|
2004-03-29 23:29:55 +02:00
|
|
|
synchronized (values) {
|
2014-04-09 08:26:28 +02:00
|
|
|
return Collections.unmodifiableList(new ArrayList<String>(values));
|
2004-03-29 23:29:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the variable name that the question is filling out.
|
2015-01-10 18:01:07 +01:00
|
|
|
* <p>
|
|
|
|
* 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")
|
|
|
|
* </p>
|
|
|
|
*
|
2004-03-29 23:29:55 +02:00
|
|
|
* @return the variable name of the question.
|
|
|
|
*/
|
|
|
|
public String getVariable() {
|
|
|
|
return variable;
|
|
|
|
}
|
|
|
|
|
2014-11-22 23:16:45 +01:00
|
|
|
/**
|
2015-03-29 12:15:32 +02:00
|
|
|
* Get validate element.
|
|
|
|
*
|
2014-11-22 23:16:45 +01:00
|
|
|
* @return the validateElement
|
|
|
|
*/
|
|
|
|
public ValidateElement getValidateElement() {
|
|
|
|
return validateElement;
|
|
|
|
}
|
|
|
|
|
2004-03-29 23:29:55 +02:00
|
|
|
/**
|
|
|
|
* Sets a description that provides extra clarification about the question. This information
|
2006-09-16 00:42:06 +02:00
|
|
|
* could be presented to the user either in tool-tip, help button, or as a section of text
|
2015-04-03 19:15:35 +02:00
|
|
|
* before the question.
|
|
|
|
* <p>
|
2004-03-29 23:29:55 +02:00
|
|
|
* If the question is of type FIXED then the description should remain empty.
|
2015-04-03 19:15:35 +02:00
|
|
|
* </p>
|
2006-09-16 00:42:06 +02:00
|
|
|
*
|
2004-03-29 23:29:55 +02:00
|
|
|
* @param description provides extra clarification about the question.
|
|
|
|
*/
|
|
|
|
public void setDescription(String description) {
|
|
|
|
this.description = description;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-09-16 00:42:06 +02:00
|
|
|
* Sets the label of the question which should give enough information to the user to
|
2004-03-29 23:29:55 +02:00
|
|
|
* fill out the form.
|
2006-09-16 00:42:06 +02:00
|
|
|
*
|
2004-03-29 23:29:55 +02:00
|
|
|
* @param label the label of the question.
|
|
|
|
*/
|
|
|
|
public void setLabel(String label) {
|
|
|
|
this.label = label;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets if the question must be answered in order to complete the questionnaire.
|
2006-09-16 00:42:06 +02:00
|
|
|
*
|
2004-03-29 23:29:55 +02:00
|
|
|
* @param required if the question must be answered in order to complete the questionnaire.
|
|
|
|
*/
|
|
|
|
public void setRequired(boolean required) {
|
|
|
|
this.required = required;
|
|
|
|
}
|
|
|
|
|
2014-11-22 23:16:45 +01:00
|
|
|
/**
|
2015-03-29 12:15:32 +02:00
|
|
|
* Set validate element.
|
2014-11-22 23:16:45 +01:00
|
|
|
* @param validateElement the validateElement to set
|
|
|
|
*/
|
|
|
|
public void setValidateElement(ValidateElement validateElement) {
|
|
|
|
validateElement.checkConsistency(this);
|
|
|
|
this.validateElement = validateElement;
|
|
|
|
}
|
|
|
|
|
2004-03-29 23:29:55 +02:00
|
|
|
/**
|
2014-12-27 20:47:57 +01:00
|
|
|
* Sets an indicative of the format for the data to answer.
|
2015-01-10 18:01:07 +01:00
|
|
|
* <p>
|
|
|
|
* This method will throw an IllegalArgumentException if type is 'fixed'. To create FormFields of type 'fixed' use
|
|
|
|
* {@link #FormField()} instead.
|
|
|
|
* </p>
|
2006-09-16 00:42:06 +02:00
|
|
|
*
|
2004-03-29 23:29:55 +02:00
|
|
|
* @param type an indicative of the format for the data to answer.
|
2014-12-27 20:47:57 +01:00
|
|
|
* @see Type
|
2015-01-10 18:01:07 +01:00
|
|
|
* @throws IllegalArgumentException if type is 'fixed'.
|
2004-03-29 23:29:55 +02:00
|
|
|
*/
|
2014-12-27 20:47:57 +01:00
|
|
|
public void setType(Type type) {
|
2015-01-10 18:01:07 +01:00
|
|
|
if (type == Type.fixed) {
|
|
|
|
throw new IllegalArgumentException("Can not set type to fixed, use FormField constructor without arguments instead.");
|
|
|
|
}
|
2004-03-29 23:29:55 +02:00
|
|
|
this.type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-09-16 00:42:06 +02:00
|
|
|
* Adds a default value to the question if the question is part of a form to fill out.
|
2004-03-29 23:29:55 +02:00
|
|
|
* Otherwise, adds an answered value to the question.
|
2006-09-16 00:42:06 +02:00
|
|
|
*
|
2004-03-29 23:29:55 +02:00
|
|
|
* @param value a default value or an answered value of the question.
|
|
|
|
*/
|
|
|
|
public void addValue(String value) {
|
|
|
|
synchronized (values) {
|
|
|
|
values.add(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-09-16 00:42:06 +02:00
|
|
|
* Adds a default values to the question if the question is part of a form to fill out.
|
2004-03-29 23:29:55 +02:00
|
|
|
* Otherwise, adds an answered values to the question.
|
2006-09-16 00:42:06 +02:00
|
|
|
*
|
2004-04-08 21:09:19 +02:00
|
|
|
* @param newValues default values or an answered values of the question.
|
2004-03-29 23:29:55 +02:00
|
|
|
*/
|
2006-07-18 07:14:33 +02:00
|
|
|
public void addValues(List<String> newValues) {
|
2004-03-29 23:29:55 +02:00
|
|
|
synchronized (values) {
|
|
|
|
values.addAll(newValues);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-07 21:48:39 +02:00
|
|
|
/**
|
|
|
|
* Removes all the values of the field.
|
|
|
|
*/
|
|
|
|
protected void resetValues() {
|
|
|
|
synchronized (values) {
|
2006-07-18 07:14:33 +02:00
|
|
|
values.removeAll(new ArrayList<String>(values));
|
2004-04-07 21:48:39 +02:00
|
|
|
}
|
|
|
|
}
|
2006-09-16 00:42:06 +02:00
|
|
|
|
2004-03-29 23:29:55 +02:00
|
|
|
/**
|
2006-09-16 00:42:06 +02:00
|
|
|
* Adss an available options to the question that the user has in order to answer
|
2004-03-29 23:29:55 +02:00
|
|
|
* the question.
|
2006-09-16 00:42:06 +02:00
|
|
|
*
|
2004-03-29 23:29:55 +02:00
|
|
|
* @param option a new available option for the question.
|
|
|
|
*/
|
|
|
|
public void addOption(Option option) {
|
|
|
|
synchronized (options) {
|
|
|
|
options.add(option);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-21 09:49:57 +01:00
|
|
|
@Override
|
|
|
|
public String getElementName() {
|
|
|
|
return ELEMENT;
|
|
|
|
}
|
|
|
|
|
2014-06-19 11:48:01 +02:00
|
|
|
public XmlStringBuilder toXML() {
|
2015-01-21 09:49:57 +01:00
|
|
|
XmlStringBuilder buf = new XmlStringBuilder(this);
|
2004-03-29 23:29:55 +02:00
|
|
|
// Add attributes
|
2014-06-19 11:48:01 +02:00
|
|
|
buf.optAttribute("label", getLabel());
|
|
|
|
buf.optAttribute("var", getVariable());
|
|
|
|
buf.optAttribute("type", getType());
|
2014-08-20 21:25:14 +02:00
|
|
|
buf.rightAngleBracket();
|
2004-03-29 23:29:55 +02:00
|
|
|
// Add elements
|
2014-06-19 11:48:01 +02:00
|
|
|
buf.optElement("desc", getDescription());
|
|
|
|
buf.condEmptyElement(isRequired(), "required");
|
2004-03-29 23:29:55 +02:00
|
|
|
// Loop through all the values and append them to the string buffer
|
2014-04-09 08:26:28 +02:00
|
|
|
for (String value : getValues()) {
|
|
|
|
buf.element("value", value);
|
2004-03-29 23:29:55 +02:00
|
|
|
}
|
|
|
|
// Loop through all the values and append them to the string buffer
|
2014-04-09 08:26:28 +02:00
|
|
|
for (Option option : getOptions()) {
|
|
|
|
buf.append(option.toXML());
|
2004-03-29 23:29:55 +02:00
|
|
|
}
|
2014-11-22 23:16:45 +01:00
|
|
|
buf.optElement(validateElement);
|
2015-01-21 09:49:57 +01:00
|
|
|
buf.closeElement(this);
|
2014-06-19 11:48:01 +02:00
|
|
|
return buf;
|
2004-03-29 23:29:55 +02:00
|
|
|
}
|
|
|
|
|
2013-03-31 16:24:50 +02:00
|
|
|
@Override
|
2013-03-18 09:50:48 +01:00
|
|
|
public boolean equals(Object obj) {
|
|
|
|
if (obj == null)
|
|
|
|
return false;
|
|
|
|
if (obj == this)
|
|
|
|
return true;
|
2013-03-31 16:24:50 +02:00
|
|
|
if (!(obj instanceof FormField))
|
2013-03-18 09:50:48 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
FormField other = (FormField) obj;
|
|
|
|
|
2013-03-31 16:24:50 +02:00
|
|
|
return toXML().equals(other.toXML());
|
|
|
|
}
|
2013-03-18 09:50:48 +01:00
|
|
|
|
2013-03-31 16:24:50 +02:00
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
return toXML().hashCode();
|
2013-03-18 09:50:48 +01:00
|
|
|
}
|
|
|
|
|
2004-03-29 23:29:55 +02:00
|
|
|
/**
|
2006-10-17 15:15:35 +02:00
|
|
|
* Represents the available option of a given FormField.
|
|
|
|
*
|
2004-03-29 23:29:55 +02:00
|
|
|
* @author Gaston Dombiak
|
|
|
|
*/
|
2015-01-21 09:49:57 +01:00
|
|
|
public static class Option implements NamedElement {
|
2006-10-17 15:15:35 +02:00
|
|
|
|
2014-07-30 21:58:10 +02:00
|
|
|
public static final String ELEMENT = "option";
|
2014-06-19 11:48:01 +02:00
|
|
|
|
|
|
|
private final String value;
|
2004-03-29 23:29:55 +02:00
|
|
|
private String label;
|
|
|
|
|
|
|
|
public Option(String value) {
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Option(String label, String value) {
|
|
|
|
this.label = label;
|
|
|
|
this.value = value;
|
|
|
|
}
|
2006-10-17 15:15:35 +02:00
|
|
|
|
2004-03-29 23:29:55 +02:00
|
|
|
/**
|
2006-10-17 15:15:35 +02:00
|
|
|
* Returns the label that represents the option.
|
|
|
|
*
|
2004-03-29 23:29:55 +02:00
|
|
|
* @return the label that represents the option.
|
|
|
|
*/
|
|
|
|
public String getLabel() {
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the value of the option.
|
2006-10-17 15:15:35 +02:00
|
|
|
*
|
2004-03-29 23:29:55 +02:00
|
|
|
* @return the value of the option.
|
|
|
|
*/
|
|
|
|
public String getValue() {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2013-03-31 16:24:50 +02:00
|
|
|
@Override
|
2006-10-17 15:15:35 +02:00
|
|
|
public String toString() {
|
2005-10-30 02:39:49 +02:00
|
|
|
return getLabel();
|
|
|
|
}
|
|
|
|
|
2015-01-21 09:49:57 +01:00
|
|
|
@Override
|
|
|
|
public String getElementName() {
|
|
|
|
return ELEMENT;
|
|
|
|
}
|
|
|
|
|
2014-06-19 11:48:01 +02:00
|
|
|
public XmlStringBuilder toXML() {
|
2015-01-21 09:49:57 +01:00
|
|
|
XmlStringBuilder xml = new XmlStringBuilder(this);
|
2004-03-29 23:29:55 +02:00
|
|
|
// Add attribute
|
2014-06-19 11:48:01 +02:00
|
|
|
xml.optAttribute("label", getLabel());
|
2014-08-20 21:25:14 +02:00
|
|
|
xml.rightAngleBracket();
|
2014-06-19 11:48:01 +02:00
|
|
|
|
2004-03-29 23:29:55 +02:00
|
|
|
// Add element
|
2014-06-19 11:48:01 +02:00
|
|
|
xml.element("value", getValue());
|
2004-03-29 23:29:55 +02:00
|
|
|
|
2015-01-21 09:49:57 +01:00
|
|
|
xml.closeElement(this);
|
2014-06-19 11:48:01 +02:00
|
|
|
return xml;
|
2004-03-29 23:29:55 +02:00
|
|
|
}
|
2013-03-18 09:50:48 +01:00
|
|
|
|
2013-03-31 16:24:50 +02:00
|
|
|
@Override
|
2013-03-18 09:50:48 +01:00
|
|
|
public boolean equals(Object obj) {
|
|
|
|
if (obj == null)
|
|
|
|
return false;
|
|
|
|
if (obj == this)
|
|
|
|
return true;
|
|
|
|
if (obj.getClass() != getClass())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Option other = (Option) obj;
|
|
|
|
|
|
|
|
if (!value.equals(other.value))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
String thisLabel = label == null ? "" : label;
|
|
|
|
String otherLabel = other.label == null ? "" : other.label;
|
|
|
|
|
|
|
|
if (!thisLabel.equals(otherLabel))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2013-03-31 16:24:50 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
int result = 1;
|
|
|
|
result = 37 * result + value.hashCode();
|
|
|
|
result = 37 * result + (label == null ? 0 : label.hashCode());
|
|
|
|
return result;
|
|
|
|
}
|
2004-03-29 23:29:55 +02:00
|
|
|
}
|
|
|
|
}
|