abstractdomparser.java
来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 1,652 行 · 第 1/5 页
JAVA
1,652 行
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.toString ()); fInternalSubset.append (' '); fInternalSubset.append (data.toString ()); fInternalSubset.append ("?>"); } return; } if (DEBUG_EVENTS) { System.out.println ("==>processingInstruction ("+target+")"); } if (!fDeferNodeExpansion) { if (fFilterReject) { return; } ProcessingInstruction pi = fDocument.createProcessingInstruction (target, data.toString ()); setCharacterData (false); fCurrentNode.appendChild (pi); if (fDOMFilter !=null && !fInEntityRef && (fDOMFilter.getWhatToShow () & NodeFilter.SHOW_PROCESSING_INSTRUCTION)!= 0) { short code = fDOMFilter.acceptNode (pi); switch (code) { case LSParserFilter.FILTER_INTERRUPT:{ throw abort; } case LSParserFilter.FILTER_REJECT:{ // fall through to SKIP since PI has no children. } case LSParserFilter.FILTER_SKIP: { fCurrentNode.removeChild(pi); // fFirstChunk must be set to true so that data // won't be lost in the case where the child before PI is // a text node and the next event is characters. fFirstChunk = true; return; } default: { } } } } else { int pi = fDeferredDocumentImpl. createDeferredProcessingInstruction(target, data.toString()); fDeferredDocumentImpl.appendChild(fCurrentNodeIndex, pi); } } // processingInstruction(String,XMLString) /** * 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 { if (!fDeferNodeExpansion) { if (fDocumentClassName.equals (DEFAULT_DOCUMENT_CLASS_NAME)) { fDocument = new DocumentImpl (); fDocumentImpl = (CoreDocumentImpl)fDocument; // REVISIT: when DOM Level 3 is REC rely on Document.support // instead of specific class // set DOM error checking off fDocumentImpl.setStrictErrorChecking (false); // set actual encoding fDocumentImpl.setInputEncoding (encoding); // set documentURI fDocumentImpl.setDocumentURI (locator.getExpandedSystemId ()); } else if (fDocumentClassName.equals (PSVI_DOCUMENT_CLASS_NAME)) { fDocument = new PSVIDocumentImpl(); fDocumentImpl = (CoreDocumentImpl)fDocument; fStorePSVI = true; // REVISIT: when DOM Level 3 is REC rely on Document.support // instead of specific class // set DOM error checking off fDocumentImpl.setStrictErrorChecking (false); // set actual encoding fDocumentImpl.setInputEncoding (encoding); // set documentURI fDocumentImpl.setDocumentURI (locator.getExpandedSystemId ()); } else { // use specified document class try { ClassLoader cl = ObjectFactory.findClassLoader(); Class documentClass = ObjectFactory.findProviderClass (fDocumentClassName, cl, true); fDocument = (Document)documentClass.newInstance (); // if subclass of our own class that's cool too Class defaultDocClass = ObjectFactory.findProviderClass (CORE_DOCUMENT_CLASS_NAME, cl, true); if (defaultDocClass.isAssignableFrom (documentClass)) { fDocumentImpl = (CoreDocumentImpl)fDocument; Class psviDocClass = ObjectFactory.findProviderClass (PSVI_DOCUMENT_CLASS_NAME, cl, true); if (psviDocClass.isAssignableFrom (documentClass)) { fStorePSVI = true; } // REVISIT: when DOM Level 3 is REC rely on // Document.support instead of specific class // set DOM error checking off fDocumentImpl.setStrictErrorChecking(false); // set actual encoding fDocumentImpl.setInputEncoding(encoding); // set documentURI if (locator != null) { fDocumentImpl.setDocumentURI(locator.getExpandedSystemId()); } } } catch (ClassNotFoundException e) { // won't happen we already checked that earlier } catch (Exception e) { throw new RuntimeException ( DOMMessageFormatter.formatMessage( DOMMessageFormatter.DOM_DOMAIN, "CannotCreateDocumentClass", new Object [] {fDocumentClassName})); } } fCurrentNode = fDocument; } else { fDeferredDocumentImpl = new DeferredDocumentImpl(fNamespaceAware); fDocument = fDeferredDocumentImpl; fDocumentIndex = fDeferredDocumentImpl.createDeferredDocument(); // REVISIT: strict error checking is not implemented in deferred dom. // Document.support instead of specific class // set actual encoding fDeferredDocumentImpl.setInputEncoding(encoding); // set documentURI fDeferredDocumentImpl.setDocumentURI(locator.getExpandedSystemId()); fCurrentNodeIndex = fDocumentIndex; } } // startDocument(String,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 { if (!fDeferNodeExpansion) { // REVISIT: when DOM Level 3 is REC rely on Document.support // instead of specific class if (fDocumentImpl != null) { if(version != null) fDocumentImpl.setXmlVersion(version); fDocumentImpl.setXmlEncoding(encoding); fDocumentImpl.setXmlStandalone("yes".equals(standalone)); } } else { if(version != null) fDeferredDocumentImpl.setXmlVersion(version); fDeferredDocumentImpl.setXmlEncoding(encoding); fDeferredDocumentImpl.setXmlStandalone("yes".equals(standalone)); } } // 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 { if (!fDeferNodeExpansion) { if (fDocumentImpl != null) { fDocumentType = fDocumentImpl.createDocumentType( rootElement, publicId, systemId); fCurrentNode.appendChild(fDocumentType); } } else { fDocumentTypeIndex = fDeferredDocumentImpl. createDeferredDocumentType(rootElement, publicId, systemId); fDeferredDocumentImpl.appendChild(fCurrentNodeIndex, fDocumentTypeIndex); } } // doctypeDecl(String,String,String) /** * The start of an element. If the document specifies the start element * by using an empty tag, then the startElement method will immediately * be followed by the endElement method, with no intervening methods. * * @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 { if (DEBUG_EVENTS) { System.out.println("==>startElement ("+element.rawname+")"); } if (!fDeferNodeExpansion) { if (fFilterReject) { return; } Element el = createElementNode(element); int attrCount = attributes.getLength(); for (int i = 0; i < attrCount; i++) { attributes.getName (i, fAttrQName); Attr attr = createAttrNode (fAttrQName); String attrValue = attributes.getValue (i); Augmentations aaugs = attributes.getAugmentations(i); AttributePSVI attrPSVI =(AttributePSVI) aaugs.getItem(Constants.ATTRIBUTE_PSVI); if (fStorePSVI && attrPSVI != null){ ((PSVIAttrNSImpl) attr).setPSVI (attrPSVI); } attr.setValue(attrValue); el.setAttributeNode(attr); // NOTE: The specified value MUST be set after you set // the node value because that turns the "specified" // flag to "true" which may overwrite a "false" // value from the attribute list. -Ac if (fDocumentImpl != null) { AttrImpl attrImpl = (AttrImpl)attr; attrImpl.setType(getAttributeType(attributes,aaugs,i)); if (isIdAttribute(attributes,aaugs,i)) { ((ElementImpl)el).setIdAttributeNode(attr, true); } attrImpl.setSpecified(attributes.isSpecified(i)); // REVISIT: Handle entities in attribute value. } } setCharacterData (false); ((ElementImpl)el).setType(getElementTypeInfoFromAugs(augs)); // filter nodes if (fDOMFilter != null && !fInEntityRef) { if (fRoot.rawname == null) { // fill value of the root element fRoot.setValues(element); } else { short code = fDOMFilter.startElement(el); switch (code) { case LSParserFilter.FILTER_INTERRUPT : { throw abort; } case LSParserFilter.FILTER_REJECT : { fFilterReject = true;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?