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

📄 xmlnode.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  $Author: chris $
 *
 * j.komzak
 * Changed to XMLNode - general XML node representation.
 *
 */

package edu.ou.kmi.buddyspace.xml;

import java.util.*;

import org.xml.sax.AttributeList;

import org.jabber.jabberbeans.*;
import org.jabber.jabberbeans.Extension.*;

/**
 * <code>XMLNode</code> is a backend-specific handler for extensions
 * which are not known. Like all other Extension-derived objects, the one real
 * requirement is that it be able to render itself back as equivalent XML.
 * <p>
 * This class should be used instead the DefaultExtension...
 */
public class XMLNode
    extends XMLData
    implements MessageExtension, 
	       QueryExtension,  
               PresenceExtension,
               Packet
{
    /** XML base element name*/
    private String name;

    /** XML base element attributes (including namespace) */
    private AttributeList attributes;
    
    /** XML subnodes */
    private Vector children;
    
    /** Creates a new <code>XMLNode</code> instance.
     *
     * @param XMLNS the XML Namespace
     * @param XMLSnippet the full XML to be handled by the extension.
     * @exception InstantiationException if either parameter is not passed in 
     * correctly
     */
    public XMLNode(XMLNodeBuilder builder) 
    {
	name = builder.getName();
	attributes = builder.getAttributes();
        children = (Vector)builder.getChildren().clone();
    }
    
    /** <code>getXMLNamespace</code> returns the XML namespace
     *
     * @return a <code>String</code> holding the XML Namespace
     */
    public String getXMLNamespace()
    { return (attributes == null)? null : attributes.getValue("xmlns"); }

    /** <code>getName</code> returns the name of element
     *
     * @return a <code>String</code> holding the name
     */
    public String getName()
    { return name; }

    /** <code>getAttributes</code> returns the node attributes
     *
     * @return a <code>AttributeList</code> holding the attributes
     */
    public AttributeList getAttributes()
    { return attributes; }

    /** <code>getCharacters</code> returns the tag characters - all pieces
     * concatenated together. to get them separately use children.
     *
     * @return a <code>String</code> holding the characters
     */
    /* returns all text concatenated into one string */
    public String getCharacters() {
        if (children == null) return null;
        StringBuffer characters = new StringBuffer();
        Enumeration chEnum = children.elements();
        while (chEnum.hasMoreElements()) {
            Object o = chEnum.nextElement();
            if (o instanceof String) {
                characters.append((String)o);
            }
        }
        return characters.toString();
    }

    /** <code>getChildren</code> returns the children nodes
     *
     * @return a <code>Vector</code> holding the children
     */
    public Vector getChildren()
    { return children; }
    
    /** <code>children</code> returns the children nodes
     *
     * @return a <code>Enumeration</code> of the children
     */
    public Enumeration children()
    { return (children == null)? null : children.elements(); }

    /** Returns the XML representation for the data contained within.
     */
    public void appendItem(StringBuffer retval)
    { 
        retval.append('<');
        
        if (name == null) retval.append("query");
        else retval.append(name);
        
        // xmlns is also in attributes
        //if (xmlns != null) appendAttrib(retval, "xmlns", getXMLNamespace());
        
        for (int i=0; attributes != null && i < attributes.getLength(); i++) {
            appendAttrib(retval, attributes.getName(i), attributes.getValue(i));
        }
        
        retval.append('>');
        
        Enumeration chEnum = children.elements();
        while (chEnum.hasMoreElements()) {
            Object o = chEnum.nextElement();
            if (o instanceof String) {
                //retval.append((String)o);
                escapeString(retval, (String)o);
            }
            else if (o instanceof XMLData)
                ((XMLData)o).appendItem(retval);
        }
        
        retval.append("</");
        if (name == null) retval.append("query");
        else retval.append(name);
        retval.append('>');
    }
}

⌨️ 快捷键说明

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