abstractsaxparser.java

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

JAVA
1,695
字号
     *     * @param errorHandler The error handler.     * @see #getErrorHandler     */    public void setErrorHandler(ErrorHandler errorHandler) {                try {            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 locale to use for messages.     *     * @param locale The locale object to use for localization of messages.     *     * @exception SAXException An exception thrown if the parser does not     *                         support the specified locale.     *     * @see org.xml.sax.Parser     */    public void setLocale(Locale locale) throws SAXException {        //REVISIT:this methods is not part of SAX2 interfaces, we should throw exception        //if any application uses SAX2 and sets locale also. -nb        fConfiguration.setLocale(locale);            } // setLocale(Locale)        /**     * Allow an application to register a DTD event handler.     * <p>     * If the application does not register a DTD handler, all DTD     * events reported by the SAX parser will be silently ignored.     * <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.     *     * @param dtdHandler The DTD handler.     *     *     * @see #getDTDHandler     */    public void setDTDHandler(DTDHandler dtdHandler) {        fDTDHandler = dtdHandler;    } // setDTDHandler(DTDHandler)        //    // Parser methods    //        /**     * Allow an application to register a document event handler.     * <p>     * If the application does not register a document handler, all     * document events reported by the SAX parser will be silently     * ignored (this is the default behaviour implemented by     * HandlerBase).     * <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.     *     * @param documentHandler The document handler.     */    public void setDocumentHandler(DocumentHandler documentHandler) {        fDocumentHandler = documentHandler;    } // setDocumentHandler(DocumentHandler)        //    // XMLReader methods    //        /**     * Allow an application to register a content event handler.     * <p>     * If the application does not register a content handler, all     * content events reported by the SAX parser will be silently     * ignored.     * <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.     *     * @param contentHandler The content handler.     *     * @see #getContentHandler     */    public void setContentHandler(ContentHandler contentHandler) {        fContentHandler = contentHandler;    } // setContentHandler(ContentHandler)        /**     * Return the current content handler.     *     * @return The current content handler, or null if none     *         has been registered.     *     * @see #setContentHandler     */    public ContentHandler getContentHandler() {        return fContentHandler;    } // getContentHandler():ContentHandler        /**     * Return the current DTD handler.     *     * @return The current DTD handler, or null if none     *         has been registered.     * @see #setDTDHandler     */    public DTDHandler getDTDHandler() {        return fDTDHandler;    } // getDTDHandler():DTDHandler        /**     * 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 {            //            // SAX2 Features            //                        if (featureId.startsWith(Constants.SAX_FEATURE_PREFIX)) {                final int suffixLength = featureId.length() - Constants.SAX_FEATURE_PREFIX.length();                                // http://xml.org/sax/features/namespaces                if (suffixLength == Constants.NAMESPACES_FEATURE.length() &&                featureId.endsWith(Constants.NAMESPACES_FEATURE)) {                    fConfiguration.setFeature(featureId, state);                    fNamespaces = state;                    return;                }                // http://xml.org/sax/features/namespace-prefixes                //   controls the reporting of raw prefixed names and Namespace                //   declarations (xmlns* attributes): when this feature is false                //   (the default), raw prefixed names may optionally be reported,                //   and xmlns* attributes must not be reported.                //                if (suffixLength == Constants.NAMESPACE_PREFIXES_FEATURE.length() &&                featureId.endsWith(Constants.NAMESPACE_PREFIXES_FEATURE)) {                    fConfiguration.setFeature(featureId, state);                    fNamespacePrefixes = state;                    return;                }                // http://xml.org/sax/features/string-interning                //   controls the use of java.lang.String#intern() for strings                //   passed to SAX handlers.                //                if (suffixLength == Constants.STRING_INTERNING_FEATURE.length() &&                featureId.endsWith(Constants.STRING_INTERNING_FEATURE)) {                    if (!state) {                        throw new SAXNotSupportedException(                        SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),                        "false-not-supported", new Object [] {featureId}));                    }                    return;                }                // http://xml.org/sax/features/lexical-handler/parameter-entities                //   controls whether the beginning and end of parameter entities                //   will be reported to the LexicalHandler.                //                if (suffixLength == Constants.LEXICAL_HANDLER_PARAMETER_ENTITIES_FEATURE.length() &&                featureId.endsWith(Constants.LEXICAL_HANDLER_PARAMETER_ENTITIES_FEATURE)) {                    fLexicalHandlerParameterEntities = state;                    return;                }                                if(suffixLength == Constants.RESOLVE_DTD_URIS_FEATURE.length() && featureId.endsWith(Constants.RESOLVE_DTD_URIS_FEATURE)){                    resolve_dtd_uris = state;                    fConfiguration.setFeature(featureId, state);                    return;                }                                if((suffixLength == Constants.XML_11_FEATURE.length() &&                featureId.endsWith(Constants.XML_11_FEATURE)) ||                (suffixLength == Constants.USE_ENTITY_RESOLVER2_FEATURE.length() &&                featureId.endsWith(Constants.USE_ENTITY_RESOLVER2_FEATURE))||                (suffixLength == Constants.USE_LOCATOR2_FEATURE.length() &&                featureId.endsWith(Constants.USE_LOCATOR2_FEATURE))||                (suffixLength == Constants.USE_ATTRIBUTES2_FEATURE.length() &&                featureId.endsWith(Constants.USE_ATTRIBUTES2_FEATURE))||                (suffixLength == Constants.IS_STANDALONE_FEATURE.length() &&                featureId.endsWith(Constants.IS_STANDALONE_FEATURE))                ){                    throw new SAXNotSupportedException(                    SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),                    "feature-read-only", new Object [] {featureId}));                }                                                //                // Drop through and perform default processing                //            }                        //            // Xerces Features            //                        /*            else if (featureId.startsWith(XERCES_FEATURES_PREFIX)) {                String feature = featureId.substring(XERCES_FEATURES_PREFIX.length());                //                // Drop through and perform default processing                //            }             */                        //            // 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 {            //            // SAX2 Features            //                        if (featureId.startsWith(Constants.SAX_FEATURE_PREFIX)) {                final int suffixLength = featureId.length() - Constants.SAX_FEATURE_PREFIX.length();                                // http://xml.org/sax/features/namespace-prefixes                //   controls the reporting of raw prefixed names and Namespace                //   declarations (xmlns* attributes): when this feature is false                //   (the default), raw prefixed names may optionally be reported,                //   and xmlns* attributes must not be reported.                //                if (suffixLength == Constants.NAMESPACE_PREFIXES_FEATURE.length() &&                featureId.endsWith(Constants.NAMESPACE_PREFIXES_FEATURE)) {                    boolean state = fConfiguration.getFeature(featureId);                    return state;                }                // http://xml.org/sax/features/string-interning                //   controls the use of java.lang.String#intern() for strings                //   passed to SAX handlers.                //                if (suffixLength == Constants.STRING_INTERNING_FEATURE.length() &&                featureId.endsWith(Constants.STRING_INTERNING_FEATURE)) {                    return true;                }                                // http://xml.org/sax/features/lexical-handler/parameter-entities                //   controls whether the beginning and end of parameter entities                //   will be reported to the LexicalHandler.                //                if (suffixLength == Constants.LEXICAL_HANDLER_PARAMETER_ENTITIES_FEATURE.length() &&                featureId.endsWith(Constants.LEXICAL_HANDLER_PARAMETER_ENTITIES_FEATURE)) {                    return fLexicalHandlerParameterEntities;                }                                if(suffixLength == Constants.USE_ENTITY_RESOLVER2_FEATURE.length() &&                featureId.endsWith(Constants.USE_ENTITY_RESOLVER2_FEATURE)){                    return resolverType;                }                                if(suffixLength == Constants.USE_LOCATOR2_FEATURE.length() && featureId.endsWith(Constants.USE_LOCATOR2_FEATURE)){                    return locatorType;                                    }                if(suffixLength == Constants.USE_ATTRIBUTES2_FEATURE.

⌨️ 快捷键说明

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