You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by an...@apache.org on 2001/07/18 05:36:25 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/impl/validation/grammars DTDGrammar.java
andyc 01/07/17 20:36:25
Modified: java/src/org/apache/xerces/impl/validation/grammars Tag:
xerces_j_2 DTDGrammar.java
Log:
Fixed bug in DTD grammar that was creating mixed content models
incorrectly. This code really needs to be re-written.
Revision Changes Path
No revision
No revision
1.1.2.43 +176 -6 xml-xerces/java/src/org/apache/xerces/impl/validation/grammars/Attic/DTDGrammar.java
Index: DTDGrammar.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/validation/grammars/Attic/DTDGrammar.java,v
retrieving revision 1.1.2.42
retrieving revision 1.1.2.43
diff -u -r1.1.2.42 -r1.1.2.43
--- DTDGrammar.java 2001/07/09 11:03:32 1.1.2.42
+++ DTDGrammar.java 2001/07/18 03:36:25 1.1.2.43
@@ -93,7 +93,7 @@
* @author Jeffrey Rodriguez, IBM
* @author Andy Clark, IBM
*
- * @version $Id: DTDGrammar.java,v 1.1.2.42 2001/07/09 11:03:32 andyc Exp $
+ * @version $Id: DTDGrammar.java,v 1.1.2.43 2001/07/18 03:36:25 andyc Exp $
*/
public class DTDGrammar
extends Grammar
@@ -141,6 +141,9 @@
/** Mixed. */
private boolean fMixed;
+ /** Children. */
+ private boolean fChildren;
+
/** Element declaration. */
private XMLElementDecl fElementDecl = new XMLElementDecl();
@@ -207,6 +210,8 @@
int prevNodeIndex = -1;
int nodeIndex = -1;
+ private String fElementName;
+
//
// Constructors
//
@@ -352,6 +357,7 @@
*/
public void elementDecl(String name, String contentModel)
throws XNIException {
+ /***
XMLElementDecl tmpElementDecl = (XMLElementDecl) fElementDeclTab.get(name) ;
@@ -423,6 +429,7 @@
int index = fCurrentElementIndex & CHUNK_MASK;
ensureElementDeclCapacity(chunk);
fElementDeclIsExternal[chunk][index] = fReadingExternalDTD? 1 : 0;
+ /***/
} // elementDecl(String,String)
@@ -787,40 +794,135 @@
}
fDepth = 0;
initializeContentModelStack();
+ fElementName = elementName;
+ fMixed = false;
+ fChildren = false;
} // startContentModel(String)
/** ANY. */
- public void any() throws XNIException {}
+ public void any() throws XNIException {
+ //System.out.println("<!ELEMENT "+fElementName+" ANY>");
+
+ XMLElementDecl tmpElementDecl =
+ (XMLElementDecl) fElementDeclTab.get(fElementName) ;
+
+ // check if it is already defined
+ if ( tmpElementDecl != null ) {
+ if (tmpElementDecl.type == -1) {
+ fCurrentElementIndex = getElementDeclIndex(fElementName, -1);
+ }
+ else {
+ // duplicate element, ignored.
+ return;
+ }
+ }
+ else {
+ fCurrentElementIndex = createElementDecl();//create element decl
+ }
+
+ XMLElementDecl elementDecl = new XMLElementDecl();
+ elementDecl.name.setValues(null, fElementName, fElementName, null);
+
+ elementDecl.contentModelValidator = null;
+ elementDecl.scope= -1;
+ elementDecl.type = XMLElementDecl.TYPE_ANY;
+
+ //add(or set) this elementDecl to the local cache
+ this.fElementDeclTab.put(fElementName, elementDecl );
+ fElementDecl = 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? 1 : 0;
+
+ } // any()
+
/** EMPTY. */
- public void empty() throws XNIException {}
+ public void empty() throws XNIException {
+ //System.out.println("<!ELEMENT "+fElementName+" EMPTY>");
+
+ XMLElementDecl tmpElementDecl =
+ (XMLElementDecl) fElementDeclTab.get(fElementName) ;
+
+ // check if it is already defined
+ if ( tmpElementDecl != null ) {
+ if (tmpElementDecl.type == -1) {
+ fCurrentElementIndex = getElementDeclIndex(fElementName, -1);
+ }
+ else {
+ // duplicate element, ignored.
+ return;
+ }
+ }
+ else {
+ fCurrentElementIndex = createElementDecl();//create element decl
+ }
+
+ XMLElementDecl elementDecl = new XMLElementDecl();
+ elementDecl.name.setValues(null, fElementName, fElementName, null);
+
+ elementDecl.contentModelValidator = null;
+ elementDecl.scope= -1;
+ elementDecl.type = XMLElementDecl.TYPE_EMPTY;
+
+ //add(or set) this elementDecl to the local cache
+ this.fElementDeclTab.put(fElementName, elementDecl );
+
+ fElementDecl = 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? 1 : 0;
+
+ } // empty()
+
/** Start group. */
public void startGroup() throws XNIException {
fDepth++;
initializeContentModelStack();
- fMixed = false;
} // startGroup()
/** #PCDATA. */
public void pcdata() throws XNIException {
fMixed = true;
+ fNodeIndexStack[fDepth] = addUniqueLeafNode(null);
} // pcdata()
/** Element. */
public void element(String elementName) throws XNIException {
if (fMixed) {
+ /***
if (fNodeIndexStack[fDepth] == -1 ) {
fNodeIndexStack[fDepth] = addUniqueLeafNode(elementName);
}
else {
+ /***/
fNodeIndexStack[fDepth] = addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_CHOICE,
fNodeIndexStack[fDepth],
addUniqueLeafNode(elementName));
- }
+ //}
}
else {
+ fChildren = true;
fNodeIndexStack[fDepth] = addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_LEAF, elementName);
}
} // element(String)
@@ -876,7 +978,75 @@
/** End content model. */
public void endContentModel() throws XNIException {
- // no-op
+
+ if (fMixed || fChildren) {
+ XMLElementDecl tmpElementDecl =
+ (XMLElementDecl) fElementDeclTab.get(fElementName) ;
+
+ // check if it is already defined
+ if ( tmpElementDecl != null ) {
+ if (tmpElementDecl.type == -1) {
+ fCurrentElementIndex = getElementDeclIndex(fElementName, -1);
+ }
+ else {
+ // duplicate element, ignored.
+ return;
+ }
+ }
+ else {
+ fCurrentElementIndex = createElementDecl();//create element decl
+ }
+
+ XMLElementDecl elementDecl = new XMLElementDecl();
+
+ elementDecl.name.setValues(null, fElementName, fElementName, null);
+
+ elementDecl.contentModelValidator = null;
+ elementDecl.scope= -1;
+ if (fMixed) {
+ elementDecl.type = XMLElementDecl.TYPE_MIXED;
+ }
+ else if (fChildren) {
+ elementDecl.type = XMLElementDecl.TYPE_CHILDREN;
+ }
+
+ //add(or set) this elementDecl to the local cache
+ this.fElementDeclTab.put(fElementName, elementDecl );
+
+ fElementDecl = elementDecl;
+
+ if (fDepth >= 0 && 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]);
+ /***
+ fNodeIndexStack[0] = addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE,
+ fNodeIndexStack[0], -1);
+ /***/
+ }
+ }
+ setContentSpecIndex(fCurrentElementIndex, fNodeIndexStack[fDepth]);
+ }
+
+ if ( DEBUG ) {
+ System.out.println( "name = " + fElementDecl.name.localpart );
+ System.out.println( "Type = " + fElementDecl.type );
+ }
+
+ setElementDecl(fCurrentElementIndex, fElementDecl );//set internal structure
+ //System.out.println("<!ELEMENT "+fElementDecl.name.rawname+" "+getContentSpecAsString(fCurrentElementIndex)+">");
+
+ int chunk = fCurrentElementIndex >> CHUNK_SHIFT;
+ int index = fCurrentElementIndex & CHUNK_MASK;
+ ensureElementDeclCapacity(chunk);
+ fElementDeclIsExternal[chunk][index] = fReadingExternalDTD? 1 : 0;
+ }
+
} // endContentModel()
//
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org