abstractdomparser.java

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

JAVA
1,652
字号
/* * 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.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.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.DOMMessageFormatter;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.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.xs.XSTypeDefinition;import com.sun.org.apache.xerces.internal.util.DOMErrorHandlerWrapper;import com.sun.org.apache.xerces.internal.util.TypeInfoImpl;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 org.w3c.dom.Attr;import org.w3c.dom.CDATASection;import org.w3c.dom.Comment;import org.w3c.dom.DOMError;import org.w3c.dom.Document;import org.w3c.dom.DocumentType;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.TypeInfo;import org.w3c.dom.ls.LSParserFilter;import org.w3c.dom.traversal.NodeFilter;/** * 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.108 2004/02/17 07:14:48 neeraj 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);

⌨️ 快捷键说明

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