xmldocumentscannerimpl.java

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

JAVA
1,359
字号
/* * 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.dtd.XMLDTDDescription;import com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException;import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager;import com.sun.org.apache.xerces.internal.util.NamespaceSupport;import com.sun.org.apache.xerces.internal.util.XMLChar;import com.sun.org.apache.xerces.internal.util.XMLEntityDescriptionImpl;import com.sun.org.apache.xerces.internal.util.XMLStringBuffer;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.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.XMLComponentManager;import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDScanner;import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;/** * This class is responsible for scanning XML document structure * and content. 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/namespaces</li> *  <li>http://xml.org/sax/features/validation</li> *  <li>http://apache.org/xml/features/nonvalidating/load-external-dtd</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> *  <li>http://apache.org/xml/properties/internal/dtd-scanner</li> * </ul> * * @author Glenn Marcy, IBM * @author Andy Clark, IBM * @author Arnaud  Le Hors, IBM * @author Eric Ye, IBM * * @version $Id: XMLDocumentScannerImpl.java,v 1.45 2004/04/30 15:36:38 mrglavas Exp $ */public class XMLDocumentScannerImpl    extends XMLDocumentFragmentScannerImpl {    //    // Constants    //    // scanner states    /** Scanner state: XML declaration. */    protected static final int SCANNER_STATE_XML_DECL = 0;    /** Scanner state: prolog. */    protected static final int SCANNER_STATE_PROLOG = 5;    /** Scanner state: trailing misc. */    protected static final int SCANNER_STATE_TRAILING_MISC = 12;    /** Scanner state: DTD internal declarations. */    protected static final int SCANNER_STATE_DTD_INTERNAL_DECLS = 17;    /** Scanner state: open DTD external subset. */    protected static final int SCANNER_STATE_DTD_EXTERNAL = 18;    /** Scanner state: DTD external declarations. */    protected static final int SCANNER_STATE_DTD_EXTERNAL_DECLS = 19;    // feature identifiers    /** Feature identifier: load external DTD. */    protected static final String LOAD_EXTERNAL_DTD =        Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE;    /** Feature identifier: load external DTD. */    protected static final String DISALLOW_DOCTYPE_DECL_FEATURE =        Constants.XERCES_FEATURE_PREFIX + Constants.DISALLOW_DOCTYPE_DECL_FEATURE;    // property identifiers    /** Property identifier: DTD scanner. */    protected static final String DTD_SCANNER =        Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_SCANNER_PROPERTY;    /** property identifier:  ValidationManager */    protected static final String VALIDATION_MANAGER =        Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY;    /** property identifier:  NamespaceContext */    protected static final String NAMESPACE_CONTEXT =        Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_CONTEXT_PROPERTY;            // recognized features and properties    /** Recognized features. */    private static final String[] RECOGNIZED_FEATURES = {        LOAD_EXTERNAL_DTD,        DISALLOW_DOCTYPE_DECL_FEATURE,    };    /** Feature defaults. */    private static final Boolean[] FEATURE_DEFAULTS = {        Boolean.TRUE,        Boolean.FALSE,    };    /** Recognized properties. */    private static final String[] RECOGNIZED_PROPERTIES = {        DTD_SCANNER,        VALIDATION_MANAGER,        NAMESPACE_CONTEXT,    };    /** Property defaults. */    private static final Object[] PROPERTY_DEFAULTS = {        null,        null,        null,    };    //    // Data    //    // properties    /** DTD scanner. */    protected XMLDTDScanner fDTDScanner;    /** Validation manager . */    protected ValidationManager fValidationManager;    // protected data    /** Scanning DTD. */    protected boolean fScanningDTD;    // other info    /** Doctype name. */    protected String fDoctypeName;    /** Doctype declaration public identifier. */    protected String fDoctypePublicId;    /** Doctype declaration system identifier. */    protected String fDoctypeSystemId;    /** Namespace support. */    protected NamespaceContext fNamespaceContext = new NamespaceSupport();    // features    /** Load external DTD. */    protected boolean fLoadExternalDTD = true;    /** Disallow doctype declaration. */    protected boolean fDisallowDoctype = false;    // state    /** Seen doctype declaration. */    protected boolean fSeenDoctypeDecl;    // dispatchers    /** XML declaration dispatcher. */    protected Dispatcher fXMLDeclDispatcher = new XMLDeclDispatcher();    /** Prolog dispatcher. */    protected Dispatcher fPrologDispatcher = new PrologDispatcher();    /** DTD dispatcher. */    protected Dispatcher fDTDDispatcher = new DTDDispatcher();    /** Trailing miscellaneous section dispatcher. */    protected Dispatcher fTrailingMiscDispatcher = new TrailingMiscDispatcher();    // temporary variables    /** Array of 3 strings. */    private String[] fStrings = new String[3];    /** String. */    private XMLString fString = new XMLString();    /** String buffer. */    private XMLStringBuffer fStringBuffer = new XMLStringBuffer();        /** External subset source. */    private XMLInputSource fExternalSubsetSource = null;    //    // Constructors    //    /** Default constructor. */    public XMLDocumentScannerImpl() {} // <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.startDocumentEntity(inputSource);        //fDocumentSystemId = fEntityManager.expandSystemId(inputSource.getSystemId());    } // setInputSource(XMLInputSource)    //    // XMLComponent methods    //    /**     * Resets the component. The component can query the component manager     * about any features and properties that affect the operation of the     * component.     *     * @param componentManager The component manager.     *     * @throws SAXException Thrown by component on initialization error.     *                      For example, if a feature or property is     *                      required for the operation of the component, the     *                      component manager may throw a     *                      SAXNotRecognizedException or a     *                      SAXNotSupportedException.     */    public void reset(XMLComponentManager componentManager)        throws XMLConfigurationException {        super.reset(componentManager);        // other settings        fDoctypeName = null;        fDoctypePublicId = null;        fDoctypeSystemId = null;        fSeenDoctypeDecl = false;        fScanningDTD = false;        fExternalSubsetSource = null;		if (!fParserSettings) {			// parser settings have not been changed			fNamespaceContext.reset();			// setup dispatcher			setScannerState(SCANNER_STATE_XML_DECL);			setDispatcher(fXMLDeclDispatcher);			return;		}        // xerces features        try {            fLoadExternalDTD = componentManager.getFeature(LOAD_EXTERNAL_DTD);        }        catch (XMLConfigurationException e) {            fLoadExternalDTD = true;        }        try {            fDisallowDoctype = componentManager.getFeature(DISALLOW_DOCTYPE_DECL_FEATURE);        }        catch (XMLConfigurationException e) {            fDisallowDoctype = false;        }        // xerces properties        fDTDScanner = (XMLDTDScanner)componentManager.getProperty(DTD_SCANNER);        try {            fValidationManager = (ValidationManager)componentManager.getProperty(VALIDATION_MANAGER);

⌨️ 快捷键说明

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