nonvalidatingconfiguration.java

来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 817 行 · 第 1/2 页

JAVA
817
字号
/* * The Apache Software License, Version 1.1 * * * Copyright (c) 2001-2004 The Apache Software Foundation.   * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer.  * * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in *    the documentation and/or other materials provided with the *    distribution. * * 3. The end-user documentation included with the redistribution, *    if any, must include the following acknowledgment:   *       "This product includes software developed by the *        Apache Software Foundation (http://www.apache.org/)." *    Alternately, this acknowledgment may appear in the software itself, *    if and wherever such third-party acknowledgments normally appear. * * 4. The names "Xerces" and "Apache Software Foundation" must *    not be used to endorse or promote products derived from this *    software without prior written permission. For written  *    permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", *    nor may "Apache" appear in their name, without prior written *    permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation and was * originally based on software copyright (c) 1999, International * Business Machines, Inc., http://www.apache.org.  For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */package com.sun.org.apache.xerces.internal.parsers;import java.io.IOException;import java.util.Locale;import com.sun.org.apache.xerces.internal.impl.Constants;import com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl;import com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl;import com.sun.org.apache.xerces.internal.impl.XMLEntityManager;import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;import com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl;import com.sun.org.apache.xerces.internal.impl.dv.DTDDVFactory;import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager;import com.sun.org.apache.xerces.internal.util.SymbolTable;import com.sun.org.apache.xerces.internal.xni.XMLLocator;import com.sun.org.apache.xerces.internal.xni.XNIException;import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool;import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent;import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDScanner;import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentScanner;import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;import com.sun.org.apache.xerces.internal.xni.parser.XMLPullParserConfiguration;/** * This is the non validating parser configuration. It extends the basic * configuration with the set of following parser components: * Document scanner, DTD scanner, namespace binder, document handler. * <p> * Xerces parser that uses this configuration is <strong>not</strong> <a href="http://www.w3.org/TR/REC-xml#sec-conformance">conformant</a>  * non-validating XML processor, since conformant non-validating processor is required   * to process "all the declarations they read in the internal DTD subset ... must use the information in those declarations to normalize attribute values,  * include the replacement text of internal entities, and supply default attribute values". *  * @author Elena Litani, IBM * @version $Id: NonValidatingConfiguration.java,v 1.12 2004/01/26 17:28:10 mrglavas Exp $ */public class NonValidatingConfiguration    extends BasicParserConfiguration     implements XMLPullParserConfiguration {    //    // Constants    //    // feature identifiers    /** Feature identifier: warn on duplicate attribute definition. */    protected static final String WARN_ON_DUPLICATE_ATTDEF =        Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ATTDEF_FEATURE;    /** Feature identifier: warn on duplicate entity definition. */    protected static final String WARN_ON_DUPLICATE_ENTITYDEF =        Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ENTITYDEF_FEATURE;        /** Feature identifier: warn on undeclared element definition. */    protected static final String WARN_ON_UNDECLARED_ELEMDEF =        Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_UNDECLARED_ELEMDEF_FEATURE;        /** Feature identifier: allow Java encodings. */    protected static final String ALLOW_JAVA_ENCODINGS =         Constants.XERCES_FEATURE_PREFIX + Constants.ALLOW_JAVA_ENCODINGS_FEATURE;        /** Feature identifier: continue after fatal error. */    protected static final String CONTINUE_AFTER_FATAL_ERROR =         Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE;    /** Feature identifier: load external DTD. */    protected static final String LOAD_EXTERNAL_DTD =        Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE;    /** Feature identifier: notify built-in refereces. */    protected static final String NOTIFY_BUILTIN_REFS =        Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_BUILTIN_REFS_FEATURE;        /** Feature identifier: notify character refereces. */    protected static final String NOTIFY_CHAR_REFS =        Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_CHAR_REFS_FEATURE;        /** Feature identifier: expose schema normalized value */    protected static final String NORMALIZE_DATA =    Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_NORMALIZED_VALUE;    /** Feature identifier: send element default value via characters() */    protected static final String SCHEMA_ELEMENT_DEFAULT =    Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_ELEMENT_DEFAULT;    // property identifiers    /** Property identifier: error reporter. */    protected static final String ERROR_REPORTER =         Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY;    /** Property identifier: entity manager. */    protected static final String ENTITY_MANAGER =         Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY;        /** Property identifier document scanner: */    protected static final String DOCUMENT_SCANNER =         Constants.XERCES_PROPERTY_PREFIX + Constants.DOCUMENT_SCANNER_PROPERTY;    /** Property identifier: DTD scanner. */    protected static final String DTD_SCANNER =         Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_SCANNER_PROPERTY;    /** Property identifier: grammar pool. */    protected static final String XMLGRAMMAR_POOL =         Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY;        /** Property identifier: DTD validator. */    protected static final String DTD_VALIDATOR =         Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_VALIDATOR_PROPERTY;    /** Property identifier: namespace binder. */    protected static final String NAMESPACE_BINDER =        Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_BINDER_PROPERTY;    /** Property identifier: datatype validator factory. */    protected static final String DATATYPE_VALIDATOR_FACTORY =         Constants.XERCES_PROPERTY_PREFIX + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY;    protected static final String VALIDATION_MANAGER =        Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY;    /** Property identifier: XML Schema validator. */    protected static final String SCHEMA_VALIDATOR =        Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_VALIDATOR_PROPERTY;    // debugging    /** Set to true and recompile to print exception stack trace. */    private static final boolean PRINT_EXCEPTION_STACK_TRACE = false;    //    // Data    //    // components (non-configurable)    /** Grammar pool. */    protected XMLGrammarPool fGrammarPool;    /** Datatype validator factory. */    protected DTDDVFactory fDatatypeValidatorFactory;    // components (configurable)    /** Error reporter. */    protected XMLErrorReporter fErrorReporter;    /** Entity manager. */    protected XMLEntityManager fEntityManager;    /** Document scanner. */    protected XMLDocumentScanner fScanner;    /** Input Source */    protected XMLInputSource fInputSource;    /** DTD scanner. */    protected XMLDTDScanner fDTDScanner;    protected ValidationManager fValidationManager;    // private data    /** Document scanner that does namespace binding. */    private XMLNSDocumentScannerImpl fNamespaceScanner;    /** Default Xerces implementation of scanner*/    private XMLDocumentScannerImpl fNonNSScanner;        	/** fConfigUpdated is set to true if there has been any change to the configuration settings, 	 * i.e a feature or a property was changed.	 */	protected boolean fConfigUpdated = false;    // state    /** Locator */    protected XMLLocator fLocator;    /**      * True if a parse is in progress. This state is needed because     * some features/properties cannot be set while parsing (e.g.     * validation and namespaces).     */    protected boolean fParseInProgress = false;    //    // Constructors    //    /** Default constructor. */    public NonValidatingConfiguration() {        this(null, null, null);    } // <init>()    /**      * Constructs a parser configuration using the specified symbol table.      *     * @param symbolTable The symbol table to use.     */    public NonValidatingConfiguration(SymbolTable symbolTable) {        this(symbolTable, null, null);    } // <init>(SymbolTable)    /**     * Constructs a parser configuration using the specified symbol table and     * grammar pool.     * <p>     * <strong>REVISIT:</strong>      * Grammar pool will be updated when the new validation engine is     * implemented.     *     * @param symbolTable The symbol table to use.     * @param grammarPool The grammar pool to use.     */    public NonValidatingConfiguration(SymbolTable symbolTable,                                       XMLGrammarPool grammarPool) {        this(symbolTable, grammarPool, null);    } // <init>(SymbolTable,XMLGrammarPool)    /**     * Constructs a parser configuration using the specified symbol table,     * grammar pool, and parent settings.     * <p>     * <strong>REVISIT:</strong>      * Grammar pool will be updated when the new validation engine is     * implemented.     *     * @param symbolTable    The symbol table to use.     * @param grammarPool    The grammar pool to use.     * @param parentSettings The parent settings.     */    public NonValidatingConfiguration(SymbolTable symbolTable,                                       XMLGrammarPool grammarPool,                                       XMLComponentManager parentSettings) {        super(symbolTable, parentSettings);        // add default recognized features        final String[] recognizedFeatures = {        	        	PARSER_SETTINGS,			NAMESPACES,            //WARN_ON_DUPLICATE_ATTDEF,     // from XMLDTDScannerImpl            //WARN_ON_UNDECLARED_ELEMDEF,   // from XMLDTDScannerImpl            //ALLOW_JAVA_ENCODINGS,         // from XMLEntityManager            CONTINUE_AFTER_FATAL_ERROR,            //LOAD_EXTERNAL_DTD,    // from XMLDTDScannerImpl            //NOTIFY_BUILTIN_REFS,  // from XMLDocumentFragmentScannerImpl            //NOTIFY_CHAR_REFS,		// from XMLDocumentFragmentScannerImpl            //WARN_ON_DUPLICATE_ENTITYDEF   // from XMLEntityManager        };        addRecognizedFeatures(recognizedFeatures);        // set state for default features        //setFeature(WARN_ON_DUPLICATE_ATTDEF, false);  // from XMLDTDScannerImpl        //setFeature(WARN_ON_UNDECLARED_ELEMDEF, false);    // from XMLDTDScannerImpl        //setFeature(ALLOW_JAVA_ENCODINGS, false);      // from XMLEntityManager        fFeatures.put(CONTINUE_AFTER_FATAL_ERROR, Boolean.FALSE);		fFeatures.put(PARSER_SETTINGS, Boolean.TRUE);		fFeatures.put(NAMESPACES, Boolean.TRUE);        //setFeature(LOAD_EXTERNAL_DTD, true);      // from XMLDTDScannerImpl        //setFeature(NOTIFY_BUILTIN_REFS, false);   // from XMLDocumentFragmentScannerImpl        //setFeature(NOTIFY_CHAR_REFS, false);      // from XMLDocumentFragmentScannerImpl        //setFeature(WARN_ON_DUPLICATE_ENTITYDEF, false);   // from XMLEntityManager        // add default recognized properties        final String[] recognizedProperties = {            ERROR_REPORTER,                         ENTITY_MANAGER,             DOCUMENT_SCANNER,            DTD_SCANNER,            DTD_VALIDATOR,            NAMESPACE_BINDER,            XMLGRAMMAR_POOL,               DATATYPE_VALIDATOR_FACTORY,            VALIDATION_MANAGER        };        addRecognizedProperties(recognizedProperties);	        fGrammarPool = grammarPool;        if(fGrammarPool != null){			fProperties.put(XMLGRAMMAR_POOL, fGrammarPool);        }        fEntityManager = createEntityManager();		fProperties.put(ENTITY_MANAGER, fEntityManager);        addComponent(fEntityManager);        fErrorReporter = createErrorReporter();        fErrorReporter.setDocumentLocator(fEntityManager.getEntityScanner());		fProperties.put(ERROR_REPORTER, fErrorReporter);        addComponent(fErrorReporter);        // this configuration delays creation of the scanner        // till it is known if namespace processing should be performed        fDTDScanner = createDTDScanner();        if (fDTDScanner != null) {			fProperties.put(DTD_SCANNER, fDTDScanner);            if (fDTDScanner instanceof XMLComponent) {                addComponent((XMLComponent)fDTDScanner);            }        }        fDatatypeValidatorFactory = createDatatypeValidatorFactory();        if (fDatatypeValidatorFactory != null) {			fProperties.put(DATATYPE_VALIDATOR_FACTORY,                        fDatatypeValidatorFactory);        }        fValidationManager = createValidationManager();        if (fValidationManager != null) {			fProperties.put(VALIDATION_MANAGER, fValidationManager);        }        // add message formatters        if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) {            XMLMessageFormatter xmft = new XMLMessageFormatter();            fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft);            fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft);        }        		fConfigUpdated = false;        // set locale        try {            setLocale(Locale.getDefault());        }        catch (XNIException e) {            // do nothing            // REVISIT: What is the right thing to do? -Ac        }    } // <init>(SymbolTable,XMLGrammarPool)    //    // Public methods    //	public void setFeature(String featureId, boolean state)		throws XMLConfigurationException {		fConfigUpdated = true;		super.setFeature(featureId, state);	}

⌨️ 快捷键说明

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