xmldtdvalidator.java

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

JAVA
1,655
字号
/* * The Apache Software License, Version 1.1 * * * Copyright (c) 1999-2003 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.dtd;import com.sun.org.apache.xerces.internal.impl.Constants;import com.sun.org.apache.xerces.internal.impl.XMLEntityManager;import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;import com.sun.org.apache.xerces.internal.impl.dtd.models.ContentModelValidator;import com.sun.org.apache.xerces.internal.impl.dv.DTDDVFactory;import com.sun.org.apache.xerces.internal.impl.dv.DatatypeValidator;import com.sun.org.apache.xerces.internal.impl.dv.InvalidDatatypeValueException;import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager;import com.sun.org.apache.xerces.internal.impl.validation.ValidationState;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.XMLSymbols;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.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.XMLLocator;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.grammars.Grammar;import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarDescription;import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool;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.XMLDocumentFilter;import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentSource;/** * The DTD validator. The validator implements a document * filter: receiving document events from the scanner; validating * the content and structure; augmenting the InfoSet, if applicable; * and notifying the parser of the information resulting from the * validation process. * <p> Formerly, this component also handled DTD events and grammar construction. * To facilitate the development of a meaningful DTD grammar caching/preparsing * framework, this functionality has been moved into the XMLDTDLoader * class.  Therefore, this class no longer implements the DTDFilter * or DTDContentModelFilter interfaces. * <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/validation/dynamic</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/grammar-pool</li> *  <li>http://apache.org/xml/properties/internal/datatype-validator-factory</li> * </ul> * * @author Eric Ye, IBM * @author Andy Clark, IBM * @author Jeffrey Rodriguez IBM * @author Neil Graham, IBM * * @version $Id: XMLDTDValidator.java,v 1.59 2004/04/25 05:05:49 mrglavas Exp $ */public class XMLDTDValidator        implements XMLComponent, XMLDocumentFilter, XMLDTDValidatorFilter {    //    // Constants    //    /** Symbol: "&lt;&lt;datatypes>>". */    /** Top level scope (-1). */    private static final int TOP_LEVEL_SCOPE = -1;    // feature identifiers    /** Feature identifier: namespaces. */    protected static final String NAMESPACES =    Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE;    /** Feature identifier: validation. */    protected static final String VALIDATION =    Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE;    /** Feature identifier: dynamic validation. */    protected static final String DYNAMIC_VALIDATION =     Constants.XERCES_FEATURE_PREFIX + Constants.DYNAMIC_VALIDATION_FEATURE;    /** Feature identifier: warn on duplicate attdef */    protected static final String WARN_ON_DUPLICATE_ATTDEF =     Constants.XERCES_FEATURE_PREFIX +Constants.WARN_ON_DUPLICATE_ATTDEF_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: grammar pool. */    protected static final String GRAMMAR_POOL =        Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY;    /** Property identifier: datatype validator factory. */    protected static final String DATATYPE_VALIDATOR_FACTORY =        Constants.XERCES_PROPERTY_PREFIX + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY;    // property identifier:  ValidationManager    protected static final String VALIDATION_MANAGER =        Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY;    // recognized features and properties    /** Recognized features. */    private static final String[] RECOGNIZED_FEATURES = {        NAMESPACES,        VALIDATION,        DYNAMIC_VALIDATION    };    /** Feature defaults. */    private static final Boolean[] FEATURE_DEFAULTS = {        null,        null,        Boolean.FALSE,    };    /** Recognized properties. */    private static final String[] RECOGNIZED_PROPERTIES = {        SYMBOL_TABLE,               ERROR_REPORTER,        GRAMMAR_POOL,        DATATYPE_VALIDATOR_FACTORY,        VALIDATION_MANAGER    };    /** Property defaults. */    private static final Object[] PROPERTY_DEFAULTS = {        null,        null,        null,        null,        null,    };    // debugging    /** Compile to true to debug attributes. */    private static final boolean DEBUG_ATTRIBUTES = false;    /** Compile to true to debug element children. */    private static final boolean DEBUG_ELEMENT_CHILDREN = false;    //            // Data    //    // updated during reset    protected ValidationManager fValidationManager = null;        // validation state    protected ValidationState   fValidationState   = new ValidationState();    // features    /** Namespaces. */    protected boolean fNamespaces;    /** Validation. */    protected boolean fValidation;    /** Validation against only DTD */    protected boolean fDTDValidation;    /**      * Dynamic validation. This state of this feature is only useful when     * the validation feature is set to <code>true</code>.     */    protected boolean fDynamicValidation;    /** warn on duplicate attribute definition, this feature works only when validation is true */    protected boolean fWarnDuplicateAttdef;            // properties    /** Symbol table. */    protected SymbolTable fSymbolTable;    /** Error reporter. */    protected XMLErrorReporter fErrorReporter;    // the grammar pool    protected XMLGrammarPool fGrammarPool;    /** Grammar bucket. */    protected DTDGrammarBucket fGrammarBucket;    /* location of the document as passed in from startDocument call */    protected XMLLocator fDocLocation;    /** Namespace support. */    protected NamespaceContext fNamespaceContext = null;    /** Datatype validator factory. */    protected DTDDVFactory fDatatypeValidatorFactory;    // handlers    /** Document handler. */    protected XMLDocumentHandler fDocumentHandler;    protected XMLDocumentSource fDocumentSource;    // grammars    /** DTD Grammar. */    protected DTDGrammar fDTDGrammar;    // state    /** True if seen DOCTYPE declaration. */    protected boolean fSeenDoctypeDecl = false;    /** Perform validation. */    private boolean fPerformValidation;        /** Schema type: None, DTD, Schema */    private String fSchemaType;    // information regarding the current element    /** Current element name. */    private final QName fCurrentElement = new QName();    /** Current element index. */    private int fCurrentElementIndex = -1;    /** Current content spec type. */    private int fCurrentContentSpecType = -1;    /** The root element name. */    private final QName fRootElement = new QName();    private boolean fInCDATASection = false;    // element stack    /** Element index stack. */    private int[] fElementIndexStack = new int[8];    /** Content spec type stack. */    private int[] fContentSpecTypeStack = new int[8];    /** Element name stack. */    private QName[] fElementQNamePartsStack = new QName[8];    // children list and offset stack    /**      * Element children. This data structure is a growing stack that     * holds the children of elements from the root to the current     * element depth. This structure never gets "deeper" than the     * deepest element. Space is re-used once each element is closed.     * <p>     * <strong>Note:</strong> This is much more efficient use of memory     * than creating new arrays for each element depth.

⌨️ 快捷键说明

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