xml11dtdconfiguration.java

来自「JAVA 所有包」· Java 代码 · 共 1,338 行 · 第 1/4 页

JAVA
1,338
字号
            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()    	/**	 * reset all components before parsing and namespace context	 */	protected void resetXML11() throws XNIException {		// reset every component		int count = fXML11Components.size();		for (int i = 0; i < count; i++) {						XMLComponent c = (XMLComponent) fXML11Components.get(i);			c.reset(this);		}	} // resetXML11()    /**     *  Configures the XML 1.1 pipeline.      *  Note: this method also resets the new XML11 components.     */    protected void configureXML11Pipeline() {        if (fCurrentDVFactory != fXML11DatatypeFactory) {            fCurrentDVFactory = fXML11DatatypeFactory;            setProperty(DATATYPE_VALIDATOR_FACTORY, fCurrentDVFactory);        }        if (fCurrentDTDScanner != fXML11DTDScanner) {            fCurrentDTDScanner = fXML11DTDScanner;            setProperty(DTD_SCANNER, fCurrentDTDScanner);			setProperty(DTD_PROCESSOR, fXML11DTDProcessor);        }        fXML11DTDScanner.setDTDHandler(fXML11DTDProcessor);        fXML11DTDProcessor.setDTDSource(fXML11DTDScanner);        fXML11DTDProcessor.setDTDHandler(fDTDHandler);        if (fDTDHandler != null) {            fDTDHandler.setDTDSource(fXML11DTDProcessor);        }        fXML11DTDScanner.setDTDContentModelHandler(fXML11DTDProcessor);        fXML11DTDProcessor.setDTDContentModelSource(fXML11DTDScanner);        fXML11DTDProcessor.setDTDContentModelHandler(fDTDContentModelHandler);        if (fDTDContentModelHandler != null) {            fDTDContentModelHandler.setDTDContentModelSource(fXML11DTDProcessor);        }        // setup XML 1.1 document pipeline        if (fFeatures.get(NAMESPACES) == Boolean.TRUE) {            if (fCurrentScanner != fXML11NSDocScanner) {                fCurrentScanner = fXML11NSDocScanner;                setProperty(DOCUMENT_SCANNER, fXML11NSDocScanner);                setProperty(DTD_VALIDATOR, fXML11NSDTDValidator);            }            fXML11NSDocScanner.setDTDValidator(fXML11NSDTDValidator);            fXML11NSDocScanner.setDocumentHandler(fXML11NSDTDValidator);            fXML11NSDTDValidator.setDocumentSource(fXML11NSDocScanner);            fXML11NSDTDValidator.setDocumentHandler(fDocumentHandler);            if (fDocumentHandler != null) {                fDocumentHandler.setDocumentSource(fXML11NSDTDValidator);            }            fLastComponent = fXML11NSDTDValidator;        } else {			// create components			  if (fXML11DocScanner == null) {					// non namespace document pipeline					fXML11DocScanner = new XML11DocumentScannerImpl();					addXML11Component(fXML11DocScanner);					fXML11DTDValidator = new XML11DTDValidator();					addXML11Component(fXML11DTDValidator);			  }            if (fCurrentScanner != fXML11DocScanner) {                fCurrentScanner = fXML11DocScanner;                setProperty(DOCUMENT_SCANNER, fXML11DocScanner);                setProperty(DTD_VALIDATOR, fXML11DTDValidator);            }            fXML11DocScanner.setDocumentHandler(fXML11DTDValidator);            fXML11DTDValidator.setDocumentSource(fXML11DocScanner);            fXML11DTDValidator.setDocumentHandler(fDocumentHandler);            if (fDocumentHandler != null) {                fDocumentHandler.setDocumentSource(fXML11DTDValidator);            }            fLastComponent = fXML11DTDValidator;        }    } // configureXML11Pipeline()    /** Configures the pipeline. */    protected void configurePipeline() {        if (fCurrentDVFactory != fDatatypeValidatorFactory) {            fCurrentDVFactory = fDatatypeValidatorFactory;            // use XML 1.0 datatype library            setProperty(DATATYPE_VALIDATOR_FACTORY, fCurrentDVFactory);        }        // setup DTD pipeline        if (fCurrentDTDScanner != fDTDScanner) {            fCurrentDTDScanner = fDTDScanner;            setProperty(DTD_SCANNER, fCurrentDTDScanner);            setProperty(DTD_PROCESSOR, fDTDProcessor);        }        fDTDScanner.setDTDHandler(fDTDProcessor);        fDTDProcessor.setDTDSource(fDTDScanner);        fDTDProcessor.setDTDHandler(fDTDHandler);        if (fDTDHandler != null) {            fDTDHandler.setDTDSource(fDTDProcessor);        }        fDTDScanner.setDTDContentModelHandler(fDTDProcessor);        fDTDProcessor.setDTDContentModelSource(fDTDScanner);        fDTDProcessor.setDTDContentModelHandler(fDTDContentModelHandler);

⌨️ 快捷键说明

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