abstractsaxparser.java

来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 1,695 行 · 第 1/5 页

JAVA
1,695
字号
            }        }        catch (SAXException e) {            throw new XNIException(e);        }            } // internalEntityDecl(String,XMLString,XMLString)        /**     * An external entity declaration.     *     * @param name     The name of the entity. Parameter entity names start     *                 with '%', whereas the name of a general entity is just     *                 the entity name.     * @param identifier    An object containing all location information     *                      pertinent to this entity.     * @param augs Additional information that may include infoset     *                      augmentations.     *     * @throws XNIException Thrown by handler to signal an error.     */    public void externalEntityDecl(String name, XMLResourceIdentifier identifier,    Augmentations augs) throws XNIException {                String publicId = identifier.getPublicId();        String literalSystemId = identifier.getLiteralSystemId();        String expandedSystemId = identifier.getExpandedSystemId();        try {            // SAX2 extension            if (fDeclHandler != null) {                fDeclHandler.externalEntityDecl(name, publicId, ((resolve_dtd_uris) ? expandedSystemId : literalSystemId));            }        }        catch (SAXException e) {            throw new XNIException(e);        }            } // externalEntityDecl(String,,XMLResourceIdentifier, Augmentations)        /**     * An unparsed entity declaration.     *     * @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 {                String publicId = identifier.getPublicId();        String expandedSystemId = identifier.getExpandedSystemId();        String literalSystemId = identifier.getLiteralSystemId();        try {            // SAX2 extension            if (fDTDHandler != null) {                fDTDHandler.unparsedEntityDecl(name, publicId,                ((resolve_dtd_uris) ? expandedSystemId : literalSystemId), 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 {                String publicId = identifier.getPublicId();        String expandedSystemId = identifier.getExpandedSystemId();        String literalSystemId = identifier.getLiteralSystemId();        try {            // SAX1 and SAX2            if (fDTDHandler != null) {                fDTDHandler.notationDecl(name, publicId, ((resolve_dtd_uris) ? expandedSystemId : literalSystemId));            }        }        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                locatorType  = true;                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                locatorType  = true;                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 {            if(resolver instanceof EntityResolver2){                resolverType = true;                fConfiguration.setProperty(ENTITY_RESOLVER, new EntityResolver2Wrapper((EntityResolver2)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>

⌨️ 快捷键说明

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