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

📄 xdata.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 $
 *
 * j.komzak
 * Changed into XData
 */

package edu.ou.kmi.buddyspace.xml;

/*
 * XData.java
 *
 * Project: BuddySpace
 * (C) Copyright Knowledge Media Institute 2003
 *
 *
 * Created on 4 February 2003, 16:16
 */

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

/**
 * <code>XData</code> contains &lt;x xmlns='jabber:x:data'&gt tag.
 *
 * @author Jiri Komzak, Knowledge Media Institute, Open University, United Kingdom
 */
public class XData
    extends XMLData
    implements MessageExtension, QueryExtension, PresenceExtension
{
    /** Vector of 'Field' objects contained */
    private Vector fields;
    /** Vector of 'Items'/'Reported' objects contained */
    private Vector items;
    
    private String type = null;
    private String title = null;
    private String instructions = null;

    /**
     * Creates a new <code>XData</code> instance, based on the builder
     * state.
     *
     * @param builder an <code>XDataBuilder</code> value
     * @exception InstantiationException if malformed or insufficient data is
     * in the builder.
     */
    public XData(XDataBuilder builder)
        throws InstantiationException
    {
        fields = (Vector) builder.getFields().clone();
        items = (Vector) builder.getItems().clone();
        type = builder.getType();
        title = builder.getTitle();
        instructions = builder.getInstructions();
    }
    
    public String getType() {
        return type;
    }
    
    
    public void setType(String type) {
        this.type = type;
    }

    public String getTitle() {
        return title;
    }

    public String getInstructions() {
        return instructions;
    }

    /**
     * returns an enumeration of <code>fields</code> contained within this
     * object.
     *
     * @return an <code>Enumeration</code> value
     */
    public Enumeration fields()
    {
        return fields.elements();
    }
    
    
    /**
     * returns an enumeration of <code>items</code> contained within this
     * object.
     *
     * @return an <code>Enumeration</code> value
     */
    public Enumeration items()
    {
        return items.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("<x xmlns='jabber:x:data'" + 
                       ((type != null)? " type='" + type + "'" : ""));
        
        boolean emptyTag = true;
        
        if (title != null) {
            retval.append(">\n<title>");
            escapeString(retval, title);
            retval.append("</title>\n");
            emptyTag = false;
        }
        
        if (instructions != null) {
            if (emptyTag)
                retval.append(">\n");
            retval.append("<instructions>");
            escapeString(retval, instructions);
            retval.append("</instructions>\n");
            emptyTag = false;
        }
        
        // prints all fields
        Enumeration fieldEnum = fields();
        if (fieldEnum.hasMoreElements() && emptyTag) {
            retval.append(">\n");
            emptyTag = false;
        }
        while (fieldEnum.hasMoreElements())
            ((XDataField)fieldEnum.nextElement()).appendItem(retval);
        
        // prints all items/reported
        fieldEnum = items();
        if (fieldEnum.hasMoreElements() && emptyTag) {
            retval.append(">\n");
            emptyTag = false;
        }
        while (fieldEnum.hasMoreElements())
            ((XDataItem)fieldEnum.nextElement()).appendItem(retval);
        
        if (emptyTag)
            retval.append("/>\n");
        else
            retval.append("</x>\n");
    }
}

⌨️ 快捷键说明

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