📄 dtdgrammar.java
字号:
/* * The Apache Software License, Version 1.1 * * * Copyright (c) 1999-2002 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 java.util.Hashtable;import java.util.Vector;import com.sun.org.apache.xerces.internal.impl.dtd.models.CMAny;import com.sun.org.apache.xerces.internal.impl.dtd.models.CMBinOp;import com.sun.org.apache.xerces.internal.impl.dtd.models.CMLeaf;import com.sun.org.apache.xerces.internal.impl.dtd.models.CMNode;import com.sun.org.apache.xerces.internal.impl.dtd.models.CMUniOp;import com.sun.org.apache.xerces.internal.impl.dtd.models.ContentModelValidator;import com.sun.org.apache.xerces.internal.impl.dtd.models.DFAContentModel;import com.sun.org.apache.xerces.internal.impl.dtd.models.MixedContentModel;import com.sun.org.apache.xerces.internal.impl.dtd.models.SimpleContentModel;import com.sun.org.apache.xerces.internal.impl.dv.DatatypeValidator;import com.sun.org.apache.xerces.internal.impl.validation.EntityState;import com.sun.org.apache.xerces.internal.util.SymbolTable;import com.sun.org.apache.xerces.internal.xni.Augmentations;import com.sun.org.apache.xerces.internal.xni.QName;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.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.parser.XMLDTDContentModelSource;import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDSource;/** * A DTD grammar. This class implements the XNI handler interfaces * for DTD information so that it can build the approprate validation * structures automatically from the callbacks. * * @xerces.internal * * @author Eric Ye, IBM * @author Jeffrey Rodriguez, IBM * @author Andy Clark, IBM * @author Neil Graham, IBM * * @version $Id: DTDGrammar.java,v 1.1.2.1 2005/08/01 03:36:39 jeffsuttor Exp $ */public class DTDGrammar implements XMLDTDHandler, XMLDTDContentModelHandler, EntityState, Grammar { // // Constants // /** Top level scope (-1). */ public static final int TOP_LEVEL_SCOPE = -1; // private /** Chunk shift (8). */ private static final int CHUNK_SHIFT = 8; // 2^8 = 256 /** Chunk size (1 << CHUNK_SHIFT). */ private static final int CHUNK_SIZE = (1 << CHUNK_SHIFT); /** Chunk mask (CHUNK_SIZE - 1). */ private static final int CHUNK_MASK = CHUNK_SIZE - 1; /** Initial chunk count (1 << (10 - CHUNK_SHIFT)). */ private static final int INITIAL_CHUNK_COUNT = (1 << (10 - CHUNK_SHIFT)); // 2^10 = 1k /** List flag (0x80). */ private static final short LIST_FLAG = 0x80; /** List mask (~LIST_FLAG). */ private static final short LIST_MASK = ~LIST_FLAG; // debugging /** Debug DTDGrammar. */ private static final boolean DEBUG = false; // // Data // protected XMLDTDSource fDTDSource = null; protected XMLDTDContentModelSource fDTDContentModelSource = null; /** Current element index. */ protected int fCurrentElementIndex; /** Current attribute index. */ protected int fCurrentAttributeIndex; /** fReadingExternalDTD */ protected boolean fReadingExternalDTD = false; /** Symbol table. */ private SymbolTable fSymbolTable; // The XMLDTDDescription with which this Grammar is associated protected XMLDTDDescription fGrammarDescription = null; // element declarations /** Number of element declarations. */ private int fElementDeclCount = 0; /** Element declaration name. */ private QName fElementDeclName[][] = new QName[INITIAL_CHUNK_COUNT][]; /** * Element declaration type. * @see XMLElementDecl */ private short fElementDeclType[][] = new short[INITIAL_CHUNK_COUNT][]; /** * Element declaration content spec index. This index value is used * to refer to the content spec information tables. */ private int fElementDeclContentSpecIndex[][] = new int[INITIAL_CHUNK_COUNT][]; /** * Element declaration content model validator. This validator is * constructed from the content spec nodes. */ private ContentModelValidator fElementDeclContentModelValidator[][] = new ContentModelValidator[INITIAL_CHUNK_COUNT][]; /** First attribute declaration of an element declaration. */ private int fElementDeclFirstAttributeDeclIndex[][] = new int[INITIAL_CHUNK_COUNT][]; /** Last attribute declaration of an element declaration. */ private int fElementDeclLastAttributeDeclIndex[][] = new int[INITIAL_CHUNK_COUNT][]; // attribute declarations /** Number of attribute declarations. */ private int fAttributeDeclCount = 0 ; /** Attribute declaration name. */ private QName fAttributeDeclName[][] = new QName[INITIAL_CHUNK_COUNT][]; // is this grammar immutable? (fully constructed and not changeable) private boolean fIsImmutable = false; /** * Attribute declaration type. * @see XMLAttributeDecl */ private short fAttributeDeclType[][] = new short[INITIAL_CHUNK_COUNT][]; /** Attribute declaration enumeration values. */ private String[] fAttributeDeclEnumeration[][] = new String[INITIAL_CHUNK_COUNT][][]; private short fAttributeDeclDefaultType[][] = new short[INITIAL_CHUNK_COUNT][]; private DatatypeValidator fAttributeDeclDatatypeValidator[][] = new DatatypeValidator[INITIAL_CHUNK_COUNT][]; private String fAttributeDeclDefaultValue[][] = new String[INITIAL_CHUNK_COUNT][]; private String fAttributeDeclNonNormalizedDefaultValue[][] = new String[INITIAL_CHUNK_COUNT][]; private int fAttributeDeclNextAttributeDeclIndex[][] = new int[INITIAL_CHUNK_COUNT][]; // content specs // here saves the content spec binary trees for element decls, // each element with a content model will hold a pointer which is // the index of the head node of the content spec tree. private int fContentSpecCount = 0; private short fContentSpecType[][] = new short[INITIAL_CHUNK_COUNT][]; private Object fContentSpecValue[][] = new Object[INITIAL_CHUNK_COUNT][]; private Object fContentSpecOtherValue[][] = new Object[INITIAL_CHUNK_COUNT][]; // entities private int fEntityCount = 0; private String fEntityName[][] = new String[INITIAL_CHUNK_COUNT][]; private String[][] fEntityValue = new String[INITIAL_CHUNK_COUNT][]; private String[][] fEntityPublicId = new String[INITIAL_CHUNK_COUNT][]; private String[][] fEntitySystemId = new String[INITIAL_CHUNK_COUNT][]; private String[][] fEntityBaseSystemId = new String[INITIAL_CHUNK_COUNT][]; private String[][] fEntityNotation = new String[INITIAL_CHUNK_COUNT][]; private byte[][] fEntityIsPE = new byte[INITIAL_CHUNK_COUNT][]; private byte[][] fEntityInExternal = new byte[INITIAL_CHUNK_COUNT][]; // notations private int fNotationCount = 0; private String fNotationName[][] = new String[INITIAL_CHUNK_COUNT][]; private String[][] fNotationPublicId = new String[INITIAL_CHUNK_COUNT][]; private String[][] fNotationSystemId = new String[INITIAL_CHUNK_COUNT][]; private String[][] fNotationBaseSystemId = new String[INITIAL_CHUNK_COUNT][]; // other information /** Element index mapping table. */ private QNameHashtable fElementIndexMap = new QNameHashtable(); /** Entity index mapping table. */ private QNameHashtable fEntityIndexMap = new QNameHashtable(); /** Notation index mapping table. */ private QNameHashtable fNotationIndexMap = new QNameHashtable(); // temp variables /** Mixed. */ private boolean fMixed; /** Temporary qualified name. */ private QName fQName = new QName(); /** Temporary qualified name. */ private QName fQName2 = new QName(); /** Temporary Attribute decl. */ protected XMLAttributeDecl fAttributeDecl = new XMLAttributeDecl(); // for buildSyntaxTree method private int fLeafCount = 0; private int fEpsilonIndex = -1; /** Element declaration. */ private XMLElementDecl fElementDecl = new XMLElementDecl(); /** Entity declaration. */ private XMLEntityDecl fEntityDecl = new XMLEntityDecl(); /** Simple type. */ private XMLSimpleType fSimpleType = new XMLSimpleType(); /** Content spec node. */ private XMLContentSpec fContentSpec = new XMLContentSpec(); /** table of XMLElementDecl */ Hashtable fElementDeclTab = new Hashtable(); /** Children content model operation stack. */ private short[] fOpStack = null; /** Children content model index stack. */ private int[] fNodeIndexStack = null; /** Children content model previous node index stack. */ private int[] fPrevNodeIndexStack = null; /** Stack depth */ private int fDepth = 0; /** Entity stack. */ private boolean[] fPEntityStack = new boolean[4]; private int fPEDepth = 0; // additional fields(columns) for the element Decl pool in the Grammar /** flag if the elementDecl is External. */ private int fElementDeclIsExternal[][] = new int[INITIAL_CHUNK_COUNT][]; // additional fields(columns) for the attribute Decl pool in the Grammar /** flag if the AttributeDecl is External. */ private int fAttributeDeclIsExternal[][] = new int[INITIAL_CHUNK_COUNT][]; // for mixedElement method int valueIndex = -1; int prevNodeIndex = -1; int nodeIndex = -1; // // Constructors // /** Default constructor. */ public DTDGrammar(SymbolTable symbolTable, XMLDTDDescription desc) { fSymbolTable = symbolTable; fGrammarDescription = desc; } // <init>(SymbolTable) // Grammar methods
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -