xml11nonvalidatingconfiguration.java
来自「JAVA 所有包」· Java 代码 · 共 1,233 行 · 第 1/3 页
JAVA
1,233 行
// set locale try { setLocale(Locale.getDefault()); } catch (XNIException e) { // do nothing // REVISIT: What is the right thing to do? -Ac } fConfigUpdated = false; } // <init>(SymbolTable,XMLGrammarPool) /** * Sets the input source for the document to parse. * * @param inputSource The document's input source. * * @exception XMLConfigurationException Thrown if there is a * configuration error when initializing the * parser. * @exception IOException Thrown on I/O error. * * @see #parse(boolean) */ public void setInputSource(XMLInputSource inputSource) throws XMLConfigurationException, IOException { // REVISIT: this method used to reset all the components and // construct the pipeline. Now reset() is called // in parse (boolean) just before we parse the document // Should this method still throw exceptions..? fInputSource = inputSource; } // setInputSource(XMLInputSource) /** * Set the locale to use for messages. * * @param locale The locale object to use for localization of messages. * * @exception XNIException Thrown if the parser does not support the * specified locale. */ public void setLocale(Locale locale) throws XNIException { fLocale = locale; fErrorReporter.setLocale(locale); } // setLocale(Locale) /** * Sets the document handler on the last component in the pipeline * to receive information about the document. * * @param documentHandler The document handler. */ public void setDocumentHandler(XMLDocumentHandler documentHandler) { fDocumentHandler = documentHandler; if (fLastComponent != null) { fLastComponent.setDocumentHandler(fDocumentHandler); if (fDocumentHandler !=null){ fDocumentHandler.setDocumentSource(fLastComponent); } } } // setDocumentHandler(XMLDocumentHandler) /** Returns the registered document handler. */ public XMLDocumentHandler getDocumentHandler() { return fDocumentHandler; } // getDocumentHandler():XMLDocumentHandler /** * Sets the DTD handler. * * @param dtdHandler The DTD handler. */ public void setDTDHandler(XMLDTDHandler dtdHandler) { fDTDHandler = dtdHandler; } // setDTDHandler(XMLDTDHandler) /** Returns the registered DTD handler. */ public XMLDTDHandler getDTDHandler() { return fDTDHandler; } // getDTDHandler():XMLDTDHandler /** * Sets the DTD content model handler. * * @param handler The DTD content model handler. */ public void setDTDContentModelHandler(XMLDTDContentModelHandler handler) { fDTDContentModelHandler = handler; } // setDTDContentModelHandler(XMLDTDContentModelHandler) /** Returns the registered DTD content model handler. */ public XMLDTDContentModelHandler getDTDContentModelHandler() { return fDTDContentModelHandler; } // getDTDContentModelHandler():XMLDTDContentModelHandler /** * 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(XMLEntityResolver resolver) { fProperties.put(ENTITY_RESOLVER, resolver); } // setEntityResolver(XMLEntityResolver) /** * Return the current entity resolver. * * @return The current entity resolver, or null if none * has been registered. * @see #setEntityResolver */ public XMLEntityResolver getEntityResolver() { return (XMLEntityResolver)fProperties.get(ENTITY_RESOLVER); } // getEntityResolver():XMLEntityResolver /** * 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(XMLErrorHandler errorHandler) { fProperties.put(ERROR_HANDLER, errorHandler); } // setErrorHandler(XMLErrorHandler) /** * Return the current error handler. * * @return The current error handler, or null if none * has been registered. * @see #setErrorHandler */ public XMLErrorHandler getErrorHandler() { // REVISIT: Should this be a property? return (XMLErrorHandler)fProperties.get(ERROR_HANDLER); } // getErrorHandler():XMLErrorHandler /** * If the application decides to terminate parsing before the xml document * is fully parsed, the application should call this method to free any * resource allocated during parsing. For example, close all opened streams. */ public void cleanup() { fEntityManager.closeReaders(); } /** * Parses the specified input source. * * @param source The input source. * * @exception XNIException Throws exception on XNI error. * @exception java.io.IOException Throws exception on i/o error. */ public void parse(XMLInputSource source) throws XNIException, IOException { if (fParseInProgress) { // REVISIT - need to add new error message throw new XNIException("FWK005 parse may not be called while parsing."); } fParseInProgress = true; try { setInputSource(source); parse(true); } catch (XNIException ex) { if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace(); throw ex; } catch (IOException ex) { if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace(); throw ex; } catch (RuntimeException ex) { if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace(); throw ex; } catch (Exception ex) { if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace(); throw new XNIException(ex); } finally { fParseInProgress = false; // close all streams opened by xerces this.cleanup(); } } // parse(InputSource) public boolean parse(boolean complete) throws XNIException, IOException { // // reset and configure pipeline and set InputSource. if (fInputSource != null) { try { fValidationManager.reset(); fVersionDetector.reset(this); resetCommon(); short version = fVersionDetector.determineDocVersion(fInputSource); if (version == Constants.XML_VERSION_1_1) { initXML11Components(); configureXML11Pipeline(); resetXML11(); } else { configurePipeline(); reset(); } // mark configuration as fixed fConfigUpdated = false; // resets and sets the pipeline. fVersionDetector.startDocumentParsing((XMLEntityHandler) fCurrentScanner, version); fInputSource = null; } catch (XNIException ex) { if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace(); throw ex; } catch (IOException ex) { if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace(); throw ex; } catch (RuntimeException ex) { if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace(); throw ex; } catch (Exception ex) { if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace(); throw new XNIException(ex); } } try { return fCurrentScanner.scanDocument(complete); } catch (XNIException ex) { if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace(); throw ex; } catch (IOException ex) { if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace(); throw ex; } catch (RuntimeException ex) { if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace(); throw ex; } catch (Exception ex) { if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace(); throw new XNIException(ex); } } // parse(boolean):boolean /** * Returns the state of a feature. * * @param featureId The feature identifier. * @return true if the feature is supported * * @throws XMLConfigurationException Thrown for configuration error. * In general, components should * only throw this exception if * it is <strong>really</strong> * a critical error. */ public boolean getFeature(String featureId) throws XMLConfigurationException { // make this feature special if (featureId.equals(PARSER_SETTINGS)){ return fConfigUpdated; } return super.getFeature(featureId); } // getFeature(String):boolean /** * Set the state of a feature. * * 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 com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException If the * requested feature is not known. */ public void setFeature(String featureId, boolean state) throws XMLConfigurationException { fConfigUpdated = true; // forward to every XML 1.0 component int count = fComponents.size(); for (int i = 0; i < count; i++) { XMLComponent c = (XMLComponent) fComponents.get(i); c.setFeature(featureId, state); } // forward it to common components count = fCommonComponents.size(); for (int i = 0; i < count; i++) { XMLComponent c = (XMLComponent) fCommonComponents.get(i); c.setFeature(featureId, state); } // forward to every XML 1.1 component count = fXML11Components.size(); for (int i = 0; i < count; i++) { XMLComponent c = (XMLComponent) fXML11Components.get(i); try{ c.setFeature(featureId, state); } catch (Exception e){ // no op } } // save state if noone "objects" super.setFeature(featureId, state); } // setFeature(String,boolean) /** * setProperty * * @param propertyId * @param value */ public void setProperty(String propertyId, Object value) throws XMLConfigurationException { fConfigUpdated = true; // forward to every XML 1.0 component int count = fComponents.size(); for (int i = 0; i < count; i++) { XMLComponent c = (XMLComponent) fComponents.get(i); c.setProperty(propertyId, value); } // forward it to every common Component count = fCommonComponents.size(); for (int i = 0; i < count; i++) { XMLComponent c = (XMLComponent) fCommonComponents.get(i); c.setProperty(propertyId, value); } // forward it to every XML 1.1 component count = fXML11Components.size(); for (int i = 0; i < count; i++) { XMLComponent c = (XMLComponent) fXML11Components.get(i); try{ c.setProperty(propertyId, value); } catch (Exception e){ // ignore it } } // store value if noone "objects" super.setProperty(propertyId, value); } // setProperty(String,Object) /** Returns the locale. */ public Locale getLocale() { return fLocale; } // getLocale():Locale /** * reset all XML 1.0 components before parsing and namespace context */ protected void reset() throws XNIException { int count = fComponents.size(); for (int i = 0; i < count; i++) { XMLComponent c = (XMLComponent) fComponents.get(i); c.reset(this); } } // reset() /** * reset all common components before parsing */ protected void resetCommon() throws XNIException { // reset common components int count = fCommonComponents.size(); for (int i = 0; i < count; i++) { XMLComponent c = (XMLComponent) fCommonComponents.get(i); c.reset(this); } } // resetCommon()
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?