abstractsaxparser.java
来自「JAVA 所有包」· Java 代码 · 共 1,706 行 · 第 1/5 页
JAVA
1,706 行
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; } // http://xml.org/sax/features/resolve-dtd-uris // controls whether system identifiers will be absolutized relative to // their base URIs before reporting. // if (suffixLength == Constants.RESOLVE_DTD_URIS_FEATURE.length() && featureId.endsWith(Constants.RESOLVE_DTD_URIS_FEATURE)) { fResolveDTDURIs = state; return; } // http://xml.org/sax/features/unicode-normalization-checking // controls whether Unicode normalization checking is performed // as per Appendix B of the XML 1.1 specification // if (suffixLength == Constants.UNICODE_NORMALIZATION_CHECKING_FEATURE.length() && featureId.endsWith(Constants.UNICODE_NORMALIZATION_CHECKING_FEATURE)) { // REVISIT: Allow this feature to be set once Unicode normalization // checking is supported -- mrglavas. if (state) { throw new SAXNotSupportedException( SAXMessageFormatter.formatMessage(fConfiguration.getLocale(), "true-not-supported", new Object [] {featureId})); } return; } // http://xml.org/sax/features/xmlns-uris // controls whether the parser reports that namespace declaration // attributes as being in the namespace: http://www.w3.org/2000/xmlns/ // if (suffixLength == Constants.XMLNS_URIS_FEATURE.length() && featureId.endsWith(Constants.XMLNS_URIS_FEATURE)) { fXMLNSURIs = state; return; } // 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 (suffixLength == Constants.USE_ENTITY_RESOLVER2_FEATURE.length() && featureId.endsWith(Constants.USE_ENTITY_RESOLVER2_FEATURE)) { if (state != fUseEntityResolver2) { fUseEntityResolver2 = state; // Refresh EntityResolver wrapper. setEntityResolver(getEntityResolver()); } return; } // // Read only features. // // http://xml.org/sax/features/is-standalone // reports whether the document specified a standalone document declaration. // http://xml.org/sax/features/use-attributes2 // reports whether Attributes objects passed to startElement also implement // the org.xml.sax.ext.Attributes2 interface. // http://xml.org/sax/features/use-locator2 // reports whether Locator objects passed to setDocumentLocator also implement // the org.xml.sax.ext.Locator2 interface. // http://xml.org/sax/features/xml-1.1 // reports whether the parser supports both XML 1.1 and XML 1.0. if ((suffixLength == Constants.IS_STANDALONE_FEATURE.length() && featureId.endsWith(Constants.IS_STANDALONE_FEATURE)) || (suffixLength == Constants.USE_ATTRIBUTES2_FEATURE.length() && featureId.endsWith(Constants.USE_ATTRIBUTES2_FEATURE)) || (suffixLength == Constants.USE_LOCATOR2_FEATURE.length() && featureId.endsWith(Constants.USE_LOCATOR2_FEATURE)) || (suffixLength == Constants.XML_11_FEATURE.length() && featureId.endsWith(Constants.XML_11_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 f
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?