All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jivesoftware.smackx.xdata.FormField Maven / Gradle / Ivy

/**
 *
 * Copyright 2003-2007 Jive Software, 2019 Florian Schmaus.
 *
 * 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.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import javax.xml.namespace.QName;

import org.jivesoftware.smack.packet.FullyQualifiedElement;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.util.CollectionUtil;
import org.jivesoftware.smack.util.EqualsUtil;
import org.jivesoftware.smack.util.HashCode;
import org.jivesoftware.smack.util.MultiMap;
import org.jivesoftware.smack.util.XmlStringBuilder;

import org.jivesoftware.smackx.xdata.packet.DataForm;

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 final class FormField implements FullyQualifiedElement {

    public static final String ELEMENT = "field";

    public static final String NAMESPACE = DataForm.NAMESPACE;

    public static final QName QNAME = new QName(NAMESPACE, ELEMENT);

    /**
     * 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); } } } /** * The field's name. Put as value in the 'var' attribute of <field/>. */ private final String variable; private final String label; private final Type type; private final List formFieldChildElements; private final MultiMap formFieldChildElementsMap; /* * The following four fields are cache values which are represented as child elements of and hence also * appear in formFieldChildElements. */ private final List




© 2015 - 2024 Weber Informatics LLC | Privacy Policy