domparser.java

来自「JAVA 所有包」· Java 代码 · 共 596 行 · 第 1/2 页

JAVA
596
字号
            // 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.     * @exception java.lang.NullPointerException If the handler     *            argument is null.     * @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     */    public ErrorHandler getErrorHandler() {        ErrorHandler errorHandler = null;        try {            XMLErrorHandler xmlErrorHandler =                (XMLErrorHandler)fConfiguration.getProperty(ERROR_HANDLER);            if (xmlErrorHandler != null &&                xmlErrorHandler instanceof ErrorHandlerWrapper) {                errorHandler = ((ErrorHandlerWrapper)xmlErrorHandler).getErrorHandler();            }        }        catch (XMLConfigurationException e) {            // do nothing        }        return errorHandler;    } // getErrorHandler():ErrorHandler    /**     * Set the state of any feature in a SAX2 parser.  The parser     * might not recognize the feature, and if it does recognize     * it, it might not be able to fulfill the request.     *     * @param featureId The unique identifier (URI) of the feature.     * @param state The requested state of the feature (true or false).     *     * @exception SAXNotRecognizedException If the     *            requested feature is not known.     * @exception SAXNotSupportedException If the     *            requested feature is known, but the requested     *            state is not supported.     */    public void setFeature(String featureId, boolean state)        throws SAXNotRecognizedException, SAXNotSupportedException {        try {                        // http://xml.org/sax/features/use-entity-resolver2            //   controls whether the methods of an object implementing            //   org.xml.sax.ext.EntityResolver2 will be used by the parser.            //            if (featureId.equals(USE_ENTITY_RESOLVER2)) {                if (state != fUseEntityResolver2) {                    fUseEntityResolver2 = state;                    // Refresh EntityResolver wrapper.                    setEntityResolver(getEntityResolver());                }                return;            }                        //            // Default handling            //                        fConfiguration.setFeature(featureId, state);        }        catch (XMLConfigurationException e) {            String identifier = e.getIdentifier();            if (e.getType() == XMLConfigurationException.NOT_RECOGNIZED) {                throw new SAXNotRecognizedException(                    SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),                     "feature-not-recognized", new Object [] {identifier}));            }            else {                throw new SAXNotSupportedException(                    SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),                     "feature-not-supported", new Object [] {identifier}));            }        }    } // setFeature(String,boolean)    /**     * Query the state of a feature.     *     * Query the current state of any feature in a SAX2 parser.  The     * parser might not recognize the feature.     *     * @param featureId The unique identifier (URI) of the feature     *                  being set.     * @return The current state of the feature.     * @exception org.xml.sax.SAXNotRecognizedException If the     *            requested feature is not known.     * @exception SAXNotSupportedException If the     *            requested feature is known but not supported.     */    public boolean getFeature(String featureId)        throws SAXNotRecognizedException, SAXNotSupportedException {        try {            // http://xml.org/sax/features/use-entity-resolver2            //   controls whether the methods of an object implementing            //   org.xml.sax.ext.EntityResolver2 will be used by the parser.            //            if (featureId.equals(USE_ENTITY_RESOLVER2)) {                return fUseEntityResolver2;            }                        //            // Default handling            //                        return fConfiguration.getFeature(featureId);        }        catch (XMLConfigurationException e) {            String identifier = e.getIdentifier();            if (e.getType() == XMLConfigurationException.NOT_RECOGNIZED) {                throw new SAXNotRecognizedException(                    SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),                     "feature-not-recognized", new Object [] {identifier}));            }            else {                throw new SAXNotSupportedException(                    SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),                     "feature-not-supported", new Object [] {identifier}));            }        }    } // getFeature(String):boolean    /**     * Set the value of any property in a SAX2 parser.  The parser     * might not recognize the property, and if it does recognize     * it, it might not support the requested value.     *     * @param propertyId The unique identifier (URI) of the property     *                   being set.     * @param value The value to which the property is being set.     *     * @exception SAXNotRecognizedException If the     *            requested property is not known.     * @exception SAXNotSupportedException If the     *            requested property is known, but the requested     *            value is not supported.     */    public void setProperty(String propertyId, Object value)        throws SAXNotRecognizedException, SAXNotSupportedException {        try {            fConfiguration.setProperty(propertyId, value);        }        catch (XMLConfigurationException e) {            String identifier = e.getIdentifier();            if (e.getType() == XMLConfigurationException.NOT_RECOGNIZED) {                throw new SAXNotRecognizedException(                    SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),                     "property-not-recognized", new Object [] {identifier}));            }            else {                throw new SAXNotSupportedException(                    SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),                     "property-not-supported", new Object [] {identifier}));            }        }    } // setProperty(String,Object)    /**     * Query the value of a property.     *     * Return the current value of a property in a SAX2 parser.     * The parser might not recognize the property.     *     * @param propertyId The unique identifier (URI) of the property     *                   being set.     * @return The current value of the property.     * @exception org.xml.sax.SAXNotRecognizedException If the     *            requested property is not known.     * @exception SAXNotSupportedException If the     *            requested property is known but not supported.     */    public Object getProperty(String propertyId)        throws SAXNotRecognizedException, SAXNotSupportedException {       if (propertyId.equals(CURRENT_ELEMENT_NODE)) {           boolean deferred = false;           try {               deferred = getFeature(DEFER_NODE_EXPANSION);           }           catch (XMLConfigurationException e){               // ignore           }           if (deferred) {               throw new SAXNotSupportedException("Current element node cannot be queried when node expansion is deferred.");           }           return (fCurrentNode!=null &&                   fCurrentNode.getNodeType() == Node.ELEMENT_NODE)? fCurrentNode:null;       }        try {            return fConfiguration.getProperty(propertyId);        }        catch (XMLConfigurationException e) {            String identifier = e.getIdentifier();            if (e.getType() == XMLConfigurationException.NOT_RECOGNIZED) {                throw new SAXNotRecognizedException(                    SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),                     "property-not-recognized", new Object [] {identifier}));            }            else {                throw new SAXNotSupportedException(                    SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),                     "property-not-supported", new Object [] {identifier}));            }        }    } // getProperty(String):Object        /**      * Returns this parser's XMLParserConfiguration.     */    public XMLParserConfiguration getXMLParserConfiguration() {        return fConfiguration;    } // getXMLParserConfiguration():XMLParserConfiguration} // class DOMParser

⌨️ 快捷键说明

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