abstractdomparser.java

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

JAVA
1,657
字号
/* * Copyright 2001-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.util.Locale;import java.util.Stack;import com.sun.org.apache.xerces.internal.dom.AttrImpl;import com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl;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.DeferredDocumentImpl;import com.sun.org.apache.xerces.internal.dom.DocumentImpl;import com.sun.org.apache.xerces.internal.dom.DocumentTypeImpl;import com.sun.org.apache.xerces.internal.dom.ElementDefinitionImpl;import com.sun.org.apache.xerces.internal.dom.ElementImpl;import com.sun.org.apache.xerces.internal.dom.ElementNSImpl;import com.sun.org.apache.xerces.internal.dom.EntityImpl;import com.sun.org.apache.xerces.internal.dom.EntityReferenceImpl;import com.sun.org.apache.xerces.internal.dom.NodeImpl;import com.sun.org.apache.xerces.internal.dom.NotationImpl;import com.sun.org.apache.xerces.internal.dom.PSVIAttrNSImpl;import com.sun.org.apache.xerces.internal.dom.PSVIDocumentImpl;import com.sun.org.apache.xerces.internal.dom.PSVIElementNSImpl;import com.sun.org.apache.xerces.internal.dom.TextImpl;import com.sun.org.apache.xerces.internal.impl.Constants;import com.sun.org.apache.xerces.internal.impl.dv.XSSimpleType;import com.sun.org.apache.xerces.internal.util.DOMErrorHandlerWrapper;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.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.parser.XMLParserConfiguration;import com.sun.org.apache.xerces.internal.xs.AttributePSVI;import com.sun.org.apache.xerces.internal.xs.ElementPSVI;import com.sun.org.apache.xerces.internal.xs.XSTypeDefinition;import org.w3c.dom.Attr;import org.w3c.dom.CDATASection;import org.w3c.dom.Comment;import org.w3c.dom.Document;import org.w3c.dom.DocumentType;import org.w3c.dom.DOMError;import org.w3c.dom.Element;import org.w3c.dom.EntityReference;import org.w3c.dom.NamedNodeMap;import org.w3c.dom.Node;import org.w3c.dom.NodeList;import org.w3c.dom.ProcessingInstruction;import org.w3c.dom.Text;import org.w3c.dom.ls.LSParserFilter;import org.w3c.dom.traversal.NodeFilter;import org.xml.sax.SAXException;/** * This is the base class of all DOM parsers. It implements the XNI * callback methods to create the DOM tree. After a successful parse of * an XML document, the DOM Document object can be queried using the * <code>getDocument</code> method. The actual pipeline is defined in * parser configuration. * * @author Arnaud Le Hors, IBM * @author Andy Clark, IBM * @author Elena Litani, IBM * * @version $Id: AbstractDOMParser.java,v 1.2.6.1 2005/09/06 11:47:01 sunithareddy Exp $ */public class AbstractDOMParser extends AbstractXMLDocumentParser {    //    // Constants    //    // feature ids    /** Feature id: namespace. */    protected static final String NAMESPACES =    Constants.SAX_FEATURE_PREFIX+Constants.NAMESPACES_FEATURE;    /** Feature id: create entity ref nodes. */    protected static final String CREATE_ENTITY_REF_NODES =    Constants.XERCES_FEATURE_PREFIX + Constants.CREATE_ENTITY_REF_NODES_FEATURE;    /** Feature id: include comments. */    protected static final String INCLUDE_COMMENTS_FEATURE =    Constants.XERCES_FEATURE_PREFIX + Constants.INCLUDE_COMMENTS_FEATURE;    /** Feature id: create cdata nodes. */    protected static final String CREATE_CDATA_NODES_FEATURE =    Constants.XERCES_FEATURE_PREFIX + Constants.CREATE_CDATA_NODES_FEATURE;    /** Feature id: include ignorable whitespace. */    protected static final String INCLUDE_IGNORABLE_WHITESPACE =    Constants.XERCES_FEATURE_PREFIX + Constants.INCLUDE_IGNORABLE_WHITESPACE;    /** Feature id: defer node expansion. */    protected static final String DEFER_NODE_EXPANSION =    Constants.XERCES_FEATURE_PREFIX + Constants.DEFER_NODE_EXPANSION_FEATURE;    /** Recognized features. */    private static final String[] RECOGNIZED_FEATURES = {        NAMESPACES,        CREATE_ENTITY_REF_NODES,        INCLUDE_COMMENTS_FEATURE,        CREATE_CDATA_NODES_FEATURE,        INCLUDE_IGNORABLE_WHITESPACE,        DEFER_NODE_EXPANSION    };    // property ids    /** Property id: document class name. */    protected static final String DOCUMENT_CLASS_NAME =    Constants.XERCES_PROPERTY_PREFIX + Constants.DOCUMENT_CLASS_NAME_PROPERTY;    protected static final String  CURRENT_ELEMENT_NODE=    Constants.XERCES_PROPERTY_PREFIX + Constants.CURRENT_ELEMENT_NODE_PROPERTY;    // protected static final String GRAMMAR_POOL =    // Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY;    /** Recognized properties. */    private static final String[] RECOGNIZED_PROPERTIES = {        DOCUMENT_CLASS_NAME,        CURRENT_ELEMENT_NODE,    };    // other    /** Default document class name. */    protected static final String DEFAULT_DOCUMENT_CLASS_NAME =    "com.sun.org.apache.xerces.internal.dom.DocumentImpl";    protected static final String CORE_DOCUMENT_CLASS_NAME =    "com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl";    protected static final String PSVI_DOCUMENT_CLASS_NAME =    "com.sun.org.apache.xerces.internal.dom.PSVIDocumentImpl";    /**     * If the user stops the process, this exception will be thrown.     */    public static final RuntimeException abort = new RuntimeException();    // debugging    private static final boolean DEBUG_EVENTS = false;    private static final boolean DEBUG_BASEURI = false;    //    // Data    //    /** DOM L3 error handler */    protected DOMErrorHandlerWrapper fErrorHandler = null;    /** True if inside DTD. */    protected boolean fInDTD;    // features    /** Create entity reference nodes. */    protected boolean fCreateEntityRefNodes;    /** Include ignorable whitespace. */    protected boolean fIncludeIgnorableWhitespace;    /** Include Comments. */    protected boolean fIncludeComments;    /** Create cdata nodes. */    protected boolean fCreateCDATANodes;    // dom information    /** The document. */    protected Document fDocument;    /** The default Xerces document implementation, if used. */    protected CoreDocumentImpl fDocumentImpl;    /** Whether to store PSVI information in DOM tree. */    protected boolean fStorePSVI;    /** The document class name to use. */    protected String  fDocumentClassName;    /** The document type node. */    protected DocumentType fDocumentType;    /** Current node. */    protected Node fCurrentNode;    protected CDATASection fCurrentCDATASection;    protected EntityImpl fCurrentEntityDecl;    protected int fDeferredEntityDecl;    /** Character buffer */    protected final StringBuffer fStringBuffer = new StringBuffer (50);    // internal subset    /** Internal subset buffer. */    protected StringBuffer fInternalSubset;    // deferred expansion data    protected boolean              fDeferNodeExpansion;    protected boolean              fNamespaceAware;    protected DeferredDocumentImpl fDeferredDocumentImpl;    protected int                  fDocumentIndex;    protected int                  fDocumentTypeIndex;    protected int                  fCurrentNodeIndex;    protected int                  fCurrentCDATASectionIndex;    // state    /** True if inside DTD external subset. */    protected boolean fInDTDExternalSubset;    /** Root element name */    protected QName fRoot = new QName();    /** True if inside CDATA section. */    protected boolean fInCDATASection;    /** True if saw the first chunk of characters*/    protected boolean fFirstChunk = false;    /** LSParserFilter: specifies that element with given QNAME and all its children     * must be rejected */    protected boolean fFilterReject = false;    // data    /** Base uri stack*/    protected Stack fBaseURIStack = new Stack ();    /** LSParserFilter: the QNAME of rejected element*/    protected final QName fRejectedElement = new QName ();    /** LSParserFilter: store qnames of skipped elements*/    protected Stack fSkippedElemStack = null;    /** LSParserFilter: true if inside entity reference */    protected boolean fInEntityRef = false;    /** Attribute QName. */    private QName fAttrQName = new QName ();    // handlers    protected LSParserFilter fDOMFilter = null;    //    // Constructors    //    /** Default constructor. */    protected AbstractDOMParser (XMLParserConfiguration config) {        super (config);        // add recognized features        fConfiguration.addRecognizedFeatures (RECOGNIZED_FEATURES);        // set default values        fConfiguration.setFeature (CREATE_ENTITY_REF_NODES, true);        fConfiguration.setFeature (INCLUDE_IGNORABLE_WHITESPACE, true);        fConfiguration.setFeature (DEFER_NODE_EXPANSION, true);        fConfiguration.setFeature (INCLUDE_COMMENTS_FEATURE, true);        fConfiguration.setFeature (CREATE_CDATA_NODES_FEATURE, true);        // add recognized properties        fConfiguration.addRecognizedProperties (RECOGNIZED_PROPERTIES);        // set default values        fConfiguration.setProperty (DOCUMENT_CLASS_NAME,        DEFAULT_DOCUMENT_CLASS_NAME);    } // <init>(XMLParserConfiguration)    /**     * This method retreives the name of current document class.     */    protected String getDocumentClassName () {        return fDocumentClassName;    }    /**     * This method allows the programmer to decide which document     * factory to use when constructing the DOM tree. However, doing     * so will lose the functionality of the default factory. Also,     * a document class other than the default will lose the ability     * to defer node expansion on the DOM tree produced.     *     * @param documentClassName The fully qualified class name of the     *                      document factory to use when constructing     *                      the DOM tree.     *     * @see #getDocumentClassName     * @see #DEFAULT_DOCUMENT_CLASS_NAME     */    protected void setDocumentClassName (String documentClassName) {        // normalize class name        if (documentClassName == null) {            documentClassName = DEFAULT_DOCUMENT_CLASS_NAME;        }        if (!documentClassName.equals(DEFAULT_DOCUMENT_CLASS_NAME) &&            !documentClassName.equals(PSVI_DOCUMENT_CLASS_NAME)) {

⌨️ 快捷键说明

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