| Method from org.apache.xerces.impl.dtd.DTDGrammar Detail: |
protected int addContentSpecNode(short nodeType,
String nodeValue) {
// create content spec node
int contentSpecIndex = createContentSpec();
// set content spec node values
fContentSpec.setValues(nodeType, nodeValue, null);
setContentSpec(contentSpecIndex, fContentSpec);
// return index
return contentSpecIndex;
}
Create an XMLContentSpec for a single non-leaf |
protected int addContentSpecNode(short nodeType,
int leftNodeIndex,
int rightNodeIndex) {
// create content spec node
int contentSpecIndex = createContentSpec();
// set content spec node values
int[] leftIntArray = new int[1];
int[] rightIntArray = new int[1];
leftIntArray[0] = leftNodeIndex;
rightIntArray[0] = rightNodeIndex;
fContentSpec.setValues(nodeType, leftIntArray, rightIntArray);
setContentSpec(contentSpecIndex, fContentSpec);
// return index
return contentSpecIndex;
}
Create an XMLContentSpec for a two child leaf |
protected void addContentSpecToElement(XMLElementDecl elementDecl) {
if ((fDepth == 0 || (fDepth == 1 && elementDecl.type == XMLElementDecl.TYPE_MIXED)) &&
fNodeIndexStack != null) {
if (elementDecl.type == XMLElementDecl.TYPE_MIXED) {
int pcdata = addUniqueLeafNode(null);
if (fNodeIndexStack[0] == -1) {
fNodeIndexStack[0] = pcdata;
}
else {
fNodeIndexStack[0] = addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_CHOICE,
pcdata, fNodeIndexStack[0]);
}
}
setContentSpecIndex(fCurrentElementIndex, fNodeIndexStack[fDepth]);
}
}
Adds the content spec to the given element declaration. |
protected int addUniqueLeafNode(String elementName) {
// create content spec node
int contentSpecIndex = createContentSpec();
// set content spec node values
fContentSpec.setValues( XMLContentSpec.CONTENTSPECNODE_LEAF,
elementName, null);
setContentSpec(contentSpecIndex, fContentSpec);
// return index
return contentSpecIndex;
}
create an XMLContentSpec for a leaf |
public void any(Augmentations augs) throws XNIException {
}
|
public void attributeDecl(String elementName,
String attributeName,
String type,
String[] enumeration,
String defaultType,
XMLString defaultValue,
XMLString nonNormalizedDefaultValue,
Augmentations augs) throws XNIException {
if ( this.fElementDeclTab.containsKey( (String) elementName) ) {
//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 {
fCurrentElementIndex = createElementDecl();//create element decl
XMLElementDecl elementDecl = new XMLElementDecl();
elementDecl.name.setValues(null, elementName, elementName, null);
elementDecl.scope= -1;
//add(or set) this elementDecl to the local cache
this.fElementDeclTab.put(elementName, elementDecl );
//set internal structure
setElementDecl(fCurrentElementIndex, elementDecl );
}
//Get Grammar index to grammar array
int elementIndex = getElementDeclIndex(elementName);
//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
if (getAttributeDeclIndex(elementIndex, attributeName) != -1) {
return;
}
fCurrentAttributeIndex = createAttributeDecl();// Create current Attribute Decl
fSimpleType.clear();
if ( defaultType != null ) {
if ( defaultType.equals( "#FIXED") ) {
fSimpleType.defaultType = XMLSimpleType.DEFAULT_TYPE_FIXED;
} else if ( defaultType.equals( "#IMPLIED") ) {
fSimpleType.defaultType = XMLSimpleType.DEFAULT_TYPE_IMPLIED;
} else if ( defaultType.equals( "#REQUIRED") ) {
fSimpleType.defaultType = XMLSimpleType.DEFAULT_TYPE_REQUIRED;
}
}
if ( DEBUG ) {
System.out.println("defaultvalue = " + defaultValue.toString() );
}
fSimpleType.defaultValue = defaultValue!=null ? defaultValue.toString() : null;
fSimpleType.nonNormalizedDefaultValue = nonNormalizedDefaultValue!=null ? nonNormalizedDefaultValue.toString() : null;
fSimpleType.enumeration = enumeration;
if (type.equals("CDATA")) {
fSimpleType.type = XMLSimpleType.TYPE_CDATA;
}
else if ( type.equals("ID") ) {
fSimpleType.type = XMLSimpleType.TYPE_ID;
}
else if ( type.startsWith("IDREF") ) {
fSimpleType.type = XMLSimpleType.TYPE_IDREF;
if (type.indexOf("S") > 0) {
fSimpleType.list = true;
}
}
else if (type.equals("ENTITIES")) {
fSimpleType.type = XMLSimpleType.TYPE_ENTITY;
fSimpleType.list = true;
}
else if (type.equals("ENTITY")) {
fSimpleType.type = XMLSimpleType.TYPE_ENTITY;
}
else if (type.equals("NMTOKENS")) {
fSimpleType.type = XMLSimpleType.TYPE_NMTOKEN;
fSimpleType.list = true;
}
else if (type.equals("NMTOKEN")) {
fSimpleType.type = XMLSimpleType.TYPE_NMTOKEN;
}
else if (type.startsWith("NOTATION") ) {
fSimpleType.type = XMLSimpleType.TYPE_NOTATION;
}
else if (type.startsWith("ENUMERATION") ) {
fSimpleType.type = XMLSimpleType.TYPE_ENUMERATION;
}
else {
// REVISIT: Report error message. -Ac
System.err.println("!!! unknown attribute type "+type);
}
// 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);
fQName.setValues(null, attributeName, attributeName, null);
fAttributeDecl.setValues( fQName, fSimpleType, false );
setAttributeDecl(elementIndex, fCurrentAttributeIndex, fAttributeDecl);
int chunk = fCurrentAttributeIndex > > CHUNK_SHIFT;
int index = fCurrentAttributeIndex & CHUNK_MASK;
ensureAttributeDeclCapacity(chunk);
fAttributeDeclIsExternal[chunk][index] = (fReadingExternalDTD || fPEDepth > 0) ? 1 : 0;
}
An attribute declaration. |
public void comment(XMLString text,
Augmentations augs) throws XNIException {
}
|
protected int createAttributeDecl() {
int chunk = fAttributeDeclCount > > CHUNK_SHIFT;
int index = fAttributeDeclCount & CHUNK_MASK;
ensureAttributeDeclCapacity(chunk);
fAttributeDeclName[chunk][index] = new QName();
fAttributeDeclType[chunk][index] = -1;
fAttributeDeclDatatypeValidator[chunk][index] = null;
fAttributeDeclEnumeration[chunk][index] = null;
fAttributeDeclDefaultType[chunk][index] = XMLSimpleType.DEFAULT_TYPE_IMPLIED;
fAttributeDeclDefaultValue[chunk][index] = null;
fAttributeDeclNonNormalizedDefaultValue[chunk][index] = null;
fAttributeDeclNextAttributeDeclIndex[chunk][index] = -1;
return fAttributeDeclCount++;
}
|
protected int createContentSpec() {
int chunk = fContentSpecCount > > CHUNK_SHIFT;
int index = fContentSpecCount & CHUNK_MASK;
ensureContentSpecCapacity(chunk);
fContentSpecType[chunk][index] = -1;
fContentSpecValue[chunk][index] = null;
fContentSpecOtherValue[chunk][index] = null;
return fContentSpecCount++;
}
|
protected int createElementDecl() {
int chunk = fElementDeclCount > > CHUNK_SHIFT;
int index = fElementDeclCount & CHUNK_MASK;
ensureElementDeclCapacity(chunk);
fElementDeclName[chunk][index] = new QName();
fElementDeclType[chunk][index] = -1;
fElementDeclContentModelValidator[chunk][index] = null;
fElementDeclFirstAttributeDeclIndex[chunk][index] = -1;
fElementDeclLastAttributeDeclIndex[chunk][index] = -1;
return fElementDeclCount++;
}
|
protected int createEntityDecl() {
int chunk = fEntityCount > > CHUNK_SHIFT;
int index = fEntityCount & CHUNK_MASK;
ensureEntityDeclCapacity(chunk);
fEntityIsPE[chunk][index] = 0;
fEntityInExternal[chunk][index] = 0;
return fEntityCount++;
}
|
protected int createNotationDecl() {
int chunk = fNotationCount > > CHUNK_SHIFT;
ensureNotationDeclCapacity(chunk);
return fNotationCount++;
}
|
public void element(String elementName,
Augmentations augs) throws XNIException {
if (fMixed) {
if (fNodeIndexStack[fDepth] == -1 ) {
fNodeIndexStack[fDepth] = addUniqueLeafNode(elementName);
}
else {
fNodeIndexStack[fDepth] = addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_CHOICE,
fNodeIndexStack[fDepth],
addUniqueLeafNode(elementName));
}
}
else {
fNodeIndexStack[fDepth] = addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_LEAF, elementName);
}
}
A referenced element in a mixed or children content model. |
public void elementDecl(String name,
String contentModel,
Augmentations augs) throws XNIException {
XMLElementDecl tmpElementDecl = (XMLElementDecl) fElementDeclTab.get(name) ;
// check if it is already defined
if ( tmpElementDecl != null ) {
if (tmpElementDecl.type == -1) {
fCurrentElementIndex = getElementDeclIndex(name);
}
else {
// duplicate element, ignored.
return;
}
}
else {
fCurrentElementIndex = createElementDecl();//create element decl
}
XMLElementDecl elementDecl = new XMLElementDecl();
fQName.setValues(null, name, name, null);
elementDecl.name.setValues(fQName);
elementDecl.contentModelValidator = null;
elementDecl.scope= -1;
if (contentModel.equals("EMPTY")) {
elementDecl.type = XMLElementDecl.TYPE_EMPTY;
}
else if (contentModel.equals("ANY")) {
elementDecl.type = XMLElementDecl.TYPE_ANY;
}
else if (contentModel.startsWith("(") ) {
if (contentModel.indexOf("#PCDATA") > 0 ) {
elementDecl.type = XMLElementDecl.TYPE_MIXED;
}
else {
elementDecl.type = XMLElementDecl.TYPE_CHILDREN;
}
}
//add(or set) this elementDecl to the local cache
this.fElementDeclTab.put(name, elementDecl );
fElementDecl = elementDecl;
addContentSpecToElement(elementDecl);
if ( DEBUG ) {
System.out.println( "name = " + fElementDecl.name.localpart );
System.out.println( "Type = " + fElementDecl.type );
}
setElementDecl(fCurrentElementIndex, fElementDecl );//set internal structure
int chunk = fCurrentElementIndex > > CHUNK_SHIFT;
int index = fCurrentElementIndex & CHUNK_MASK;
ensureElementDeclCapacity(chunk);
fElementDeclIsExternal[chunk][index] = (fReadingExternalDTD || fPEDepth > 0) ? 1 : 0;
}
|
public void empty(Augmentations augs) throws XNIException {
}
A content model of EMPTY. |
public void endAttlist(Augmentations augs) throws XNIException {
}
The end of an attribute list. |
public void endConditional(Augmentations augs) throws XNIException {
}
The end of a conditional section. |
public void endContentModel(Augmentations augs) throws XNIException {
}
The end of a content model. |
public void endDTD(Augmentations augs) throws XNIException {
fIsImmutable = true;
// make sure our description contains useful stuff...
if(fGrammarDescription.getRootName() == null) {
// we don't know what the root is; so use possibleRoots...
int chunk, index = 0;
String currName = null;
Vector elements = new Vector();
for (int i=0; i < fElementDeclCount; i++) {
chunk = i > > CHUNK_SHIFT;
index = i & CHUNK_MASK;
currName = fElementDeclName[chunk][index].rawname;
elements.addElement(currName);
}
fGrammarDescription.setPossibleRoots(elements);
}
}
|
public void endExternalSubset(Augmentations augs) throws XNIException {
fReadingExternalDTD = false;
}
The end of the DTD external subset. |
public void endGroup(Augmentations augs) throws XNIException {
if (!fMixed) {
if (fPrevNodeIndexStack[fDepth] != -1) {
fNodeIndexStack[fDepth] = addContentSpecNode(fOpStack[fDepth], fPrevNodeIndexStack[fDepth], fNodeIndexStack[fDepth]);
}
int nodeIndex = fNodeIndexStack[fDepth--];
fNodeIndexStack[fDepth] = nodeIndex;
}
}
The end of a group for mixed or children content models. |
public void endParameterEntity(String name,
Augmentations augs) throws XNIException {
fPEDepth--;
fReadingExternalDTD = fPEntityStack[fPEDepth];
}
This method notifies the end of an entity. The DTD has the pseudo-name
of "[dtd]" and parameter entity names start with '%'.
Note: Since the DTD is an entity, the handler
will be notified of the end of the DTD entity by calling the
endEntity method with the entity name "[dtd]" after calling
the endDTD method. |
public void externalEntityDecl(String name,
XMLResourceIdentifier identifier,
Augmentations augs) throws XNIException {
int entityIndex = getEntityDeclIndex(name);
if( entityIndex == -1){
entityIndex = createEntityDecl();
boolean isPE = name.startsWith("%");
boolean inExternal = (fReadingExternalDTD || fPEDepth > 0);
XMLEntityDecl entityDecl = new XMLEntityDecl();
entityDecl.setValues(name, identifier.getPublicId(), identifier.getLiteralSystemId(),
identifier.getBaseSystemId(),
null, null, isPE, inExternal);
setEntityDecl(entityIndex, entityDecl);
}
}
An external entity declaration. |
public boolean getAttributeDecl(int attributeDeclIndex,
XMLAttributeDecl attributeDecl) {
if (attributeDeclIndex < 0 || attributeDeclIndex >= fAttributeDeclCount) {
return false;
}
int chunk = attributeDeclIndex > > CHUNK_SHIFT;
int index = attributeDeclIndex & CHUNK_MASK;
attributeDecl.name.setValues(fAttributeDeclName[chunk][index]);
short attributeType;
boolean isList;
if (fAttributeDeclType[chunk][index] == -1) {
attributeType = -1;
isList = false;
} else {
attributeType = (short) (fAttributeDeclType[chunk][index] & LIST_MASK);
isList = (fAttributeDeclType[chunk][index] & LIST_FLAG) != 0;
}
attributeDecl.simpleType.setValues(attributeType,fAttributeDeclName[chunk][index].localpart,
fAttributeDeclEnumeration[chunk][index],
isList, fAttributeDeclDefaultType[chunk][index],
fAttributeDeclDefaultValue[chunk][index],
fAttributeDeclNonNormalizedDefaultValue[chunk][index],
fAttributeDeclDatatypeValidator[chunk][index]);
return true;
}
|
public int getAttributeDeclIndex(int elementDeclIndex,
String attributeDeclName) {
if (elementDeclIndex == -1) {
return -1;
}
int attDefIndex = getFirstAttributeDeclIndex(elementDeclIndex);
while (attDefIndex != -1) {
getAttributeDecl(attDefIndex, fAttributeDecl);
if (fAttributeDecl.name.rawname == attributeDeclName
|| attributeDeclName.equals(fAttributeDecl.name.rawname) ) {
return attDefIndex;
}
attDefIndex = getNextAttributeDeclIndex(attDefIndex);
}
return -1;
}
|
public boolean getAttributeDeclIsExternal(int attributeDeclIndex) {
if (attributeDeclIndex < 0) {
return false;
}
int chunk = attributeDeclIndex > > CHUNK_SHIFT;
int index = attributeDeclIndex & CHUNK_MASK;
return (fAttributeDeclIsExternal[chunk][index] != 0);
}
Returns true if the specified attribute declaration is external. |
public boolean getContentSpec(int contentSpecIndex,
XMLContentSpec contentSpec) {
if (contentSpecIndex < 0 || contentSpecIndex >= fContentSpecCount )
return false;
int chunk = contentSpecIndex > > CHUNK_SHIFT;
int index = contentSpecIndex & CHUNK_MASK;
contentSpec.type = fContentSpecType[chunk][index];
contentSpec.value = fContentSpecValue[chunk][index];
contentSpec.otherValue = fContentSpecOtherValue[chunk][index];
return true;
}
|
public String getContentSpecAsString(int elementDeclIndex) {
if (elementDeclIndex < 0 || elementDeclIndex >= fElementDeclCount) {
return null;
}
int chunk = elementDeclIndex > > CHUNK_SHIFT;
int index = elementDeclIndex & CHUNK_MASK;
int contentSpecIndex = fElementDeclContentSpecIndex[chunk][index];
// lookup content spec node
XMLContentSpec contentSpec = new XMLContentSpec();
if (getContentSpec(contentSpecIndex, contentSpec)) {
// build string
StringBuffer str = new StringBuffer();
int parentContentSpecType = contentSpec.type & 0x0f;
int nextContentSpec;
switch (parentContentSpecType) {
case XMLContentSpec.CONTENTSPECNODE_LEAF: {
str.append('(");
if (contentSpec.value == null && contentSpec.otherValue == null) {
str.append("#PCDATA");
}
else {
str.append(contentSpec.value);
}
str.append(')");
break;
}
case XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE: {
getContentSpec(((int[])contentSpec.value)[0], contentSpec);
nextContentSpec = contentSpec.type;
if (nextContentSpec == XMLContentSpec.CONTENTSPECNODE_LEAF) {
str.append('(");
str.append(contentSpec.value);
str.append(')");
} else if( nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE ||
nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE ||
nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE ) {
str.append('(" );
appendContentSpec(contentSpec, str,
true, parentContentSpecType );
str.append(')");
} else {
appendContentSpec(contentSpec, str,
true, parentContentSpecType );
}
str.append('?");
break;
}
case XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE: {
getContentSpec(((int[])contentSpec.value)[0], contentSpec);
nextContentSpec = contentSpec.type;
if ( nextContentSpec == XMLContentSpec.CONTENTSPECNODE_LEAF) {
str.append('(");
if (contentSpec.value == null && contentSpec.otherValue == null) {
str.append("#PCDATA");
}
else if (contentSpec.otherValue != null) {
str.append("##any:uri=").append(contentSpec.otherValue);
}
else if (contentSpec.value == null) {
str.append("##any");
}
else {
appendContentSpec(contentSpec, str,
true, parentContentSpecType );
}
str.append(')");
} else if( nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE ||
nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE ||
nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE ) {
str.append('(" );
appendContentSpec(contentSpec, str,
true, parentContentSpecType );
str.append(')");
} else {
appendContentSpec(contentSpec, str,
true, parentContentSpecType );
}
str.append('*");
break;
}
case XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE: {
getContentSpec(((int[])contentSpec.value)[0], contentSpec);
nextContentSpec = contentSpec.type;
if ( nextContentSpec == XMLContentSpec.CONTENTSPECNODE_LEAF) {
str.append('(");
if (contentSpec.value == null && contentSpec.otherValue == null) {
str.append("#PCDATA");
}
else if (contentSpec.otherValue != null) {
str.append("##any:uri=").append(contentSpec.otherValue);
}
else if (contentSpec.value == null) {
str.append("##any");
}
else {
str.append(contentSpec.value);
}
str.append(')");
} else if( nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE ||
nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE ||
nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE ) {
str.append('(" );
appendContentSpec(contentSpec, str,
true, parentContentSpecType );
str.append(')");
} else {
appendContentSpec(contentSpec, str,
true, parentContentSpecType);
}
str.append('+");
break;
}
case XMLContentSpec.CONTENTSPECNODE_CHOICE:
case XMLContentSpec.CONTENTSPECNODE_SEQ: {
appendContentSpec(contentSpec, str,
true, parentContentSpecType );
break;
}
case XMLContentSpec.CONTENTSPECNODE_ANY: {
str.append("##any");
if (contentSpec.otherValue != null) {
str.append(":uri=");
str.append(contentSpec.otherValue);
}
break;
}
case XMLContentSpec.CONTENTSPECNODE_ANY_OTHER: {
str.append("##other:uri=");
str.append(contentSpec.otherValue);
break;
}
case XMLContentSpec.CONTENTSPECNODE_ANY_LOCAL: {
str.append("##local");
break;
}
default: {
str.append("???");
}
} // switch type
// return string
return str.toString();
}
// not found
return null;
}
|
public int getContentSpecIndex(int elementDeclIndex) {
if (elementDeclIndex < 0 || elementDeclIndex >= fElementDeclCount) {
return -1;
}
final int chunk = elementDeclIndex > > CHUNK_SHIFT;
final int index = elementDeclIndex & CHUNK_MASK;
return fElementDeclContentSpecIndex[chunk][index];
}
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) {
if (elementIndex < 0 || elementIndex >= fElementDeclCount) {
return -1 ;
}
int chunk = elementIndex > > CHUNK_SHIFT;
int index = elementIndex & CHUNK_MASK;
if(fElementDeclType[chunk][index] == -1){
return -1 ;
}
else{
return (short) (fElementDeclType[chunk][index] & LIST_MASK);
}
}
make separate function for getting contentSpecType of element.
we can avoid setting of the element values. |
public XMLDTDContentModelSource getDTDContentModelSource() {
return fDTDContentModelSource;
}
|
public XMLDTDSource getDTDSource() {
return fDTDSource;
}
|
protected ContentModelValidator getElementContentModelValidator(int elementDeclIndex) {
int chunk = elementDeclIndex > > CHUNK_SHIFT;
int index = elementDeclIndex & CHUNK_MASK;
ContentModelValidator contentModel = fElementDeclContentModelValidator[chunk][index];
// If we have one, just return that. Otherwise, gotta create one
if (contentModel != null) {
return contentModel;
}
int contentType = fElementDeclType[chunk][index];
if (contentType == XMLElementDecl.TYPE_SIMPLE) {
return null;
}
// Get the type of content this element has
int contentSpecIndex = fElementDeclContentSpecIndex[chunk][index];
/***
if ( contentSpecIndex == -1 )
return null;
/***/
XMLContentSpec contentSpec = new XMLContentSpec();
getContentSpec( contentSpecIndex, contentSpec );
// And create the content model according to the spec type
if ( contentType == XMLElementDecl.TYPE_MIXED ) {
//
// Just create a mixel content model object. This type of
// content model is optimized for mixed content validation.
//
ChildrenList children = new ChildrenList();
contentSpecTree(contentSpecIndex, contentSpec, children);
contentModel = new MixedContentModel(children.qname,
children.type,
0, children.length,
false);
} else if (contentType == XMLElementDecl.TYPE_CHILDREN) {
// This method will create an optimal model for the complexity
// of the element's defined model. If its simple, it will create
// a SimpleContentModel object. If its a simple list, it will
// create a SimpleListContentModel object. If its complex, it
// will create a DFAContentModel object.
//
contentModel = createChildModel(contentSpecIndex);
} else {
throw new RuntimeException("Unknown content type for a element decl "
+ "in getElementContentModelValidator() in AbstractDTDGrammar class");
}
// Add the new model to the content model for this element
fElementDeclContentModelValidator[chunk][index] = contentModel;
return contentModel;
}
getElementContentModelValidator |
public boolean getElementDecl(int elementDeclIndex,
XMLElementDecl elementDecl) {
if (elementDeclIndex < 0 || elementDeclIndex >= fElementDeclCount) {
return false;
}
int chunk = elementDeclIndex > > CHUNK_SHIFT;
int index = elementDeclIndex & CHUNK_MASK;
elementDecl.name.setValues(fElementDeclName[chunk][index]);
if (fElementDeclType[chunk][index] == -1) {
elementDecl.type = -1;
elementDecl.simpleType.list = false;
} else {
elementDecl.type = (short) (fElementDeclType[chunk][index] & LIST_MASK);
elementDecl.simpleType.list = (fElementDeclType[chunk][index] & LIST_FLAG) != 0;
}
/* Validators are null until we add that code */
if (elementDecl.type == XMLElementDecl.TYPE_CHILDREN || elementDecl.type == XMLElementDecl.TYPE_MIXED) {
elementDecl.contentModelValidator = getElementContentModelValidator(elementDeclIndex);
}
elementDecl.simpleType.datatypeValidator = null;
elementDecl.simpleType.defaultType = -1;
elementDecl.simpleType.defaultValue = null;
return true;
}
|
public int getElementDeclIndex(String elementDeclName) {
int mapping = fElementIndexMap.get(elementDeclName);
//System.out.println("getElementDeclIndex("+elementDeclName+") - > "+mapping);
return mapping;
}
|
public int getElementDeclIndex(QName elementDeclQName) {
return getElementDeclIndex(elementDeclQName.rawname);
}
Returns the element decl index. |
public boolean getElementDeclIsExternal(int elementDeclIndex) {
if (elementDeclIndex < 0) {
return false;
}
int chunk = elementDeclIndex > > CHUNK_SHIFT;
int index = elementDeclIndex & CHUNK_MASK;
return (fElementDeclIsExternal[chunk][index] != 0);
}
Returns true if the specified element declaration is external. |
QName getElementDeclName(int elementDeclIndex) {
if (elementDeclIndex < 0 || elementDeclIndex >= fElementDeclCount) {
return null;
}
int chunk = elementDeclIndex > > CHUNK_SHIFT;
int index = elementDeclIndex & CHUNK_MASK;
return fElementDeclName[chunk][index];
}
|
public boolean getEntityDecl(int entityDeclIndex,
XMLEntityDecl entityDecl) {
if (entityDeclIndex < 0 || entityDeclIndex >= fEntityCount) {
return false;
}
int chunk = entityDeclIndex > > CHUNK_SHIFT;
int index = entityDeclIndex & CHUNK_MASK;
entityDecl.setValues(fEntityName[chunk][index],
fEntityPublicId[chunk][index],
fEntitySystemId[chunk][index],
fEntityBaseSystemId[chunk][index],
fEntityNotation[chunk][index],
fEntityValue[chunk][index],
fEntityIsPE[chunk][index] == 0 ? false : true ,
fEntityInExternal[chunk][index] == 0 ? false : true );
return true;
}
|
public int getEntityDeclIndex(String entityDeclName) {
if (entityDeclName == null) {
return -1;
}
return fEntityIndexMap.get(entityDeclName);
}
|
public int getFirstAttributeDeclIndex(int elementDeclIndex) {
int chunk = elementDeclIndex > > CHUNK_SHIFT;
int index = elementDeclIndex & CHUNK_MASK;
return fElementDeclFirstAttributeDeclIndex[chunk][index];
}
getFirstAttributeDeclIndex |
public int getFirstElementDeclIndex() {
return fElementDeclCount >= 0 ? 0 : -1;
}
Returns the index of the first element declaration. This index
is then used to query more information about the element declaration. |
public XMLGrammarDescription getGrammarDescription() {
return fGrammarDescription;
}
|
public int getNextAttributeDeclIndex(int attributeDeclIndex) {
int chunk = attributeDeclIndex > > CHUNK_SHIFT;
int index = attributeDeclIndex & CHUNK_MASK;
return fAttributeDeclNextAttributeDeclIndex[chunk][index];
}
getNextAttributeDeclIndex |
public int getNextElementDeclIndex(int elementDeclIndex) {
return elementDeclIndex < fElementDeclCount - 1
? elementDeclIndex + 1 : -1;
}
Returns the next index of the element declaration following the
specified element declaration. |
public boolean getNotationDecl(int notationDeclIndex,
XMLNotationDecl notationDecl) {
if (notationDeclIndex < 0 || notationDeclIndex >= fNotationCount) {
return false;
}
int chunk = notationDeclIndex > > CHUNK_SHIFT;
int index = notationDeclIndex & CHUNK_MASK;
notationDecl.setValues(fNotationName[chunk][index],
fNotationPublicId[chunk][index],
fNotationSystemId[chunk][index],
fNotationBaseSystemId[chunk][index]);
return true;
}
|
public int getNotationDeclIndex(String notationDeclName) {
if (notationDeclName == null) {
return -1;
}
return fNotationIndexMap.get(notationDeclName);
}
|
public SymbolTable getSymbolTable() {
return fSymbolTable;
}
Returns the symbol table. |
public void ignoredCharacters(XMLString text,
Augmentations augs) throws XNIException {
}
Characters within an IGNORE conditional section. |
protected void initializeContentModelStack() {
if (fOpStack == null) {
fOpStack = new short[8];
fNodeIndexStack = new int[8];
fPrevNodeIndexStack = new int[8];
} else if (fDepth == fOpStack.length) {
short[] newStack = new short[fDepth * 2];
System.arraycopy(fOpStack, 0, newStack, 0, fDepth);
fOpStack = newStack;
int[] newIntStack = new int[fDepth * 2];
System.arraycopy(fNodeIndexStack, 0, newIntStack, 0, fDepth);
fNodeIndexStack = newIntStack;
newIntStack = new int[fDepth * 2];
System.arraycopy(fPrevNodeIndexStack, 0, newIntStack, 0, fDepth);
fPrevNodeIndexStack = newIntStack;
}
fOpStack[fDepth] = -1;
fNodeIndexStack[fDepth] = -1;
fPrevNodeIndexStack[fDepth] = -1;
}
Initialize content model stack. |
public void internalEntityDecl(String name,
XMLString text,
XMLString nonNormalizedText,
Augmentations augs) throws XNIException {
int entityIndex = getEntityDeclIndex(name);
if( entityIndex == -1){
entityIndex = createEntityDecl();
boolean isPE = name.startsWith("%");
boolean inExternal = (fReadingExternalDTD || fPEDepth > 0);
XMLEntityDecl entityDecl = new XMLEntityDecl();
entityDecl.setValues(name,null,null, null, null,
text.toString(), isPE, inExternal);
setEntityDecl(entityIndex, entityDecl);
}
}
An internal entity declaration. |
public boolean isCDATAAttribute(QName elName,
QName atName) {
int elDeclIdx = getElementDeclIndex(elName);
if (getAttributeDecl(elDeclIdx, fAttributeDecl)
&& fAttributeDecl.simpleType.type != XMLSimpleType.TYPE_CDATA){
return false;
}
return true;
}
Returns whether the given attribute is of type CDATA or not |
public boolean isEntityDeclared(String name) {
return (getEntityDeclIndex(name)!=-1)?true:false;
}
|
public boolean isEntityUnparsed(String name) {
int entityIndex = getEntityDeclIndex(name);
if (entityIndex >-1) {
int chunk = entityIndex > > CHUNK_SHIFT;
int index = entityIndex & CHUNK_MASK;
//for unparsed entity notation!=null
return (fEntityNotation[chunk][index]!=null)?true:false;
}
return false;
}
|
boolean isImmutable() {
return fIsImmutable;
}
|
public boolean isNamespaceAware() {
return false;
}
Returns true if this grammar is namespace aware. |
public void notationDecl(String name,
XMLResourceIdentifier identifier,
Augmentations augs) throws XNIException {
XMLNotationDecl notationDecl = new XMLNotationDecl();
notationDecl.setValues(name,identifier.getPublicId(),identifier.getLiteralSystemId(),
identifier.getBaseSystemId());
int notationIndex = getNotationDeclIndex(name);
if (notationIndex == -1) {
notationIndex = createNotationDecl();
setNotationDecl(notationIndex, notationDecl);
}
}
|
public void occurrence(short occurrence,
Augmentations augs) throws XNIException {
if (!fMixed) {
if (occurrence == XMLDTDContentModelHandler.OCCURS_ZERO_OR_ONE ) {
fNodeIndexStack[fDepth] = addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE, fNodeIndexStack[fDepth], -1);
} else if ( occurrence == XMLDTDContentModelHandler.OCCURS_ZERO_OR_MORE ) {
fNodeIndexStack[fDepth] = addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE, fNodeIndexStack[fDepth], -1 );
} else if ( occurrence == XMLDTDContentModelHandler.OCCURS_ONE_OR_MORE) {
fNodeIndexStack[fDepth] = addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE, fNodeIndexStack[fDepth], -1 );
}
}
}
The occurrence count for a child in a children content model or
for the mixed content model group. |
public void pcdata(Augmentations augs) throws XNIException {
fMixed = true;
}
The appearance of "#PCDATA" within a group signifying a
mixed content model. This method will be the first called
following the content model's startGroup(). |
public void printAttributes(int elementDeclIndex) {
int attributeDeclIndex = getFirstAttributeDeclIndex(elementDeclIndex);
System.out.print(elementDeclIndex);
System.out.print(" [");
while (attributeDeclIndex != -1) {
System.out.print(' ");
System.out.print(attributeDeclIndex);
printAttribute(attributeDeclIndex);
attributeDeclIndex = getNextAttributeDeclIndex(attributeDeclIndex);
if (attributeDeclIndex != -1) {
System.out.print(",");
}
}
System.out.println(" ]");
}
|
public void printElements() {
int elementDeclIndex = 0;
XMLElementDecl elementDecl = new XMLElementDecl();
while (getElementDecl(elementDeclIndex++, elementDecl)) {
System.out.println("element decl: "+elementDecl.name+
", "+ elementDecl.name.rawname );
// ", "+ elementDecl.contentModelValidator.toString());
}
}
|
public void processingInstruction(String target,
XMLString data,
Augmentations augs) throws XNIException {
}
A processing instruction. Processing instructions consist of a
target name and, optionally, text data. The data is only meaningful
to the application.
Typically, a processing instruction's data will contain a series
of pseudo-attributes. These pseudo-attributes follow the form of
element attributes but are not parsed or presented
to the application as anything other than text. The application is
responsible for parsing the data. |
protected void putElementNameMapping(QName name,
int scope,
int elementDeclIndex) {
}
|
public void separator(short separator,
Augmentations augs) throws XNIException {
if (!fMixed) {
if (fOpStack[fDepth] != XMLContentSpec.CONTENTSPECNODE_SEQ && separator == XMLDTDContentModelHandler.SEPARATOR_CHOICE ) {
if (fPrevNodeIndexStack[fDepth] != -1) {
fNodeIndexStack[fDepth] = addContentSpecNode(fOpStack[fDepth], fPrevNodeIndexStack[fDepth], fNodeIndexStack[fDepth]);
}
fPrevNodeIndexStack[fDepth] = fNodeIndexStack[fDepth];
fOpStack[fDepth] = XMLContentSpec.CONTENTSPECNODE_CHOICE;
} else if (fOpStack[fDepth] != XMLContentSpec.CONTENTSPECNODE_CHOICE && separator == XMLDTDContentModelHandler.SEPARATOR_SEQUENCE) {
if (fPrevNodeIndexStack[fDepth] != -1) {
fNodeIndexStack[fDepth] = addContentSpecNode(fOpStack[fDepth], fPrevNodeIndexStack[fDepth], fNodeIndexStack[fDepth]);
}
fPrevNodeIndexStack[fDepth] = fNodeIndexStack[fDepth];
fOpStack[fDepth] = XMLContentSpec.CONTENTSPECNODE_SEQ;
}
}
}
The separator between choices or sequences of a mixed or children
content model. |
protected void setAttributeDecl(int elementDeclIndex,
int attributeDeclIndex,
XMLAttributeDecl attributeDecl) {
int attrChunk = attributeDeclIndex > > CHUNK_SHIFT;
int attrIndex = attributeDeclIndex & CHUNK_MASK;
fAttributeDeclName[attrChunk][attrIndex].setValues(attributeDecl.name);
fAttributeDeclType[attrChunk][attrIndex] = attributeDecl.simpleType.type;
if (attributeDecl.simpleType.list) {
fAttributeDeclType[attrChunk][attrIndex] |= LIST_FLAG;
}
fAttributeDeclEnumeration[attrChunk][attrIndex] = attributeDecl.simpleType.enumeration;
fAttributeDeclDefaultType[attrChunk][attrIndex] = attributeDecl.simpleType.defaultType;
fAttributeDeclDatatypeValidator[attrChunk][attrIndex] = attributeDecl.simpleType.datatypeValidator;
fAttributeDeclDefaultValue[attrChunk][attrIndex] = attributeDecl.simpleType.defaultValue;
fAttributeDeclNonNormalizedDefaultValue[attrChunk][attrIndex] = attributeDecl.simpleType.nonNormalizedDefaultValue;
int elemChunk = elementDeclIndex > > CHUNK_SHIFT;
int elemIndex = elementDeclIndex & CHUNK_MASK;
int index = fElementDeclFirstAttributeDeclIndex[elemChunk][elemIndex];
while (index != -1) {
if (index == attributeDeclIndex) {
break;
}
attrChunk = index > > CHUNK_SHIFT;
attrIndex = index & CHUNK_MASK;
index = fAttributeDeclNextAttributeDeclIndex[attrChunk][attrIndex];
}
if (index == -1) {
if (fElementDeclFirstAttributeDeclIndex[elemChunk][elemIndex] == -1) {
fElementDeclFirstAttributeDeclIndex[elemChunk][elemIndex] = attributeDeclIndex;
} else {
index = fElementDeclLastAttributeDeclIndex[elemChunk][elemIndex];
attrChunk = index > > CHUNK_SHIFT;
attrIndex = index & CHUNK_MASK;
fAttributeDeclNextAttributeDeclIndex[attrChunk][attrIndex] = attributeDeclIndex;
}
fElementDeclLastAttributeDeclIndex[elemChunk][elemIndex] = attributeDeclIndex;
}
}
|
protected void setContentSpec(int contentSpecIndex,
XMLContentSpec contentSpec) {
int chunk = contentSpecIndex > > CHUNK_SHIFT;
int index = contentSpecIndex & CHUNK_MASK;
fContentSpecType[chunk][index] = contentSpec.type;
fContentSpecValue[chunk][index] = contentSpec.value;
fContentSpecOtherValue[chunk][index] = contentSpec.otherValue;
}
|
protected void setContentSpecIndex(int elementDeclIndex,
int contentSpecIndex) {
if (elementDeclIndex < 0 || elementDeclIndex >= fElementDeclCount) {
return;
}
int chunk = elementDeclIndex > > CHUNK_SHIFT;
int index = elementDeclIndex & CHUNK_MASK;
fElementDeclContentSpecIndex[chunk][index] = contentSpecIndex;
}
|
public void setDTDContentModelSource(XMLDTDContentModelSource source) {
fDTDContentModelSource = source;
}
|
public void setDTDSource(XMLDTDSource source) {
fDTDSource = source;
}
|
protected void setElementDecl(int elementDeclIndex,
XMLElementDecl elementDecl) {
if (elementDeclIndex < 0 || elementDeclIndex >= fElementDeclCount) {
return;
}
int chunk = elementDeclIndex > > CHUNK_SHIFT;
int index = elementDeclIndex & CHUNK_MASK;
fElementDeclName[chunk][index].setValues(elementDecl.name);
fElementDeclType[chunk][index] = elementDecl.type;
fElementDeclContentModelValidator[chunk][index] = elementDecl.contentModelValidator;
if (elementDecl.simpleType.list == true ) {
fElementDeclType[chunk][index] |= LIST_FLAG;
}
fElementIndexMap.put(elementDecl.name.rawname, elementDeclIndex);
}
|
protected void setEntityDecl(int entityDeclIndex,
XMLEntityDecl entityDecl) {
int chunk = entityDeclIndex > > CHUNK_SHIFT;
int index = entityDeclIndex & CHUNK_MASK;
fEntityName[chunk][index] = entityDecl.name;
fEntityValue[chunk][index] = entityDecl.value;
fEntityPublicId[chunk][index] = entityDecl.publicId;
fEntitySystemId[chunk][index] = entityDecl.systemId;
fEntityBaseSystemId[chunk][index] = entityDecl.baseSystemId;
fEntityNotation[chunk][index] = entityDecl.notation;
fEntityIsPE[chunk][index] = entityDecl.isPE ? (byte)1 : (byte)0;
fEntityInExternal[chunk][index] = entityDecl.inExternal ? (byte)1 : (byte)0;
fEntityIndexMap.put(entityDecl.name, entityDeclIndex);
}
|
protected void setFirstAttributeDeclIndex(int elementDeclIndex,
int newFirstAttrIndex) {
if (elementDeclIndex < 0 || elementDeclIndex >= fElementDeclCount) {
return;
}
int chunk = elementDeclIndex > > CHUNK_SHIFT;
int index = elementDeclIndex & CHUNK_MASK;
fElementDeclFirstAttributeDeclIndex[chunk][index] = newFirstAttrIndex;
}
|
protected void setNotationDecl(int notationDeclIndex,
XMLNotationDecl notationDecl) {
int chunk = notationDeclIndex > > CHUNK_SHIFT;
int index = notationDeclIndex & CHUNK_MASK;
fNotationName[chunk][index] = notationDecl.name;
fNotationPublicId[chunk][index] = notationDecl.publicId;
fNotationSystemId[chunk][index] = notationDecl.systemId;
fNotationBaseSystemId[chunk][index] = notationDecl.baseSystemId;
fNotationIndexMap.put(notationDecl.name, notationDeclIndex);
}
|
public void startAttlist(String elementName,
Augmentations augs) throws XNIException {
}
The start of an attribute list. |
public void startConditional(short type,
Augmentations augs) throws XNIException {
}
The start of a conditional section. |
public void startContentModel(String elementName,
Augmentations augs) throws XNIException {
XMLElementDecl elementDecl = (XMLElementDecl) this.fElementDeclTab.get( elementName);
if ( elementDecl != null ) {
fElementDecl = elementDecl;
}
fDepth = 0;
initializeContentModelStack();
}
The start of a content model. Depending on the type of the content
model, specific methods may be called between the call to the
startContentModel method and the call to the endContentModel method. |
public void startDTD(XMLLocator locator,
Augmentations augs) throws XNIException {
//Initialize stack
fOpStack = null;
fNodeIndexStack = null;
fPrevNodeIndexStack = null;
}
|
public void startExternalSubset(XMLResourceIdentifier identifier,
Augmentations augs) throws XNIException {
fReadingExternalDTD = true;
}
The start of the DTD external subset. |
public void startGroup(Augmentations augs) throws XNIException {
fDepth++;
initializeContentModelStack();
fMixed = false;
}
A start of either a mixed or children content model. A mixed
content model will immediately be followed by a call to the
pcdata() method. A children content model will
contain additional groups and/or elements. |
public void startParameterEntity(String name,
XMLResourceIdentifier identifier,
String encoding,
Augmentations augs) throws XNIException {
// keep track of this entity before fEntityDepth is increased
if (fPEDepth == fPEntityStack.length) {
boolean[] entityarray = new boolean[fPEntityStack.length * 2];
System.arraycopy(fPEntityStack, 0, entityarray, 0, fPEntityStack.length);
fPEntityStack = entityarray;
}
fPEntityStack[fPEDepth] = fReadingExternalDTD;
fPEDepth++;
}
This method notifies of the start of an entity. The DTD has the
pseudo-name of "[dtd]" and parameter entity names start with '%'.
Note: Since the DTD is an entity, the handler
will be notified of the start of the DTD entity by calling the
startParameterEntity method with the entity name "[dtd]" before calling
the startDTD method. |
public void textDecl(String version,
String encoding,
Augmentations augs) throws XNIException {
}
|
public void unparsedEntityDecl(String name,
XMLResourceIdentifier identifier,
String notation,
Augmentations augs) throws XNIException {
XMLEntityDecl entityDecl = new XMLEntityDecl();
boolean isPE = name.startsWith("%");
boolean inExternal = (fReadingExternalDTD || fPEDepth > 0);
entityDecl.setValues(name,identifier.getPublicId(),identifier.getLiteralSystemId(),
identifier.getBaseSystemId(), notation,
null, isPE, inExternal);
int entityIndex = getEntityDeclIndex(name);
if (entityIndex == -1) {
entityIndex = createEntityDecl();
setEntityDecl(entityIndex, entityDecl);
}
}
An unparsed entity declaration. |