deferreddocumentimpl.java

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

JAVA
1,830
字号
    } // getNodeNameString(int):String    /**     * Returns the name of the given node.     * @param free True to free the string index.     */    public String getNodeName(int nodeIndex, boolean free) {        if (nodeIndex == -1) {            return null;        }        int chunk = nodeIndex >> CHUNK_SHIFT;        int index = nodeIndex & CHUNK_MASK;        return free ? clearChunkValue(fNodeName, chunk, index)                    : getChunkValue(fNodeName, chunk, index);    } // getNodeName(int,boolean):String    /** Returns the real value of the given node. */    public String getNodeValueString(int nodeIndex) {        return getNodeValueString(nodeIndex, true);    } // getNodeValueString(int):String    /**     * Returns the real value of the given node.     * @param free True to free the string index.     */    public String getNodeValueString(int nodeIndex, boolean free) {        if (nodeIndex == -1) {            return null;        }                int chunk = nodeIndex >> CHUNK_SHIFT;        int index = nodeIndex & CHUNK_MASK;        String value = free ? clearChunkValue(fNodeValue, chunk, index)                            : getChunkValue(fNodeValue, chunk, index);        if (value == null) {            return null;        }                int type  = getChunkIndex(fNodeType, chunk, index);        if (type == Node.TEXT_NODE) {            int prevSib = getRealPrevSibling(nodeIndex);            if (prevSib != -1 &&                getNodeType(prevSib, false) == Node.TEXT_NODE) {                // append data that is stored in fNodeValue                // REVISIT: for text nodes it works differently than for CDATA                //          nodes.                fStrChunks.addElement(value);                do {                    // go in reverse order: find last child, then                    // its previous sibling, etc                    chunk = prevSib >> CHUNK_SHIFT;                    index = prevSib & CHUNK_MASK;                    value = getChunkValue(fNodeValue, chunk, index);                    fStrChunks.addElement(value);                    prevSib = getChunkIndex(fNodePrevSib, chunk, index);                    if (prevSib == -1) {                        break;                    }                } while (getNodeType(prevSib, false) == Node.TEXT_NODE);                                int chunkCount = fStrChunks.size();                // add to the buffer in the correct order.                for (int i = chunkCount - 1; i >= 0; i--) {                                                                                   fBufferStr.append((String)fStrChunks.elementAt(i));                }                                value = fBufferStr.toString();                fStrChunks.removeAllElements();                fBufferStr.setLength(0);                return value;            }        }        else if (type == Node.CDATA_SECTION_NODE) {            // find if any other data stored in children            int child = getLastChild(nodeIndex, false);            if (child !=-1) {                // append data that is stored in fNodeValue                fBufferStr.append(value);                while (child !=-1) {                    // go in reverse order: find last child, then                    // its previous sibling, etc                   chunk = child >> CHUNK_SHIFT;                    index = child & CHUNK_MASK;                    value = getChunkValue(fNodeValue, chunk, index);                    fStrChunks.addElement(value);                    child = getChunkIndex(fNodePrevSib, chunk, index);                }                // add to the buffer in the correct order.                for (int i=fStrChunks.size()-1; i>=0; i--) {                                                                                    fBufferStr.append((String)fStrChunks.elementAt(i));                }                                                                         value = fBufferStr.toString();                fStrChunks.setSize(0);                fBufferStr.setLength(0);                return value;            }        }        return value;    } // getNodeValueString(int,boolean):String    /**     * Returns the value of the given node.     */    public String getNodeValue(int nodeIndex) {        return getNodeValue(nodeIndex, true);    }    	/**	 * Clears the type info that is stored in the fNodeValue array	 * @param nodeIndex	 * @return Object - type information for the attribute/element node	 */    public Object getTypeInfo(int nodeIndex) {        if (nodeIndex == -1) {            return null;        }        int chunk = nodeIndex >> CHUNK_SHIFT;        int index = nodeIndex & CHUNK_MASK;                        Object value = fNodeValue[chunk] != null ? fNodeValue[chunk][index] : null;        if (value != null) {            fNodeValue[chunk][index] = null;            RefCount c = (RefCount) fNodeValue[chunk][CHUNK_SIZE];            c.fCount--;            if (c.fCount == 0) {                fNodeValue[chunk] = null;            }        }        return value;    }    /**     * Returns the value of the given node.     * @param free True to free the value index.     */    public String getNodeValue(int nodeIndex, boolean free) {        if (nodeIndex == -1) {            return null;        }        int chunk = nodeIndex >> CHUNK_SHIFT;        int index = nodeIndex & CHUNK_MASK;        return free ? clearChunkValue(fNodeValue, chunk, index)                    : getChunkValue(fNodeValue, chunk, index);    } // getNodeValue(int,boolean):String    /**     * Returns the extra info of the given node.     * Used by AttrImpl to store specified value (1 == true).     */    public int getNodeExtra(int nodeIndex) {        return getNodeExtra(nodeIndex, true);    }    /**     * Returns the extra info of the given node.     * @param free True to free the value index.     */    public int getNodeExtra(int nodeIndex, boolean free) {        if (nodeIndex == -1) {            return -1;        }        int chunk = nodeIndex >> CHUNK_SHIFT;        int index = nodeIndex & CHUNK_MASK;        return free ? clearChunkIndex(fNodeExtra, chunk, index)                    : getChunkIndex(fNodeExtra, chunk, index);    } // getNodeExtra(int,boolean):int    /** Returns the type of the given node. */    public short getNodeType(int nodeIndex) {        return getNodeType(nodeIndex, true);    }    /**     * Returns the type of the given node.     * @param free True to free type index.     */    public short getNodeType(int nodeIndex, boolean free) {        if (nodeIndex == -1) {            return -1;        }        int chunk = nodeIndex >> CHUNK_SHIFT;        int index = nodeIndex & CHUNK_MASK;        return free ? (short)clearChunkIndex(fNodeType, chunk, index)                    : (short)getChunkIndex(fNodeType, chunk, index);    } // getNodeType(int):int    /** Returns the attribute value of the given name. */    public String getAttribute(int elemIndex, String name) {        if (elemIndex == -1 || name == null) {            return null;        }        int echunk = elemIndex >> CHUNK_SHIFT;        int eindex = elemIndex & CHUNK_MASK;        int attrIndex = getChunkIndex(fNodeExtra, echunk, eindex);        while (attrIndex != -1) {            int achunk = attrIndex >> CHUNK_SHIFT;            int aindex = attrIndex & CHUNK_MASK;            if (getChunkValue(fNodeName, achunk, aindex) == name) {                return getChunkValue(fNodeValue, achunk, aindex);            }            attrIndex = getChunkIndex(fNodePrevSib, achunk, aindex);        }        return null;    }    /** Returns the URI of the given node. */    public String getNodeURI(int nodeIndex) {        return getNodeURI(nodeIndex, true);    }    /**     * Returns the URI of the given node.     * @param free True to free URI index.     */    public String getNodeURI(int nodeIndex, boolean free) {        if (nodeIndex == -1) {            return null;        }        int chunk = nodeIndex >> CHUNK_SHIFT;        int index = nodeIndex & CHUNK_MASK;        return free ? clearChunkValue(fNodeURI, chunk, index)                    : getChunkValue(fNodeURI, chunk, index);    } // getNodeURI(int,int):String    // identifier maintenance    /** Registers an identifier name with a specified element node. */    public void putIdentifier(String name, int elementNodeIndex) {        if (DEBUG_IDS) {            System.out.println("putIdentifier(" + name + ", "                               + elementNodeIndex + ')' + " // " +                               getChunkValue(fNodeName,                                             elementNodeIndex >> CHUNK_SHIFT,                                             elementNodeIndex & CHUNK_MASK));        }        // initialize arrays        if (fIdName == null) {            fIdName    = new String[64];            fIdElement = new int[64];        }        // resize arrays        if (fIdCount == fIdName.length) {            String idName[] = new String[fIdCount * 2];            System.arraycopy(fIdName, 0, idName, 0, fIdCount);            fIdName = idName;            int idElement[] = new int[idName.length];            System.arraycopy(fIdElement, 0, idElement, 0, fIdCount);            fIdElement = idElement;        }        // store identifier        fIdName[fIdCount] = name;        fIdElement[fIdCount] = elementNodeIndex;        fIdCount++;    } // putIdentifier(String,int)    //    // DEBUG    //    /** Prints out the tables. */    public void print() {        if (DEBUG_PRINT_REF_COUNTS) {            System.out.print("num\t");            System.out.print("type\t");            System.out.print("name\t");            System.out.print("val\t");            System.out.print("par\t");            System.out.print("lch\t");            System.out.print("psib");            System.out.println();            for (int i = 0; i < fNodeType.length; i++) {                if (fNodeType[i] != null) {                    // separator                    System.out.print("--------");                    System.out.print("--------");                    System.out.print("--------");                    System.out.print("--------");                    System.out.print("--------");                    System.out.print("--------");                    System.out.print("--------");                    System.out.println();                    // ref count                    System.out.print(i);                    System.out.print('\t');                    switch (fNodeType[i][CHUNK_SIZE]) {                        case DocumentImpl.ELEMENT_DEFINITION_NODE: { System.out.print("EDef"); break; }                        case Node.DOCUMENT_NODE: { System.out.print("Doc"); break; }                        case Node.DOCUMENT_TYPE_NODE: { System.out.print("DType"); break; }                        case Node.COMMENT_NODE: { System.out.print("Com"); break; }                        case Node.PROCESSING_INSTRUCTION_NODE: { System.out.print("PI"); break; }                        case Node.ELEMENT_NODE: { System.out.print("Elem"); break; }                        case Node.ENTITY_NODE: { System.out.print("Ent"); break; }                        case Node.ENTITY_REFERENCE_NODE: { System.out.print("ERef"); break; }                        case Node.TEXT_NODE: { System.out.print("Text"); break; }                        case Node.ATTRIBUTE_NODE: { System.out.print("Attr"); break; }                        case DeferredNode.TYPE_NODE: { System.out.print("TypeInfo"); break; }                        default: { System.out.print("?"+fNodeType[i][CHUNK_SIZE]); }                    }                    System.out.print('\t');                    System.out.print(fNodeName[i][CHUNK_SIZE]);                    System.out.print('\t');                    System.out.print(fNodeValue[i][CHUNK_SIZE]);                    System.out.print('\t');                    System.out.print(fNodeURI[i][CHUNK_SIZE]);                    System.out.print('\t');                    System.out.print(fNodeParent[i][CHUNK_SIZE]);                    System.out.print('\t');                    System.out.print(fNodeLastChild[i][CHUNK_SIZE]);                    System.out.print('\t');                    System.out.print(fNodePrevSib[i][CHUNK_SIZE]);                    System.out.print('\t');                    System.out.print(fNodeExtra[i][CHUNK_SIZE]);                    System.out.println();                }            }        }        if (DEBUG_PRINT_TABLES) {            // This assumes that the document is small            System.out.println("# start table");            for (int i = 0; i < fNodeCount; i++) {                int chunk = i >> CHUNK_SHIFT;                int index = i & CHUNK_MASK;                if (i % 10 == 0) {                    System.out.print("num\t");                    System.out.print("type\t");                    System.out.print("name\t");                    System.out.print("val\t");                    System.out.print("uri\t");                    System.out.print("par\t");                    System.out.print("lch\t");                    System.out.print("psib\t");                    System.out.print("xtra");                    System.out.println();                }                System.out.print(i);

⌨️ 快捷键说明

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