abstractsaxparser.java

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

JAVA
1,695
字号
/* * 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.xs.PSVIProvider;import com.sun.org.apache.xerces.internal.util.EntityResolverWrapper;import com.sun.org.apache.xerces.internal.util.EntityResolver2Wrapper;import com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper;import com.sun.org.apache.xerces.internal.util.SAXMessageFormatter;import com.sun.org.apache.xerces.internal.util.SymbolHash;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.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.XMLConfigurationException;import com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver;import com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler;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 com.sun.org.apache.xerces.internal.xs.AttributePSVI;import com.sun.org.apache.xerces.internal.xs.ElementPSVI;import org.xml.sax.AttributeList;import org.xml.sax.Attributes;import org.xml.sax.ext.Attributes2;import org.xml.sax.ContentHandler;import org.xml.sax.DTDHandler;import org.xml.sax.DocumentHandler;import org.xml.sax.EntityResolver;import org.xml.sax.ErrorHandler;import org.xml.sax.InputSource;import org.xml.sax.Locator;import org.xml.sax.ext.Locator2Impl;import org.xml.sax.ext.Locator2;import org.xml.sax.Parser;import org.xml.sax.SAXException;import org.xml.sax.SAXNotRecognizedException;import org.xml.sax.SAXNotSupportedException;import org.xml.sax.SAXParseException;import org.xml.sax.XMLReader;import org.xml.sax.ext.DeclHandler;import org.xml.sax.ext.EntityResolver2;import org.xml.sax.ext.LexicalHandler;import org.xml.sax.helpers.LocatorImpl;/** * This is the base class of all SAX parsers. It implements both the * SAX1 and SAX2 parser functionality, while the actual pipeline is * defined in the parser configuration. * * @author Arnaud Le Hors, IBM * @author Andy Clark, IBM * * @version $Id: AbstractSAXParser.java,v 1.54 2004/04/07 15:42:05 mrglavas Exp $ */public abstract class AbstractSAXParserextends AbstractXMLDocumentParserimplements PSVIProvider, // PSVIParser, XMLReader // SAX1, SAX2{        //    // Constants    //        // features        /** Feature identifier: namespaces. */    protected static final String NAMESPACES =    Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE;        /** Feature identifier: namespace prefixes. */    protected static final String NAMESPACE_PREFIXES =    Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACE_PREFIXES_FEATURE;        /** Feature id: string interning. */    protected static final String STRING_INTERNING =    Constants.SAX_FEATURE_PREFIX + Constants.STRING_INTERNING_FEATURE;            /** Feature identifier: allow notation and unparsed entity events to be sent out of order. */    // this is not meant to be a recognized feature, but we need it here to use    // if it is already a recognized feature for the pipeline    protected static final String ALLOW_UE_AND_NOTATION_EVENTS =    Constants.SAX_FEATURE_PREFIX + Constants.ALLOW_DTD_EVENTS_AFTER_ENDDTD_FEATURE;        /** Recognized features. */    private static final String[] RECOGNIZED_FEATURES = {        NAMESPACES,        NAMESPACE_PREFIXES,        STRING_INTERNING,    };        // properties        /** Property id: lexical handler. */    protected static final String LEXICAL_HANDLER =    Constants.SAX_PROPERTY_PREFIX + Constants.LEXICAL_HANDLER_PROPERTY;        /** Property id: declaration handler. */    protected static final String DECLARATION_HANDLER =    Constants.SAX_PROPERTY_PREFIX + Constants.DECLARATION_HANDLER_PROPERTY;        /** Property id: DOM node. */    protected static final String DOM_NODE =    Constants.SAX_PROPERTY_PREFIX + Constants.DOM_NODE_PROPERTY;        /** Recognized properties. */    private static final String[] RECOGNIZED_PROPERTIES = {        LEXICAL_HANDLER,        DECLARATION_HANDLER,        DOM_NODE,    };        //    // Data    //        // features        /** Namespaces. */    protected boolean fNamespaces;        /** Namespace prefixes. */    protected boolean fNamespacePrefixes = false;        /** Lexical handler parameter entities. */    protected boolean fLexicalHandlerParameterEntities = true;        // parser handlers        /** Content handler. */    protected ContentHandler fContentHandler;        /** Document handler. */    protected DocumentHandler fDocumentHandler;        /** Namespace context */    protected NamespaceContext fNamespaceContext;        /** DTD handler. */    protected org.xml.sax.DTDHandler fDTDHandler;        /** Decl handler. */    protected DeclHandler fDeclHandler;        /** Lexical handler. */    protected LexicalHandler fLexicalHandler;        protected QName fQName = new QName();        protected boolean resolve_dtd_uris = true;    protected boolean startDocumentCalled = false;    protected boolean resolverType = true;    protected boolean locatorType = false;    protected boolean attributeType = true;    protected boolean  isStandalone  = false;    // state        /**     * 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;        // track the version of the document being parsed    protected String fVersion;        // temp vars    private final AttributesProxy fAttributesProxy = new AttributesProxy();    private Augmentations fAugmentations = null;        // temporary buffer for sending normalized values    // REVISIT: what should be the size of the buffer?    private static final int BUFFER_SIZE = 20;    private char[] fCharBuffer =  new char[BUFFER_SIZE];        // allows us to keep track of whether an attribute has    // been declared twice, so that we can avoid exposing the    // second declaration to any registered DeclHandler    protected SymbolHash fDeclaredAttrs = null;        //    // Constructors    //        /** Default constructor. */    protected AbstractSAXParser(XMLParserConfiguration config) {        super(config);                config.addRecognizedFeatures(RECOGNIZED_FEATURES);        config.addRecognizedProperties(RECOGNIZED_PROPERTIES);                try {            config.setFeature(ALLOW_UE_AND_NOTATION_EVENTS, false);        }        catch (XMLConfigurationException e) {            // it wasn't a recognized feature, so we don't worry about it        }    } // <init>(XMLParserConfiguration)        //    // XMLDocumentHandler methods    //        /**     * The start of the document.     *     * @param locator The document locator, or null if the document     *                 location cannot be reported during the parsing     *                 of this document. However, it is <em>strongly</em>     *                 recommended that a locator be supplied that can     *                 at least report the system identifier of the     *                 document.     * @param encoding The auto-detected IANA encoding name of the entity     *                 stream. This value will be null in those situations     *                 where the entity encoding is not auto-detected (e.g.     *                 internal entities or a document entity that is     *                 parsed from a java.io.Reader).     * @param namespaceContext     *                 The namespace context in effect at the     *                 start of this document.     *                 This object represents the current context.     *                 Implementors of this class are responsible     *                 for copying the namespace bindings from the     *                 the current context (and its parent contexts)     *                 if that information is important.     * @param augs     Additional information that may include infoset augmentations     *     * @throws XNIException Thrown by handler to signal an error.     */    public void startDocument(XMLLocator locator, String encoding,    NamespaceContext namespaceContext, Augmentations augs)    throws XNIException {                fNamespaceContext = namespaceContext;        startDocumentCalled = true;        try {            // SAX1            if (fDocumentHandler != null) {                if (locator != null) {                    fDocumentHandler.setDocumentLocator(new LocatorProxy(locator));                }                fDocumentHandler.startDocument();            }                        // SAX2            if (fContentHandler != null) {                if (locator != null) {                    locatorType = true;                    fContentHandler.setDocumentLocator(new LocatorProxy(locator));                }                fContentHandler.startDocument();            }        }        catch (SAXException e) {            throw new XNIException(e);        }            } // startDocument(locator,encoding,augs)        /**     * Notifies of the presence of an XMLDecl line in the document. If     * present, this method will be called immediately following the     * startDocument call.     *     * @param version    The XML version.     * @param encoding   The IANA encoding name of the document, or null if     *                   not specified.     * @param standalone The standalone value, or null if not specified.     * @param augs   Additional information that may include infoset augmentations     *     * @throws XNIException Thrown by handler to signal an error.     */

⌨️ 快捷键说明

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