abstractdomparser.java

来自「JAVA 所有包」· Java 代码 · 共 1,657 行 · 第 1/5 页

JAVA
1,657
字号
            // verify that this class exists and is of the right type            try {                Class _class = ObjectFactory.findProviderClass (documentClassName,                ObjectFactory.findClassLoader (), true);                //if (!_class.isAssignableFrom(Document.class)) {                if (!Document.class.isAssignableFrom (_class)) {                    throw new IllegalArgumentException (                        DOMMessageFormatter.formatMessage(                        DOMMessageFormatter.DOM_DOMAIN,                        "InvalidDocumentClassName", new Object [] {documentClassName}));                }            }            catch (ClassNotFoundException e) {                throw new IllegalArgumentException (                    DOMMessageFormatter.formatMessage(                    DOMMessageFormatter.DOM_DOMAIN,                    "MissingDocumentClassName", new Object [] {documentClassName}));            }        }        // set document class name        fDocumentClassName = documentClassName;        if (!documentClassName.equals (DEFAULT_DOCUMENT_CLASS_NAME)) {            fDeferNodeExpansion = false;        }    } // setDocumentClassName(String)    //    // Public methods    //    /** Returns the DOM document object. */    public Document getDocument () {        return fDocument;    } // getDocument():Document    //    // XMLDocumentParser methods    //    /**     * Resets the parser state.     *     * @throws SAXException Thrown on initialization error.     */    public void reset () throws XNIException {        super.reset ();        // get feature state        fCreateEntityRefNodes =        fConfiguration.getFeature (CREATE_ENTITY_REF_NODES);        fIncludeIgnorableWhitespace =        fConfiguration.getFeature (INCLUDE_IGNORABLE_WHITESPACE);        fDeferNodeExpansion =        fConfiguration.getFeature (DEFER_NODE_EXPANSION);        fNamespaceAware = fConfiguration.getFeature (NAMESPACES);        fIncludeComments = fConfiguration.getFeature (INCLUDE_COMMENTS_FEATURE);        fCreateCDATANodes = fConfiguration.getFeature (CREATE_CDATA_NODES_FEATURE);        // get property        setDocumentClassName ((String)        fConfiguration.getProperty (DOCUMENT_CLASS_NAME));        // reset dom information        fDocument = null;        fDocumentImpl = null;        fStorePSVI = false;        fDocumentType = null;        fDocumentTypeIndex = -1;        fDeferredDocumentImpl = null;        fCurrentNode = null;        // reset string buffer        fStringBuffer.setLength (0);        // reset state information        fRoot.clear();        fInDTD = false;        fInDTDExternalSubset = false;        fInCDATASection = false;        fFirstChunk = false;        fCurrentCDATASection = null;        fCurrentCDATASectionIndex = -1;        fBaseURIStack.removeAllElements ();    } // reset()    /**     * Set the locale to use for messages.     *     * @param locale The locale object to use for localization of messages.     *     */    public void setLocale (Locale locale) {        fConfiguration.setLocale (locale);    } // setLocale(Locale)    //    // XMLDocumentHandler methods    //    /**     * This method notifies the start of a general entity.     * <p>     * <strong>Note:</strong> This method is not called for entity references     * appearing as part of attribute values.     *     * @param name     The name of the general entity.     * @param identifier The resource identifier.     * @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 augs     Additional information that may include infoset augmentations     *     * @exception XNIException Thrown by handler to signal an error.     */    public void startGeneralEntity (String name,    XMLResourceIdentifier identifier,    String encoding, Augmentations augs)    throws XNIException {        if (DEBUG_EVENTS) {            System.out.println ("==>startGeneralEntity ("+name+")");            if (DEBUG_BASEURI) {                System.out.println ("   expandedSystemId( **baseURI): "+identifier.getExpandedSystemId ());                System.out.println ("   baseURI:"+ identifier.getBaseSystemId ());            }        }        // Always create entity reference nodes to be able to recreate        // entity as a part of doctype        if (!fDeferNodeExpansion) {            if (fFilterReject) {                return;            }            setCharacterData (true);            EntityReference er = fDocument.createEntityReference (name);            if (fDocumentImpl != null) {                // REVISIT: baseURI/actualEncoding                //         remove dependency on our implementation when DOM L3 is REC                //                EntityReferenceImpl erImpl =(EntityReferenceImpl)er;                // set base uri                erImpl.setBaseURI (identifier.getExpandedSystemId ());                if (fDocumentType != null) {                    // set actual encoding                    NamedNodeMap entities = fDocumentType.getEntities ();                    fCurrentEntityDecl = (EntityImpl) entities.getNamedItem (name);                    if (fCurrentEntityDecl != null) {                        fCurrentEntityDecl.setInputEncoding (encoding);                    }                }                // we don't need synchronization now, because entity ref will be                // expanded anyway. Synch only needed when user creates entityRef node                erImpl.needsSyncChildren (false);            }            fInEntityRef = true;            fCurrentNode.appendChild (er);            fCurrentNode = er;        }        else {            int er =            fDeferredDocumentImpl.createDeferredEntityReference (name, identifier.getExpandedSystemId ());            if (fDocumentTypeIndex != -1) {                // find corresponding Entity decl                int node = fDeferredDocumentImpl.getLastChild (fDocumentTypeIndex, false);                while (node != -1) {                    short nodeType = fDeferredDocumentImpl.getNodeType (node, false);                    if (nodeType == Node.ENTITY_NODE) {                        String nodeName =                        fDeferredDocumentImpl.getNodeName (node, false);                        if (nodeName.equals (name)) {                            fDeferredEntityDecl = node;                            fDeferredDocumentImpl.setInputEncoding (node, encoding);                            break;                        }                    }                    node = fDeferredDocumentImpl.getRealPrevSibling (node, false);                }            }            fDeferredDocumentImpl.appendChild (fCurrentNodeIndex, er);            fCurrentNodeIndex = er;        }    } // startGeneralEntity(String,XMLResourceIdentifier, Augmentations)    /**     * Notifies of the presence of a TextDecl line in an entity. If present,     * this method will be called immediately following the startEntity call.     * <p>     * <strong>Note:</strong> This method will never be called for the     * document entity; it is only called for external general entities     * referenced in document content.     * <p>     * <strong>Note:</strong> This method is not called for entity references     * appearing as part of attribute values.     *     * @param version  The XML version, or null if not specified.     * @param encoding The IANA encoding name of the entity.     * @param augs       Additional information that may include infoset augmentations     *     * @throws XNIException Thrown by handler to signal an error.     */    public void textDecl (String version, String encoding, Augmentations augs) throws XNIException {        if (fInDTD){            return;        }        if (!fDeferNodeExpansion) {            if (fCurrentEntityDecl != null && !fFilterReject) {                fCurrentEntityDecl.setXmlEncoding (encoding);                if (version != null)                    fCurrentEntityDecl.setXmlVersion (version);            }        }        else {            if (fDeferredEntityDecl !=-1) {                fDeferredDocumentImpl.setEntityInfo (fDeferredEntityDecl, version, encoding);            }        }    } // textDecl(String,String)    /**     * 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.     */    public void comment (XMLString text, Augmentations augs) throws XNIException {        if (fInDTD) {            if (fInternalSubset != null && !fInDTDExternalSubset) {                fInternalSubset.append ("<!-- ");                fInternalSubset.append (text.toString ());                fInternalSubset.append (" -->");            }            return;        }        if (!fIncludeComments || fFilterReject) {            return;        }        if (!fDeferNodeExpansion) {            Comment comment = fDocument.createComment (text.toString ());            setCharacterData (false);            fCurrentNode.appendChild (comment);            if (fDOMFilter !=null && !fInEntityRef &&            (fDOMFilter.getWhatToShow () & NodeFilter.SHOW_COMMENT)!= 0) {                short code = fDOMFilter.acceptNode (comment);                switch (code) {                    case LSParserFilter.FILTER_INTERRUPT:{                        throw abort;                    }                    case LSParserFilter.FILTER_REJECT:{                        // REVISIT: the constant FILTER_REJECT should be changed when new                        // DOM LS specs gets published                        // fall through to SKIP since comment has no children.                    }                    case LSParserFilter.FILTER_SKIP: {                        // REVISIT: the constant FILTER_SKIP should be changed when new                        // DOM LS specs gets published                        fCurrentNode.removeChild (comment);                        // make sure we don't loose chars if next event is characters()                        fFirstChunk = true;                        return;                    }                    default: {                        // accept node                    }                }            }        }        else {            int comment =            fDeferredDocumentImpl.createDeferredComment (text.toString ());            fDeferredDocumentImpl.appendChild (fCurrentNodeIndex, comment);        }    } // comment(XMLString)    /**     * A processing instruction. Processing instructions consist of a     * target name and, optionally, text data. The data is only meaningful     * to the application.     * <p>     * Typically, a processing instruction's data will contain a series     * of pseudo-attributes. These pseudo-attributes follow the form of     * element attributes but are <strong>not</strong> parsed or presented     * to the application as anything other than text. The application is     * responsible for parsing the data.     *     * @param target The target.     * @param data   The data or null if none specified.     * @param augs       Additional information that may include infoset augmentations     *     * @throws XNIException Thrown by handler to signal an error.     */    public void processingInstruction (String target, XMLString data, Augmentations augs)    throws XNIException {        if (fInDTD) {            if (fInternalSubset != null && !fInDTDExternalSubset) {                fInternalSubset.append ("<?");                fInternalSubset.append (target);                fInternalSubset.append (' ');                fInternalSubset.append (data.toString ());                fInternalSubset.append ("?>");            }            return;        }        if (DEBUG_EVENTS) {            System.out.println ("==>processingInstruction ("+target+")");

⌨️ 快捷键说明

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