/* * Copyright (c) 2012 Isode Limited, London, England. * All rights reserved. */ /* * Copyright (c) 2010 Remko Tronçon * All rights reserved. */ package com.isode.stroke.elements; import java.util.ArrayList; import java.util.List; import com.isode.stroke.elements.Form.Type; import com.isode.stroke.jid.JID; /** * This class implements the field element of a form. * *

* Data validation is the responsibility of the form-processing entity (commonly * a server, service, or bot) rather than the form-submitting entity (commonly a * client controlled by a human user). This helps to meet the requirement for * keeping client implementations simple. If the form-processing entity * determines that the data provided is not valid, it SHOULD return a * "Not Acceptable" error, optionally providing a textual explanation. */ public class FormField { /** * Attribute "var" */ public static final String FORM_FIELD_ATTRIBUTE_VAR = "var"; /** * Attribute "label" */ public static final String FORM_FIELD_ATTRIBUTE_LABEL = "label"; /** * Element "required" */ public static final String FORM_FIELD_ELEMENT_REQUIRED = "required"; /** * Element "desc" */ public static final String FORM_FIELD_ELEMENT_DESC = "desc"; /** * Element "value" */ public static final String FORM_FIELD_ELEMENT_VALUE = "value"; /** * Attribute "type" */ public static final String FORM_FIELD_ATTRIBUTE_TYPE = "type"; /** * Element "option" */ public static final String FORM_FIELD_ELEMENT_OPTION = "option"; /** * Attribute option "label" */ public static final String FORM_FIELD_ATTRIBUTE_OPTION_LABEL = "label"; /** * Element option "value" */ public static final String FORM_FIELD_ELEMENT_OPTION_VALUE = "value"; /** * Type "boolean" */ public static final String FORM_FIELD_TYPE_BOOLEAN = "boolean"; /** * Type "fixed" */ public static final String FORM_FIELD_TYPE_FIXED = "fixed"; /** * Type "hidden" */ public static final String FORM_FIELD_TYPE_HIDDEN = "hidden"; /** * Type "list-single" */ public static final String FORM_FIELD_TYPE_LIST_SINGLE = "list-single"; /** * Type "text-private" */ public static final String FORM_FIELD_TYPE_TEXT_PRIVATE = "text-private"; /** * Type "text-single" */ public static final String FORM_FIELD_TYPE_TEXT_SINGLE = "text-single"; /** * Type "jid-multi" */ public static final String FORM_FIELD_TYPE_JID_MULTI = "jid-multi"; /** * Type "jid-single" */ public static final String FORM_FIELD_TYPE_JID_SINGLE = "jid-single"; /** * Type "list-multi" */ public static final String FORM_FIELD_TYPE_LIST_MULTI = "list-multi"; /** * Type "text-multi" */ public static final String FORM_FIELD_TYPE_TEXT_MULTI = "text-multi"; /** * This class defines the option element that can be used in * {@link ListSingleFormField} and {@link ListMultiFormField}. TODO: This * class should be immutable. */ public static class Option { /** * Human-readable name for the option, must not be null */ public String label; /** * Option value, must not be null */ public String value; /** * Create an option element. * * @param label Human-readable name for the option, can be null in which * case an empty string will be stored * @param value Option value, must not be null */ public Option(String label, String value) { if (value == null) { throw new NullPointerException("'value' must not be null"); } this.label = (label != null) ? label : ""; this.value = value; } } private String name = ""; private String label = ""; private String description = ""; private boolean required; private List