domparserimpl.java
来自「JAVA 所有包」· Java 代码 · 共 1,309 行 · 第 1/4 页
JAVA
1,309 行
public Node parseWithContext (LSInput is, Node cnode, short action) throws DOMException, LSException { // REVISIT: need to implement. throw new DOMException (DOMException.NOT_SUPPORTED_ERR, "Not supported"); } /** * NON-DOM: convert LSInput to XNIInputSource * * @param is * @return */ XMLInputSource dom2xmlInputSource (LSInput is) { // need to wrap the LSInput with an XMLInputSource XMLInputSource xis = null; // check whether there is a Reader // according to DOM, we need to treat such reader as "UTF-16". if (is.getCharacterStream () != null) { xis = new XMLInputSource (is.getPublicId (), is.getSystemId (), is.getBaseURI (), is.getCharacterStream (), "UTF-16"); } // check whether there is an InputStream else if (is.getByteStream () != null) { xis = new XMLInputSource (is.getPublicId (), is.getSystemId (), is.getBaseURI (), is.getByteStream (), is.getEncoding ()); } // if there is a string data, use a StringReader // according to DOM, we need to treat such data as "UTF-16". else if (is.getStringData () != null && is.getStringData().length() > 0) { xis = new XMLInputSource (is.getPublicId (), is.getSystemId (), is.getBaseURI (), new StringReader (is.getStringData ()), "UTF-16"); } // otherwise, just use the public/system/base Ids else if ((is.getSystemId() != null && is.getSystemId().length() > 0) || (is.getPublicId() != null && is.getPublicId().length() > 0)) { xis = new XMLInputSource (is.getPublicId (), is.getSystemId (), is.getBaseURI ()); } else { // all inputs are null if (fErrorHandler != null) { DOMErrorImpl error = new DOMErrorImpl(); error.fType = "no-input-specified"; error.fMessage = "no-input-specified"; error.fSeverity = DOMError.SEVERITY_FATAL_ERROR; fErrorHandler.getErrorHandler().handleError(error); } throw new LSException(LSException.PARSE_ERR, "no-input-specified"); } return xis; } /** * @see org.w3c.dom.ls.LSParser#getAsync() */ public boolean getAsync () { return false; } /** * @see org.w3c.dom.ls.LSParser#getBusy() */ public boolean getBusy () { return fBusy; } /** * @see org.w3c.dom.ls.DOMParser#abort() */ public void abort () { // If parse operation is in progress then reset it if ( fBusy ) { fBusy = false; if(currentThread != null) { abortNow = true; fConfiguration.setDocumentHandler(abortHandler); fConfiguration.setDTDHandler(abortHandler); fConfiguration.setDTDContentModelHandler(abortHandler); if(currentThread == Thread.currentThread()) throw abort; currentThread.interrupt(); } } return; // If not busy then this is noop } /** * 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. * Overriding the parent to handle DOM_NAMESPACE_DECLARATIONS=false. * * @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) { // namespace declarations parameter has no effect if namespaces is false. if (!fNamespaceDeclarations && fNamespaceAware) { int len = attributes.getLength(); for (int i = len - 1; i >= 0; --i) { if (XMLSymbols.PREFIX_XMLNS == attributes.getPrefix(i) || XMLSymbols.PREFIX_XMLNS == attributes.getQName(i)) { attributes.removeAttributeAt(i); } } } super.startElement(element, attributes, augs); } private class AbortHandler implements XMLDocumentHandler, XMLDTDHandler, XMLDTDContentModelHandler { private XMLDocumentSource documentSource; private XMLDTDContentModelSource dtdContentSource; private XMLDTDSource dtdSource; public void startDocument(XMLLocator locator, String encoding, NamespaceContext namespaceContext, Augmentations augs) throws XNIException { throw abort; } public void xmlDecl(String version, String encoding, String standalone, Augmentations augs) throws XNIException { throw abort; } public void doctypeDecl(String rootElement, String publicId, String systemId, Augmentations augs) throws XNIException { throw abort; } public void comment(XMLString text, Augmentations augs) throws XNIException { throw abort; } public void processingInstruction(String target, XMLString data, Augmentations augs) throws XNIException { throw abort; } public void startElement(QName element, XMLAttributes attributes, Augmentations augs) throws XNIException { throw abort; } public void emptyElement(QName element, XMLAttributes attributes, Augmentations augs) throws XNIException { throw abort; } public void startGeneralEntity(String name, XMLResourceIdentifier identifier, String encoding, Augmentations augs) throws XNIException { throw abort; } public void textDecl(String version, String encoding, Augmentations augs) throws XNIException { throw abort; } public void endGeneralEntity(String name, Augmentations augs) throws XNIException { throw abort; } public void characters(XMLString text, Augmentations augs) throws XNIException { throw abort; } public void ignorableWhitespace(XMLString text, Augmentations augs) throws XNIException { throw abort; } public void endElement(QName element, Augmentations augs) throws XNIException { throw abort; } public void startCDATA(Augmentations augs) throws XNIException { throw abort; } public void endCDATA(Augmentations augs) throws XNIException { throw abort; } public void endDocument(Augmentations augs) throws XNIException { throw abort; } public void setDocumentSource(XMLDocumentSource source) { documentSource = source; } public XMLDocumentSource getDocumentSource() { return documentSource; } public void startDTD(XMLLocator locator, Augmentations augmentations) throws XNIException { throw abort; } public void startParameterEntity(String name, XMLResourceIdentifier identifier, String encoding, Augmentations augmentations) throws XNIException { throw abort; } public void endParameterEntity(String name, Augmentations augmentations) throws XNIException { throw abort; } public void startExternalSubset(XMLResourceIdentifier identifier, Augmentations augmentations) throws XNIException { throw abort; } public void endExternalSubset(Augmentations augmentations) throws XNIException { throw abort; } public void elementDecl(String name, String contentModel, Augmentations augmentations) throws XNIException { throw abort; } public void startAttlist(String elementName, Augmentations augmentations) throws XNIException { throw abort; } public void attributeDecl(String elementName, String attributeName, String type, String[] enumeration, String defaultType, XMLString defaultValue, XMLString nonNormalizedDefaultValue, Augmentations augmentations) throws XNIException { throw abort; } public void endAttlist(Augmentations augmentations) throws XNIException { throw abort; } public void internalEntityDecl(String name, XMLString text, XMLString nonNormalizedText, Augmentations augmentations) throws XNIException { throw abort; } public void externalEntityDecl(String name, XMLResourceIdentifier identifier, Augmentations augmentations) throws XNIException { throw abort; } public void unparsedEntityDecl(String name, XMLResourceIdentifier identifier, String notation, Augmentations augmentations) throws XNIException { throw abort; } public void notationDecl(String name, XMLResourceIdentifier identifier, Augmentations augmentations) throws XNIException { throw abort; } public void startConditional(short type, Augmentations augmentations) throws XNIException { throw abort; } public void ignoredCharacters(XMLString text, Augmentations augmentations) throws XNIException { throw abort; } public void endConditional(Augmentations augmentations) throws XNIException { throw abort; } public void endDTD(Augmentations augmentations) throws XNIException { throw abort; } public void setDTDSource(XMLDTDSource source) { dtdSource = source; } public XMLDTDSource getDTDSource() { return dtdSource; } public void startContentModel(String elementName, Augmentations augmentations) throws XNIException { throw abort; } public void any(Augmentations augmentations) throws XNIException { throw abort; } public void empty(Augmentations augmentations) throws XNIException { throw abort; } public void startGroup(Augmentations augmentations) throws XNIException { throw abort; } public void pcdata(Augmentations augmentations) throws XNIException { throw abort; } public void element(String elementName, Augmentations augmentations) throws XNIException { throw abort; } public void separator(short separator, Augmentations augmentations) throws XNIException { throw abort; } public void occurrence(short occurrence, Augmentations augmentations) throws XNIException { throw abort; } public void endGroup(Augmentations augmentations) throws XNIException { throw abort; } public void endContentModel(Augmentations augmentations) throws XNIException { throw abort; } public void setDTDContentModelSource(XMLDTDContentModelSource source) { dtdContentSource = source; } public XMLDTDContentModelSource getDTDContentModelSource() { return dtdContentSource; } } } // class DOMParserImpl
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?