/*
*/
/*
* 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
*
*
* 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.
*/
/**
* 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.
*
* @author Eric Ye, IBM
* @author Jeffrey Rodriguez, IBM
* @author Andy Clark, IBM
* @author Neil Graham, IBM
*
*/
public class DTDGrammar {
/** Top level scope (-1). */
// private
/** Chunk shift (8). */
/** Chunk size (1 << CHUNK_SHIFT). */
/** Chunk mask (CHUNK_SIZE - 1). */
/** Initial chunk count (1 << (10 - CHUNK_SHIFT)). */
/** List flag (0x80). */
/** List mask (~LIST_FLAG). */
// debugging
/** Debug DTDGrammar. */
private static final boolean DEBUG = false;
//
// Data
//
/** Current element index. */
protected int fCurrentElementIndex;
/** Current attribute index. */
protected int fCurrentAttributeIndex;
/** fReadingExternalDTD */
protected boolean fReadingExternalDTD = false;
/** Symbol table. */
// element declarations
/** Number of element declarations. */
/** Element declaration name. */
/**
* Element declaration type.
* @see XMLElementDecl
*/
/** First attribute declaration of an element declaration. */
/** Last attribute declaration of an element declaration. */
// attribute declarations
/** Number of attribute declarations. */
/** Attribute declaration name. */
/**
* Attribute declaration type.
* @see XMLAttributeDecl
*/
/** Attribute declaration enumeration values. */
/** Element index mapping table. */
/** Temporary qualified name. */
/** Temporary Attribute decl. */
/** Element declaration. */
/** Simple type. */
/** table of XMLElementDecl */
/** Default constructor. */
}
if (elementDeclIndex == -1) {
return -1;
}
while (attDefIndex != -1) {
return attDefIndex;
}
}
return -1;
}
/**
* The start of the DTD.
*
* @param locator The document locator, or null if the document
* location cannot be reported during the parsing of
* the document DTD. However, it is <em>strongly</em>
* recommended that a locator be supplied that can
* at least report the base system identifier of the
* DTD.
*
* @param augs Additional information that may include infoset
* augmentations.
* @throws XNIException Thrown by handler to signal an error.
*/
} // startDTD(XMLLocator)
// startExternalSubset(Augmentations)
// endExternalSubset(Augmentations)
/**
* An element declaration.
*
* @param name The name of the element.
* @param contentModel The element content model.
* @param augs Additional information that may include infoset
* augmentations.
* @throws XNIException Thrown by handler to signal an error.
*/
throws XNIException {
if ( tmpElementDecl != null ) {
}
else {
// duplicate element, ignored.
return;
}
}
else {
}
}
}
}
else {
}
}
//add(or set) this elementDecl to the local cache
if ( DEBUG ) {
}
}
/**
* An attribute declaration.
*
* @param elementName The name of the element that this attribute
* is associated with.
* @param attributeName The name of the attribute.
* @param type The attribute type. This value will be one of
* the following: "CDATA", "ENTITY", "ENTITIES",
* "ENUMERATION", "ID", "IDREF", "IDREFS",
* "NMTOKEN", "NMTOKENS", or "NOTATION".
* @param enumeration If the type has the value "ENUMERATION", this
* array holds the allowed attribute values;
* otherwise, this array is null.
* @param defaultType The attribute default type. This value will be
* one of the following: "#FIXED", "#IMPLIED",
* "#REQUIRED", or null.
* @param defaultValue The attribute default value, or null if no
* default value is specified.
* @param nonNormalizedDefaultValue The attribute default value with no normalization
* performed, or null if no default value is specified.
*
* @param augs Additional information that may include infoset
* augmentations.
* @throws XNIException Thrown by handler to signal an error.
*/
}
//if ElementDecl has already being created in the Grammar then remove from table,
//this.fElementDeclTab.remove( (String) elementName );
}
// then it is forward reference to a element decl, create the elementDecl first.
else {
//add(or set) this elementDecl to the local cache
//set internal structure
}
//Get Grammar index to grammar array
//return, when more than one definition is provided for the same attribute of given element type
//only the first declaration is binding and later declarations are ignored
return;
}
fSimpleType.clear();
if ( defaultType != null ) {
}
}
if ( DEBUG ) {
}
fSimpleType.nonNormalizedDefaultValue = nonNormalizedDefaultValue!=null ? nonNormalizedDefaultValue.toString() : null;
}
}
fSimpleType.list = true;
}
}
fSimpleType.list = true;
}
}
fSimpleType.list = true;
}
}
}
}
else {
// REVISIT: Report error message. -Ac
}
// REVISIT: The datatype should be stored with the attribute value
// and not special-cased in the XMLValidator. -Ac
//fSimpleType.datatypeValidator = fDatatypeValidatorFactory.createDatatypeValidator(type, null, facets, fSimpleType.list);
} // attributeDecl(String,String,String,String[],String,XMLString,XMLString, Augmentations)
/** Returns the symbol table. */
return fSymbolTable;
} // getSymbolTable():SymbolTable
/**
* Returns the index of the first element declaration. This index
* is then used to query more information about the element declaration.
*
* @see #getNextElementDeclIndex
* @see #getElementDecl
*/
public int getFirstElementDeclIndex() {
} // getFirstElementDeclIndex():int
/**
* Returns the next index of the element declaration following the
* specified element declaration.
*
* @param elementDeclIndex The element declaration index.
*/
} // getNextElementDeclIndex(int):int
/**
* getElementDeclIndex
*
* @param elementDeclName
*
* @return index of the elementDeclName in scope
*/
//System.out.println("getElementDeclIndex("+elementDeclName+") -> "+mapping);
return mapping;
} // getElementDeclIndex(String):int
/** Returns the element decl index.
* @param elementDeclQName qualilfied name of the element
*/
} // getElementDeclIndex(QName):int
/** make separate function for getting contentSpecType of element.
* we can avoid setting of the element values.
*/
return -1 ;
}
return -1 ;
}
else{
}
}
/**
* getElementDecl
*
* @param elementDeclIndex
* @param elementDecl The values of this structure are set by this call.
*
* @return True if find the element, False otherwise.
*/
return false;
}
} else {
}
return true;
}
// REVISIT: Make this getAttributeDeclCount/getAttributeDeclAt. -Ac
/**
* getFirstAttributeDeclIndex
*
* @param elementDeclIndex
*
* @return index of the first attribute for element declaration elementDeclIndex
*/
} // getFirstAttributeDeclIndex
/**
* getNextAttributeDeclIndex
*
* @param attributeDeclIndex
*
* @return index of the next attribute of the attribute at attributeDeclIndex
*/
}
/**
* getAttributeDecl
*
* @param attributeDeclIndex
* @param attributeDecl The values of this structure are set by this call.
*
* @return true if getAttributeDecl was able to fill in the value of attributeDecl
*/
return false;
}
short attributeType;
boolean isList;
attributeType = -1;
isList = false;
} else {
}
return true;
} // getAttributeDecl
/**
* Returns whether the given attribute is of type CDATA or not
*
* @param elName The element name.
* @param atName The attribute name.
*
* @return true if the attribute is of type CDATA
*/
return false;
}
return true;
}
public void printElements( ) {
int elementDeclIndex = 0;
}
}
while (attributeDeclIndex != -1) {
if (attributeDeclIndex != -1) {
}
}
}
protected int createElementDecl() {
return fElementDeclCount++;
}
return;
}
}
}
return;
}
}
protected int createAttributeDecl() {
return fAttributeDeclCount++;
}
}
fAttributeDeclNonNormalizedDefaultValue[attrChunk][attrIndex] = attributeDecl.simpleType.nonNormalizedDefaultValue;
while (index != -1) {
if (index == attributeDeclIndex) {
break;
}
}
if (index == -1) {
} else {
}
}
}
}
return notationDecls;
}
//
// Private methods
//
}
} // printAttribute(int)
fElementDeclFirstAttributeDeclIndex = resize(fElementDeclFirstAttributeDeclIndex, fElementDeclFirstAttributeDeclIndex.length * 2);
fElementDeclLastAttributeDeclIndex = resize(fElementDeclLastAttributeDeclIndex, fElementDeclLastAttributeDeclIndex.length * 2);
}
return;
}
return;
}
fAttributeDeclEnumeration = resize(fAttributeDeclEnumeration, fAttributeDeclEnumeration.length * 2);
fAttributeDeclDefaultType = resize(fAttributeDeclDefaultType, fAttributeDeclDefaultType.length * 2);
fAttributeDeclDefaultValue = resize(fAttributeDeclDefaultValue, fAttributeDeclDefaultValue.length * 2);
fAttributeDeclNonNormalizedDefaultValue = resize(fAttributeDeclNonNormalizedDefaultValue, fAttributeDeclNonNormalizedDefaultValue.length * 2);
fAttributeDeclNextAttributeDeclIndex = resize(fAttributeDeclNextAttributeDeclIndex, fAttributeDeclNextAttributeDeclIndex.length * 2);
}
return;
}
return;
}
// resize chunks
return newarray;
}
return newarray;
}
return newarray;
}
return newarray;
}
return newarray;
}
//
// Classes
//
/**
* A simple Hashtable implementation that takes a tuple (String, String)
* as the key and a int as value.
*
* @author Eric Ye, IBM
* @author Andy Clark, IBM
*/
protected static final class QNameHashtable {
//
// Constants
//
public static final boolean UNIQUE_STRINGS = true;
/** Initial bucket size (4). */
// NOTE: Changed previous hashtable size from 512 to 101 so
// that we get a better distribution for hashing. -Ac
/** Hashtable size (101). */
//
// Data
//
//
// Public methods
//
/** Associates the given value with the specified key tuple. */
// REVISIT: Why +2? -Ac
} else {
}
boolean found = false;
int j=1;
for (int i=0; i<count; i++){
found = true;
break;
}
j += 2;
}
if (! found) {
}
}
//System.out.println("put("+key+" -> "+value+')');
//System.out.println("get("+key+") -> "+get(key));
} // put(int,String,String,int)
/** Returns the value associated with the specified key tuple. */
return -1;
}
int j=1;
for (int i=0; i<count; i++){
}
j += 2;
}
return -1;
} // get(int,String,String)
//
// Protected methods
//
/** Returns a hash value for the specified symbol. */
return 0;
}
int code = 0;
for (int i = 0; i < length; i++) {
}
return code & 0x7FFFFFF;
} // hash(String):int
} // class QNameHashtable
/**
* Normalize the attribute value of a non CDATA default attribute
* collapsing sequences of space characters (x20)
*
* @param value The value to normalize
* @return Whether the value was changed or not.
*/
boolean skipSpace = true; // skip leading spaces
if (!skipSpace) {
// take the first whitespace as a space and skip the others
skipSpace = true;
}
else {
// just skip it.
}
}
else {
// simply shift non space chars if needed
if (current != i) {
}
current++;
skipSpace = false;
}
}
if (skipSpace) {
// if we finished on a space trim it
current--;
}
// set the new value length
return true;
}
return false;
}
}
}