nodeimpl.java

来自「JAVA 所有包」· Java 代码 · 共 1,687 行 · 第 1/5 页

JAVA
1,687
字号
        throws DOMException    {	throw new DOMException(DOMException.NAMESPACE_ERR,               DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN,                 "NAMESPACE_ERR", null));    }    /**     * Introduced in DOM Level 2. <p>     *     * Returns the local part of the qualified name of this node.     * For nodes created with a DOM Level 1 method, such as createElement     * from the Document interface, and for nodes of any type other than     * ELEMENT_NODE and ATTRIBUTE_NODE this is the same as the nodeName     * attribute.     * @since WD-DOM-Level-2-19990923     * @see AttrNSImpl     * @see ElementNSImpl     */    public String             getLocalName()    {        return null;    }        //    // EventTarget support    //    public void addEventListener(String type, EventListener listener,                                 boolean useCapture) {        // simply forward to Document        ownerDocument().addEventListener(this, type, listener, useCapture);    }    public void removeEventListener(String type, EventListener listener,                                    boolean useCapture) {        // simply forward to Document        ownerDocument().removeEventListener(this, type, listener, useCapture);    }    public boolean dispatchEvent(Event event) {        // simply forward to Document        return ownerDocument().dispatchEvent(this, event);    }    //    // Public DOM Level 3 methods    //    /**     * The absolute base URI of this node or <code>null</code> if undefined.      * This value is computed according to . However, when the      * <code>Document</code> supports the feature "HTML" , the base URI is      * computed using first the value of the href attribute of the HTML BASE      * element if any, and the value of the <code>documentURI</code>      * attribute from the <code>Document</code> interface otherwise.     * <br> When the node is an <code>Element</code>, a <code>Document</code>      * or a a <code>ProcessingInstruction</code>, this attribute represents      * the properties [base URI] defined in . When the node is a      * <code>Notation</code>, an <code>Entity</code>, or an      * <code>EntityReference</code>, this attribute represents the      * properties [declaration base URI] in the . How will this be affected      * by resolution of relative namespace URIs issue?It's not.Should this      * only be on Document, Element, ProcessingInstruction, Entity, and      * Notation nodes, according to the infoset? If not, what is it equal to      * on other nodes? Null? An empty string? I think it should be the      * parent's.No.Should this be read-only and computed or and actual      * read-write attribute?Read-only and computed (F2F 19 Jun 2000 and      * teleconference 30 May 2001).If the base HTML element is not yet      * attached to a document, does the insert change the Document.baseURI?     * Yes. (F2F 26 Sep 2001)     * @since DOM Level 3     */    public String getBaseURI() {        return null;    }    /**     * Compares a node with this node with regard to their position in the      * tree and according to the document order. This order can be extended      * by module that define additional types of nodes.     * @param other The node to compare against this node.     * @return Returns how the given node is positioned relatively to this      *   node.     * @since DOM Level 3     * @deprecated     */    public short compareTreePosition(Node other) {        // Questions of clarification for this method - to be answered by the        // DOM WG.   Current assumptions listed - LM        //         // 1. How do ENTITY nodes compare?          //    Current assumption: TREE_POSITION_DISCONNECTED, as ENTITY nodes         //    aren't really 'in the tree'        //        // 2. How do NOTATION nodes compare?        //    Current assumption: TREE_POSITION_DISCONNECTED, as NOTATION nodes        //    aren't really 'in the tree'        //        // 3. Are TREE_POSITION_ANCESTOR and TREE_POSITION_DESCENDANT             //    only relevant for nodes that are "part of the document tree"?           //     <outer>        //         <inner  myattr="true"/>        //     </outer>        //    Is the element node "outer" considered an ancestor of "myattr"?        //    Current assumption: No.                                             //        // 4. How do children of ATTRIBUTE nodes compare (with eachother, or          //    with children of other attribute nodes with the same element)            //    Current assumption: Children of ATTRIBUTE nodes are treated as if         //    they they are the attribute node itself, unless the 2 nodes         //    are both children of the same attribute.         //        // 5. How does an ENTITY_REFERENCE node compare with it's children?         //    Given the DOM, it should precede its children as an ancestor.         //    Given "document order",  does it represent the same position?             //    Current assumption: An ENTITY_REFERENCE node is an ancestor of its        //    children.        //        // 6. How do children of a DocumentFragment compare?           //    Current assumption: If both nodes are part of the same document         //    fragment, there are compared as if they were part of a document.                 // If the nodes are the same...        if (this==other)           return (TREE_POSITION_SAME_NODE | TREE_POSITION_EQUIVALENT);                // If either node is of type ENTITY or NOTATION, compare as disconnected        short thisType = this.getNodeType();        short otherType = other.getNodeType();        // If either node is of type ENTITY or NOTATION, compare as disconnected        if (thisType == Node.ENTITY_NODE ||             thisType == Node.NOTATION_NODE ||            otherType == Node.ENTITY_NODE ||            otherType == Node.NOTATION_NODE ) {          return TREE_POSITION_DISCONNECTED;         }        // Find the ancestor of each node, and the distance each node is from         // its ancestor.        // During this traversal, look for ancestor/descendent relationships         // between the 2 nodes in question.         // We do this now, so that we get this info correct for attribute nodes         // and their children.         Node node;         Node thisAncestor = this;        Node otherAncestor = other;        int thisDepth=0;        int otherDepth=0;        for (node=this; node != null; node = node.getParentNode()) {            thisDepth +=1;            if (node == other)               // The other node is an ancestor of this one.              return (TREE_POSITION_ANCESTOR | TREE_POSITION_PRECEDING);            thisAncestor = node;        }        for (node=other; node!=null; node=node.getParentNode()) {            otherDepth +=1;            if (node == this)               // The other node is a descendent of the reference node.              return (TREE_POSITION_DESCENDANT | TREE_POSITION_FOLLOWING);            otherAncestor = node;        }                       Node thisNode = this;        Node otherNode = other;        int thisAncestorType = thisAncestor.getNodeType();        int otherAncestorType = otherAncestor.getNodeType();        // if the ancestor is an attribute, get owning element.         // we are now interested in the owner to determine position.        if (thisAncestorType == Node.ATTRIBUTE_NODE)  {           thisNode = ((AttrImpl)thisAncestor).getOwnerElement();        }        if (otherAncestorType == Node.ATTRIBUTE_NODE) {           otherNode = ((AttrImpl)otherAncestor).getOwnerElement();        }        // Before proceeding, we should check if both ancestor nodes turned        // out to be attributes for the same element        if (thisAncestorType == Node.ATTRIBUTE_NODE &&              otherAncestorType == Node.ATTRIBUTE_NODE &&              thisNode==otherNode)                          return TREE_POSITION_EQUIVALENT;        // Now, find the ancestor of the owning element, if the original        // ancestor was an attribute         // Note:  the following 2 loops are quite close to the ones above.        // May want to common them up.  LM.        if (thisAncestorType == Node.ATTRIBUTE_NODE) {            thisDepth=0;            for (node=thisNode; node != null; node=node.getParentNode()) {                thisDepth +=1;                if (node == otherNode)                   // The other node is an ancestor of the owning element                  {                  return TREE_POSITION_PRECEDING;                  }                thisAncestor = node;            }        }        // Now, find the ancestor of the owning element, if the original        // ancestor was an attribute        if (otherAncestorType == Node.ATTRIBUTE_NODE) {            otherDepth=0;            for (node=otherNode; node != null; node=node.getParentNode()) {                otherDepth +=1;                if (node == thisNode)                   // The other node is a descendent of the reference                   // node's element                  return TREE_POSITION_FOLLOWING;                otherAncestor = node;            }        }        // thisAncestor and otherAncestor must be the same at this point,          // otherwise, we are not in the same tree or document fragment        if (thisAncestor != otherAncestor)           return TREE_POSITION_DISCONNECTED;               // Go up the parent chain of the deeper node, until we find a node         // with the same depth as the shallower node        if (thisDepth > otherDepth) {          for (int i=0; i<thisDepth - otherDepth; i++)            thisNode = thisNode.getParentNode();          // Check if the node we have reached is in fact "otherNode". This can          // happen in the case of attributes.  In this case, otherNode           // "precedes" this.          if (thisNode == otherNode)             return TREE_POSITION_PRECEDING;        }         else {          for (int i=0; i<otherDepth - thisDepth; i++)            otherNode = otherNode.getParentNode();          // Check if the node we have reached is in fact "thisNode".  This can          // happen in the case of attributes.  In this case, otherNode           // "follows" this.          if (otherNode == thisNode)             return TREE_POSITION_FOLLOWING;        }                     // We now have nodes at the same depth in the tree.  Find a common         // ancestor.                                           Node thisNodeP, otherNodeP;        for (thisNodeP=thisNode.getParentNode(),                  otherNodeP=otherNode.getParentNode();             thisNodeP!=otherNodeP;) {             thisNode = thisNodeP;             otherNode = otherNodeP;             thisNodeP = thisNodeP.getParentNode();             otherNodeP = otherNodeP.getParentNode();        }        // At this point, thisNode and otherNode are direct children of         // the common ancestor.          // See whether thisNode or otherNode is the leftmost        for (Node current=thisNodeP.getFirstChild();                   current!=null;                  current=current.getNextSibling()) {               if (current==otherNode) {                 return TREE_POSITION_PRECEDING;               }               else if (current==thisNode) {                 return TREE_POSITION_FOLLOWING;               }        }        // REVISIT:  shouldn't get here.   Should probably throw an         // exception        return 0;    }    /**     * Compares a node with this node with regard to their position in the      * document.      * @param other The node to compare against this node.     * @return Returns how the given node is positioned relatively to this      *   node.     * @since DOM Level 3     */    public short compareDocumentPosition(Node other) throws DOMException {        // If the nodes are the same, no flags should be set        if (this==other)           return 0;         // check if other is from a different implementation        try {            NodeImpl node = (NodeImpl) other;        } catch (ClassCastException e) {            // other comes from a different implementation            String msg = DOMMessageFormatter.formatMessage(               DOMMessageFormatter.DOM_DOMAIN, "NOT_SUPPORTED_ERR", null);            throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);        }        Document thisOwnerDoc, otherOwnerDoc;        // get the respective Document owners.          if (this.getNodeType() == Node.DOCUMENT_NODE)           thisOwnerDoc = (Document)this;        else          thisOwnerDoc = this.getOwnerDocument();        if (other.getNodeType() == Node.DOCUMENT_NODE)           otherOwnerDoc = (Document)other;        else          otherOwnerDoc = other.getOwnerDocument();        // If from different documents, we know they are disconnected.         // and have an implementation dependent order         if (thisOwnerDoc != otherOwnerDoc &&             thisOwnerDoc !=null &&             otherOwnerDoc !=null)  {          int otherDocNum = ((CoreDocumentImpl)otherOwnerDoc).getNodeNumber();          int thisDocNum = ((CoreDocumentImpl)thisOwnerDoc).getNodeNumber();          if (otherDocNum > thisDocNum)              return DOCUMENT_POSITION_DISCONNECTED |                    DOCUMENT_POSITION_FOLLOWING |                    DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC;          else            return DOCUMENT_POSITION_DISCONNECTED |                    DOCUMENT_POSITION_PRECEDING |                    DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC;                          }     

⌨️ 快捷键说明

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