abstractdomparser.java
来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 1,652 行 · 第 1/5 页
JAVA
1,652 行
// add recognized properties fConfiguration.addRecognizedProperties (RECOGNIZED_PROPERTIES); // set default values fConfiguration.setProperty (DOCUMENT_CLASS_NAME, DEFAULT_DOCUMENT_CLASS_NAME); } // <init>(XMLParserConfiguration) /** * This method retreives the name of current document class. */ protected String getDocumentClassName() { return fDocumentClassName; } /** * This method allows the programmer to decide which document * factory to use when constructing the DOM tree. However, doing * so will lose the functionality of the default factory. Also, * a document class other than the default will lose the ability * to defer node expansion on the DOM tree produced. * * @param documentClassName The fully qualified class name of the * document factory to use when constructing * the DOM tree. * * @see #getDocumentClassName * @see #DEFAULT_DOCUMENT_CLASS_NAME */ protected void setDocumentClassName (String documentClassName) { // normalize class name if (documentClassName == null) { documentClassName = DEFAULT_DOCUMENT_CLASS_NAME; } if (!documentClassName.equals(DEFAULT_DOCUMENT_CLASS_NAME) && !documentClassName.equals(PSVI_DOCUMENT_CLASS_NAME)) { // 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());
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?