/** * * Copyright 2003-2007 Jive Software. * * Licensed under the Apache License, Version 2.0 (the "License"); * 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. */ package org.jivesoftware.smackx.xdata; import java.text.ParseException; import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.List; import org.jivesoftware.smack.packet.NamedElement; import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.util.XmlStringBuilder; import org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement; import org.jxmpp.util.XmppDateTime; /** * 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. * * @author Gaston Dombiak */ public class FormField implements NamedElement { public static final String ELEMENT = "field"; /** * The constant String "FORM_TYPE". */ public static final String FORM_TYPE = "FORM_TYPE"; /** * Form Field Types as defined in XEP-4 § 3.3. * * @see XEP-4 § 3.3 Field Types */ public enum Type { /** * Boolean type. Can be 0 or 1, true or false, yes or no. Default value is 0. *

* 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. *

*/ bool, /** * Fixed for putting in text to show sections, or just advertise your web site in the middle of the form. */ fixed, /** * Is not given to the user at all, but returned with the questionnaire. */ hidden, /** * multiple entries for JIDs. */ 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('_', '-'); } } /** * Get a form field type from the given string. If string is null, then null will be returned. * * @param string the string to transform or null. * @return the type or null. */ public static Type fromString(String string) { if (string == null) { return null; } switch (string) { case "boolean": return bool; default: string = string.replace('-', '_'); return Type.valueOf(string); } } } private final String variable; private String description; private boolean required = false; private String label; private Type type; private final List