xmlentityscanner.java

来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 1,660 行 · 第 1/5 页

JAVA
1,660
字号
     * <strong>Note:</strong> This method does not guarantee to return     * the longest run of parsed character data. This method may return     * before markup due to reaching the end of the input buffer or any     * other reason.     * <p>     * <strong>Note:</strong> The fields contained in the XMLString     * structure are not guaranteed to remain valid upon subsequent calls     * to the entity scanner. Therefore, the caller is responsible for     * immediately using the returned character data or making a copy of     * the character data.     *     * @param content The content structure to fill.     *     * @return Returns the next character on the input, if known. This     *         value may be -1 but this does <em>note</em> designate     *         end of file.     *     * @throws IOException  Thrown if i/o error occurs.     * @throws EOFException Thrown on end of file.     */    public int scanContent(XMLString content) throws IOException {        if (DEBUG_BUFFER) {            System.out.print("(scanContent: ");            XMLEntityManager.print(fCurrentEntity);            System.out.println();        }        // load more characters, if needed        if (fCurrentEntity.position == fCurrentEntity.count) {            load(0, true);        }        else if (fCurrentEntity.position == fCurrentEntity.count - 1) {            fCurrentEntity.ch[0] = fCurrentEntity.ch[fCurrentEntity.count - 1];            load(1, false);            fCurrentEntity.position = 0;        }        // normalize newlines        int offset = fCurrentEntity.position;        int c = fCurrentEntity.ch[offset];        int newlines = 0;        boolean external = fCurrentEntity.isExternal();        if (c == '\n' || (c == '\r' && external)) {            if (DEBUG_BUFFER) {                System.out.print("[newline, "+offset+", "+fCurrentEntity.position+": ");                XMLEntityManager.print(fCurrentEntity);                System.out.println();            }            do {                c = fCurrentEntity.ch[fCurrentEntity.position++];                if (c == '\r' && external) {                    newlines++;                    fCurrentEntity.lineNumber++;                    fCurrentEntity.columnNumber = 1;                    if (fCurrentEntity.position == fCurrentEntity.count) {                        offset = 0;                        fCurrentEntity.position = newlines;                        if (load(newlines, false)) {                            break;                        }                    }                    if (fCurrentEntity.ch[fCurrentEntity.position] == '\n') {                        fCurrentEntity.position++;                        offset++;                    }                    /*** NEWLINE NORMALIZATION ***/                    else {                        newlines++;                    }                }                else if (c == '\n') {                    newlines++;                    fCurrentEntity.lineNumber++;                    fCurrentEntity.columnNumber = 1;                    if (fCurrentEntity.position == fCurrentEntity.count) {                        offset = 0;                        fCurrentEntity.position = newlines;                        if (load(newlines, false)) {                            break;                        }                    }                }                else {                    fCurrentEntity.position--;                    break;                }            } while (fCurrentEntity.position < fCurrentEntity.count - 1);            for (int i = offset; i < fCurrentEntity.position; i++) {                fCurrentEntity.ch[i] = '\n';            }            int length = fCurrentEntity.position - offset;            if (fCurrentEntity.position == fCurrentEntity.count - 1) {                content.setValues(fCurrentEntity.ch, offset, length);                if (DEBUG_BUFFER) {                    System.out.print("]newline, "+offset+", "+fCurrentEntity.position+": ");                    XMLEntityManager.print(fCurrentEntity);                    System.out.println();                }                return -1;            }            if (DEBUG_BUFFER) {                System.out.print("]newline, "+offset+", "+fCurrentEntity.position+": ");                XMLEntityManager.print(fCurrentEntity);                System.out.println();            }        }        // inner loop, scanning for content        while (fCurrentEntity.position < fCurrentEntity.count) {            c = fCurrentEntity.ch[fCurrentEntity.position++];            if (!XMLChar.isContent(c)) {                fCurrentEntity.position--;                break;            }        }        int length = fCurrentEntity.position - offset;        fCurrentEntity.columnNumber += length - newlines;        content.setValues(fCurrentEntity.ch, offset, length);        // return next character        if (fCurrentEntity.position != fCurrentEntity.count) {            c = fCurrentEntity.ch[fCurrentEntity.position];            // REVISIT: Does this need to be updated to fix the            //          #x0D ^#x0A newline normalization problem? -Ac            if (c == '\r' && external) {                c = '\n';            }        }        else {            c = -1;        }        if (DEBUG_BUFFER) {            System.out.print(")scanContent: ");            XMLEntityManager.print(fCurrentEntity);            System.out.println(" -> '"+(char)c+"'");        }        return c;    } // scanContent(XMLString):int    /**     * Scans a range of attribute value data, setting the fields of the     * XMLString structure, appropriately.     * <p>     * <strong>Note:</strong> The characters are consumed.     * <p>     * <strong>Note:</strong> This method does not guarantee to return     * the longest run of attribute value data. This method may return     * before the quote character due to reaching the end of the input     * buffer or any other reason.     * <p>     * <strong>Note:</strong> The fields contained in the XMLString     * structure are not guaranteed to remain valid upon subsequent calls     * to the entity scanner. Therefore, the caller is responsible for     * immediately using the returned character data or making a copy of     * the character data.     *     * @param quote   The quote character that signifies the end of the     *                attribute value data.     * @param content The content structure to fill.     *     * @return Returns the next character on the input, if known. This     *         value may be -1 but this does <em>note</em> designate     *         end of file.     *     * @throws IOException  Thrown if i/o error occurs.     * @throws EOFException Thrown on end of file.     */    public int scanLiteral(int quote, XMLString content)        throws IOException {        if (DEBUG_BUFFER) {            System.out.print("(scanLiteral, '"+(char)quote+"': ");            XMLEntityManager.print(fCurrentEntity);            System.out.println();        }        // load more characters, if needed        if (fCurrentEntity.position == fCurrentEntity.count) {            load(0, true);        }        else if (fCurrentEntity.position == fCurrentEntity.count - 1) {            fCurrentEntity.ch[0] = fCurrentEntity.ch[fCurrentEntity.count - 1];            load(1, false);            fCurrentEntity.position = 0;        }        // normalize newlines        int offset = fCurrentEntity.position;        int c = fCurrentEntity.ch[offset];        int newlines = 0;        boolean external = fCurrentEntity.isExternal();        if (c == '\n' || (c == '\r' && external)) {            if (DEBUG_BUFFER) {                System.out.print("[newline, "+offset+", "+fCurrentEntity.position+": ");                XMLEntityManager.print(fCurrentEntity);                System.out.println();            }            do {                c = fCurrentEntity.ch[fCurrentEntity.position++];                if (c == '\r' && external) {                    newlines++;                    fCurrentEntity.lineNumber++;                    fCurrentEntity.columnNumber = 1;                    if (fCurrentEntity.position == fCurrentEntity.count) {                        offset = 0;                        fCurrentEntity.position = newlines;                        if (load(newlines, false)) {                            break;                        }                    }                    if (fCurrentEntity.ch[fCurrentEntity.position] == '\n') {                        fCurrentEntity.position++;                        offset++;                    }                    /*** NEWLINE NORMALIZATION ***/                    else {                        newlines++;                    }                    /***/                }                else if (c == '\n') {                    newlines++;                    fCurrentEntity.lineNumber++;                    fCurrentEntity.columnNumber = 1;                    if (fCurrentEntity.position == fCurrentEntity.count) {                        offset = 0;                        fCurrentEntity.position = newlines;                        if (load(newlines, false)) {                            break;                        }                    }                }                else {                    fCurrentEntity.position--;                    break;                }            } while (fCurrentEntity.position < fCurrentEntity.count - 1);            for (int i = offset; i < fCurrentEntity.position; i++) {                fCurrentEntity.ch[i] = '\n';            }            int length = fCurrentEntity.position - offset;            if (fCurrentEntity.position == fCurrentEntity.count - 1) {                content.setValues(fCurrentEntity.ch, offset, length);                if (DEBUG_BUFFER) {                    System.out.print("]newline, "+offset+", "+fCurrentEntity.position+": ");                    XMLEntityManager.print(fCurrentEntity);                    System.out.println();                }                return -1;            }            if (DEBUG_BUFFER) {                System.out.print("]newline, "+offset+", "+fCurrentEntity.position+": ");                XMLEntityManager.print(fCurrentEntity);                System.out.println();            }        }        // scan literal value        while (fCurrentEntity.position < fCurrentEntity.count) {            c = fCurrentEntity.ch[fCurrentEntity.position++];            if ((c == quote &&                 (!fCurrentEntity.literal || external))                || c == '%' || !XMLChar.isContent(c)) {                fCurrentEntity.position--;                break;            }        }        int length = fCurrentEntity.position - offset;        fCurrentEntity.columnNumber += length - newlines;        content.setValues(fCurrentEntity.ch, offset, length);        // return next character        if (fCurrentEntity.position != fCurrentEntity.count) {            c = fCurrentEntity.ch[fCurrentEntity.position];            // NOTE: We don't want to accidentally signal the            //       end of the literal if we're expanding an            //       entity appearing in the literal. -Ac            if (c == quote && fCurrentEntity.literal) {                c = -1;            }        }        else {            c = -1;        }        if (DEBUG_BUFFER) {            System.out.print(")scanLiteral, '"+(char)quote+"': ");            XMLEntityManager.print(fCurrentEntity);            System.out.println(" -> '"+(char)c+"'");        }        return c;    } // scanLiteral(int,XMLString):int    /**     * Scans a range of character data up to the specified delimiter,     * setting the fields of the XMLString structure, appropriately.     * <p>     * <strong>Note:</strong> The characters are consumed.     * <p>     * <strong>Note:</strong> This assumes that the internal buffer is     * at least the same size, or bigger, than the length of the delimiter     * and that the delimiter contains at least one character.     * <p>     * <strong>Note:</strong> This method does not guarantee to return     * the longest run of character data. This method may return before     * the delimiter due to reaching the end of the input buffer or any     * other reason.     * <p>     * <strong>Note:</strong> The fields contained in the XMLString     * structure are not guaranteed to remain valid upon subsequent calls     * to the entity scanner. Therefore, the caller is responsible for     * immediately using the returned character data or making a copy of     * the character data.     *     * @param delimiter The string that signifies the end of the character     *                  data to be scanned.     * @param data      The data structure to fill.     *     * @return Returns true if there is more data to scan, false otherwise.     *     * @throws IOException  Thrown if i/o error occurs.     * @throws EOFException Thrown on end of file.     */    public boolean scanData(String delimiter, XMLStringBuffer buffer)        throws IOException {        // REVISIT: This method does not need to use a string buffer.        //          The change would avoid the array copies and increase        //          performance. -Ac        //        //          Currently, this method is called for scanning CDATA        //          sections, comments,  and processing instruction data. 

⌨️ 快捷键说明

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