xincludehandler.java

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

JAVA
1,684
字号
    private boolean fIsXML11;    // track whether a DTD is being parsed    private boolean fInDTD;        // track whether the root element of the result infoset has been processed    private boolean fSeenRootElement;        // track whether the child config needs its features refreshed    private boolean fNeedCopyFeatures = true;    // Constructors    public XIncludeHandler() {        fDepth = 0;        fSawFallback[fDepth] = false;        fSawInclude[fDepth] = false;        fState[fDepth] = STATE_NORMAL_PROCESSING;        fNotations = new ArrayList();        fUnparsedEntities = new ArrayList();        fBaseURIScope = new IntStack();        fBaseURI = new Stack();        fLiteralSystemID = new Stack();        fExpandedSystemID = new Stack();        fCurrentBaseURI = new XMLResourceIdentifierImpl();                fLanguageScope = new IntStack();        fLanguageStack = new Stack();        fCurrentLanguage = null;    }    // XMLComponent methods    public void reset(XMLComponentManager componentManager)        throws XNIException {        fNamespaceContext = null;        fDepth = 0;        fResultDepth = isRootDocument() ? 0 : fParentXIncludeHandler.getResultDepth();        fNotations.clear();        fUnparsedEntities.clear();        fParentRelativeURI = null;        fIsXML11 = false;        fInDTD = false;        fSeenRootElement = false;        fBaseURIScope.clear();        fBaseURI.clear();        fLiteralSystemID.clear();        fExpandedSystemID.clear();        fLanguageScope.clear();        fLanguageStack.clear();        // REVISIT: Find a better method for maintaining        // the state of the XInclude processor. These arrays        // can potentially grow quite large. Cleaning them        // out on reset may be very time consuming. -- mrglavas        //        // clear the previous settings from the arrays        for (int i = 0; i < fState.length; ++i) {            fState[i] = STATE_NORMAL_PROCESSING;        }        for (int i = 0; i < fSawFallback.length; ++i) {            fSawFallback[i] = false;        }        for (int i = 0; i < fSawInclude.length; ++i) {            fSawInclude[i] = false;        }                try {            if (!componentManager.getFeature(PARSER_SETTINGS)) {                // if parser settings have not changed return.                return;            }        }         catch (XMLConfigurationException e) {}                // parser settings changed. Need to refresh features on child config.        fNeedCopyFeatures = true;        try {            fSendUEAndNotationEvents =                componentManager.getFeature(ALLOW_UE_AND_NOTATION_EVENTS);            if (fChildConfig != null) {                fChildConfig.setFeature(                    ALLOW_UE_AND_NOTATION_EVENTS,                    fSendUEAndNotationEvents);            }        }        catch (XMLConfigurationException e) {        }                try {            fFixupBaseURIs =                componentManager.getFeature(XINCLUDE_FIXUP_BASE_URIS);            if (fChildConfig != null) {                fChildConfig.setFeature(                    XINCLUDE_FIXUP_BASE_URIS,                    fFixupBaseURIs);            }        }        catch (XMLConfigurationException e) {            fFixupBaseURIs = true;        }                try {            fFixupLanguage =                componentManager.getFeature(XINCLUDE_FIXUP_LANGUAGE);            if (fChildConfig != null) {                fChildConfig.setFeature(                    XINCLUDE_FIXUP_LANGUAGE,                    fFixupLanguage);            }        }        catch (XMLConfigurationException e) {            fFixupLanguage = true;        }                // Get symbol table.        try {            SymbolTable value =                (SymbolTable)componentManager.getProperty(SYMBOL_TABLE);            if (value != null) {                fSymbolTable = value;                if (fChildConfig != null) {                    fChildConfig.setProperty(SYMBOL_TABLE, value);                }            }        }        catch (XMLConfigurationException e) {            fSymbolTable = null;        }        // Get error reporter.        try {            XMLErrorReporter value =                (XMLErrorReporter)componentManager.getProperty(ERROR_REPORTER);            if (value != null) {                setErrorReporter(value);                if (fChildConfig != null) {                    fChildConfig.setProperty(ERROR_REPORTER, value);                }            }        }        catch (XMLConfigurationException e) {            fErrorReporter = null;        }        // Get entity resolver.        try {            XMLEntityResolver value =                (XMLEntityResolver)componentManager.getProperty(                    ENTITY_RESOLVER);            if (value != null) {                fEntityResolver = value;                if (fChildConfig != null) {                    fChildConfig.setProperty(ENTITY_RESOLVER, value);                }            }        }        catch (XMLConfigurationException e) {            fEntityResolver = null;        }        // Get security manager.        try {            SecurityManager value =                (SecurityManager)componentManager.getProperty(                    SECURITY_MANAGER);            if (value != null) {                fSecurityManager = value;                if (fChildConfig != null) {                    fChildConfig.setProperty(SECURITY_MANAGER, value);                }            }        }        catch (XMLConfigurationException e) {            fSecurityManager = null;        }                // Get buffer size.        try {            Integer value =                (Integer)componentManager.getProperty(                    BUFFER_SIZE);            if (value != null && value.intValue() > 0) {                fBufferSize = value.intValue();                if (fChildConfig != null) {                    fChildConfig.setProperty(BUFFER_SIZE, value);                }            }            else {            	fBufferSize = ((Integer)getPropertyDefault(BUFFER_SIZE)).intValue();            }        }        catch (XMLConfigurationException e) {        	fBufferSize = ((Integer)getPropertyDefault(BUFFER_SIZE)).intValue();        }                // Reset XML 1.0 text reader.        if (fXInclude10TextReader != null) {        	fXInclude10TextReader.setBufferSize(fBufferSize);        }        // Reset XML 1.1 text reader.        if (fXInclude11TextReader != null) {            fXInclude11TextReader.setBufferSize(fBufferSize);           }        fSettings = new ParserConfigurationSettings();        copyFeatures(componentManager, fSettings);                // We don't want a schema validator on the new pipeline,        // so if it was enabled, we set the feature to false. If        // the validation feature was also enabled we turn on        // dynamic validation, so that DTD validation is performed        // on the included documents only if they have a DOCTYPE.         // This is consistent with the behaviour on the main pipeline.        try {            if (componentManager.getFeature(SCHEMA_VALIDATION)) {                fSettings.setFeature(SCHEMA_VALIDATION, false);                if (componentManager.getFeature(VALIDATION)) {                    fSettings.setFeature(DYNAMIC_VALIDATION, true);                }            }        }        catch (XMLConfigurationException e) {}                // Don't reset fChildConfig -- we don't want it to share the same components.        // It will be reset when it is actually used to parse something.    } // reset(XMLComponentManager)    /**     * Returns a list of feature identifiers that are recognized by     * this component. This method may return null if no features     * are recognized by this component.     */    public String[] getRecognizedFeatures() {        return (String[])(RECOGNIZED_FEATURES.clone());    } // getRecognizedFeatures():String[]    /**     * Sets the state of a feature. This method is called by the component     * manager any time after reset when a feature changes state.     * <p>     * <strong>Note:</strong> Components should silently ignore features     * that do not affect the operation of the component.     *     * @param featureId The feature identifier.     * @param state     The state of the feature.     *     * @throws SAXNotRecognizedException The component should not throw     *                                   this exception.     * @throws SAXNotSupportedException The component should not throw     *                                  this exception.     */    public void setFeature(String featureId, boolean state)        throws XMLConfigurationException {        if (featureId.equals(ALLOW_UE_AND_NOTATION_EVENTS)) {            fSendUEAndNotationEvents = state;        }        if (fSettings != null) {            fNeedCopyFeatures = true;            fSettings.setFeature(featureId, state);        }    } // setFeature(String,boolean)    /**     * Returns a list of property identifiers that are recognized by     * this component. This method may return null if no properties     * are recognized by this component.     */    public String[] getRecognizedProperties() {        return (String[])(RECOGNIZED_PROPERTIES.clone());    } // getRecognizedProperties():String[]    /**     * Sets the value of a property. This method is called by the component     * manager any time after reset when a property changes value.     * <p>     * <strong>Note:</strong> Components should silently ignore properties     * that do not affect the operation of the component.     *     * @param propertyId The property identifier.     * @param value      The value of the property.     *     * @throws SAXNotRecognizedException The component should not throw     *                                   this exception.     * @throws SAXNotSupportedException The component should not throw     *                                  this exception.     */    public void setProperty(String propertyId, Object value)        throws XMLConfigurationException {        if (propertyId.equals(SYMBOL_TABLE)) {            fSymbolTable = (SymbolTable)value;            if (fChildConfig != null) {                fChildConfig.setProperty(propertyId, value);            }            return;        }        if (propertyId.equals(ERROR_REPORTER)) {            setErrorReporter((XMLErrorReporter)value);            if (fChildConfig != null) {                fChildConfig.setProperty(propertyId, value);            }            return;        }        if (propertyId.equals(ENTITY_RESOLVER)) {            fEntityResolver = (XMLEntityResolver)value;            if (fChildConfig != null) {                fChildConfig.setProperty(propertyId, value);            }            return;        }        if (propertyId.equals(SECURITY_MANAGER)) {            fSecurityManager = (SecurityManager)value;            if (fChildConfig != null) {                fChildConfig.setProperty(propertyId, value);            }            return;        }        if (propertyId.equals(BUFFER_SIZE)) {            Integer bufferSize = (Integer) value;            if (fChildConfig != null) {                fChildConfig.setProperty(propertyId, value);            }            if (bufferSize != null && bufferSize.intValue() > 0) {                fBufferSize = bufferSize.intValue();                // Reset XML 1.0 text reader.                if (fXInclude10TextReader != null) {                    fXInclude10TextReader.setBufferSize(fBufferSize);                }                // Reset XML 1.1 text reader.                if (fXInclude11TextReader != null) {

⌨️ 快捷键说明

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