dtdconfiguration.java
来自「JAVA 所有包」· Java 代码 · 共 849 行 · 第 1/3 页
JAVA
849 行
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) // // Protected methods // /** * Reset all components before parsing. * * @throws XNIException Thrown if an error occurs during initialization. */ protected void reset() throws XNIException { if (fValidationManager != null) fValidationManager.reset(); // configure the pipeline and initialize the components configurePipeline(); super.reset(); } // reset() /** Configures the pipeline. */ protected void configurePipeline() { // REVISIT: This should be better designed. In other words, we // need to figure out what is the best way for people to // re-use *most* of the standard configuration but do // things common things such as remove a component (e.g. // the validator), insert a new component (e.g. XInclude), // etc... -Ac // setup document pipeline if (fDTDValidator != null) { fScanner.setDocumentHandler(fDTDValidator); if (fFeatures.get(NAMESPACES) == Boolean.TRUE) { // filters fDTDValidator.setDocumentHandler(fNamespaceBinder); fDTDValidator.setDocumentSource(fScanner); fNamespaceBinder.setDocumentHandler(fDocumentHandler); fNamespaceBinder.setDocumentSource(fDTDValidator); fLastComponent = fNamespaceBinder; } else { fDTDValidator.setDocumentHandler(fDocumentHandler); fDTDValidator.setDocumentSource(fScanner); fLastComponent = fDTDValidator; } } else { if (fFeatures.get(NAMESPACES) == Boolean.TRUE) { fScanner.setDocumentHandler(fNamespaceBinder); fNamespaceBinder.setDocumentHandler(fDocumentHandler); fNamespaceBinder.setDocumentSource(fScanner); fLastComponent = fNamespaceBinder; } else { fScanner.setDocumentHandler(fDocumentHandler); fLastComponent = fScanner; } } configureDTDPipeline(); } // configurePipeline() protected void configureDTDPipeline (){ // setup dtd pipeline if (fDTDScanner != null) { fProperties.put(DTD_SCANNER, fDTDScanner); if (fDTDProcessor != null) { fProperties.put(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); if (fDTDContentModelHandler != null) { fDTDContentModelHandler.setDTDContentModelSource(fDTDProcessor); } } else { fDTDScanner.setDTDHandler(fDTDHandler); if (fDTDHandler != null) { fDTDHandler.setDTDSource(fDTDScanner); } fDTDScanner.setDTDContentModelHandler(fDTDContentModelHandler); if (fDTDContentModelHandler != null) { fDTDContentModelHandler.setDTDContentModelSource(fDTDScanner); } } } } // features and properties /** * Check a feature. If feature is know and supported, this method simply * returns. Otherwise, the appropriate exception is thrown. * * @param featureId The unique identifier (URI) of the feature. * * @throws XMLConfigurationException Thrown for configuration error. * In general, components should * only throw this exception if * it is <strong>really</strong> * a critical error. */ protected void checkFeature(String featureId) throws XMLConfigurationException { // // Xerces Features // if (featureId.startsWith(Constants.XERCES_FEATURE_PREFIX)) { final int suffixLength = featureId.length() - Constants.XERCES_FEATURE_PREFIX.length(); // // http://apache.org/xml/features/validation/dynamic // Allows the parser to validate a document only when it // contains a grammar. Validation is turned on/off based // on each document instance, automatically. // if (suffixLength == Constants.DYNAMIC_VALIDATION_FEATURE.length() && featureId.endsWith(Constants.DYNAMIC_VALIDATION_FEATURE)) { return; } // // http://apache.org/xml/features/validation/default-attribute-values // if (suffixLength == Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE.length() && featureId.endsWith(Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE)) { // REVISIT short type = XMLConfigurationException.NOT_SUPPORTED; throw new XMLConfigurationException(type, featureId); } // // http://apache.org/xml/features/validation/default-attribute-values // if (suffixLength == Constants.VALIDATE_CONTENT_MODELS_FEATURE.length() && featureId.endsWith(Constants.VALIDATE_CONTENT_MODELS_FEATURE)) { // REVISIT short type = XMLConfigurationException.NOT_SUPPORTED; throw new XMLConfigurationException(type, featureId); } // // http://apache.org/xml/features/validation/nonvalidating/load-dtd-grammar // if (suffixLength == Constants.LOAD_DTD_GRAMMAR_FEATURE.length() && featureId.endsWith(Constants.LOAD_DTD_GRAMMAR_FEATURE)) { return; } // // http://apache.org/xml/features/validation/nonvalidating/load-external-dtd // if (suffixLength == Constants.LOAD_EXTERNAL_DTD_FEATURE.length() && featureId.endsWith(Constants.LOAD_EXTERNAL_DTD_FEATURE)) { return; } // // http://apache.org/xml/features/validation/default-attribute-values // if (suffixLength == Constants.VALIDATE_DATATYPES_FEATURE.length() && featureId.endsWith(Constants.VALIDATE_DATATYPES_FEATURE)) { short type = XMLConfigurationException.NOT_SUPPORTED; throw new XMLConfigurationException(type, featureId); } } // // Not recognized // super.checkFeature(featureId); } // checkFeature(String) /** * Check a property. If the property is know and supported, this method * simply returns. Otherwise, the appropriate exception is thrown. * * @param propertyId The unique identifier (URI) of the property * being set. * * @throws XMLConfigurationException Thrown for configuration error. * In general, components should * only throw this exception if * it is <strong>really</strong> * a critical error. */ protected void checkProperty(String propertyId) throws XMLConfigurationException { // // Xerces Properties // if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) { final int suffixLength = propertyId.length() - Constants.XERCES_PROPERTY_PREFIX.length(); if (suffixLength == Constants.DTD_SCANNER_PROPERTY.length() && propertyId.endsWith(Constants.DTD_SCANNER_PROPERTY)) { return; } } // // Not recognized // super.checkProperty(propertyId); } // checkProperty(String) // factory methods /** Creates an entity manager. */ protected XMLEntityManager createEntityManager() { return new XMLEntityManager(); } // createEntityManager():XMLEntityManager /** Creates an error reporter. */ protected XMLErrorReporter createErrorReporter() { return new XMLErrorReporter(); } // createErrorReporter():XMLErrorReporter /** Create a document scanner. */ protected XMLDocumentScanner createDocumentScanner() { return new XMLDocumentScannerImpl(); } // createDocumentScanner():XMLDocumentScanner /** Create a DTD scanner. */ protected XMLDTDScanner createDTDScanner() { return new XMLDTDScannerImpl(); } // createDTDScanner():XMLDTDScanner /** Create a DTD loader . */ protected XMLDTDProcessor createDTDProcessor() { return new XMLDTDProcessor(); } // createDTDProcessor():XMLDTDProcessor /** Create a DTD validator. */ protected XMLDTDValidator createDTDValidator() { return new XMLDTDValidator(); } // createDTDValidator():XMLDTDValidator /** Create a namespace binder. */ protected XMLNamespaceBinder createNamespaceBinder() { return new XMLNamespaceBinder(); } // createNamespaceBinder():XMLNamespaceBinder /** Create a datatype validator factory. */ protected DTDDVFactory createDatatypeValidatorFactory() { return DTDDVFactory.getInstance(); } // createDatatypeValidatorFactory():DatatypeValidatorFactory protected ValidationManager createValidationManager(){ return new ValidationManager(); }} // class DTDConfiguration
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?