domparserimpl.java

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

JAVA
1,309
字号
/* * Copyright 2000-2005 The Apache Software Foundation. *  * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at *  *      http://www.apache.org/licenses/LICENSE-2.0 *  * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.sun.org.apache.xerces.internal.parsers;import java.io.StringReader;import java.util.Locale;import java.util.Stack;import java.util.StringTokenizer;import java.util.Vector;import com.sun.org.apache.xerces.internal.dom.DOMErrorImpl;import com.sun.org.apache.xerces.internal.dom.DOMMessageFormatter;import com.sun.org.apache.xerces.internal.dom.DOMStringListImpl;import com.sun.org.apache.xerces.internal.impl.Constants;import com.sun.org.apache.xerces.internal.util.DOMEntityResolverWrapper;import com.sun.org.apache.xerces.internal.util.DOMErrorHandlerWrapper;import com.sun.org.apache.xerces.internal.util.SymbolTable;import com.sun.org.apache.xerces.internal.util.XMLSymbols;import com.sun.org.apache.xerces.internal.xni.Augmentations;import com.sun.org.apache.xerces.internal.xni.NamespaceContext;import com.sun.org.apache.xerces.internal.xni.QName;import com.sun.org.apache.xerces.internal.xni.XMLAttributes;import com.sun.org.apache.xerces.internal.xni.XMLDTDContentModelHandler;import com.sun.org.apache.xerces.internal.xni.XMLDTDHandler;import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler;import com.sun.org.apache.xerces.internal.xni.XMLLocator;import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier;import com.sun.org.apache.xerces.internal.xni.XMLString;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.XMLConfigurationException;import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDContentModelSource;import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDSource;import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentSource;import com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver;import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;import com.sun.org.apache.xerces.internal.xni.parser.XMLParseException;import com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration;import org.w3c.dom.DOMConfiguration;import org.w3c.dom.DOMError;import org.w3c.dom.DOMErrorHandler;import org.w3c.dom.DOMException;import org.w3c.dom.DOMStringList;import org.w3c.dom.Document;import org.w3c.dom.Node;import org.w3c.dom.ls.LSException;import org.w3c.dom.ls.LSInput;import org.w3c.dom.ls.LSParser;import org.w3c.dom.ls.LSParserFilter;import org.w3c.dom.ls.LSResourceResolver;import org.xml.sax.SAXException;/** * This is Xerces DOM Builder class. It uses the abstract DOM * parser with a document scanner, a dtd scanner, and a validator, as * well as a grammar pool. * * @author Pavani Mukthipudi, Sun Microsystems Inc. * @author Elena Litani, IBM * @author Rahul Srivastava, Sun Microsystems Inc. * @version $Id: DOMParserImpl.java,v 1.2.6.1 2005/09/06 13:27:46 sunithareddy Exp $ */public class DOMParserImplextends AbstractDOMParser implements LSParser, DOMConfiguration {    // SAX & Xerces feature ids    /** Feature identifier: namespaces. */    protected static final String NAMESPACES =    Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE;    /** Feature id: validation. */    protected static final String VALIDATION_FEATURE =    Constants.SAX_FEATURE_PREFIX+Constants.VALIDATION_FEATURE;    /** XML Schema validation */    protected static final String XMLSCHEMA =    Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE;        /** XML Schema full checking */    protected static final String XMLSCHEMA_FULL_CHECKING =    Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_FULL_CHECKING;        /** Dynamic validation */    protected static final String DYNAMIC_VALIDATION =    Constants.XERCES_FEATURE_PREFIX + Constants.DYNAMIC_VALIDATION_FEATURE;    /** Feature identifier: expose schema normalized value */    protected static final String NORMALIZE_DATA =    Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_NORMALIZED_VALUE;    /** Feature identifier: disallow docType Decls. */    protected static final String DISALLOW_DOCTYPE_DECL_FEATURE =        Constants.XERCES_FEATURE_PREFIX + Constants.DISALLOW_DOCTYPE_DECL_FEATURE;    // internal properties    protected static final String SYMBOL_TABLE =    Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY;    protected static final String PSVI_AUGMENT =    Constants.XERCES_FEATURE_PREFIX +Constants.SCHEMA_AUGMENT_PSVI;    //    // Data    //    /** Include namespace declaration attributes in the document. **/    protected boolean fNamespaceDeclarations = true;        // REVISIT: this value should be null by default and should be set during creation of    //          LSParser    protected String fSchemaType = null;    protected boolean fBusy = false;        private boolean abortNow = false;        private Thread currentThread;    protected final static boolean DEBUG = false;    private Vector fSchemaLocations = new Vector ();    private String fSchemaLocation = null;	private DOMStringList fRecognizedParameters;        private AbortHandler abortHandler = new AbortHandler();    //    // Constructors    //    /**     * Constructs a DOM Builder using the standard parser configuration.     */    public DOMParserImpl (String configuration, String schemaType) {        this (        (XMLParserConfiguration) ObjectFactory.createObject (        "com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration",        configuration));        if (schemaType != null) {            if (schemaType.equals (Constants.NS_DTD)) {                //Schema validation is false by default and hence there is no                //need to set it to false here.  Also, schema validation is                  //not a recognized feature for DTDConfiguration's and so                 //setting this feature here would result in a Configuration                 //Exception.                            fConfiguration.setProperty (                Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE,                Constants.NS_DTD);                fSchemaType = Constants.NS_DTD;            }            else if (schemaType.equals (Constants.NS_XMLSCHEMA)) {                // XML Schem validation                fConfiguration.setProperty (                Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE,                Constants.NS_XMLSCHEMA);            }        }    }    /**     * Constructs a DOM Builder using the specified parser configuration.     */    public DOMParserImpl (XMLParserConfiguration config) {        super (config);        // add recognized features        final String[] domRecognizedFeatures = {            Constants.DOM_CANONICAL_FORM,            Constants.DOM_CDATA_SECTIONS,            Constants.DOM_CHARSET_OVERRIDES_XML_ENCODING,            Constants.DOM_INFOSET,            Constants.DOM_NAMESPACE_DECLARATIONS,            Constants.DOM_SPLIT_CDATA,            Constants.DOM_SUPPORTED_MEDIATYPES_ONLY,            Constants.DOM_CERTIFIED,            Constants.DOM_WELLFORMED,            Constants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS,        };        fConfiguration.addRecognizedFeatures (domRecognizedFeatures);        // turn off deferred DOM        fConfiguration.setFeature (DEFER_NODE_EXPANSION, false);        // Set values so that the value of the        // infoset parameter is true (its default value).        //        // true: namespace-declarations, well-formed,        // element-content-whitespace, comments, namespaces        //        // false: validate-if-schema, entities,        // datatype-normalization, cdata-sections        fConfiguration.setFeature(Constants.DOM_NAMESPACE_DECLARATIONS, true);        fConfiguration.setFeature(Constants.DOM_WELLFORMED, true);        fConfiguration.setFeature(INCLUDE_COMMENTS_FEATURE, true);        fConfiguration.setFeature(INCLUDE_IGNORABLE_WHITESPACE, true);        fConfiguration.setFeature(NAMESPACES, true);		        fConfiguration.setFeature(DYNAMIC_VALIDATION, false);        fConfiguration.setFeature(CREATE_ENTITY_REF_NODES, false);        fConfiguration.setFeature(CREATE_CDATA_NODES_FEATURE, false);        // set other default values        fConfiguration.setFeature (Constants.DOM_CANONICAL_FORM, false);        fConfiguration.setFeature (Constants.DOM_CHARSET_OVERRIDES_XML_ENCODING, true);        fConfiguration.setFeature (Constants.DOM_SPLIT_CDATA, true);        fConfiguration.setFeature (Constants.DOM_SUPPORTED_MEDIATYPES_ONLY, false);        fConfiguration.setFeature (Constants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS, true);        // REVISIT: by default Xerces assumes that input is certified.        //          default is different from the one specified in the DOM spec        fConfiguration.setFeature (Constants.DOM_CERTIFIED, true);        // Xerces datatype-normalization feature is on by default        // This is a recognized feature only for XML Schemas. If the        // configuration doesn't support this feature, ignore it.        try {            fConfiguration.setFeature ( NORMALIZE_DATA, false );        }        catch (XMLConfigurationException exc) {}        } // <init>(XMLParserConfiguration)    /**     * Constructs a DOM Builder using the specified symbol table.     */    public DOMParserImpl (SymbolTable symbolTable) {        this (        (XMLParserConfiguration) ObjectFactory.createObject (        "com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration",        "com.sun.org.apache.xerces.internal.parsers.XIncludeAwareParserConfiguration"));        fConfiguration.setProperty (        Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY,        symbolTable);    } // <init>(SymbolTable)    /**     * Constructs a DOM Builder using the specified symbol table and     * grammar pool.     */    public DOMParserImpl (SymbolTable symbolTable, XMLGrammarPool grammarPool) {        this (        (XMLParserConfiguration) ObjectFactory.createObject (        "com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration",        "com.sun.org.apache.xerces.internal.parsers.XIncludeAwareParserConfiguration"));        fConfiguration.setProperty (        Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY,        symbolTable);        fConfiguration.setProperty (        Constants.XERCES_PROPERTY_PREFIX        + Constants.XMLGRAMMAR_POOL_PROPERTY,        grammarPool);    }    /**     * Resets the parser state.     *     * @throws SAXException Thrown on initialization error.     */    public void reset () {        super.reset ();                // get state of namespace-declarations parameter.        fNamespaceDeclarations =             fConfiguration.getFeature(Constants.DOM_NAMESPACE_DECLARATIONS);                        // DOM Filter        if (fSkippedElemStack!=null) {            fSkippedElemStack.removeAllElements ();        }        fSchemaLocations.clear ();        fRejectedElement.clear ();        fFilterReject = false;        fSchemaType = null;    } // reset()    //    // DOMParser methods    //    public DOMConfiguration getDomConfig (){        return this;    }    /**     *  When the application provides a filter, the parser will call out to     * the filter at the completion of the construction of each     * <code>Element</code> node. The filter implementation can choose to     * remove the element from the document being constructed (unless the     * element is the document element) or to terminate the parse early. If     * the document is being validated when it's loaded the validation     * happens before the filter is called.     */    public LSParserFilter getFilter () {        return fDOMFilter;    }    /**     *  When the application provides a filter, the parser will call out to     * the filter at the completion of the construction of each     * <code>Element</code> node. The filter implementation can choose to     * remove the element from the document being constructed (unless the

⌨️ 快捷键说明

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