⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xdatafield.java

📁 一款即时通讯软件
💻 JAVA
字号:
/*
 *   License
 *
 * The contents of this file are subject to the Jabber Open Source License
 * Version 1.0 (the "License").  You may not copy or use this file, in either
 * source code or executable form, except in compliance with the License.  You
 * may obtain a copy of the License at http://www.jabber.com/license/ or at
 * http://www.opensource.org/.  
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 *   Copyrights
 *
 * Portions created by or assigned to Jabber.com, Inc. are 
 * Copyright (c) 2000 Jabber.com, Inc.  All Rights Reserved.  Contact
 * information for Jabber.com, Inc. is available at http://www.jabber.com/.
 *
 * Portions Copyright (c) 1999-2000 David Waite 
 *
 *   Acknowledgements
 * 
 * Special thanks to the Jabber Open Source Contributors for their
 * suggestions and support of Jabber.
 * 
 *   Changes
 *
 * @author  David Waite <a href="mailto:dwaite@jabber.com">
 *                      <i>&lt;dwaite@jabber.com&gt;</i></a>
 *
 * @author  $Author: chris $
 * @version $Revision: 1.1 $
 *
 * @author  Jiri Komzak <a href="mailto:j.komzak@open.ac.uk">
 *                      <i>&lt;j.komzak@open.ac.uk&gt;</i></a>
 * j.komzak
 * Changed into XDataField
 */

package edu.ou.kmi.buddyspace.xml;

/*
 * XDataField.java
 *
 * Project: BuddySpace
 * (C) Copyright Knowledge Media Institute 2003
 *
 *
 * Created on 5 February 2003, 12:43
 */

import java.util.Vector;
import java.util.Enumeration;
import org.jabber.jabberbeans.*;
import org.jabber.jabberbeans.Extension.*;

/**
 * <code>XDataField</code> contains &lt;field&gt tag from jabber:x:data.
 *
 * @author  Jiri Komzak, Knowledge Media Institute, Open University, United Kingdom
 */
public class XDataField
    extends XMLData
    implements MessageExtension, QueryExtension
{
    /** Vector of values fields contained. */
    private Vector valueList;
    
    /** Vector of option tags contained. */
    private Vector optionList;
    
    /** Attributes. */
    private String label;
    private String type;
    private String var;
    private String desc;
    private boolean required;

    /**
     * Creates a new <code>XDataField</code> instance, based on the builder
     * state.
     *
     * @param builder an <code>XDataFieldBuilder</code> value
     * @exception InstantiationException if malformed or insufficient data is
     * in the builder.
     */
    public XDataField(XDataFieldBuilder builder)
        throws InstantiationException
    {
        optionList = (Vector) builder.getOptions().clone();
        valueList = (Vector) builder.getValues().clone();
        
        type = builder.getType();
        label = builder.getLabel();
        var = builder.getVar();
        desc = builder.getDesc();
        
        required = builder.getRequired();
    }
    
    public String getLabel() {
        return label;
    }

    public String getType() {
        return type;
    }

    public String getVar() {
        return var;
    }

    public String getDesc() {
        return desc;
    }

    public boolean getRequired() {
        return required;
    }

    /**
     * <code>getOptions</code> returns the enumeration representing the option
     * objects associated with this object.
     *
     * @return a <code>Enumeration</code> value
     */
    public Enumeration options()
    { return optionList.elements(); }

    /**
     * <code>getOptions</code> returns the enumeration representing the value
     * objects associated with this object.
     *
     * @return a <code>Enumeration</code> value
     */
    public Enumeration values()
    { return valueList.elements(); }
    
    
    /**
     * <code>appendItem</code> converts this packet to XML. 
     * It then appends it to a StringBuffer.
     *
     * @param retval The <code>StringBuffer</code> to append to
     */
    public void appendItem(StringBuffer retval)
    {
	retval.append("<field"
                        + ((type != null)? " type=\"" + type + "\"" : "")
                        + ((label != null)? " label=\"" + label + "\"" : "")
                        + ((var != null)? " var=\"" + var + "\"" : ""));
                        
        boolean emptyTag = true;
        
        if (required) {
            retval.append(">\n<required/>\n");
            emptyTag = false;
        }
        
        if (desc != null) {
            if (emptyTag)
                retval.append(">\n");
            retval.append("<desc>");
            escapeString(retval, desc);
            retval.append("</desc>\n");
            emptyTag = false;
        }
        
        Enumeration items = values();
        if (items.hasMoreElements() && emptyTag) {
            retval.append(">\n");
            emptyTag = false;
        }
        while (items.hasMoreElements()) {
            String val = (String)items.nextElement();
            if ("".equals(val))
                retval.append("<value/>\n");
            else {
                retval.append("<value>");
                escapeString(retval, val);
                retval.append("</value>\n");
            }
        }
            
        items = options();
        if (items.hasMoreElements() && emptyTag) {
            retval.append(">\n");
            emptyTag = false;
        }
        while (items.hasMoreElements())
            ((XDataFieldOption)items.nextElement()).appendItem(retval);
        
        if (emptyTag)
            retval.append("/>\n");
        else
            retval.append("</field>\n");
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -