xmldtdvalidator.java

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

JAVA
1,655
字号
    /**     * The start of the document.     *     * @param locator The system identifier of the entity if the entity     *                 is external, null otherwise.     * @param encoding The auto-detected IANA encoding name of the entity     *                 stream. This value will be null in those situations     *                 where the entity encoding is not auto-detected (e.g.     *                 internal entities or a document entity that is     *                 parsed from a java.io.Reader).     * @param namespaceContext     *                 The namespace context in effect at the     *                 start of this document.     *                 This object represents the current context.     *                 Implementors of this class are responsible     *                 for copying the namespace bindings from the     *                 the current context (and its parent contexts)     *                 if that information is important.     * @param augs   Additional information that may include infoset augmentations     *     * @throws XNIException Thrown by handler to signal an error.     */    public void startDocument(XMLLocator locator, String encoding,                               NamespaceContext namespaceContext, Augmentations augs)     throws XNIException {        // call handlers        // get initial grammars        if(fGrammarPool != null) {            Grammar [] grammars = fGrammarPool.retrieveInitialGrammarSet(XMLGrammarDescription.XML_DTD);            for(int i = 0; i<grammars.length; i++) {                fGrammarBucket.putGrammar((DTDGrammar)grammars[i]);            }        }        fDocLocation = locator;        fNamespaceContext = namespaceContext;           if (fDocumentHandler != null) {            fDocumentHandler.startDocument(locator, encoding, namespaceContext, augs);        }    } // startDocument(XMLLocator,String)    /**     * Notifies of the presence of an XMLDecl line in the document. If     * present, this method will be called immediately following the     * startDocument call.     *      * @param version    The XML version.     * @param encoding   The IANA encoding name of the document, or null if     *                   not specified.     * @param standalone The standalone value, or null if not specified.          * @param augs   Additional information that may include infoset augmentations     *     * @throws XNIException Thrown by handler to signal an error.     */    public void xmlDecl(String version, String encoding, String standalone, Augmentations augs)    throws XNIException {        // save standalone state        fGrammarBucket.setStandalone(standalone != null && standalone.equals("yes"));        // call handlers        if (fDocumentHandler != null) {            fDocumentHandler.xmlDecl(version, encoding, standalone, augs);        }    } // xmlDecl(String,String,String)    /**     * Notifies of the presence of the DOCTYPE line in the document.     *      * @param rootElement The name of the root element.     * @param publicId    The public identifier if an external DTD or null     *                    if the external DTD is specified using SYSTEM.     * @param systemId    The system identifier if an external DTD, null     *                    otherwise.          * @param augs   Additional information that may include infoset augmentations     *     * @throws XNIException Thrown by handler to signal an error.     */    public void doctypeDecl(String rootElement, String publicId, String systemId,                             Augmentations augs)    throws XNIException {        // save root element state        fSeenDoctypeDecl = true;        fRootElement.setValues(null, rootElement, rootElement, null);        // find or create grammar:        String eid = null;        try {            eid = XMLEntityManager.expandSystemId(systemId, fDocLocation.getExpandedSystemId(), false);        } catch (java.io.IOException e) {        }        XMLDTDDescription grammarDesc = new XMLDTDDescription(publicId, systemId, fDocLocation.getExpandedSystemId(), eid, rootElement);        fDTDGrammar = fGrammarBucket.getGrammar(grammarDesc);        if(fDTDGrammar == null) {            // give grammar pool a chance...            if(fGrammarPool != null) {                fDTDGrammar = (DTDGrammar)fGrammarPool.retrieveGrammar(grammarDesc);            }        }        if(fDTDGrammar == null) {            // we'll have to create it...            fDTDGrammar = new DTDGrammar(fSymbolTable, grammarDesc);        } else {            // we've found a cached one;so let's make sure not to read            // any external subset!            fValidationManager.setCachedDTD(true);        }        fGrammarBucket.setActiveGrammar(fDTDGrammar);        // call handlers        if (fDocumentHandler != null) {            fDocumentHandler.doctypeDecl(rootElement, publicId, systemId, augs);        }    } // doctypeDecl(String,String,String, Augmentations)    /**     * The start of an element.     *      * @param element    The name of the element.     * @param attributes The element attributes.          * @param augs   Additional information that may include infoset augmentations     *     * @throws XNIException Thrown by handler to signal an error.     */    public void startElement(QName element, XMLAttributes attributes, Augmentations augs)    throws XNIException {        handleStartElement(element, attributes, augs);        // call handlers        if (fDocumentHandler != null) {            fDocumentHandler.startElement(element, attributes, augs);        }    } // startElement(QName,XMLAttributes)    /**     * An empty element.     *      * @param element    The name of the element.     * @param attributes The element attributes.          * @param augs   Additional information that may include infoset augmentations     *     * @throws XNIException Thrown by handler to signal an error.     */    public void emptyElement(QName element, XMLAttributes attributes, Augmentations augs)    throws XNIException {        boolean removed = handleStartElement(element, attributes, augs);        if (fDocumentHandler !=null) {            fDocumentHandler.emptyElement(element, attributes, augs);        }        if (!removed) {            handleEndElement(element, augs, true);        }            } // emptyElement(QName,XMLAttributes)    /**     * Character content.     *      * @param text The content.     *     * @param augs   Additional information that may include infoset augmentations     *     * @throws XNIException Thrown by handler to signal an error.     */    public void characters(XMLString text, Augmentations augs) throws XNIException {        boolean callNextCharacters = true;        // REVISIT: [Q] Is there a more efficient way of doing this?        //          Perhaps if the scanner told us so we don't have to        //          look at the characters again. -Ac        boolean allWhiteSpace = true;        for (int i=text.offset; i< text.offset+text.length; i++) {            if (!isSpace(text.ch[i])) {                allWhiteSpace = false;                break;            }        }        // call the ignoreableWhiteSpace callback        // never call ignorableWhitespace if we are in cdata section        if (fInElementContent && allWhiteSpace && !fInCDATASection) {            if (fDocumentHandler != null) {                fDocumentHandler.ignorableWhitespace(text, augs);                callNextCharacters = false;            }        }        // validate        if (fPerformValidation) {            if (fInElementContent) {                if (fGrammarBucket.getStandalone() &&                    fDTDGrammar.getElementDeclIsExternal(fCurrentElementIndex)) {                    if (allWhiteSpace) {                        fErrorReporter.reportError( XMLMessageFormatter.XML_DOMAIN,                                                    "MSG_WHITE_SPACE_IN_ELEMENT_CONTENT_WHEN_STANDALONE",                                                    null, XMLErrorReporter.SEVERITY_ERROR);                    }                }                if (!allWhiteSpace) {                    charDataInContent();                }                                // For E15.2                if (augs != null && augs.getItem(Constants.CHAR_REF_PROBABLE_WS) == Boolean.TRUE) {                    fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,                                                "MSG_CONTENT_INVALID_SPECIFIED",                                               new Object[]{ fCurrentElement.rawname,                                                    fDTDGrammar.getContentSpecAsString(fElementDepth),                                                   "character reference"},                                               XMLErrorReporter.SEVERITY_ERROR);                                }            }            if (fCurrentContentSpecType == XMLElementDecl.TYPE_EMPTY) {                charDataInContent();            }        }        // call handlers        if (callNextCharacters && fDocumentHandler != null) {            fDocumentHandler.characters(text, augs);        }    } // characters(XMLString)    /**     * Ignorable whitespace. For this method to be called, the document     * source must have some way of determining that the text containing     * only whitespace characters should be considered ignorable. For     * example, the validator can determine if a length of whitespace     * characters in the document are ignorable based on the element     * content model.     *      * @param text The ignorable whitespace.     * @param augs   Additional information that may include infoset augmentations     *     * @throws XNIException Thrown by handler to signal an error.     */    public void ignorableWhitespace(XMLString text, Augmentations augs) throws XNIException {        // call handlers        if (fDocumentHandler != null) {            fDocumentHandler.ignorableWhitespace(text, augs);        }    } // ignorableWhitespace(XMLString)    /**     * The end of an element.     *      * @param element The name of the element.     * @param augs   Additional information that may include infoset augmentations     *     * @throws XNIException Thrown by handler to signal an error.     */    public void endElement(QName element, Augmentations augs) throws XNIException {        handleEndElement(element,  augs, false);    } // endElement(QName)    /**      * The start of a CDATA section.      * @param augs   Additional information that may include infoset augmentations     *     * @throws XNIException Thrown by handler to signal an error.     */    public void startCDATA(Augmentations augs) throws XNIException {        if (fPerformValidation && fInElementContent) {            charDataInContent();        }        fInCDATASection = true;        // call handlers        if (fDocumentHandler != null) {            fDocumentHandler.startCDATA(augs);        }    } // startCDATA()    /**     * The end of a CDATA section.      * @param augs   Additional information that may include infoset augmentations     *     * @throws XNIException Thrown by handler to signal an error.     */    public void endCDATA(Augmentations augs) throws XNIException {        fInCDATASection = false;        // call handlers        if (fDocumentHandler != null) {            fDocumentHandler.endCDATA(augs);        }    } // endCDATA()    /**     * The end of the document.     * @param augs   Additional information that may include infoset augmentations     *     * @throws XNIException Thrown by handler to signal an error.     */    public void endDocument(Augmentations augs) throws XNIException {        // call handlers        if (fDocumentHandler != null) {            fDocumentHandler.endDocument(augs);        }    } // endDocument()    /**     * A comment.     *      * @param text The text in the comment.     * @param augs   Additional information that may include infoset augmentations     *     * @throws XNIException Thrown by application to signal an error.     */

⌨️ 快捷键说明

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