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

📄 litexmlelement.java

📁 jxme的一些相关程序,主要是手机上程序开发以及手机和计算机通信的一些程序资料,程序编译需要Ant支持
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/*
 * $Id: LiteXMLElement.java,v 1.2 2002/03/04 21:42:56 echtcherbina Exp $
 ********************
 *
 * Copyright (c) 2001 Sun Microsystems, Inc.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *       Sun Microsystems, Inc. for Project JXTA."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Sun", "Sun Microsystems, Inc.", "JXTA" and "Project JXTA" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact Project JXTA at http://www.jxta.org.
 *
 * 5. Products derived from this software may not be called "JXTA",
 *    nor may "JXTA" appear in their name, without prior written
 *    permission of Sun.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL SUN MICROSYSTEMS OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of Project JXTA.  For more
 * information on Project JXTA, please see
 * <http://www.jxta.org/>.
 *
 * This license is based on the BSD license adopted by the Apache Foundation.
 ********************
 */

package net.jxta.impl.document;

import java.io.Writer;
//PDA requirements 19.02.2002
//class java.lang.Comparable did not exist in jdk 1.1.8, it was excluded
//import java.lang.Comparable;
//PDA requirements 19.02.2002
import java.lang.String;
import java.util.Enumeration;
import java.util.Vector;

import java.io.IOException;
import java.lang.ClassCastException;
import java.lang.IllegalArgumentException;

import net.jxta.document.Attributable;
import net.jxta.document.Attribute;
import net.jxta.document.Element;
import net.jxta.document.StructuredDocument;
import net.jxta.document.TextElement;

/** An element of a <CODE>StructuredDocument</CODE>. <CODE>StructuredDocument</CODE>s
 * are made up of hierarchies of elements. LiteXMLElement is part of an implementation
 * while makes use of XML-style document conventions, but without the overhead of a
 * full parser.
 *
 * @since Jxta 0.1
 * @Version $Revision: 1.2 $
 */

public class LiteXMLElement extends TextElementCommon implements Attributable {

    /**
     * A charRange defines a range of characters, probably within a string. The
     * range is deemed to be invalid if 'start' is -1.  A zero length range is,
     * by convention, described by an 'end' value of 'start' - 1.
     */
    //PDA requirements 19.02.2002
    //class java.lang.Comparable did not exist in jdk 1.1.8, it was excluded
    //static protected class charRange implements Comparable {
    static protected class charRange {
    //PDA requirements 19.02.2002

        /**
         *  Contains the start position of this range.
         **/
        public int start;

        /**
         * Contains the end position of this range. one weird thing: if end == start -1,
         * then the item is of zero length begining at start.
         **/
        public int end;

        /**
         * Constructor for a null charRange.
         **/
        public charRange() {
            start = -1;
            end = -1;
        }

        /**
         * Constructor for which the bounds are specified.
         *
         **/
        public charRange( int start, int end ) {
            this.start = start;
            this.end = end;
        }

        /**
         * Returns the length of this range.
         * @return The length of the range or -1 if the range is null.
         **/
        public int length() {
            if( (-1 == start) || (-1 == end) )
                return -1;

            return ( end - start + 1 );
        }

        /**
         * Returns true if the range is both non-null and has a length of greater
         * than or equal to zero.
         *
         * @return true if the range is a valid one, otherwise false.
         *
         **/
        public boolean isValid() {
            return length() >= 0;
        }

        /**
         * Compares two ranges for equality.
         *
         * @param someRange The range against which this range will be compared.
         * @return true if the two ranges are equal, otherwise false.
         *
         */
        public boolean equals( Object aRange ) {
            if (this == aRange)
                return true;

            if( !(aRange instanceof charRange) )
                return false;

            charRange someRange = (charRange) aRange;

            return( (start == someRange.start) &&
            (end == someRange.end) );
        }

        /**
         * Compares two ranges for equality.
         *
         * @param someRange The range against which this range will be compared.
         * @return true if the two ranges are equal, otherwise false.
         *
         */
        public int compareTo(Object aRange) {
            if (this == aRange)
                return 0;

            if( !(aRange instanceof charRange) )
                throw new ClassCastException( "type mismatch error" );

            charRange someRange = (charRange) aRange;

            if( start < someRange.start )
                return -1;

            if( start > someRange.start )
                return 1;

            if( end < someRange.end )
                return -1;

            if( end > someRange.end )
                return 1;

            return 0;
        }

        /**
         * Returns true if the <CODE>charRange</CODE> specified by someRange is
         * contained within this range.
         *
         *
         * @param someRange The range which must be contained within this range.
         *
         * @return true if the specified range is contained with this range otherwise false.
         *
         */
        public boolean contains( charRange someRange ) {
            return( isValid() &&
            someRange.isValid() &&
            ( start <= someRange.start ) &&
            ( end >= someRange.end ) );
        }

        /**
         * Returns true if the <CODE>tagRange</CODE> specified by someRange is
         * contained within this range.
         *
         * @param someRange The range which must be contained within this range.
         *
         * @return true if the specified range is contained with this range otherwise false.
         *
         */
        public boolean contains( tagRange someRange ) {
            return( isValid() &&
            someRange.isValid() &&
            ( start <= someRange.startTag.start ) &&
            ( end >= someRange.endTag.end ) );
        }

        /**
         *  Returns true if the location specified is contained in this range.
         *
         *  @param someLoc the location which is to be tested.
         *  @return true if the location is in this range, otherwise false.
         */
        public boolean contains( int someLoc ) {
            return( isValid() &&
            ( someLoc >= 0 ) &&
            ( start <= someLoc ) &&
            ( end >= someLoc ) );
        }
    }

    /**
     * A tagRange is a collection of char ranges useful for describing XML
     * structures. 'startTag' is the range of the opening tag, ie. <tag>
     * 'endTag' is the range of the terminating tag, ie. </tag>. The 'body'
     * range everything between the start and end tags. For empty-element tags
     * the 'startTag' and 'endTag' will be equal and the 'body' tag will be
     * NULL.
     **/
    //PDA requirements 19.02.2002
    //class java.lang.Comparable did not exist in jdk 1.1.8, it was excluded
    //static protected class tagRange implements Comparable {
    static protected class tagRange {
    //PDA requirements 19.02.2002
        public charRange startTag = null;
        public charRange body = null;
        public charRange endTag = null;

        public tagRange( ) {
            startTag = new charRange();
            body = new charRange();
            endTag = new charRange();
        }

        public tagRange( charRange startTag, charRange body, charRange endTag ) {
            this.startTag = startTag;
            this.body = body;
            this.endTag = endTag;
        }

        public boolean isValid() {
            return (null != startTag) && (null != body) && (null != endTag) &&
            startTag.isValid() && body.isValid() && endTag.isValid();
        }

        public boolean equals( Object aRange ) {
            if (this == aRange)
                return true;

            if( !(aRange instanceof tagRange) )
                return false;

            tagRange someRange = (tagRange) aRange;

            return( startTag.equals(someRange.startTag) &&
            body.equals(someRange.body) &&
            endTag.equals(someRange.endTag) );
        }

        /**
         * Compares two ranges for equality.
         *
         * @param someRange The range against which this range will be compared.
         * @return true if the two ranges are equal, otherwise false.
         *
         */
        public int compareTo(Object aRange) {
            if (this == aRange)
                return 0;

            if( !(aRange instanceof tagRange) )
                throw new ClassCastException( "type mismatch error" );

            tagRange someRange = (tagRange) aRange;

            int compared = startTag.compareTo( someRange.startTag );

            if( 0 != compared )
                return compared;

            return endTag.compareTo( someRange.endTag );
        }

        /**
         * Returns true if the <CODE>tagRange</CODE> specified by someRange is
         * contained within the body portion of this range.
         *
         * @param someRange The range which must be contained within this range.
         *
         * @return true if the specified range is contained with this range
         * otherwise false.
         */
        public boolean contains( tagRange someRange ) {
            return( isValid() &&
            someRange.isValid() &&
            ( body.start <= someRange.startTag.start ) &&
            ( body.end >= someRange.endTag.end ) );
        }

        /**
         * Returns true if the <CODE>charRange</CODE> specified by someRange is
         * contained within the body portion of this range.
         *
         * @param someRange The range which must be contained within this range.
         *
         * @return true if the specified range is contained with this range
         * otherwise false.

⌨️ 快捷键说明

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