xmldocumentfragmentscannerimpl.java

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

JAVA
1,788
字号
/* * The Apache Software License, Version 1.1 * * * Copyright (c) 1999-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.impl;import java.io.CharConversionException;import java.io.EOFException;import java.io.IOException;import com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException;import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;import com.sun.org.apache.xerces.internal.util.AugmentationsImpl;import com.sun.org.apache.xerces.internal.util.XMLAttributesImpl;import com.sun.org.apache.xerces.internal.util.XMLChar;import com.sun.org.apache.xerces.internal.util.XMLStringBuffer;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.QName;import com.sun.org.apache.xerces.internal.xni.XMLAttributes;import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler;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.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.XMLDocumentScanner;import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;import com.sun.org.apache.xerces.internal.util.SecurityManager;/** * This class is responsible for scanning the structure and content * of document fragments. The scanner acts as the source for the  * document information which is communicated to the document handler. * <p> * This component requires the following features and properties from the * component manager that uses it: * <ul> *  <li>http://xml.org/sax/features/validation</li> *  <li>http://apache.org/xml/features/scanner/notify-char-refs</li> *  <li>http://apache.org/xml/features/scanner/notify-builtin-refs</li> *  <li>http://apache.org/xml/properties/internal/symbol-table</li> *  <li>http://apache.org/xml/properties/internal/error-reporter</li> *  <li>http://apache.org/xml/properties/internal/entity-manager</li> * </ul> * * @author Glenn Marcy, IBM * @author Andy Clark, IBM * @author Arnaud  Le Hors, IBM * @author Eric Ye, IBM * * @version $Id: XMLDocumentFragmentScannerImpl.java,v 1.52 2004/04/08 22:24:52 mrglavas Exp $ */public class XMLDocumentFragmentScannerImpl    extends XMLScanner    implements XMLDocumentScanner, XMLComponent, XMLEntityHandler {    //    // Constants    //   	protected SecurityManager fSecurityManager = null;    	// scanner states    /** Scanner state: start of markup. */    protected static final int SCANNER_STATE_START_OF_MARKUP = 1;    /** Scanner state: comment. */    protected static final int SCANNER_STATE_COMMENT = 2;    /** Scanner state: processing instruction. */    protected static final int SCANNER_STATE_PI = 3;    /** Scanner state: DOCTYPE. */    protected static final int SCANNER_STATE_DOCTYPE = 4;    /** Scanner state: root element. */    protected static final int SCANNER_STATE_ROOT_ELEMENT = 6;    /** Scanner state: content. */    protected static final int SCANNER_STATE_CONTENT = 7;    /** Scanner state: reference. */    protected static final int SCANNER_STATE_REFERENCE = 8;    /** Scanner state: end of input. */    protected static final int SCANNER_STATE_END_OF_INPUT = 13;    /** Scanner state: terminated. */    protected static final int SCANNER_STATE_TERMINATED = 14;    /** Scanner state: CDATA section. */    protected static final int SCANNER_STATE_CDATA = 15;    /** Scanner state: Text declaration. */    protected static final int SCANNER_STATE_TEXT_DECL = 16;    // feature identifiers    /** Feature identifier: namespaces. */    protected static final String NAMESPACES =         Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE;    /** Feature identifier: notify built-in refereces. */    protected static final String NOTIFY_BUILTIN_REFS =        Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_BUILTIN_REFS_FEATURE;            // property identifiers        /** Property identifier: entity resolver. */    protected static final String ENTITY_RESOLVER =        Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY;        // recognized features and properties    /** Recognized features. */    private static final String[] RECOGNIZED_FEATURES = {        NAMESPACES,         VALIDATION,         NOTIFY_BUILTIN_REFS,        NOTIFY_CHAR_REFS,     };    /** Feature defaults. */    private static final Boolean[] FEATURE_DEFAULTS = {        null,        null,        Boolean.FALSE,        Boolean.FALSE,    };    /** Recognized properties. */    private static final String[] RECOGNIZED_PROPERTIES = {        SYMBOL_TABLE,        ERROR_REPORTER,        ENTITY_MANAGER,        ENTITY_RESOLVER,    };    /** Property defaults. */    private static final Object[] PROPERTY_DEFAULTS = {        null,        null,        null,        null,    };    // debugging    /** Debug scanner state. */    private static final boolean DEBUG_SCANNER_STATE = false;    /** Debug dispatcher. */    private static final boolean DEBUG_DISPATCHER = false;    /** Debug content dispatcher scanning. */    protected static final boolean DEBUG_CONTENT_SCANNING = false;    //    // Data    //    // protected data    /** Document handler. */    protected XMLDocumentHandler fDocumentHandler;    /** Entity stack. */    protected int[] fEntityStack = new int[4];    /** Markup depth. */    protected int fMarkupDepth;    /** Scanner state. */    protected int fScannerState;    /** SubScanner state: inside scanContent method. */    protected boolean fInScanContent = false;    /** has external dtd */    protected boolean fHasExternalDTD;        /** Standalone. */    protected boolean fStandalone;    //variable to restrict attribute limit    protected int fElementAttributeLimit;            /** External subset resolver. **/    protected ExternalSubsetResolver fExternalSubsetResolver;    // element information    /** Current element. */    protected QName fCurrentElement;    /** Element stack. */    protected ElementStack fElementStack = new ElementStack();    // other info    /** Document system identifier.      * REVISIT:  So what's this used for?  - NG    * protected String fDocumentSystemId;     ******/    // features    /** Notify built-in references. */    protected boolean fNotifyBuiltInRefs = false;    // dispatchers    /** Active dispatcher. */    protected Dispatcher fDispatcher;    /** Content dispatcher. */    protected Dispatcher fContentDispatcher = createContentDispatcher();    // temporary variables    /** Element QName. */    protected QName fElementQName = new QName();    /** Attribute QName. */    protected QName fAttributeQName = new QName();    /** Element attributes. */    protected XMLAttributesImpl fAttributes = new XMLAttributesImpl();    /** String. */    protected XMLString fTempString = new XMLString();        /** String. */    protected XMLString fTempString2 = new XMLString();    /** Array of 3 strings. */    private String[] fStrings = new String[3];    /** String buffer. */    private XMLStringBuffer fStringBuffer = new XMLStringBuffer();    /** String buffer. */    private XMLStringBuffer fStringBuffer2 = new XMLStringBuffer();    /** Another QName. */    private QName fQName = new QName();    /** Single character array. */    private final char[] fSingleChar = new char[1];    /** External entity. */    private XMLEntityManager.ExternalEntity fExternalEntity = new XMLEntityManager.ExternalEntity();        /**      * Saw spaces after element name or between attributes.     *      * This is reserved for the case where scanning of a start element spans     * several methods, as is the case when scanning the start of a root element      * where a DTD external subset may be read after scanning the element name.     */    private boolean fSawSpace;    //    // Constructors    //    /** Default constructor. */    public XMLDocumentFragmentScannerImpl() {} // <init>()    //    // XMLDocumentScanner methods    //    /**      * Sets the input source.      *     * @param inputSource The input source.     *     * @throws IOException Thrown on i/o error.     */    public void setInputSource(XMLInputSource inputSource) throws IOException {        fEntityManager.setEntityHandler(this);        fEntityManager.startEntity("$fragment$", inputSource, false, true);        //fDocumentSystemId = fEntityManager.expandSystemId(inputSource.getSystemId());    } // setInputSource(XMLInputSource)    /**      * Scans a document.     *     * @param complete True if the scanner should scan the document     *                 completely, pushing all events to the registered     *                 document handler. A value of false indicates that     *                 that the scanner should only scan the next portion     *                 of the document and return. A scanner instance is     *                 permitted to completely scan a document if it does     *                 not support this "pull" scanning model.     *     * @return True if there is more to scan, false otherwise.     */

⌨️ 快捷键说明

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