xml11entityscanner.java

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

JAVA
1,469
字号
                }            }            else {                break;            }        }        while (true);                int length = fCurrentEntity.position - offset;        fCurrentEntity.columnNumber += length;                if (length > 0) {            String prefix = null;            String localpart = null;            String rawname = fSymbolTable.addSymbol(fCurrentEntity.ch,                                                    offset, length);            if (index != -1) {                int prefixLength = index - offset;                prefix = fSymbolTable.addSymbol(fCurrentEntity.ch,                                                    offset, prefixLength);                int len = length - prefixLength - 1;                int startLocal = index +1;                if (!XML11Char.isXML11NCNameStart(fCurrentEntity.ch[startLocal]) &&                    (!XML11Char.isXML11NameHighSurrogate(fCurrentEntity.ch[startLocal]) ||                    sawIncompleteSurrogatePair)){                    fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,                                               "IllegalQName",                                               null,                                               XMLErrorReporter.SEVERITY_FATAL_ERROR);                }                localpart = fSymbolTable.addSymbol(fCurrentEntity.ch,                                                   index + 1, len);            }            else {                localpart = rawname;            }            qname.setValues(prefix, localpart, rawname, null);            return true;        }        return false;    } // scanQName(QName):boolean    /**     * Scans a range of parsed character 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 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 {        // 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' || c == 0x85 || c == 0x2028) && external)) {            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;                        }                    }                    int cc = fCurrentEntity.ch[fCurrentEntity.position];                     if (cc == '\n' || cc == 0x85) {                        fCurrentEntity.position++;                        offset++;                    }                    /*** NEWLINE NORMALIZATION ***/                    else {                        newlines++;                    }                }                else if (c == '\n' || ((c == 0x85 || c == 0x2028) && external)) {                    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);                return -1;            }        }        // inner loop, scanning for content        if (external) {            while (fCurrentEntity.position < fCurrentEntity.count) {                c = fCurrentEntity.ch[fCurrentEntity.position++];                if (!XML11Char.isXML11Content(c) || c == 0x85 || c == 0x2028) {                    fCurrentEntity.position--;                    break;                }            }        }        else {            while (fCurrentEntity.position < fCurrentEntity.count) {                c = fCurrentEntity.ch[fCurrentEntity.position++];                // In internal entities control characters are allowed to appear unescaped.                if (!XML11Char.isXML11InternalEntityContent(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' || c == 0x85 || c == 0x2028) && external) {                c = '\n';            }        }        else {            c = -1;        }        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 {        // 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' || c == 0x85 || c == 0x2028) && external)) {            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;                        }                    }                    int cc = fCurrentEntity.ch[fCurrentEntity.position];                     if (cc == '\n' || cc == 0x85) {                        fCurrentEntity.position++;                        offset++;                    }                    /*** NEWLINE NORMALIZATION ***/                    else {                        newlines++;                    }                }                else if (c == '\n' || ((c == 0x85 || c == 0x2028) && external)) {                    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);                return -1;            }        }        // scan literal value        if (external) {            while (fCurrentEntity.position < fCurrentEntity.count) {                c = fCurrentEntity.ch[fCurrentEntity.position++];                if (c == quote || c == '%' || !XML11Char.isXML11Content(c)                     || c == 0x85 || c == 0x2028) {                    fCurrentEntity.position--;                    break;                }            }        }        else {            while (fCurrentEntity.position < fCurrentEntity.count) {                c = fCurrentEntity.ch[fCurrentEntity.position++];                // In internal entities control characters are allowed to appear unescaped.                if ((c == quote && !fCurrentEntity.literal)                    || c == '%' || !XML11Char.isXML11InternalEntityContent(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;        }        return c;    } // scanLiteral(int,XMLString):int    /**     * Scans a range of character data up to the specicied 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 {        boolean done = false;        int delimLen = delimiter.length();        char charAt0 = delimiter.charAt(0);        boolean external = fCurrentEntity.isExternal();        do {            // load more characters, if needed             if (fCurrentEntity.position == fCurrentEntity.count) {                load(0, true);            }            boolean bNextEntity = false;            while ((fCurrentEntity.position >= fCurrentEntity.count - delimLen)                && (!bNextEntity))            {              System.arraycopy(fCurrentEntity.ch,                               fCurrentEntity.position,

⌨️ 快捷键说明

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