xmlscanner.java

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

JAVA
1,453
字号
/* * 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.IOException;import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;import com.sun.org.apache.xerces.internal.util.SymbolTable;import com.sun.org.apache.xerces.internal.util.XMLChar;import com.sun.org.apache.xerces.internal.util.XMLResourceIdentifierImpl;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.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;/** * This class is responsible for holding scanning methods common to * scanning the XML document structure and content as well as the DTD * structure and content. Both XMLDocumentScanner and XMLDTDScanner inherit * from this base class. * * <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://xml.org/sax/features/namespaces</li> *  <li>http://apache.org/xml/features/scanner/notify-char-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 Andy Clark, IBM * @author Arnaud  Le Hors, IBM * @author Eric Ye, IBM * * @version $Id: XMLScanner.java,v 1.48 2004/04/25 05:05:50 mrglavas Exp $ */public abstract class XMLScanner     implements XMLComponent {    //    // Constants    //    // feature identifiers    /** Feature identifier: validation. */    protected static final String VALIDATION =        Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE;    /** Feature identifier: namespaces. */    protected static final String NAMESPACES =         Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE;    /** Feature identifier: notify character references. */    protected static final String NOTIFY_CHAR_REFS =        Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_CHAR_REFS_FEATURE;		protected static final String PARSER_SETTINGS = 				Constants.XERCES_FEATURE_PREFIX + Constants.PARSER_SETTINGS;    // property identifiers    /** Property identifier: symbol table. */    protected static final String SYMBOL_TABLE =         Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY;    /** Property identifier: error reporter. */    protected static final String ERROR_REPORTER =         Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY;    /** Property identifier: entity manager. */    protected static final String ENTITY_MANAGER =         Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY;    // debugging    /** Debug attribute normalization. */    protected static final boolean DEBUG_ATTR_NORMALIZATION = false;    //    // Data    //        // features    /**      * Validation. This feature identifier is:     * http://xml.org/sax/features/validation     */    protected boolean fValidation = false;        /** Namespaces. */    protected boolean fNamespaces;    /** Character references notification. */    protected boolean fNotifyCharRefs = false;        /** Internal parser-settings feature */	protected boolean fParserSettings = true;	    // properties    /** Symbol table. */    protected SymbolTable fSymbolTable;    /** Error reporter. */    protected XMLErrorReporter fErrorReporter;    /** Entity manager. */    protected XMLEntityManager fEntityManager;    // protected data    /** Entity scanner. */    protected XMLEntityScanner fEntityScanner;    /** Entity depth. */    protected int fEntityDepth;    /** Literal value of the last character refence scanned. */    protected String fCharRefLiteral = null;    /** Scanning attribute. */    protected boolean fScanningAttribute;    /** Report entity boundary. */    protected boolean fReportEntity;    // symbols    /** Symbol: "version". */    protected final static String fVersionSymbol = "version".intern();    /** Symbol: "encoding". */    protected final static String fEncodingSymbol = "encoding".intern();    /** Symbol: "standalone". */    protected final static String fStandaloneSymbol = "standalone".intern();    /** Symbol: "amp". */    protected final static String fAmpSymbol = "amp".intern();    /** Symbol: "lt". */    protected final static String fLtSymbol = "lt".intern();    /** Symbol: "gt". */    protected final static String fGtSymbol = "gt".intern();    /** Symbol: "quot". */    protected final static String fQuotSymbol = "quot".intern();    /** Symbol: "apos". */    protected final static String fAposSymbol = "apos".intern();    // temporary variables    // NOTE: These objects are private to help prevent accidental modification    //       of values by a subclass. If there were protected *and* the sub-    //       modified the values, it would be difficult to track down the real    //       cause of the bug. By making these private, we avoid this     //       possibility.    /** String. */    private XMLString fString = new XMLString();    /** String buffer. */    private XMLStringBuffer fStringBuffer = new XMLStringBuffer();    /** String buffer. */    private XMLStringBuffer fStringBuffer2 = new XMLStringBuffer();    /** String buffer. */    private XMLStringBuffer fStringBuffer3 = new XMLStringBuffer();    // temporary location for Resource identification information.    protected XMLResourceIdentifierImpl fResourceIdentifier = new XMLResourceIdentifierImpl();    //    // XMLComponent methods    //    /**     *      *      * @param componentManager The component manager.     *     * @throws SAXException Throws exception if required features and     *                      properties cannot be found.     */    public void reset(XMLComponentManager componentManager)        throws XMLConfigurationException {		try {			fParserSettings = componentManager.getFeature(PARSER_SETTINGS);		} catch (XMLConfigurationException e) {			fParserSettings = true;		}		if (!fParserSettings) {			// parser settings have not been changed			init();			return;		}        // Xerces properties        fSymbolTable = (SymbolTable)componentManager.getProperty(SYMBOL_TABLE);        fErrorReporter = (XMLErrorReporter)componentManager.getProperty(ERROR_REPORTER);        fEntityManager = (XMLEntityManager)componentManager.getProperty(ENTITY_MANAGER);        // sax features        try {            fValidation = componentManager.getFeature(VALIDATION);        }        catch (XMLConfigurationException e) {            fValidation = false;        }        try {            fNamespaces = componentManager.getFeature(NAMESPACES);        }        catch (XMLConfigurationException e) {            fNamespaces = true;        }        try {            fNotifyCharRefs = componentManager.getFeature(NOTIFY_CHAR_REFS);        }        catch (XMLConfigurationException e) {            fNotifyCharRefs = false;        }                init();    } // reset(XMLComponentManager)    /**     * Sets the value of a property during parsing.     *      * @param propertyId      * @param value      */    public void setProperty(String propertyId, Object value)        throws XMLConfigurationException {                // Xerces properties        if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) {        	final int suffixLength = propertyId.length() - Constants.XERCES_PROPERTY_PREFIX.length();        	            if (suffixLength == Constants.SYMBOL_TABLE_PROPERTY.length() &&                 propertyId.endsWith(Constants.SYMBOL_TABLE_PROPERTY)) {                fSymbolTable = (SymbolTable)value;            }            else if (suffixLength == Constants.ERROR_REPORTER_PROPERTY.length() &&                 propertyId.endsWith(Constants.ERROR_REPORTER_PROPERTY)) {                fErrorReporter = (XMLErrorReporter)value;            }            else if (suffixLength == Constants.ENTITY_MANAGER_PROPERTY.length() &&                 propertyId.endsWith(Constants.ENTITY_MANAGER_PROPERTY)) {                fEntityManager = (XMLEntityManager)value;            }        }    } // setProperty(String,Object)    /*     * Sets the feature of the scanner.     */    public void setFeature(String featureId, boolean value)        throws XMLConfigurationException {                    if (VALIDATION.equals(featureId)) {            fValidation = value;        } else if (NOTIFY_CHAR_REFS.equals(featureId)) {            fNotifyCharRefs = value;        }    }        /*     * Gets the state of the feature of the scanner.     */    public boolean getFeature(String featureId)        throws XMLConfigurationException {                    if (VALIDATION.equals(featureId)) {            return fValidation;        } else if (NOTIFY_CHAR_REFS.equals(featureId)) {            return fNotifyCharRefs;        }        throw new XMLConfigurationException(XMLConfigurationException.NOT_RECOGNIZED, featureId);    }        //    // Protected methods    //    // anybody calling this had better have set Symtoltable!    protected void reset() {        init();        // DTD preparsing defaults:        fValidation = true;        fNotifyCharRefs = false;

⌨️ 快捷键说明

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