xmlentityscanner.java

来自「JAVA 所有包」· Java 代码 · 共 1,674 行 · 第 1/5 页

JAVA
1,674
字号
/* * The contents of this file are subject to the terms * of the Common Development and Distribution License * (the "License").  You may not use this file except * in compliance with the License. * * You can obtain a copy of the license at * https://jaxp.dev.java.net/CDDLv1.0.html. * See the License for the specific language governing * permissions and limitations under the License. * * When distributing Covered Code, include this CDDL * HEADER in each file and include the License file at * https://jaxp.dev.java.net/CDDLv1.0.html * If applicable add the following below this CDDL HEADER * with the fields enclosed by brackets "[]" replaced with * your own identifying information: Portions Copyright * [year] [name of copyright owner] *//* * $Id: XMLEntityScanner.java,v 1.9 2006/01/20 14:13:07 sunithareddy Exp $ * @(#)XMLEntityScanner.java	1.16 06/07/13 * * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. *//* * Copyright 2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *      http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.sun.org.apache.xerces.internal.impl;import com.sun.xml.internal.stream.Entity;import com.sun.xml.internal.stream.XMLBufferListener;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.Reader;import java.util.Locale;import java.util.Vector;import com.sun.org.apache.xerces.internal.impl.io.ASCIIReader;import com.sun.org.apache.xerces.internal.impl.io.UCSReader;import com.sun.org.apache.xerces.internal.impl.io.UTF8Reader;import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;import com.sun.org.apache.xerces.internal.util.EncodingMap;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.XMLStringBuffer;import com.sun.org.apache.xerces.internal.xni.QName;import com.sun.org.apache.xerces.internal.xni.XMLString;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.*;/** * Implements the entity scanner methods. * * @author Neeraj Bajaj, Sun Microsystems * @author Andy Clark, IBM * @author Arnaud  Le Hors, IBM * @author K.Venugopal Sun Microsystems * */public class XMLEntityScanner implements XMLLocator  {            protected Entity.ScannedEntity fCurrentEntity = null ;    protected int fBufferSize = XMLEntityManager.DEFAULT_BUFFER_SIZE;        protected XMLEntityManager fEntityManager ;        /** Debug switching readers for encodings. */    private static final boolean DEBUG_ENCODINGS = false;    /** Listeners which should know when load is being called */    private Vector listeners = new Vector();        public static final boolean [] VALID_NAMES = new boolean[127];        /**     * Debug printing of buffer. This debugging flag works best when you     * resize the DEFAULT_BUFFER_SIZE down to something reasonable like     * 64 characters.     */    private static final boolean DEBUG_BUFFER = false;    private static final boolean DEBUG_SKIP_STRING = false;        protected SymbolTable fSymbolTable = null;    protected XMLErrorReporter fErrorReporter = null;    int [] whiteSpaceLookup = new int[100];    int whiteSpaceLen = 0;    boolean whiteSpaceInfoNeeded = true;        /**     * Allow Java encoding names. This feature identifier is:     * http://apache.org/xml/features/allow-java-encodings     */    protected boolean fAllowJavaEncodings;        //Will be used only during internal subsets.    //for appending data.        /** 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;        /** Feature identifier: allow Java encodings. */    protected static final String ALLOW_JAVA_ENCODINGS =            Constants.XERCES_FEATURE_PREFIX + Constants.ALLOW_JAVA_ENCODINGS_FEATURE;        protected PropertyManager fPropertyManager = null ;        boolean isExternal = false;    static {                for(int i=0x0041;i<=0x005A ; i++){            VALID_NAMES[i]=true;        }        for(int i=0x0061;i<=0x007A; i++){            VALID_NAMES[i]=true;        }        for(int i=0x0030;i<=0x0039; i++){            VALID_NAMES[i]=true;        }        VALID_NAMES[45]=true;        VALID_NAMES[46]=true;        VALID_NAMES[58]=true;        VALID_NAMES[95]=true;    }        //    // Constructors    //        /** Default constructor. */    public XMLEntityScanner() {    } // <init>()                /**  private constructor, this class can only be instantiated within this class. Instance of this class should     *    be obtained using getEntityScanner() or getEntityScanner(ScannedEntity scannedEntity)     *    @see getEntityScanner()     *    @see getEntityScanner(ScannedEntity)     */    public XMLEntityScanner(PropertyManager propertyManager, XMLEntityManager entityManager) {        fEntityManager = entityManager ;        reset(propertyManager);    } // <init>()            // set buffer size:    public void setBufferSize(int size) {        // REVISIT: Buffer size passed to entity scanner        // was not being kept in synch with the actual size        // of the buffers in each scanned entity. If any        // of the buffers were actually resized, it was possible        // that the parser would throw an ArrayIndexOutOfBoundsException        // for documents which contained names which are longer than        // the current buffer size. Conceivably the buffer size passed        // to entity scanner could be used to determine a minimum size        // for resizing, if doubling its size is smaller than this        // minimum. -- mrglavas        fBufferSize = size;    }        /**     * Resets the components.     */    public void reset(PropertyManager propertyManager){        fSymbolTable = (SymbolTable)propertyManager.getProperty(SYMBOL_TABLE) ;        fErrorReporter = (XMLErrorReporter)propertyManager.getProperty(ERROR_REPORTER) ;        fCurrentEntity = null;        whiteSpaceLen = 0;        whiteSpaceInfoNeeded = true;        listeners.clear();    }        /**     * 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 {                //System.out.println(" this is being called");        // xerces features        try {            fAllowJavaEncodings = componentManager.getFeature(ALLOW_JAVA_ENCODINGS);        } catch (XMLConfigurationException e) {            fAllowJavaEncodings = false;        }                //xerces properties        fSymbolTable = (SymbolTable)componentManager.getProperty(SYMBOL_TABLE);        fErrorReporter = (XMLErrorReporter)componentManager.getProperty(ERROR_REPORTER);        fCurrentEntity = null;        whiteSpaceLen = 0;        whiteSpaceInfoNeeded = true;        listeners.clear();    } // reset(XMLComponentManager)            public void reset(SymbolTable symbolTable, XMLEntityManager entityManager,            XMLErrorReporter reporter) {        fCurrentEntity = null;        fSymbolTable = symbolTable;        fEntityManager = entityManager;        fErrorReporter = reporter;    }        /**     * Returns the XML version of the current entity. This will normally be the     * value from the XML or text declaration or defaulted by the parser. Note that     * that this value may be different than the version of the processing rules      * applied to the current entity. For instance, an XML 1.1 document may refer to     * XML 1.0 entities. In such a case the rules of XML 1.1 are applied to the entire      * document. Also note that, for a given entity, this value can only be considered     * final once the XML or text declaration has been read or once it has been     * determined that there is no such declaration.     */    public String getXMLVersion() {        if (fCurrentEntity != null) {            return fCurrentEntity.xmlVersion;        }        return null;    } // getXMLVersion():String        void setXMLVersion(String version) {        fCurrentEntity.xmlVersion = version;    }            /** set the instance of current scanned entity.     *   @param ScannedEntity     */        public  void setCurrentEntity(Entity.ScannedEntity scannedEntity){        fCurrentEntity = scannedEntity ;        if(fCurrentEntity != null){            isExternal = fCurrentEntity.isExternal();            if(DEBUG_BUFFER)                System.out.println("Current Entity is "+scannedEntity.name);        }    }        public  Entity.ScannedEntity getCurrentEntity(){        return fCurrentEntity ;    }    //    // XMLEntityReader methods    //        /**     * Returns the base system identifier of the currently scanned     * entity, or null if none is available.     */    public String getBaseSystemId() {        return (fCurrentEntity != null && fCurrentEntity.entityLocation != null) ? fCurrentEntity.entityLocation.getExpandedSystemId() : null;    } // getBaseSystemId():String        /**     * @see com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier#setBaseSystemId(String)     */    public void setBaseSystemId(String systemId) {        //no-op    }        ///////////// Locator methods start.    public int getLineNumber(){        //if the entity is closed, we should return -1        //xxx at first place why such call should be there...        return fCurrentEntity != null ? fCurrentEntity.lineNumber : -1 ;    }        /**     * @see com.sun.org.apache.xerces.internal.xni.XMLLocator#setLineNumber(int)     */    public void setLineNumber(int line) {        //no-op    }            public int getColumnNumber(){        //if the entity is closed, we should return -1        //xxx at first place why such call should be there...        return fCurrentEntity != null ? fCurrentEntity.columnNumber : -1 ;    }        /**     * @see com.sun.org.apache.xerces.internal.xni.XMLLocator#setColumnNumber(int)     */    public void setColumnNumber(int col) {        // no-op    }            public int getCharacterOffset(){        return fCurrentEntity != null ? fCurrentEntity.fTotalCountTillLastLoad + fCurrentEntity.position : -1 ;    }        /** Returns the expanded system identifier.  */    public String getExpandedSystemId() {        return (fCurrentEntity != null && fCurrentEntity.entityLocation != null) ? fCurrentEntity.entityLocation.getExpandedSystemId() : null;    }        /**

⌨️ 快捷键说明

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