Top Description Inners Fields Constructors Methods
org.apache.xerces.impl.dtd

public Class DTDGrammar

extends Object
implements XMLDTDHandler, XMLDTDContentModelHandler, EntityState, Grammar
Class Inheritance
All Implemented Interfaces
org.apache.xerces.xni.grammars.Grammar, org.apache.xerces.impl.validation.EntityState, org.apache.xerces.xni.XMLDTDContentModelHandler, org.apache.xerces.xni.XMLDTDHandler
Known Direct Subclasses
org.apache.xerces.impl.dtd.BalancedDTDGrammar
Imports
java.util.ArrayList, .Hashtable, .Random, org.apache.xerces.impl.dtd.models.CMAny, .CMBinOp, .CMLeaf, .CMNode, .CMUniOp, .ContentModelValidator, .DFAContentModel, .MixedContentModel, .SimpleContentModel, org.apache.xerces.impl.dv.DatatypeValidator, org.apache.xerces.impl.validation.EntityState, org.apache.xerces.util.SymbolTable, org.apache.xerces.xni.Augmentations, .QName, .XMLDTDContentModelHandler, .XMLDTDHandler, .XMLLocator, .XMLResourceIdentifier, .XMLString, .XNIException, org.apache.xerces.xni.grammars.Grammar, .XMLGrammarDescription, org.apache.xerces.xni.parser.XMLDTDContentModelSource, .XMLDTDSource

A DTD grammar. This class implements the XNI handler interfaces for DTD information so that it can build the appropriate validation structures automatically from the callbacks.
Authors
Eric Ye, IBM, Jeffrey Rodriguez, IBM, Andy Clark, IBM, Neil Graham, IBM
Version
$Id: DTDGrammar.java 1357390 2012-07-04 20:20:20Z mrglavas $

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
DTDGrammar.ChildrenList

Children list for contentSpecTree method.

protected static class
DTDGrammar.QNameHashtable

A simple Hashtable implementation that takes a tuple (String, String) as the key and a int as value.

Field Summary

Modifier and TypeField and Description
private static final int
CHUNK_MASK

Chunk mask (CHUNK_SIZE - 1).

private static final int
CHUNK_SHIFT

Chunk shift (8).

private static final int
CHUNK_SIZE

Chunk size (1 << CHUNK_SHIFT).

private static final boolean
DEBUG

Debug DTDGrammar.

protected final XMLAttributeDecl
fAttributeDecl

Temporary Attribute decl.

private int
fAttributeDeclCount

Number of attribute declarations.

private DatatypeValidator[][]
private short[][]
private String[][]
private String[][][]
fAttributeDeclEnumeration

Attribute declaration enumeration values.

private int[][]
fAttributeDeclIsExternal

flag if the AttributeDecl is External.

private QName[][]
fAttributeDeclName

Attribute declaration name.

private int[][]
private String[][]
private short[][]
fAttributeDeclType

Attribute declaration type.

private XMLContentSpec
fContentSpec

Content spec node.

private int
private Object[][]
private short[][]
private Object[][]
protected int
fCurrentAttributeIndex

Current attribute index.

protected int
fCurrentElementIndex

Current element index.

private int
fDepth

Stack depth

protected XMLDTDContentModelSource
protected XMLDTDSource
private XMLElementDecl
fElementDecl

Element declaration.

private ContentModelValidator[][]
fElementDeclContentModelValidator

Element declaration content model validator.

private int[][]
fElementDeclContentSpecIndex

Element declaration content spec index.

private int
fElementDeclCount

Number of element declarations.

private int[][]
fElementDeclFirstAttributeDeclIndex

First attribute declaration of an element declaration.

private int[][]
fElementDeclIsExternal

flag if the elementDecl is External.

private int[][]
fElementDeclLastAttributeDeclIndex

Last attribute declaration of an element declaration.

private QName[][]
fElementDeclName

Element declaration name.

pack-priv Hashtable<K, V>
fElementDeclTab

table of XMLElementDecl

private short[][]
fElementDeclType

Element declaration type.

private DTDGrammar.QNameHashtable
fElementIndexMap

Element index mapping table.

private String[][]
private int
private XMLEntityDecl
fEntityDecl

Entity declaration.

private DTDGrammar.QNameHashtable
fEntityIndexMap

Entity index mapping table.

private byte[][]
private byte[][]
private String[][]
private String[][]
private String[][]
private String[][]
private String[][]
private int
protected XMLDTDDescription
private boolean
private int
private boolean
fMixed

Mixed.

private int[]
fNodeIndexStack

Children content model index stack.

private String[][]
private int
private DTDGrammar.QNameHashtable
fNotationIndexMap

Notation index mapping table.

private String[][]
private String[][]
private String[][]
private short[]
fOpStack

Children content model operation stack.

private int
private boolean[]
fPEntityStack

Entity stack.

private int[]
fPrevNodeIndexStack

Children content model previous node index stack.

private final QName
fQName

Temporary qualified name.

private final QName
fQName2

Temporary qualified name.

protected boolean
fReadingExternalDTD

fReadingExternalDTD

private XMLSimpleType
fSimpleType

Simple type.

private SymbolTable
fSymbolTable

Symbol table.

private static final int
INITIAL_CHUNK_COUNT

Initial chunk count (1 << (10 - CHUNK_SHIFT)).

private static final short
LIST_FLAG

List flag (0x80).

private static final short
LIST_MASK

List mask (~LIST_FLAG).

pack-priv int
pack-priv int
public static final int
TOP_LEVEL_SCOPE

Top level scope (-1).

pack-priv int

Constructor Summary

AccessConstructor and Description
public
DTDGrammar(SymbolTable symbolTable, XMLDTDDescription desc)

Default constructor.

Method Summary

Modifier and TypeMethod and Description
protected int

Returns:

handle to the newly create XMLContentSpec
addContentSpecNode
(short
the type of XMLContentSpec to create - from XMLContentSpec.CONTENTSPECNODE_*
nodeType
,
String
handle to an XMLContentSpec
nodeValue
)

Create an XMLContentSpec for a single non-leaf

protected int

Returns:

handle to the newly create XMLContentSpec
addContentSpecNode
(short
the type of XMLContentSpec to create - from XMLContentSpec.CONTENTSPECNODE_*
nodeType
,
int
handle to an XMLContentSpec
leftNodeIndex
,
int
handle to an XMLContentSpec
rightNodeIndex
)

Create an XMLContentSpec for a two child leaf

protected void
addContentSpecToElement(XMLElementDecl elementDecl)

Adds the content spec to the given element declaration.

protected int

Returns:

handle to the newly create XMLContentSpec
addUniqueLeafNode
(String
the name (Element) for the node
elementName
)

create an XMLContentSpec for a leaf

public void
any(Augmentations
Additional information that may include infoset augmentations.
augs
)

Implements org.apache.xerces.xni.XMLDTDContentModelHandler.any.

A content model of ANY.
private void
appendContentSpec(XMLContentSpec contentSpec, StringBuffer str, boolean parens, int parentContentSpecType)

public void
attributeDecl(String
The name of the element that this attribute is associated with.
elementName
,
String
The name of the attribute.
attributeName
,
String
The attribute type. This value will be one of the following: "CDATA", "ENTITY", "ENTITIES", "ENUMERATION", "ID", "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", or "NOTATION".
type
,
String[]
If the type has the value "ENUMERATION", this array holds the allowed attribute values; otherwise, this array is null.
enumeration
,
String
The attribute default type. This value will be one of the following: "#FIXED", "#IMPLIED", "#REQUIRED", or null.
defaultType
,
XMLString
The attribute default value, or null if no default value is specified.
defaultValue
,
XMLString
The attribute default value with no normalization performed, or null if no default value is specified.
nonNormalizedDefaultValue
,
Augmentations
Additional information that may include infoset augmentations.
augs
)

Implements org.apache.xerces.xni.XMLDTDHandler.attributeDecl.

An attribute declaration.
private final CMNode
buildSyntaxTree(int startNode, XMLContentSpec contentSpec)

public void
comment(XMLString
The text in the comment.
text
,
Augmentations
Additional information that may include infoset augmentations.
augs
)

Implements org.apache.xerces.xni.XMLDTDHandler.comment.

A comment.
private void
contentSpecTree(int
Content Spec index
contentSpecIndex
,
XMLContentSpec
Array of QName
contentSpec
,
DTDGrammar.ChildrenList children)

Build a vector of valid QNames from Content Spec table.

protected int
private synchronized ContentModelValidator
createChildModel(int contentSpecIndex)

When the element has a 'CHILDREN' model, this method is called to create the content model object.

protected int
protected int
protected int
protected int
public void
element(String
The name of the referenced element.
elementName
,
Augmentations
Additional information that may include infoset augmentations.
augs
)

Implements org.apache.xerces.xni.XMLDTDContentModelHandler.element.

A referenced element in a mixed or children content model.
public void
elementDecl(String
The name of the element.
name
,
String
The element content model.
contentModel
,
Augmentations
Additional information that may include infoset augmentations.
augs
)

Implements org.apache.xerces.xni.XMLDTDHandler.elementDecl.

An element declaration.
public void
empty(Augmentations
Additional information that may include infoset augmentations.
augs
)

Implements org.apache.xerces.xni.XMLDTDContentModelHandler.empty.

A content model of EMPTY.
public void
endAttlist(Augmentations
Additional information that may include infoset augmentations.
augs
)

Implements org.apache.xerces.xni.XMLDTDHandler.endAttlist.

The end of an attribute list.
public void
endConditional(Augmentations
Additional information that may include infoset augmentations.
augs
)

Implements org.apache.xerces.xni.XMLDTDHandler.endConditional.

The end of a conditional section.
public void
endContentModel(Augmentations
Additional information that may include infoset augmentations.
augs
)

Implements org.apache.xerces.xni.XMLDTDContentModelHandler.endContentModel.

The end of a content model.
public void
endDTD(Augmentations
Additional information that may include infoset augmentations.
augs
)

Implements org.apache.xerces.xni.XMLDTDHandler.endDTD.

The end of the DTD.
public void
endExternalSubset(Augmentations
Additional information that may include infoset augmentations.
augs
)

Implements org.apache.xerces.xni.XMLDTDHandler.endExternalSubset.

The end of the DTD external subset.
public void
endGroup(Augmentations
Additional information that may include infoset augmentations.
augs
)

Implements org.apache.xerces.xni.XMLDTDContentModelHandler.endGroup.

The end of a group for mixed or children content models.
public void
endParameterEntity(String
The name of the entity.
name
,
Augmentations
Additional information that may include infoset augmentations.
augs
)

Implements org.apache.xerces.xni.XMLDTDHandler.endParameterEntity.

This method notifies the end of an entity.
private void
private void
private void
private void
private void
public void
externalEntityDecl(String
The name of the entity. Parameter entity names start with '%', whereas the name of a general entity is just the entity name.
name
,
XMLResourceIdentifier
An object containing all location information pertinent to this external entity declaration.
identifier
,
Augmentations
Additional information that may include infoset augmentations.
augs
)

Implements org.apache.xerces.xni.XMLDTDHandler.externalEntityDecl.

An external entity declaration.
public boolean

Returns:

true if getAttributeDecl was able to fill in the value of attributeDecl
getAttributeDecl
(int attributeDeclIndex, XMLAttributeDecl
The values of this structure are set by this call.
attributeDecl
)

getAttributeDecl

public int
getAttributeDeclIndex(int elementDeclIndex, String attributeDeclName)

public boolean
getAttributeDeclIsExternal(int
Attribute declaration index.
attributeDeclIndex
)

Returns true if the specified attribute declaration is external.

public boolean

Returns:

true if find the requested contentSpec node, false otherwise
getContentSpec
(int contentSpecIndex, XMLContentSpec contentSpec)

getContentSpec

public String

Returns:

String
getContentSpecAsString
(int elementDeclIndex)

getContentSpecAsString

public int
getContentSpecIndex(int elementDeclIndex)

Returns the index to the content spec for the given element declaration, or -1 if the element declaration index was invalid.

public short
getContentSpecType(int elementIndex)

make separate function for getting contentSpecType of element.

public XMLDTDContentModelSource
public XMLDTDSource
protected ContentModelValidator

Returns:

its ContentModelValidator if any.
getElementContentModelValidator
(int elementDeclIndex)

getElementContentModelValidator

public boolean

Returns:

True if find the element, False otherwise.
getElementDecl
(int elementDeclIndex, XMLElementDecl
The values of this structure are set by this call.
elementDecl
)

getElementDecl

public int

Returns:

index of the elementDeclName in scope
getElementDeclIndex
(String elementDeclName)

getElementDeclIndex

public int
getElementDeclIndex(QName
qualilfied name of the element
elementDeclQName
)

Returns the element decl index.

public boolean
getElementDeclIsExternal(int
The element declaration index.
elementDeclIndex
)

Returns true if the specified element declaration is external.

pack-priv QName
getElementDeclName(int elementDeclIndex)

public boolean

Returns:

true if getEntityDecl was able to fill entityDecl with the contents of the entity with index entityDeclIndex
getEntityDecl
(int entityDeclIndex, XMLEntityDecl entityDecl)

getEntityDecl

public int

Returns:

the index of the EntityDecl
getEntityDeclIndex
(String entityDeclName)

getEntityDeclIndex

public int

Returns:

index of the first attribute for element declaration elementDeclIndex
getFirstAttributeDeclIndex
(int elementDeclIndex)

getFirstAttributeDeclIndex

public int
getFirstElementDeclIndex()

Returns the index of the first element declaration.

public XMLGrammarDescription
getGrammarDescription()

Implements org.apache.xerces.xni.grammars.Grammar.getGrammarDescription.

get the XMLGrammarDescription associated with this object
public int

Returns:

index of the next attribute of the attribute at attributeDeclIndex
getNextAttributeDeclIndex
(int attributeDeclIndex)

getNextAttributeDeclIndex

public int
getNextElementDeclIndex(int
The element declaration index.
elementDeclIndex
)

Returns the next index of the element declaration following the specified element declaration.

public boolean

Returns:

return true of getNotationDecl can fill notationDecl with information about the notation at notationDeclIndex.
getNotationDecl
(int notationDeclIndex, XMLNotationDecl notationDecl)

getNotationDecl

public int

Returns:

the index if found a notation with the name, otherwise -1.
getNotationDeclIndex
(String notationDeclName)

getNotationDeclIndex

public SymbolTable
getSymbolTable()

Returns the symbol table.

public void
ignoredCharacters(XMLString
The ignored text.
text
,
Augmentations
Additional information that may include infoset augmentations.
augs
)

Implements org.apache.xerces.xni.XMLDTDHandler.ignoredCharacters.

Characters within an IGNORE conditional section.
protected void
initializeContentModelStack()

Initialize content model stack.

public void
internalEntityDecl(String
The name of the entity. Parameter entity names start with '%', whereas the name of a general entity is just the entity name.
name
,
XMLString
The value of the entity.
text
,
XMLString
The non-normalized value of the entity. This value contains the same sequence of characters that was in the internal entity declaration, without any entity references expanded.
nonNormalizedText
,
Augmentations
Additional information that may include infoset augmentations.
augs
)

Implements org.apache.xerces.xni.XMLDTDHandler.internalEntityDecl.

An internal entity declaration.
public boolean

Returns:

true if the attribute is of type CDATA
isCDATAAttribute
(QName
The element name.
elName
,
QName
The attribute name.
atName
)

Returns whether the given attribute is of type CDATA or not

public boolean
isEntityDeclared(String name)

Implements org.apache.xerces.impl.validation.EntityState.isEntityDeclared.

Query method to check if entity with this name was declared.
public boolean
isEntityUnparsed(String name)

Implements org.apache.xerces.impl.validation.EntityState.isEntityUnparsed.

Query method to check if entity is unparsed.
pack-priv boolean
public boolean
isNamespaceAware()

Returns true if this grammar is namespace aware.

public void
notationDecl(String
The name of the notation.
name
,
XMLResourceIdentifier
An object containing all location information pertinent to this notation.
identifier
,
Augmentations
Additional information that may include infoset augmentations.
augs
)

Implements org.apache.xerces.xni.XMLDTDHandler.notationDecl.

A notation declaration
public void
occurrence(short
The occurrence count for the last element or group.
occurrence
,
Augmentations
Additional information that may include infoset augmentations.
augs
)

Implements org.apache.xerces.xni.XMLDTDContentModelHandler.occurrence.

The occurrence count for a child in a children content model or for the mixed content model group.
public void
pcdata(Augmentations
Additional information that may include infoset augmentations.
augs
)

Implements org.apache.xerces.xni.XMLDTDContentModelHandler.pcdata.

The appearance of "#PCDATA" within a group signifying a mixed content model.
private void
printAttribute(int attributeDeclIndex)

public void
printAttributes(int elementDeclIndex)

public void
public void
processingInstruction(String
The target.
target
,
XMLString
The data or null if none specified.
data
,
Augmentations
Additional information that may include infoset augmentations.
augs
)

Implements org.apache.xerces.xni.XMLDTDHandler.processingInstruction.

A processing instruction.
protected void
putElementNameMapping(QName name, int scope, int elementDeclIndex)

private static byte[][]
resize(byte[][] array, int newsize)

private static short[][]
resize(short[][] array, int newsize)

private static int[][]
resize(int[][] array, int newsize)

private static DatatypeValidator[][]
resize(DatatypeValidator[][] array, int newsize)

private static ContentModelValidator[][]
resize(ContentModelValidator[][] array, int newsize)

private static Object[][]
resize(Object[][] array, int newsize)

private static QName[][]
resize(QName[][] array, int newsize)

private static String[][]
resize(String[][] array, int newsize)

private static String[][][]
resize(String[][][] array, int newsize)

public void
separator(short
The type of children separator.
separator
,
Augmentations
Additional information that may include infoset augmentations.
augs
)

Implements org.apache.xerces.xni.XMLDTDContentModelHandler.separator.

The separator between choices or sequences of a mixed or children content model.
protected void
setAttributeDecl(int elementDeclIndex, int attributeDeclIndex, XMLAttributeDecl attributeDecl)

protected void
setContentSpec(int contentSpecIndex, XMLContentSpec contentSpec)

protected void
setContentSpecIndex(int elementDeclIndex, int contentSpecIndex)

public void
public void
protected void
setElementDecl(int elementDeclIndex, XMLElementDecl elementDecl)

protected void
setEntityDecl(int entityDeclIndex, XMLEntityDecl entityDecl)

protected void
setFirstAttributeDeclIndex(int elementDeclIndex, int newFirstAttrIndex)

protected void
setNotationDecl(int notationDeclIndex, XMLNotationDecl notationDecl)

public void
startAttlist(String
The name of the element that this attribute list is associated with.
elementName
,
Augmentations
Additional information that may include infoset augmentations.
augs
)

Implements org.apache.xerces.xni.XMLDTDHandler.startAttlist.

The start of an attribute list.
public void
startConditional(short
The type of the conditional section. This value will either be CONDITIONAL_INCLUDE or CONDITIONAL_IGNORE.
type
,
Augmentations
Additional information that may include infoset augmentations.
augs
)

Implements org.apache.xerces.xni.XMLDTDHandler.startConditional.

The start of a conditional section.
public void
startContentModel(String
The name of the element.
elementName
,
Augmentations
Additional information that may include infoset augmentations.
augs
)

Implements org.apache.xerces.xni.XMLDTDContentModelHandler.startContentModel.

The start of a content model.
public void
startDTD(XMLLocator
The document locator, or null if the document location cannot be reported during the parsing of the document DTD. However, it is strongly recommended that a locator be supplied that can at least report the base system identifier of the DTD.
locator
,
Augmentations
Additional information that may include infoset augmentations.
augs
)

Implements org.apache.xerces.xni.XMLDTDHandler.startDTD.

The start of the DTD.
public void
startExternalSubset(XMLResourceIdentifier
The resource identifier.
identifier
,
Augmentations
Additional information that may include infoset augmentations.
augs
)

Implements org.apache.xerces.xni.XMLDTDHandler.startExternalSubset.

The start of the DTD external subset.
public void
startGroup(Augmentations
Additional information that may include infoset augmentations.
augs
)

Implements org.apache.xerces.xni.XMLDTDContentModelHandler.startGroup.

A start of either a mixed or children content model.
public void
startParameterEntity(String
The name of the parameter entity.
name
,
XMLResourceIdentifier
The resource identifier.
identifier
,
String
The auto-detected IANA encoding name of the entity stream. This value will be null in those situations where the entity encoding is not auto-detected (e.g. internal parameter entities).
encoding
,
Augmentations
Additional information that may include infoset augmentations.
augs
)

Implements org.apache.xerces.xni.XMLDTDHandler.startParameterEntity.

This method notifies of the start of an entity.
public void
textDecl(String
The XML version, or null if not specified.
version
,
String
The IANA encoding name of the entity.
encoding
,
Augmentations
Additional information that may include infoset augmentations.
augs
)

Implements org.apache.xerces.xni.XMLDTDHandler.textDecl.

Notifies of the presence of a TextDecl line in an entity.
public void
unparsedEntityDecl(String
The name of the entity.
name
,
XMLResourceIdentifier
An object containing all location information pertinent to this entity.
identifier
,
String
The name of the notation.
notation
,
Augmentations
Additional information that may include infoset augmentations.
augs
)

Implements org.apache.xerces.xni.XMLDTDHandler.unparsedEntityDecl.

An unparsed entity declaration.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait