xmldtdscannerimpl.java

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

JAVA
1,765
字号
/* * 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.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.xni.Augmentations;import com.sun.org.apache.xerces.internal.xni.XMLDTDContentModelHandler;import com.sun.org.apache.xerces.internal.xni.XMLDTDHandler;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.XMLDTDScanner;import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;/** * This class is responsible for scanning the declarations found * in the internal and external subsets of a DTD in an XML document. * The scanner acts as the sources for the DTD information which is  * communicated to the DTD handlers. * <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/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 Arnaud  Le Hors, IBM * @author Andy Clark, IBM * @author Glenn Marcy, IBM * @author Eric Ye, IBM * * @version $Id: XMLDTDScannerImpl.java,v 1.49 2004/02/27 20:36:07 mrglavas Exp $ */public class XMLDTDScannerImpl    extends XMLScanner    implements XMLDTDScanner, XMLComponent, XMLEntityHandler {    //    // Constants    //    // scanner states    /** Scanner state: end of input. */    protected static final int SCANNER_STATE_END_OF_INPUT = 0;    /** Scanner state: text declaration. */    protected static final int SCANNER_STATE_TEXT_DECL = 1;    /** Scanner state: markup declaration. */    protected static final int SCANNER_STATE_MARKUP_DECL = 2;    // recognized features and properties        /** Recognized features. */    private static final String[] RECOGNIZED_FEATURES = {        VALIDATION,        NOTIFY_CHAR_REFS,    };    /** Feature defaults. */    private static final Boolean[] FEATURE_DEFAULTS = {        null,        Boolean.FALSE,    };    /** Recognized properties. */    private static final String[] RECOGNIZED_PROPERTIES = {        SYMBOL_TABLE,        ERROR_REPORTER,        ENTITY_MANAGER,    };    /** Property defaults. */    private static final Object[] PROPERTY_DEFAULTS = {        null,        null,        null,    };    // debugging    /** Debug scanner state. */    private static final boolean DEBUG_SCANNER_STATE = false;    //    // Data    //    // handlers    /** DTD handler. */    protected XMLDTDHandler fDTDHandler;    /** DTD content model handler. */    protected XMLDTDContentModelHandler fDTDContentModelHandler;    // state    /** Scanner state. */    protected int fScannerState;    /** Standalone. */    protected boolean fStandalone;    /** Seen external DTD. */    protected boolean fSeenExternalDTD;    /** Seen external parameter entity. */    protected boolean fSeenExternalPE;    // private data    /** Start DTD called. */    private boolean fStartDTDCalled;    /** Default attribute */    private XMLAttributesImpl fAttributes = new XMLAttributesImpl();    /**      * Stack of content operators (either '|' or ',') in children      * content.     */    private int[] fContentStack = new int[5];    /** Size of content stack. */    private int fContentDepth;    /** Parameter entity stack to check well-formedness. */    private int[] fPEStack = new int[5];    /** Parameter entity stack to report start/end entity calls. */    private boolean[] fPEReport = new boolean[5];    /** Number of opened parameter entities. */    private int fPEDepth;    /** Markup depth. */    private int fMarkUpDepth;    /** Number of opened external entities. */    private int fExtEntityDepth;    /** Number of opened include sections. */    private int fIncludeSectDepth;    // 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();    /** String buffer. */    private XMLStringBuffer fStringBuffer2 = new XMLStringBuffer();    /** Literal text. */    private XMLString fLiteral = new XMLString();    /** Literal text. */    private XMLString fLiteral2 = new XMLString();    /** Enumeration values. */    private String[] fEnumeration = new String[5];    /** Enumeration values count. */    private int fEnumerationCount;    /** Ignore conditional section buffer. */    private XMLStringBuffer fIgnoreConditionalBuffer = new XMLStringBuffer(128);    //    // Constructors    //    /** Default constructor. */    public XMLDTDScannerImpl() {} // <init>()    /** Constructor for he use of non-XMLComponentManagers. */    public XMLDTDScannerImpl(SymbolTable symbolTable,                XMLErrorReporter errorReporter, XMLEntityManager entityManager) {        fSymbolTable = symbolTable;        fErrorReporter = errorReporter;        fEntityManager = entityManager;        entityManager.setProperty(SYMBOL_TABLE, fSymbolTable);    }    //    // XMLDTDScanner methods    //    /**      * Sets the input source.      *     * @param inputSource The input source or null.     *     * @throws IOException Thrown on i/o error.     */    public void setInputSource(XMLInputSource inputSource) throws IOException {        if (inputSource == null) {            // no system id was available            if (fDTDHandler != null) {                fDTDHandler.startDTD(null, null);                fDTDHandler.endDTD(null);            }            return;        }        fEntityManager.setEntityHandler(this);        fEntityManager.startDTDEntity(inputSource);    } // setInputSource(XMLInputSource)    /**     * Scans the external subset of the 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.     */    public boolean scanDTDExternalSubset(boolean complete)         throws IOException, XNIException {        fEntityManager.setEntityHandler(this);        if (fScannerState == SCANNER_STATE_TEXT_DECL) {            fSeenExternalDTD = true;            boolean textDecl = scanTextDecl();            if (fScannerState == SCANNER_STATE_END_OF_INPUT) {                return false;            }            else {                // next state is markup decls regardless of whether there                // is a TextDecl or not                setScannerState(SCANNER_STATE_MARKUP_DECL);                if (textDecl && !complete) {                    return true;                }            }        }        // keep dispatching "events"        do {            if (!scanDecls(complete)) {                return false;            }        } while (complete);        // return that there is more to scan        return true;    } // scanDTDExternalSubset(boolean):boolean    /**      * Scans the internal subset of the 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.     * @param standalone True if the document was specified as standalone.     *                   This value is important for verifying certain     *                   well-formedness constraints.     * @param hasExternalDTD True if the document has an external DTD.     *                       This allows the scanner to properly notify     *                       the handler of the end of the DTD in the     *                       absence of an external subset.     *     * @return True if there is more to scan, false otherwise.     */    public boolean scanDTDInternalSubset(boolean complete, boolean standalone,                                         boolean hasExternalSubset)        throws IOException, XNIException {        // reset entity scanner        fEntityScanner = fEntityManager.getEntityScanner();

⌨️ 快捷键说明

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