xmldtdscannerimpl.java

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

JAVA
1,765
字号
     * <p>     * <strong>Note:</strong> Called after scanning past '&lt;!ENTITY'     */    private final void scanEntityDecl() throws IOException, XNIException {        boolean isPEDecl = false;        boolean sawPERef = false;        fReportEntity = false;        if (fEntityScanner.skipSpaces()) {            if (!fEntityScanner.skipChar('%')) {                isPEDecl = false; // <!ENTITY x "x">            }            else if (skipSeparator(true, !scanningInternalSubset())) {                // <!ENTITY % x "x">                isPEDecl = true;            }            else if (scanningInternalSubset()) {                reportFatalError("MSG_SPACE_REQUIRED_BEFORE_ENTITY_NAME_IN_ENTITYDECL",                                 null);                isPEDecl = true;            }            else if (fEntityScanner.peekChar() == '%') {                // <!ENTITY %%x; "x"> is legal                skipSeparator(false, !scanningInternalSubset());                isPEDecl = true;            }            else {                sawPERef = true;            }        }        else if (scanningInternalSubset() || !fEntityScanner.skipChar('%')) {            // <!ENTITY[^ ]...> or <!ENTITY[^ %]...>            reportFatalError("MSG_SPACE_REQUIRED_BEFORE_ENTITY_NAME_IN_ENTITYDECL",                             null);            isPEDecl = false;        }        else if (fEntityScanner.skipSpaces()) {            // <!ENTITY% ...>            reportFatalError("MSG_SPACE_REQUIRED_BEFORE_PERCENT_IN_PEDECL",                             null);            isPEDecl = false;        }        else {            sawPERef = true;        }        if (sawPERef) {            while (true) {                String peName = fEntityScanner.scanName();                if (peName == null) {                    reportFatalError("NameRequiredInPEReference", null);                }                else if (!fEntityScanner.skipChar(';')) {                    reportFatalError("SemicolonRequiredInPEReference",                                     new Object[]{peName});                }                else {                    startPE(peName, false);                }                fEntityScanner.skipSpaces();                if (!fEntityScanner.skipChar('%'))                    break;                if (!isPEDecl) {                    if (skipSeparator(true, !scanningInternalSubset())) {                        isPEDecl = true;                        break;                    }                    isPEDecl = fEntityScanner.skipChar('%');                }            }        }        // name        String name = null;        if(fNamespaces) {            name = fEntityScanner.scanNCName();        } else {             name = fEntityScanner.scanName();        }        if (name == null) {            reportFatalError("MSG_ENTITY_NAME_REQUIRED_IN_ENTITYDECL", null);        }        // spaces        if (!skipSeparator(true, !scanningInternalSubset())) {            if(fNamespaces && fEntityScanner.peekChar() == ':') {                fEntityScanner.scanChar();                XMLStringBuffer colonName = new XMLStringBuffer(name);                colonName.append(":");                String str = fEntityScanner.scanName();                if (str != null)                    colonName.append(str);                reportFatalError("ColonNotLegalWithNS", new Object[] {colonName.toString()});                if (!skipSeparator(true, !scanningInternalSubset())) {                    reportFatalError("MSG_SPACE_REQUIRED_AFTER_ENTITY_NAME_IN_ENTITYDECL",                             new Object[]{name});                }            } else {                reportFatalError("MSG_SPACE_REQUIRED_AFTER_ENTITY_NAME_IN_ENTITYDECL",                             new Object[]{name});            }        }        // external id        scanExternalID(fStrings, false);        String systemId = fStrings[0];        String publicId = fStrings[1];        if (isPEDecl && systemId != null) {            fSeenExternalPE = true;        }        String notation = null;        // NDATA        boolean sawSpace = skipSeparator(true, !scanningInternalSubset());        if (!isPEDecl && fEntityScanner.skipString("NDATA")) {            // check whether there was space before NDATA            if (!sawSpace) {                reportFatalError("MSG_SPACE_REQUIRED_BEFORE_NDATA_IN_UNPARSED_ENTITYDECL",                                 new Object[]{name});            }            // spaces            if (!skipSeparator(true, !scanningInternalSubset())) {                reportFatalError("MSG_SPACE_REQUIRED_BEFORE_NOTATION_NAME_IN_UNPARSED_ENTITYDECL",                                 new Object[]{name});            }            notation = fEntityScanner.scanName();            if (notation == null) {                reportFatalError("MSG_NOTATION_NAME_REQUIRED_FOR_UNPARSED_ENTITYDECL",                                 new Object[]{name});            }        }        // internal entity        if (systemId == null) {            scanEntityValue(fLiteral, fLiteral2);            // since we need it's value anyway, let's snag it so it doesn't get corrupted             // if a new load takes place before we store the entity values            fStringBuffer.clear();            fStringBuffer2.clear();            fStringBuffer.append(fLiteral.ch, fLiteral.offset, fLiteral.length);            fStringBuffer2.append(fLiteral2.ch, fLiteral2.offset, fLiteral2.length);        }        // skip possible trailing space        skipSeparator(false, !scanningInternalSubset());        // end        if (!fEntityScanner.skipChar('>')) {            reportFatalError("EntityDeclUnterminated", new Object[]{name});        }        fMarkUpDepth--;        // register entity and make callback        if (isPEDecl) {            name = "%" + name;        }        if (systemId != null) {            String baseSystemId = fEntityScanner.getBaseSystemId();            if (notation != null) {                fEntityManager.addUnparsedEntity(name, publicId, systemId, baseSystemId, notation);            }            else {                fEntityManager.addExternalEntity(name, publicId, systemId,                                                  baseSystemId);            }            if (fDTDHandler != null) {                fResourceIdentifier.setValues(publicId, systemId, baseSystemId, XMLEntityManager.expandSystemId(systemId, baseSystemId, false));                if (notation != null) {                    fDTDHandler.unparsedEntityDecl(name, fResourceIdentifier,                                                    notation, null);                }                else {                    fDTDHandler.externalEntityDecl(name, fResourceIdentifier, null);                }            }        }        else {            fEntityManager.addInternalEntity(name, fStringBuffer.toString());            if (fDTDHandler != null) {                fDTDHandler.internalEntityDecl(name, fStringBuffer, fStringBuffer2, null);             }        }        fReportEntity = true;    } // scanEntityDecl()    /**     * Scans an entity value.     *     * @param value The string to fill in with the value.     * @param nonNormalizedValue The string to fill in with the      *                           non-normalized value.     *     * <strong>Note:</strong> This method uses fString, fStringBuffer (through     * the use of scanCharReferenceValue), and fStringBuffer2, anything in them     * at the time of calling is lost.     */    protected final void scanEntityValue(XMLString value,                                          XMLString nonNormalizedValue)        throws IOException, XNIException    {        int quote = fEntityScanner.scanChar();        if (quote != '\'' && quote != '"') {            reportFatalError("OpenQuoteMissingInDecl", null);        }        // store at which depth of entities we start        int entityDepth = fEntityDepth;        XMLString literal = fString;        XMLString literal2 = fString;        if (fEntityScanner.scanLiteral(quote, fString) != quote) {            fStringBuffer.clear();            fStringBuffer2.clear();            do {                fStringBuffer.append(fString);                fStringBuffer2.append(fString);                if (fEntityScanner.skipChar('&')) {                    if (fEntityScanner.skipChar('#')) {                        fStringBuffer2.append("&#");                        scanCharReferenceValue(fStringBuffer, fStringBuffer2);                    }                    else {                        fStringBuffer.append('&');                        fStringBuffer2.append('&');                        String eName = fEntityScanner.scanName();                        if (eName == null) {                            reportFatalError("NameRequiredInReference",                                             null);                        }                        else {                            fStringBuffer.append(eName);                            fStringBuffer2.append(eName);                        }                        if (!fEntityScanner.skipChar(';')) {                            reportFatalError("SemicolonRequiredInReference",                                             new Object[]{eName});                        }                        else {                            fStringBuffer.append(';');                            fStringBuffer2.append(';');                        }                    }                }                else if (fEntityScanner.skipChar('%')) {                    while (true) {                        fStringBuffer2.append('%');                        String peName = fEntityScanner.scanName();                        if (peName == null) {                            reportFatalError("NameRequiredInPEReference",                                             null);                        }                        else if (!fEntityScanner.skipChar(';')) {                            reportFatalError("SemicolonRequiredInPEReference",                                             new Object[]{peName});                        }                        else {                            if (scanningInternalSubset()) {                                reportFatalError("PEReferenceWithinMarkup",                                                 new Object[]{peName});                            }                            fStringBuffer2.append(peName);                            fStringBuffer2.append(';');                        }                        startPE(peName, true);                        // REVISIT: [Q] Why do we skip spaces here? -Ac                        // REVISIT: This will make returning the non-                        //          normalized value harder. -Ac                        fEntityScanner.skipSpaces();                        if (!fEntityScanner.skipChar('%'))                            break;                    }                }                else {                    int c = fEntityScanner.peekChar();                    if (XMLChar.isHighSurrogate(c)) {                        scanSurrogates(fStringBuffer2);                    }                    else if (isInvalidLiteral(c)) {                        reportFatalError("InvalidCharInLiteral",                                         new Object[]{Integer.toHexString(c)});                        fEntityScanner.scanChar();                    }                    // if it's not the delimiting quote or if it is but from a                    // different entity than the one this literal started from,                    // simply append the character to our buffer                    else if (c != quote || entityDepth != fEntityDepth) {                        fStringBuffer.append((char)c);                        fStringBuffer2.append((char)c);                        fEntityScanner.scanChar();                    }                }            } while (fEntityScanner.scanLiteral(quote, fString) != quote);            fStringBuffer.append(fString);            fStringBuffer2.append(fString);            literal = fStringBuffer;            literal2 = fStringBuffer2;        }        value.setValues(literal);        nonNormalizedValue.setValues(literal2);        if (!fEntityScanner.skipChar(quote)) {            reportFatalError("CloseQuoteMissingInDecl", null);        }    } // scanEntityValue(XMLString,XMLString):void    /**     * Scans a notation declaration     * <p>     * <pre>     * [82] NotationDecl ::= '&lt;!NOTATION' S Name S (ExternalID|PublicID) S? '>'     * [83]  PublicID    ::= 'PUBLIC' S PubidLiteral       * </pre>     * <p>     * <strong>Note:</strong> Called after scanning past '&lt;!NOTATION'     */    private final void scanNotationDecl() throws IOException, XNIException {        // spaces        fReportEntity = false;        if (!skipSeparator(true, !scanningInternalSubset())) {            reportFatalError("MSG_SPACE_REQUIRED_BEFORE_NOTATION_NAME_IN_NOTATIONDECL",                             null);        }        // notation name        String name = null;        if(fNamespaces) {            name = fEntityScanner.scanNCName();        } else {            name = fEntityScanner.scanName();        }        if (name == null) {            reportFatalError("MSG_NOTATION_NAME_REQUIRED_IN_NOTATIONDECL",                             null);        }        // spaces        if (!skipSeparator(true, !scanningInternalSubset())) {            // check for invalid ":"            if(fNamespaces && fEntityScanner.peekChar() == ':') {                fEntityScanner.scanChar();                XMLStringBuffer colonName = new XMLStringBuffer(name);                colonName.append(":");                colonName.append(fEntityScanner.scanName());                reportFatalError("ColonNotLegalWithNS", new Object[] {colonName.toString()});                skipSeparator(true, !scanningInternalSubset());            } else {                reportFatalError("MSG_SPACE_REQUIRED_AFTER_NOTATION_NAME_IN_NOTATIONDECL",                                new Object[]{name});            }        }        // external id   

⌨️ 快捷键说明

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