xml11dtdconfiguration.java

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

JAVA
1,338
字号
        if (fDTDContentModelHandler != null) {            fDTDContentModelHandler.setDTDContentModelSource(fDTDProcessor);        }        // setup document pipeline        if (fFeatures.get(NAMESPACES) == Boolean.TRUE) {            if (fCurrentScanner != fNamespaceScanner) {                fCurrentScanner = fNamespaceScanner;                setProperty(DOCUMENT_SCANNER, fNamespaceScanner);                setProperty(DTD_VALIDATOR, fDTDValidator);            }            fNamespaceScanner.setDTDValidator(fDTDValidator);            fNamespaceScanner.setDocumentHandler(fDTDValidator);            fDTDValidator.setDocumentSource(fNamespaceScanner);            fDTDValidator.setDocumentHandler(fDocumentHandler);            if (fDocumentHandler != null) {                fDocumentHandler.setDocumentSource(fDTDValidator);            }            fLastComponent = fDTDValidator;        } else {            // create components            if (fNonNSScanner == null) {                fNonNSScanner = new XMLDocumentScannerImpl();                fNonNSDTDValidator = new XMLDTDValidator();                // add components                addComponent((XMLComponent) fNonNSScanner);                addComponent((XMLComponent) fNonNSDTDValidator);            }            if (fCurrentScanner != fNonNSScanner) {                fCurrentScanner = fNonNSScanner;                setProperty(DOCUMENT_SCANNER, fNonNSScanner);                setProperty(DTD_VALIDATOR, fNonNSDTDValidator);            }            fNonNSScanner.setDocumentHandler(fNonNSDTDValidator);            fNonNSDTDValidator.setDocumentSource(fNonNSScanner);            fNonNSDTDValidator.setDocumentHandler(fDocumentHandler);            if (fDocumentHandler != null) {                fDocumentHandler.setDocumentSource(fNonNSDTDValidator);            }            fLastComponent = fNonNSDTDValidator;        }    } // configurePipeline()    // 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);            }            			             // special performance feature: only component manager is allowed to set it.			             if (suffixLength == Constants.PARSER_SETTINGS.length() &&                 featureId.endsWith(Constants.PARSER_SETTINGS)) {                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;            }        }                // special cases        if (propertyId.startsWith(Constants.SAX_PROPERTY_PREFIX)) {            final int suffixLength = propertyId.length() - Constants.SAX_PROPERTY_PREFIX.length();			            //            // http://xml.org/sax/properties/xml-string            // Value type: String            // Access: read-only            //   Get the literal string of characters associated with the            //   current event.  If the parser recognises and supports this            //   property but is not currently parsing text, it should return            //   null (this is a good way to check for availability before the            //   parse begins).            //            if (suffixLength == Constants.XML_STRING_PROPERTY.length() &&                 propertyId.endsWith(Constants.XML_STRING_PROPERTY)) {                // REVISIT - we should probably ask xml-dev for a precise                // definition of what this is actually supposed to return, and                // in exactly which circumstances.                short type = XMLConfigurationException.NOT_SUPPORTED;                throw new XMLConfigurationException(type, propertyId);            }        }        //        // Not recognized        //        super.checkProperty(propertyId);    } // checkProperty(String)    /**      * Adds a component to the parser configuration. This method will     * also add all of the component's recognized features and properties     * to the list of default recognized features and properties.     *     * @param component The component to add.     */    protected void addComponent(XMLComponent component) {        // don't add a component more than once        if (fComponents.contains(component)) {            return;        }        fComponents.add(component);        addRecognizedParamsAndSetDefaults(component);	    } // addComponent(XMLComponent)        /**      * Adds common component to the parser configuration. This method will     * also add all of the component's recognized features and properties     * to the list of default recognized features and properties.     *     * @param component The component to add.     */    protected void addCommonComponent(XMLComponent component) {        // don't add a component more than once        if (fCommonComponents.contains(component)) {            return;        }        fCommonComponents.add(component);        addRecognizedParamsAndSetDefaults(component);    } // addCommonComponent(XMLComponent)	    /**      * Adds an XML 1.1 component to the parser configuration. This method will     * also add all of the component's recognized features and properties     * to the list of default recognized features and properties.     *     * @param component The component to add.     */    protected void addXML11Component(XMLComponent component) {        // don't add a component more than once        if (fXML11Components.contains(component)) {            return;        }        fXML11Components.add(component);        addRecognizedParamsAndSetDefaults(component);            } // addXML11Component(XMLComponent)        /**     * Adds all of the component's recognized features and properties     * to the list of default recognized features and properties, and     * sets default values on the configuration for features and     * properties which were previously absent from the configuration.     *     * @param component The component whose recognized features     * and properties will be added to the configuration     */    protected void addRecognizedParamsAndSetDefaults(XMLComponent component) {                // register component's recognized features        String[] recognizedFeatures = component.getRecognizedFeatures();        addRecognizedFeatures(recognizedFeatures);                // register component's recognized properties        String[] recognizedProperties = component.getRecognizedProperties();        addRecognizedProperties(recognizedProperties);        // set default values        if (recognizedFeatures != null) {            for (int i = 0; i < recognizedFeatures.length; ++i) {                String featureId = recognizedFeatures[i];                Boolean state = component.getFeatureDefault(featureId);                if (state != null) {                    // Do not overwrite values already set on the configuration.                    if (!fFeatures.containsKey(featureId)) {                        fFeatures.put(featureId, state);                        // For newly added components who recognize this feature                        // but did not offer a default value, we need to make                        // sure these components will get an opportunity to read                        // the value before parsing begins.                        fConfigUpdated = true;                    }                }            }        }        if (recognizedProperties != null) {            for (int i = 0; i < recognizedProperties.length; ++i) {                String propertyId = recognizedProperties[i];                Object value = component.getPropertyDefault(propertyId);                if (value != null) {                    // Do not overwrite values already set on the configuration.                    if (!fProperties.containsKey(propertyId)) {                        fProperties.put(propertyId, value);                        // For newly added components who recognize this property                        // but did not offer a default value, we need to make                        // sure these components will get an opportunity to read                        // the value before parsing begins.                        fConfigUpdated = true;                    }                }            }        }    }     private void initXML11Components() {        if (!f11Initialized) {            // create datatype factory            fXML11DatatypeFactory = DTDDVFactory.getInstance(XML11_DATATYPE_VALIDATOR_FACTORY);            // setup XML 1.1 DTD pipeline            fXML11DTDScanner = new XML11DTDScannerImpl();            addXML11Component(fXML11DTDScanner);            fXML11DTDProcessor = new XML11DTDProcessor();            addXML11Component(fXML11DTDProcessor);            // setup XML 1.1. document pipeline - namespace aware            fXML11NSDocScanner = new XML11NSDocumentScannerImpl();            addXML11Component(fXML11NSDocScanner);            fXML11NSDTDValidator = new XML11NSDTDValidator();            addXML11Component(fXML11NSDTDValidator);				            f11Initialized = true;        }    }} // class XML11DTDConfiguration

⌨️ 快捷键说明

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