deferreddocumentimpl.java

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

JAVA
1,830
字号
        int extra = getChunkIndex(fNodeExtra, chunk, index);        extra = extra | ID;        setChunkIndex(fNodeExtra, extra, chunk, index);    }    /** Inserts a child before the specified node in the table. */    public int insertBefore(int parentIndex, int newChildIndex, int refChildIndex) {        if (refChildIndex == -1) {            appendChild(parentIndex, newChildIndex);            return newChildIndex;        }        int nchunk = newChildIndex >> CHUNK_SHIFT;        int nindex = newChildIndex & CHUNK_MASK;        int rchunk = refChildIndex >> CHUNK_SHIFT;        int rindex = refChildIndex & CHUNK_MASK;        int previousIndex = getChunkIndex(fNodePrevSib, rchunk, rindex);        setChunkIndex(fNodePrevSib, newChildIndex, rchunk, rindex);        setChunkIndex(fNodePrevSib, previousIndex, nchunk, nindex);        return newChildIndex;    } // insertBefore(int,int,int):int    /** Sets the last child of the parentIndex to childIndex. */    public void setAsLastChild(int parentIndex, int childIndex) {        int pchunk = parentIndex >> CHUNK_SHIFT;        int pindex = parentIndex & CHUNK_MASK;        setChunkIndex(fNodeLastChild, childIndex, pchunk, pindex);    } // setAsLastChild(int,int)    /**     * Returns the parent node of the given node.     * <em>Calling this method does not free the parent index.</em>     */    public int getParentNode(int nodeIndex) {        return getParentNode(nodeIndex, false);    }    /**     * Returns the parent node of the given node.     * @param free True to free parent node.     */    public int getParentNode(int nodeIndex, boolean free) {        if (nodeIndex == -1) {            return -1;        }        int chunk = nodeIndex >> CHUNK_SHIFT;        int index = nodeIndex & CHUNK_MASK;        return free ? clearChunkIndex(fNodeParent, chunk, index)                    : getChunkIndex(fNodeParent, chunk, index);    } // getParentNode(int):int    /** Returns the last child of the given node. */    public int getLastChild(int nodeIndex) {        return getLastChild(nodeIndex, true);    }    /**     * Returns the last child of the given node.     * @param free True to free child index.     */    public int getLastChild(int nodeIndex, boolean free) {        if (nodeIndex == -1) {            return -1;        }        int chunk = nodeIndex >> CHUNK_SHIFT;        int index = nodeIndex & CHUNK_MASK;        return free ? clearChunkIndex(fNodeLastChild, chunk, index)                    : getChunkIndex(fNodeLastChild, chunk, index);    } // getLastChild(int,boolean):int    /**     * Returns the prev sibling of the given node.     * This is post-normalization of Text Nodes.     */    public int getPrevSibling(int nodeIndex) {        return getPrevSibling(nodeIndex, true);    }    /**     * Returns the prev sibling of the given node.     * @param free True to free sibling index.     */    public int getPrevSibling(int nodeIndex, boolean free) {        if (nodeIndex == -1) {            return -1;        }        int chunk = nodeIndex >> CHUNK_SHIFT;        int index = nodeIndex & CHUNK_MASK;        int type = getChunkIndex(fNodeType, chunk, index);        if (type == Node.TEXT_NODE) {            do {                nodeIndex = getChunkIndex(fNodePrevSib, chunk, index);                if (nodeIndex == -1) {                    break;                }                chunk = nodeIndex >> CHUNK_SHIFT;                index = nodeIndex & CHUNK_MASK;                type = getChunkIndex(fNodeType, chunk, index);            } while (type == Node.TEXT_NODE);        }        else {            nodeIndex = getChunkIndex(fNodePrevSib, chunk, index);        }        return nodeIndex;    } // getPrevSibling(int,boolean):int    /**     * Returns the <i>real</i> prev sibling of the given node,     * directly from the data structures. Used by TextImpl#getNodeValue()     * to normalize values.     */    public int getRealPrevSibling(int nodeIndex) {        return getRealPrevSibling(nodeIndex, true);    }    /**     * Returns the <i>real</i> prev sibling of the given node.     * @param free True to free sibling index.     */    public int getRealPrevSibling(int nodeIndex, boolean free) {        if (nodeIndex == -1) {            return -1;        }        int chunk = nodeIndex >> CHUNK_SHIFT;        int index = nodeIndex & CHUNK_MASK;        return free ? clearChunkIndex(fNodePrevSib, chunk, index)                    : getChunkIndex(fNodePrevSib, chunk, index);    } // getReadPrevSibling(int,boolean):int    /**     * Returns the index of the element definition in the table     * with the specified name index, or -1 if no such definition     * exists.     */    public int lookupElementDefinition(String elementName) {        if (fNodeCount > 1) {            // find doctype            int docTypeIndex = -1;            int nchunk = 0;            int nindex = 0;            for (int index = getChunkIndex(fNodeLastChild, nchunk, nindex);                 index != -1;                 index = getChunkIndex(fNodePrevSib, nchunk, nindex)) {                nchunk = index >> CHUNK_SHIFT;                nindex = index  & CHUNK_MASK;                if (getChunkIndex(fNodeType, nchunk, nindex) == Node.DOCUMENT_TYPE_NODE) {                    docTypeIndex = index;                    break;                }            }            // find element definition            if (docTypeIndex == -1) {                return -1;            }            nchunk = docTypeIndex >> CHUNK_SHIFT;            nindex = docTypeIndex & CHUNK_MASK;            for (int index = getChunkIndex(fNodeLastChild, nchunk, nindex);                 index != -1;                 index = getChunkIndex(fNodePrevSib, nchunk, nindex)) {                nchunk = index >> CHUNK_SHIFT;                nindex = index & CHUNK_MASK;                if (getChunkIndex(fNodeType, nchunk, nindex) ==                                           NodeImpl.ELEMENT_DEFINITION_NODE                 && getChunkValue(fNodeName, nchunk, nindex) == elementName) {                    return index;                }            }        }        return -1;    } // lookupElementDefinition(String):int    /** Instantiates the requested node object. */    public DeferredNode getNodeObject(int nodeIndex) {        // is there anything to do?        if (nodeIndex == -1) {            return null;        }        // get node type        int chunk = nodeIndex >> CHUNK_SHIFT;        int index = nodeIndex & CHUNK_MASK;        int type = getChunkIndex(fNodeType, chunk, index);        if (type != Node.TEXT_NODE && type != Node.CDATA_SECTION_NODE) {            clearChunkIndex(fNodeType, chunk, index);        }        // create new node        DeferredNode node = null;        switch (type) {            //            // Standard DOM node types            //            case Node.ATTRIBUTE_NODE: {                if (fNamespacesEnabled) {                    node = new DeferredAttrNSImpl(this, nodeIndex);                } else {                    node = new DeferredAttrImpl(this, nodeIndex);                }                break;            }            case Node.CDATA_SECTION_NODE: {                node = new DeferredCDATASectionImpl(this, nodeIndex);                break;            }            case Node.COMMENT_NODE: {                node = new DeferredCommentImpl(this, nodeIndex);                break;            }            // NOTE: Document fragments can never be "fast".            //            //       The parser will never ask to create a document            //       fragment during the parse. Document fragments            //       are used by the application *after* the parse.            //            // case Node.DOCUMENT_FRAGMENT_NODE: { break; }            case Node.DOCUMENT_NODE: {                // this node is never "fast"                node = this;                break;            }            case Node.DOCUMENT_TYPE_NODE: {                node = new DeferredDocumentTypeImpl(this, nodeIndex);                // save the doctype node                docType = (DocumentTypeImpl)node;                break;            }            case Node.ELEMENT_NODE: {                if (DEBUG_IDS) {                    System.out.println("getNodeObject(ELEMENT_NODE): "+nodeIndex);                }                // create node                if (fNamespacesEnabled) {                    node = new DeferredElementNSImpl(this, nodeIndex);                } else {                    node = new DeferredElementImpl(this, nodeIndex);                }                // save the document element node                if (docElement == null) {                    docElement = (ElementImpl)node;                }                // check to see if this element needs to be                // registered for its ID attributes                if (fIdElement != null) {                    int idIndex = binarySearch(fIdElement, 0,                                               fIdCount-1, nodeIndex);                    while (idIndex != -1) {                        if (DEBUG_IDS) {                            System.out.println("  id index: "+idIndex);                            System.out.println("  fIdName["+idIndex+                                               "]: "+fIdName[idIndex]);                        }                        // register ID                        String name = fIdName[idIndex];                        if (name != null) {                            if (DEBUG_IDS) {                                System.out.println("  name: "+name);                                System.out.print("getNodeObject()#");                            }                            putIdentifier0(name, (Element)node);                            fIdName[idIndex] = null;                        }                        // continue if there are more IDs for                        // this element                        if (idIndex + 1 < fIdCount &&                            fIdElement[idIndex + 1] == nodeIndex) {                            idIndex++;                        }                        else {                            idIndex = -1;                        }                    }                }                break;            }            case Node.ENTITY_NODE: {                node = new DeferredEntityImpl(this, nodeIndex);                break;            }            case Node.ENTITY_REFERENCE_NODE: {                node = new DeferredEntityReferenceImpl(this, nodeIndex);                break;            }            case Node.NOTATION_NODE: {                node = new DeferredNotationImpl(this, nodeIndex);                break;            }            case Node.PROCESSING_INSTRUCTION_NODE: {                node = new DeferredProcessingInstructionImpl(this, nodeIndex);                break;            }            case Node.TEXT_NODE: {                node = new DeferredTextImpl(this, nodeIndex);                break;            }            //            // non-standard DOM node types            //            case NodeImpl.ELEMENT_DEFINITION_NODE: {                node = new DeferredElementDefinitionImpl(this, nodeIndex);                break;            }            default: {                throw new IllegalArgumentException("type: "+type);            }        } // switch node type        // store and return        if (node != null) {            return node;        }        // error        throw new IllegalArgumentException();    } // createNodeObject(int):Node    /** Returns the name of the given node. */    public String getNodeName(int nodeIndex) {        return getNodeName(nodeIndex, true);

⌨️ 快捷键说明

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