xmlnsdocumentscannerimpl.java

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

JAVA
815
字号
                    // checkDuplicates(fAttributeQName, fAttributes);                    continue;                }                if (aprefix != XMLSymbols.EMPTY_STRING) {                    fAttributeQName.uri = uri;                    if (uri == null) {                        fErrorReporter.reportError(XMLMessageFormatter.XMLNS_DOMAIN,                                                   "AttributePrefixUnbound",                                                   new Object[]{fElementQName.rawname,fAttributeQName.rawname,aprefix},                                                   XMLErrorReporter.SEVERITY_FATAL_ERROR);                    }                    fAttributes.setURI(i, uri);                    // checkDuplicates(fAttributeQName, fAttributes);                }            }                        if (length > 1) {                QName name = fAttributes.checkDuplicatesNS();                if (name != null) {                    if (name.uri != null) {                        fErrorReporter.reportError(XMLMessageFormatter.XMLNS_DOMAIN,                                                   "AttributeNSNotUnique",                                                   new Object[]{fElementQName.rawname, name.localpart, name.uri},                                                   XMLErrorReporter.SEVERITY_FATAL_ERROR);                    }                    else {                        fErrorReporter.reportError(XMLMessageFormatter.XMLNS_DOMAIN,                                                   "AttributeNotUnique",                                                   new Object[]{fElementQName.rawname, name.rawname},                                                    XMLErrorReporter.SEVERITY_FATAL_ERROR);                    }                }            }        }        // call handler        if (fDocumentHandler != null) {            if (empty) {                //decrease the markup depth..                fMarkupDepth--;                // check that this element was opened in the same entity                if (fMarkupDepth < fEntityStack[fEntityDepth - 1]) {                    reportFatalError("ElementEntityMismatch",                                     new Object[]{fCurrentElement.rawname});                }                fDocumentHandler.emptyElement(fElementQName, fAttributes, null);                if (fBindNamespaces) {                    fNamespaceContext.popContext();                }                //pop the element off the stack..                fElementStack.popElement(fElementQName);            } else {                fDocumentHandler.startElement(fElementQName, fAttributes, null);            }        }        if (DEBUG_CONTENT_SCANNING) System.out.println("<<< scanStartElement(): "+empty);        return empty;    } // scanStartElement():boolean    /**     * Scans the name of an element in a start or empty tag.      *      * @see #scanStartElement()     */    protected void scanStartElementName ()        throws IOException, XNIException {        // Note: namespace processing is on by default        fEntityScanner.scanQName(fElementQName);        // Must skip spaces here because the DTD scanner        // would consume them at the end of the external subset.        fSawSpace = fEntityScanner.skipSpaces();    } // scanStartElementName()    /**     * Scans the remainder of a start or empty tag after the element name.     *      * @see #scanStartElement     * @return True if element is empty.     */    protected boolean scanStartElementAfterName()        throws IOException, XNIException {    	        // REVISIT - [Q] Why do we need this temp variable? -- mrglavas        String rawname = fElementQName.rawname;        if (fBindNamespaces) {            fNamespaceContext.pushContext();            if (fScannerState == SCANNER_STATE_ROOT_ELEMENT) {                if (fPerformValidation) {                    fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,                                               "MSG_GRAMMAR_NOT_FOUND",                                               new Object[]{ rawname},                                               XMLErrorReporter.SEVERITY_ERROR);                    if (fDoctypeName == null || !fDoctypeName.equals(rawname)) {                        fErrorReporter.reportError( XMLMessageFormatter.XML_DOMAIN,                                                    "RootElementTypeMustMatchDoctypedecl",                                                    new Object[]{fDoctypeName, rawname},                                                    XMLErrorReporter.SEVERITY_ERROR);                    }                }            }        }        // push element stack        fCurrentElement = fElementStack.pushElement(fElementQName);        // attributes        boolean empty = false;        fAttributes.removeAllAttributes();        do {        	            // end tag?            int c = fEntityScanner.peekChar();            if (c == '>') {                fEntityScanner.scanChar();                break;            }            else if (c == '/') {                fEntityScanner.scanChar();                if (!fEntityScanner.skipChar('>')) {                    reportFatalError("ElementUnterminated",                                     new Object[]{rawname});                }                empty = true;                break;            }            else if (!isValidNameStartChar(c) || !fSawSpace) {                reportFatalError("ElementUnterminated", new Object[]{rawname});            }            // attributes            scanAttribute(fAttributes);                        // spaces            fSawSpace = fEntityScanner.skipSpaces();        } while (true);        if (fBindNamespaces) {            // REVISIT: is it required? forbit xmlns prefix for element            if (fElementQName.prefix == XMLSymbols.PREFIX_XMLNS) {                fErrorReporter.reportError(XMLMessageFormatter.XMLNS_DOMAIN,                                           "ElementXMLNSPrefix",                                           new Object[]{fElementQName.rawname},                                           XMLErrorReporter.SEVERITY_FATAL_ERROR);            }            // bind the element            String prefix = fElementQName.prefix != null                            ? fElementQName.prefix : XMLSymbols.EMPTY_STRING;            // assign uri to the element            fElementQName.uri = fNamespaceContext.getURI(prefix);            // make sure that object in the element stack is updated as well            fCurrentElement.uri = fElementQName.uri;            if (fElementQName.prefix == null && fElementQName.uri != null) {                fElementQName.prefix = XMLSymbols.EMPTY_STRING;                // making sure that the object in the element stack is updated too.                fCurrentElement.prefix = XMLSymbols.EMPTY_STRING;            }            if (fElementQName.prefix != null && fElementQName.uri == null) {                fErrorReporter.reportError(XMLMessageFormatter.XMLNS_DOMAIN,                                           "ElementPrefixUnbound",                                           new Object[]{fElementQName.prefix, fElementQName.rawname},                                           XMLErrorReporter.SEVERITY_FATAL_ERROR);            }            // bind attributes (xmlns are already bound bellow)            int length = fAttributes.getLength();            // fLength = 0; //initialize structure            for (int i = 0; i < length; i++) {                fAttributes.getName(i, fAttributeQName);                String aprefix = fAttributeQName.prefix != null                                 ? fAttributeQName.prefix : XMLSymbols.EMPTY_STRING;                String uri = fNamespaceContext.getURI(aprefix);                // REVISIT: try removing the first "if" and see if it is faster.                //                if (fAttributeQName.uri != null && fAttributeQName.uri == uri) {                    // checkDuplicates(fAttributeQName, fAttributes);                    continue;                }                if (aprefix != XMLSymbols.EMPTY_STRING) {                    fAttributeQName.uri = uri;                    if (uri == null) {                        fErrorReporter.reportError(XMLMessageFormatter.XMLNS_DOMAIN,                                                   "AttributePrefixUnbound",                                                   new Object[]{fElementQName.rawname,fAttributeQName.rawname,aprefix},                                                   XMLErrorReporter.SEVERITY_FATAL_ERROR);                    }                    fAttributes.setURI(i, uri);                    // checkDuplicates(fAttributeQName, fAttributes);                }            }                        if (length > 1) {                QName name = fAttributes.checkDuplicatesNS();                if (name != null) {                    if (name.uri != null) {                        fErrorReporter.reportError(XMLMessageFormatter.XMLNS_DOMAIN,                                                   "AttributeNSNotUnique",                                                   new Object[]{fElementQName.rawname, name.localpart, name.uri},                                                   XMLErrorReporter.SEVERITY_FATAL_ERROR);                    }                    else {                        fErrorReporter.reportError(XMLMessageFormatter.XMLNS_DOMAIN,                                                   "AttributeNotUnique",                                                   new Object[]{fElementQName.rawname, name.rawname},                                                    XMLErrorReporter.SEVERITY_FATAL_ERROR);                    }                }            }        }        // call handler        if (fDocumentHandler != null) {            if (empty) {                //decrease the markup depth..                fMarkupDepth--;                // check that this element was opened in the same entity                if (fMarkupDepth < fEntityStack[fEntityDepth - 1]) {                    reportFatalError("ElementEntityMismatch",                                     new Object[]{fCurrentElement.rawname});                }                fDocumentHandler.emptyElement(fElementQName, fAttributes, null);                if (fBindNamespaces) {                    fNamespaceContext.popContext();                }                //pop the element off the stack..                fElementStack.popElement(fElementQName);            } else {                fDocumentHandler.startElement(fElementQName, fAttributes, null);            }        }        if (DEBUG_CONTENT_SCANNING) System.out.println("<<< scanStartElementAfterName(): "+empty);        return empty;    } // scanStartElementAfterName()    /**     * Scans an attribute.     * <p>     * <pre>     * [41] Attribute ::= Name Eq AttValue     * </pre>     * <p>     * <strong>Note:</strong> This method assumes that the next     * character on the stream is the first character of the attribute     * name.     * <p>     * <strong>Note:</strong> This method uses the fAttributeQName and     * fQName variables. The contents of these variables will be     * destroyed.     *     * @param attributes The attributes list for the scanned attribute.     */    protected void scanAttribute(XMLAttributesImpl attributes)    throws IOException, XNIException {        if (DEBUG_CONTENT_SCANNING) System.out.println(">>> scanAttribute()");

⌨️ 快捷键说明

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