abstractsaxparser.java
来自「JAVA 所有包」· Java 代码 · 共 1,706 行 · 第 1/5 页
JAVA
1,706 行
* @param name The name of the entity. * @param identifier An object containing all location information * pertinent to this entity. * @param notation The name of the notation. * * @param augs Additional information that may include infoset * augmentations. * * @throws XNIException Thrown by handler to signal an error. */ public void unparsedEntityDecl(String name, XMLResourceIdentifier identifier, String notation, Augmentations augs) throws XNIException { try { // SAX2 extension if (fDTDHandler != null) { String publicId = identifier.getPublicId(); String systemId = fResolveDTDURIs ? identifier.getExpandedSystemId() : identifier.getLiteralSystemId(); fDTDHandler.unparsedEntityDecl(name, publicId, systemId, notation); } } catch (SAXException e) { throw new XNIException(e); } } // unparsedEntityDecl(String,XMLResourceIdentifier, String, Augmentations) /** * A notation declaration * * @param name The name of the notation. * @param identifier An object containing all location information * pertinent to this notation. * @param augs Additional information that may include infoset * augmentations. * * @throws XNIException Thrown by handler to signal an error. */ public void notationDecl(String name, XMLResourceIdentifier identifier, Augmentations augs) throws XNIException { try { // SAX1 and SAX2 if (fDTDHandler != null) { String publicId = identifier.getPublicId(); String systemId = fResolveDTDURIs ? identifier.getExpandedSystemId() : identifier.getLiteralSystemId(); fDTDHandler.notationDecl(name, publicId, systemId); } } catch (SAXException e) { throw new XNIException(e); } } // notationDecl(String,XMLResourceIdentifier, Augmentations) /** * The end of the DTD. * * @param augs Additional information that may include infoset * augmentations. * * @throws XNIException Thrown by handler to signal an error. */ public void endDTD(Augmentations augs) throws XNIException { fInDTD = false; try { // SAX2 extension if (fLexicalHandler != null) { fLexicalHandler.endDTD(); } } catch (SAXException e) { throw new XNIException(e); } if(fDeclaredAttrs != null) { // help out the GC fDeclaredAttrs.clear(); } } // endDTD() // // Parser and XMLReader methods // /** * Parses the input source specified by the given system identifier. * <p> * This method is equivalent to the following: * <pre> * parse(new InputSource(systemId)); * </pre> * * @param systemId The system identifier (URI). * * @exception org.xml.sax.SAXException Throws exception on SAX error. * @exception java.io.IOException Throws exception on i/o error. */ public void parse(String systemId) throws SAXException, IOException { // parse document XMLInputSource source = new XMLInputSource(null, systemId, null); try { parse(source); } // wrap XNI exceptions as SAX exceptions catch (XMLParseException e) { Exception ex = e.getException(); if (ex == null) { // must be a parser exception; mine it for locator info and throw // a SAXParseException LocatorImpl locatorImpl = new LocatorImpl(){ public String getXMLVersion() { return fVersion; } // since XMLParseExceptions know nothing about encoding, // we cannot return anything meaningful in this context. // We *could* consult the LocatorProxy, but the // application can do this itself if it wishes to possibly // be mislead. public String getEncoding() { return null; } }; locatorImpl.setPublicId(e.getPublicId()); locatorImpl.setSystemId(e.getExpandedSystemId()); locatorImpl.setLineNumber(e.getLineNumber()); locatorImpl.setColumnNumber(e.getColumnNumber()); throw new SAXParseException(e.getMessage(), locatorImpl); } if (ex instanceof SAXException) { // why did we create an XMLParseException? throw (SAXException)ex; } if (ex instanceof IOException) { throw (IOException)ex; } throw new SAXException(ex); } catch (XNIException e) { Exception ex = e.getException(); if (ex == null) { throw new SAXException(e.getMessage()); } if (ex instanceof SAXException) { throw (SAXException)ex; } if (ex instanceof IOException) { throw (IOException)ex; } throw new SAXException(ex); } } // parse(String) /** * parse * * @param inputSource * * @exception org.xml.sax.SAXException * @exception java.io.IOException */ public void parse(InputSource inputSource) throws SAXException, IOException { // parse document try { XMLInputSource xmlInputSource = new XMLInputSource(inputSource.getPublicId(), inputSource.getSystemId(), null); xmlInputSource.setByteStream(inputSource.getByteStream()); xmlInputSource.setCharacterStream(inputSource.getCharacterStream()); xmlInputSource.setEncoding(inputSource.getEncoding()); parse(xmlInputSource); } // wrap XNI exceptions as SAX exceptions catch (XMLParseException e) { Exception ex = e.getException(); if (ex == null) { // must be a parser exception; mine it for locator info and throw // a SAXParseException LocatorImpl locatorImpl = new LocatorImpl() { public String getXMLVersion() { return fVersion; } // since XMLParseExceptions know nothing about encoding, // we cannot return anything meaningful in this context. // We *could* consult the LocatorProxy, but the // application can do this itself if it wishes to possibly // be mislead. public String getEncoding() { return null; } }; locatorImpl.setPublicId(e.getPublicId()); locatorImpl.setSystemId(e.getExpandedSystemId()); locatorImpl.setLineNumber(e.getLineNumber()); locatorImpl.setColumnNumber(e.getColumnNumber()); throw new SAXParseException(e.getMessage(), locatorImpl); } if (ex instanceof SAXException) { // why did we create an XMLParseException? throw (SAXException)ex; } if (ex instanceof IOException) { throw (IOException)ex; } throw new SAXException(ex); } catch (XNIException e) { Exception ex = e.getException(); if (ex == null) { throw new SAXException(e.getMessage()); } if (ex instanceof SAXException) { throw (SAXException)ex; } if (ex instanceof IOException) { throw (IOException)ex; } throw new SAXException(ex); } } // parse(InputSource) /** * Sets the resolver used to resolve external entities. The EntityResolver * interface supports resolution of public and system identifiers. * * @param resolver The new entity resolver. Passing a null value will * uninstall the currently installed resolver. */ public void setEntityResolver(EntityResolver resolver) { try { XMLEntityResolver xer = (XMLEntityResolver) fConfiguration.getProperty(ENTITY_RESOLVER); if (fUseEntityResolver2 && resolver instanceof EntityResolver2) { if (xer instanceof EntityResolver2Wrapper) { EntityResolver2Wrapper er2w = (EntityResolver2Wrapper) xer; er2w.setEntityResolver((EntityResolver2) resolver); } else { fConfiguration.setProperty(ENTITY_RESOLVER, new EntityResolver2Wrapper((EntityResolver2) resolver)); } } else { if (xer instanceof EntityResolverWrapper) { EntityResolverWrapper erw = (EntityResolverWrapper) xer; erw.setEntityResolver(resolver); } else { fConfiguration.setProperty(ENTITY_RESOLVER, new EntityResolverWrapper(resolver)); } } } catch (XMLConfigurationException e) { // do nothing } } // setEntityResolver(EntityResolver) /** * Return the current entity resolver. * * @return The current entity resolver, or null if none * has been registered. * @see #setEntityResolver */ public EntityResolver getEntityResolver() { EntityResolver entityResolver = null; try { XMLEntityResolver xmlEntityResolver = (XMLEntityResolver)fConfiguration.getProperty(ENTITY_RESOLVER); if (xmlEntityResolver != null) { if (xmlEntityResolver instanceof EntityResolverWrapper) { entityResolver = ((EntityResolverWrapper) xmlEntityResolver).getEntityResolver(); } else if (xmlEntityResolver instanceof EntityResolver2Wrapper) { entityResolver = ((EntityResolver2Wrapper) xmlEntityResolver).getEntityResolver(); } } } catch (XMLConfigurationException e) { // do nothing } return entityResolver; } // getEntityResolver():EntityResolver /** * Allow an application to register an error event handler. * * <p>If the application does not register an error handler, all * error events reported by the SAX parser will be silently * ignored; however, normal processing may not continue. It is * highly recommended that all SAX applications implement an * error handler to avoid unexpected bugs.</p> * * <p>Applications may register a new or different handler in the * middle of a parse, and the SAX parser must begin using the new * handler immediately.</p> * * @param errorHandler The error handler. * @see #getErrorHandler */ public void setErrorHandler(ErrorHandler errorHandler) { try { XMLErrorHandler xeh = (XMLErrorHandler) fConfiguration.getProperty(ERROR_HANDLER); if (xeh instanceof ErrorHandlerWrapper) { ErrorHandlerWrapper ehw = (ErrorHandlerWrapper) xeh; ehw.setErrorHandler(errorHandler); } else { fConfiguration.setProperty(ERROR_HANDLER, new ErrorHandlerWrapper(errorHandler)); } } catch (XMLConfigurationException e) { // do nothing } } // setErrorHandler(ErrorHandler) /** * Return the current error handler. * * @return The current error handler, or null if none * has been registered. * @see #setErrorHandler */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?