You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by sb...@apache.org on 2001/05/16 07:33:23 UTC
cvs commit: xml-xalan/java/src/org/apache/xml/utils TreeWalker.java
sboag 01/05/15 22:33:23
Modified: java/src/org/apache/xml/dtm Tag: DTM_EXP
CoroutineSAXParser_Xerces.java DTM.java
DTMDefaultBase.java DTMDocumentImpl.java
DTMManager.java DTMManagerDefault.java
DTMTreeWalker.java
java/src/org/apache/xml/dtm/dom2dtm Tag: DTM_EXP
DOM2DTM.java UnitTest.java
java/src/org/apache/xml/dtm/sax2dtm Tag: DTM_EXP
SAX2DTM.java
java/src/org/apache/xml/utils Tag: DTM_EXP TreeWalker.java
Log:
Removed all dependencies of non-stree classes on stree. RTF construction
is now being done with the DTM.
Defined null Source object for DTMManager#getDTM(Source...
to mean "make me a DTM but don't construct it".
Added incremental arg to DTMManager#getDTM(Source... to tell
if it should build a CoRoutineParser and pass it to the DTM.
Added getLexicalHandler, getDTDHandler, etc., to the DTM
interface. Ultimately needs review.
Fixed some bugs...
Revision Changes Path
No revision
No revision
1.1.2.6 +74 -74 xml-xalan/java/src/org/apache/xml/dtm/Attic/CoroutineSAXParser_Xerces.java
Index: CoroutineSAXParser_Xerces.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/Attic/CoroutineSAXParser_Xerces.java,v
retrieving revision 1.1.2.5
retrieving revision 1.1.2.6
diff -u -r1.1.2.5 -r1.1.2.6
--- CoroutineSAXParser_Xerces.java 2001/05/14 19:09:06 1.1.2.5
+++ CoroutineSAXParser_Xerces.java 2001/05/16 05:33:19 1.1.2.6
@@ -138,16 +138,16 @@
// Not supported by all SAX2 parsers but should work in Xerces:
try
{
- setProperty("http://xml.org/sax/properties/lexical-handler",
- this);
+ setProperty("http://xml.org/sax/properties/lexical-handler",
+ this);
}
catch(org.xml.sax.SAXNotRecognizedException e)
{
- // Nothing we can do about it
+ // Nothing we can do about it
}
catch(org.xml.sax.SAXNotSupportedException e)
{
- // Nothing we can do about it
+ // Nothing we can do about it
}
}
@@ -180,7 +180,7 @@
*/
public void run() {
try {
-
+
Object arg = null;
while (true) {
arg = fCoroutineManager.co_resume(arg, fParserCoroutineID, fAppCoroutineID);
@@ -222,15 +222,15 @@
}
}
}
-
+
}
catch(java.lang.NoSuchMethodException e)
- {
- // Shouldn't happen unless we've miscoded our coroutine logic
- // "Shut down the garbage smashers on the detention level!"
- e.printStackTrace(System.err);
+ {
+ // Shouldn't happen unless we've miscoded our coroutine logic
+ // "Shut down the garbage smashers on the detention level!"
+ e.printStackTrace(System.err);
fCoroutineManager.co_exit(fParserCoroutineID);
- }
+ }
}
//================================================================
@@ -258,18 +258,18 @@
{
try
{
- Object result=
- fCoroutineManager.co_resume(source, appCoroutineID, fParserCoroutineID);
-
- // %REVIEW% Better error reporting needed... though most of these
- // should never arise during normal operation.
- // Should this rethrow the parse exception?
- if (result instanceof Exception) {
- System.out.println("\nParser threw exception:");
- ((Exception)result).printStackTrace();
- }
+ Object result=
+ fCoroutineManager.co_resume(source, appCoroutineID, fParserCoroutineID);
+
+ // %REVIEW% Better error reporting needed... though most of these
+ // should never arise during normal operation.
+ // Should this rethrow the parse exception?
+ if (result instanceof Exception) {
+ System.out.println("\nParser threw exception:");
+ ((Exception)result).printStackTrace();
+ }
- return result;
+ return result;
}
// SHOULD NEVER OCCUR, since the coroutine number and coroutine manager
@@ -277,7 +277,7 @@
// So I'm just going to return it as a parsing exception, for now.
catch(NoSuchMethodException e)
{
- return e;
+ return e;
}
}
@@ -302,21 +302,21 @@
{
try
{
- Object result =
- fCoroutineManager.co_resume(parsemore?Boolean.TRUE:Boolean.FALSE,
- appCoroutineID, fParserCoroutineID);
-
- // %REVIEW% Better error reporting needed
- if (result == null)
- {
- System.out.println("\nUNEXPECTED: Parser doMore says shut down prematurely.\n");
- }
- else if (result instanceof Exception) {
- System.out.println("\nParser threw exception:");
- ((Exception)result).printStackTrace();
- }
-
- return result;
+ Object result =
+ fCoroutineManager.co_resume(parsemore?Boolean.TRUE:Boolean.FALSE,
+ appCoroutineID, fParserCoroutineID);
+
+ // %REVIEW% Better error reporting needed
+ if (result == null)
+ {
+ System.out.println("\nUNEXPECTED: Parser doMore says shut down prematurely.\n");
+ }
+ else if (result instanceof Exception) {
+ System.out.println("\nParser threw exception:");
+ ((Exception)result).printStackTrace();
+ }
+
+ return result;
}
// SHOULD NEVER OCCUR, since the coroutine number and coroutine manager
@@ -324,7 +324,7 @@
// So I'm just going to return it as a parsing exception, for now.
catch(NoSuchMethodException e)
{
- return e;
+ return e;
}
}
@@ -346,15 +346,15 @@
try
{
Object result =
- fCoroutineManager.co_resume(null, appCoroutineID, fParserCoroutineID);
+ fCoroutineManager.co_resume(null, appCoroutineID, fParserCoroutineID);
- // Debugging; shouldn't arise in normal operation
+ // Debugging; shouldn't arise in normal operation
if(result!=null)
System.out.println("\nUNEXPECTED: Parser doTerminate answers "+result);
}
catch(java.lang.NoSuchMethodException e)
{
- // That's OK; if it doesn't exist, we don't need to terminate it
+ // That's OK; if it doesn't exist, we don't need to terminate it
}
}
@@ -386,41 +386,41 @@
// Tell coroutine to begin parsing, run while parsing is in progress
for(int arg=0;arg<args.length;++arg)
{
- InputSource source = new InputSource(args[arg]);
- Object result=null;
- boolean more=true;
- /**
- for(result = co.co_resume(source, appCoroutineID, parserCoroutineID);
- (result instanceof Boolean && ((Boolean)result)==Boolean.TRUE);
- result = co.co_resume(more, appCoroutineID, parserCoroutineID))
- **/
- for(result = parser.doParse(source, appCoroutineID);
- (result instanceof Boolean && ((Boolean)result)==Boolean.TRUE);
- result = parser.doMore(more, appCoroutineID))
- {
- System.out.println("\nSome parsing successful, trying more.\n");
+ InputSource source = new InputSource(args[arg]);
+ Object result=null;
+ boolean more=true;
+ /**
+ for(result = co.co_resume(source, appCoroutineID, parserCoroutineID);
+ (result instanceof Boolean && ((Boolean)result)==Boolean.TRUE);
+ result = co.co_resume(more, appCoroutineID, parserCoroutineID))
+ **/
+ for(result = parser.doParse(source, appCoroutineID);
+ (result instanceof Boolean && ((Boolean)result)==Boolean.TRUE);
+ result = parser.doMore(more, appCoroutineID))
+ {
+ System.out.println("\nSome parsing successful, trying more.\n");
- // Special test: Terminate parsing early.
- if(arg+1<args.length && "!".equals(args[arg+1]))
- {
- ++arg;
- more=false;
- }
+ // Special test: Terminate parsing early.
+ if(arg+1<args.length && "!".equals(args[arg+1]))
+ {
+ ++arg;
+ more=false;
+ }
- }
+ }
+
+ if (result instanceof Boolean && ((Boolean)result)==Boolean.FALSE)
+ {
+ System.out.println("\nParser ended (EOF or on request).\n");
+ }
+ else if (result == null) {
+ System.out.println("\nUNEXPECTED: Parser says shut down prematurely.\n");
+ }
+ else if (result instanceof Exception) {
+ System.out.println("\nParser threw exception:");
+ ((Exception)result).printStackTrace();
+ }
- if (result instanceof Boolean && ((Boolean)result)==Boolean.FALSE)
- {
- System.out.println("\nParser ended (EOF or on request).\n");
- }
- else if (result == null) {
- System.out.println("\nUNEXPECTED: Parser says shut down prematurely.\n");
- }
- else if (result instanceof Exception) {
- System.out.println("\nParser threw exception:");
- ((Exception)result).printStackTrace();
- }
-
}
parser.doTerminate(appCoroutineID);
1.1.2.13 +44 -65 xml-xalan/java/src/org/apache/xml/dtm/Attic/DTM.java
Index: DTM.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/Attic/DTM.java,v
retrieving revision 1.1.2.12
retrieving revision 1.1.2.13
diff -u -r1.1.2.12 -r1.1.2.13
--- DTM.java 2001/05/14 20:52:14 1.1.2.12
+++ DTM.java 2001/05/16 05:33:20 1.1.2.13
@@ -286,60 +286,6 @@
*/
public int getNextNamespaceNode(int baseHandle, int namespaceHandle, boolean inScope);
- /** Lightweight subtree-walker. Given a node handle, find the next
- * node in document order. (Preorder left-to-right traversal). The
- * walk stops (returning DTM.NULL) when it would otherwise have to
- * step out of the subtree of the node indicated by the
- * subtreeRootHandle.
- * <p>
- * One application would be as a subroutine for DTMIterators.
- * <p>
- * %REVIEW% Joe would like to rename this to walkNextDescendent
- * to distinguish it more strongly from getFirstChild
- *
- * @param subtreeRootHandle int Handle of the root of the subtree
- * being walked. Sets an outer limit that we will not walk past.
- * @param nodeHandle int Handle of a node within the subtree.
- * @return handle of the next node within the subtree, in document order.
- * or DTM.NULL to indicate none exists. */
- public int getNextDescendant(int subtreeRootHandle, int nodeHandle);
-
- /** Lightweight tree-walker. Given a node handle, find the next
- * node in document order. The walk stops (returning DTM.NULL) when
- * it would otherwise run off the end of the document.
- * <p>
- * Note that this is roughly equivalent to getNextDescendent() with
- * subtreeRootHandle set to the Document node (or maybe the root element).
- * <p>
- * %REVIEW% Joe would like to rename this to walkNextFollowing
- * (or perhaps just walkFollowing?)
- * to distinguish it more strongly from getNextSibling.
- *
- * @param axisContextHandle the start of the axis that is being traversed.
- * %REVIEW% As far as Joe can tell, this parameter is unnecessary...?
- * @param nodeHandle the node whose successor we're looking for.
- * @return handle of next node in the DTM tree
- * or DTM.NULL to indicate none exists.
- */
- public int getNextFollowing(int axisContextHandle, int nodeHandle);
-
- /** Lightweight tree-walker. Given a node handle, find the next
- * node in reverse document order. (Postorder right-to-left traversal). The
- * walk stops (returning DTM.NULL) when it would otherwise run off the
- * beginning of the document.
- * <p>
- * %REVIEW% Joe would like to rename this to walkNextPreceeding
- * (or perhaps just walkPreceeding?)
- * to distinguish it more strongly from getPreviousSibling.
- *
- * @param axisContextHandle the start of the axis that is being traversed.
- * %REVIEW% As far as Joe can tell, this parameter is unnecessary...?
- * @param nodeHandle the node whose predecessor we're looking for.
- * @return handle of next node in the DTM tree
- * or DTM.NULL to indicate none exists.
- */
- public int getNextPreceding(int axisContextHandle, int nodeHandle);
-
/**
* Given a node handle, find its parent node.
*
@@ -826,17 +772,6 @@
// ==== Construction methods (may not be supported by some implementations!) =====
// %REVIEW% What response occurs if not supported?
- /** getContentHandler returns "our SAX builder" -- the thing that
- * someone else should send SAX events to in order to extend this
- * DTM model.
- *
- * @return null if this model doesn't respond to SAX events,
- * "this" if the DTM object has a built-in SAX ContentHandler,
- * the CoroutineParser if we're bound to one and should receive
- * the SAX stream via it for incremental build purposes...
- * */
- public org.xml.sax.ContentHandler getContentHandler();
-
/** @return true iff we're building this model incrementally (eg
* we're partnered with a CoroutineParser) and thus require that the
* transformation and the parse run simultaneously. Guidance to the
@@ -849,6 +784,50 @@
// current DTMDocumentImpl draft), or should we just support SAX
// listener interfaces? Should it be a separate interface to
// make that distinction explicit?
+
+ /**
+ * Return this DTM's content handler, if it has one.
+ *
+ * @return null if this model doesn't respond to SAX events.
+ */
+ public org.xml.sax.ContentHandler getContentHandler();
+
+ /**
+ * Return this DTM's lexical handler, if it has one.
+ *
+ * %REVIEW% Should this return null if constrution already done/begun?
+ *
+ * @return null if this model doesn't respond to lexical SAX events.
+ */
+ public org.xml.sax.ext.LexicalHandler getLexicalHandler();
+
+ /**
+ * Return this DTM's EntityResolver, if it has one.
+ *
+ * @return null if this model doesn't respond to SAX entity ref events.
+ */
+ public org.xml.sax.EntityResolver getEntityResolver();
+
+ /**
+ * Return this DTM's DTDHandler, if it has one.
+ *
+ * @return null if this model doesn't respond to SAX dtd events.
+ */
+ public org.xml.sax.DTDHandler getDTDHandler();
+
+ /**
+ * Return this DTM's ErrorHandler, if it has one.
+ *
+ * @return null if this model doesn't respond to SAX error events.
+ */
+ public org.xml.sax.ErrorHandler getErrorHandler();
+
+ /**
+ * Return this DTM's DeclHandler, if it has one.
+ *
+ * @return null if this model doesn't respond to SAX Decl events.
+ */
+ public org.xml.sax.ext.DeclHandler getDeclHandler();
/** Append a child to "the end of the document". Please note that
* the node is always cloned in a base DTM, since our basic behavior
1.1.2.4 +7 -2 xml-xalan/java/src/org/apache/xml/dtm/Attic/DTMDefaultBase.java
Index: DTMDefaultBase.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/Attic/DTMDefaultBase.java,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -r1.1.2.3 -r1.1.2.4
--- DTMDefaultBase.java 2001/05/15 06:31:42 1.1.2.3
+++ DTMDefaultBase.java 2001/05/16 05:33:20 1.1.2.4
@@ -167,7 +167,7 @@
{
m_mgr = mgr;
- m_documentBaseURI = source.getSystemId();
+ m_documentBaseURI = (null != source) ? source.getSystemId() : null;
m_dtmIdent = dtmIdentity;
m_mask = mgr.getNodeIdentityMask();
m_wsfilter = whiteSpaceFilter;
@@ -233,12 +233,17 @@
// processed.
while (info == NOTPROCESSED)
{
- nextNode();
+ boolean isMore = nextNode();
if (identity >= getNumberOfNodes())
+ {
info = NOTPROCESSED;
+ }
else
info = m_info.elementAt(base + offsetValue);
+
+ if(!isMore && NOTPROCESSED == info)
+ return DTM.NULL;
}
return info;
1.1.2.16 +103 -40 xml-xalan/java/src/org/apache/xml/dtm/Attic/DTMDocumentImpl.java
Index: DTMDocumentImpl.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/Attic/DTMDocumentImpl.java,v
retrieving revision 1.1.2.15
retrieving revision 1.1.2.16
diff -u -r1.1.2.15 -r1.1.2.16
--- DTMDocumentImpl.java 2001/05/14 20:52:18 1.1.2.15
+++ DTMDocumentImpl.java 2001/05/16 05:33:20 1.1.2.16
@@ -182,9 +182,9 @@
// means it needs to attach to them AFTER we've resolved their
// startup. Or it needs to attach to this document and
// retrieve them each time. Or this needs to be
- // an interface _implemented_ by this class... which might be simplest!
- private ExpandedNameTable m_expandedNames=
- new ExpandedNameTable(m_localNames,m_nsNames);
+ // an interface _implemented_ by this class... which might be simplest!
+ private ExpandedNameTable m_expandedNames=
+ new ExpandedNameTable(m_localNames,m_nsNames);
/**
@@ -373,6 +373,69 @@
return this;
}
+ /**
+ * Return this DTM's lexical handler.
+ *
+ * %REVIEW% Should this return null if constrution already done/begun?
+ *
+ * @return null if this model doesn't respond to lexical SAX events,
+ * "this" if the DTM object has a built-in SAX ContentHandler,
+ * the CoroutineParser if we're bound to one and should receive
+ * the SAX stream via it for incremental build purposes...
+ */
+ public LexicalHandler getLexicalHandler()
+ {
+
+ if (m_coroutineParser instanceof CoroutineSAXParser)
+ return (LexicalHandler) m_coroutineParser;
+ else
+ return this;
+ }
+
+ /**
+ * Return this DTM's EntityResolver.
+ *
+ * @return null if this model doesn't respond to SAX entity ref events.
+ */
+ public org.xml.sax.EntityResolver getEntityResolver()
+ {
+
+ return null;
+ }
+
+ /**
+ * Return this DTM's DTDHandler.
+ *
+ * @return null if this model doesn't respond to SAX dtd events.
+ */
+ public org.xml.sax.DTDHandler getDTDHandler()
+ {
+
+ return null;
+ }
+
+ /**
+ * Return this DTM's ErrorHandler.
+ *
+ * @return null if this model doesn't respond to SAX error events.
+ */
+ public org.xml.sax.ErrorHandler getErrorHandler()
+ {
+
+ return null;
+ }
+
+ /**
+ * Return this DTM's DeclHandler.
+ *
+ * @return null if this model doesn't respond to SAX Decl events.
+ */
+ public org.xml.sax.ext.DeclHandler getDeclHandler()
+ {
+
+ return null;
+ }
+
/** @return true iff we're building this model incrementally (eg
* we're partnered with a CoroutineParser) and thus require that the
* transformation and the parse run simultaneously. Guidance to the
@@ -491,7 +554,7 @@
}
else
{
- // %REVEIW% Null or ""?
+ // %REVEIW% Null or ""?
prefix=null; // Default prefix
}
@@ -1007,11 +1070,11 @@
(type == ENTITY_REFERENCE_NODE)) {
// In case when Document root is given
- // if (nodeHandle == 0) nodeHandle = 1;
- // %TBD% Probably was a mistake.
- // If someone explicitly asks for first child
- // of Document, I would expect them to want
- // that and only that.
+ // if (nodeHandle == 0) nodeHandle = 1;
+ // %TBD% Probably was a mistake.
+ // If someone explicitly asks for first child
+ // of Document, I would expect them to want
+ // that and only that.
int kid = nodeHandle + 1;
nodes.readSlot(kid, gotslot);
@@ -1131,17 +1194,17 @@
/**
* Given a node handle, advance to its next sibling.
- *
- * %TBD% This currently uses the DTM-internal definition of
- * sibling; eg, the last attr's next sib is the first
- * child. In the old DTM, the DOM proxy layer provided the
- * additional logic for the public view. If we're rewriting
- * for XPath emulation, that test must be done here.
- *
+ *
+ * %TBD% This currently uses the DTM-internal definition of
+ * sibling; eg, the last attr's next sib is the first
+ * child. In the old DTM, the DOM proxy layer provided the
+ * additional logic for the public view. If we're rewriting
+ * for XPath emulation, that test must be done here.
+ *
* %TBD% CODE INTERACTION WITH COROUTINE PARSE - If not yet
* resolved, should wait for more nodes to be added to the document
* and tries again.
- *
+ *
* @param nodeHandle int Handle of the node.
* @return int Node-number of next sibling,
* or DTM.NULL to indicate none exists.
@@ -1528,7 +1591,7 @@
// Remove prefix from expanded name
int colonpos = expandedName.indexOf(":");
String localName = expandedName.substring(colonpos+1);
- return localName;
+ return localName;
}
@@ -1576,13 +1639,13 @@
short type = (short) (gotslot[0] & 0xFFFF);
String name = fixednames[type];
if (null == name) {
- int i=gotslot[3];
- /**/System.out.println("got i="+i+" "+(i>>16)+"/"+(i&0xffff));
-
- name=m_localNames.indexToString(i & 0xFFFF);
- String prefix=m_prefixNames.indexToString(i >>16);
- if(prefix!=null && prefix.length()>0)
- name=prefix+":"+name;
+ int i=gotslot[3];
+ /**/System.out.println("got i="+i+" "+(i>>16)+"/"+(i&0xffff));
+
+ name=m_localNames.indexToString(i & 0xFFFF);
+ String prefix=m_prefixNames.indexToString(i >>16);
+ if(prefix!=null && prefix.length()>0)
+ name=prefix+":"+name;
}
return name;
}
@@ -1603,7 +1666,7 @@
* colon character)
*
* %REVIEW% What's the local name of something other than Element/Attr?
- * Should this be DOM-style (undefined unless namespaced), or other?
+ * Should this be DOM-style (undefined unless namespaced), or other?
*
* @param nodeHandle the id of the node.
* @return String Local name of this node.
@@ -1612,10 +1675,10 @@
nodes.readSlot(nodeHandle, gotslot);
short type = (short) (gotslot[0] & 0xFFFF);
String name = "";
- if ((type==ELEMENT_NODE) || (type==ATTRIBUTE_NODE)) {
- int i=gotslot[3];
- name=m_localNames.indexToString(i & 0xFFFF);
- if(name==null) name="";
+ if ((type==ELEMENT_NODE) || (type==ATTRIBUTE_NODE)) {
+ int i=gotslot[3];
+ name=m_localNames.indexToString(i & 0xFFFF);
+ if(name==null) name="";
}
return name;
}
@@ -1628,8 +1691,8 @@
* <p> %REVIEW% Are you sure you want "" for no prefix? </p>
*
* %REVIEW% Should this be DOM-style (undefined unless namespaced),
- * or other?
- *
+ * or other?
+ *
* @param nodeHandle the id of the node.
* @return String prefix of this node's name, or "" if no explicit
* namespace prefix was given.
@@ -1637,11 +1700,11 @@
public String getPrefix(int nodeHandle) {
nodes.readSlot(nodeHandle, gotslot);
short type = (short) (gotslot[0] & 0xFFFF);
- String name = "";
- if((type==ELEMENT_NODE) || (type==ATTRIBUTE_NODE)) {
- int i=gotslot[3];
- name=m_prefixNames.indexToString(i >>16);
- if(name==null) name="";
+ String name = "";
+ if((type==ELEMENT_NODE) || (type==ATTRIBUTE_NODE)) {
+ int i=gotslot[3];
+ name=m_prefixNames.indexToString(i >>16);
+ if(name==null) name="";
}
return name;
}
@@ -2107,9 +2170,9 @@
int w1 = currentParent;
// W2: Next (initialized as 0)
int w2 = 0;
- // W3: Tagname high: prefix Low: local name
- int w3 = localNameIndex | prefixIndex<<16;
- /**/System.out.println("set w3="+w3+" "+(w3>>16)+"/"+(w3&0xffff));
+ // W3: Tagname high: prefix Low: local name
+ int w3 = localNameIndex | prefixIndex<<16;
+ /**/System.out.println("set w3="+w3+" "+(w3>>16)+"/"+(w3&0xffff));
//int ourslot = nodes.appendSlot(w0, w1, w2, w3);
int ourslot = appendNode(w0, w1, w2, w3);
1.1.2.10 +6 -2 xml-xalan/java/src/org/apache/xml/dtm/Attic/DTMManager.java
Index: DTMManager.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/Attic/DTMManager.java,v
retrieving revision 1.1.2.9
retrieving revision 1.1.2.10
diff -u -r1.1.2.9 -r1.1.2.10
--- DTMManager.java 2001/05/06 02:09:41 1.1.2.9
+++ DTMManager.java 2001/05/16 05:33:20 1.1.2.10
@@ -182,16 +182,20 @@
* (I think more parameters will need to be added for error handling, and entity
* resolution).
*
- * @param source the specification of the source object.
+ * @param source the specification of the source object, which may be null,
+ * in which case it is assumed that node construction will take
+ * by some other means.
* @param unique true if the returned DTM must be unique, probably because it
* is going to be mutated.
* @param whiteSpaceFilter Enables filtering of whitespace nodes, and may
* be null.
+ * @param incremental true if the construction should try and be incremental.
*
* @return a non-null DTM reference.
*/
public abstract DTM getDTM(javax.xml.transform.Source source,
- boolean unique, DTMWSFilter whiteSpaceFilter);
+ boolean unique, DTMWSFilter whiteSpaceFilter,
+ boolean incremental);
/**
* Get the instance of DTM that "owns" a node handle.
1.1.2.12 +170 -96 xml-xalan/java/src/org/apache/xml/dtm/Attic/DTMManagerDefault.java
Index: DTMManagerDefault.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/Attic/DTMManagerDefault.java,v
retrieving revision 1.1.2.11
retrieving revision 1.1.2.12
diff -u -r1.1.2.11 -r1.1.2.12
--- DTMManagerDefault.java 2001/05/15 21:54:03 1.1.2.11
+++ DTMManagerDefault.java 2001/05/16 05:33:20 1.1.2.12
@@ -81,6 +81,9 @@
import org.xml.sax.XMLReader;
import org.xml.sax.ContentHandler;
import org.xml.sax.EntityResolver;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.helpers.XMLReaderFactory;
import org.xml.sax.ext.DeclHandler;
import org.xml.sax.ext.LexicalHandler;
@@ -91,7 +94,7 @@
public class DTMManagerDefault extends DTMManager
{
- /** NEEDSDOC Field m_dtms */
+ /** NEEDSDOC Field m_dtms */
protected Vector m_dtms = new Vector();
/**
@@ -99,7 +102,8 @@
*
*/
public DTMManagerDefault(){}
-
+
+ /** NEEDSDOC Field DUMPTREE */
private static final boolean DUMPTREE = false;
/**
@@ -116,22 +120,24 @@
* is going to be mutated.
* @param whiteSpaceFilter Enables filtering of whitespace nodes, and may
* be null.
+ * NEEDSDOC @param incremental
*
* @return a non-null DTM reference.
*/
public DTM getDTM(Source source, boolean unique,
- DTMWSFilter whiteSpaceFilter)
+ DTMWSFilter whiteSpaceFilter, boolean incremental)
{
int documentID = m_dtms.size() << 20;
- if (source instanceof DOMSource)
+ if ((null != source) && source instanceof DOMSource)
{
DOM2DTM dtm = new DOM2DTM(this, (DOMSource) source, documentID,
- whiteSpaceFilter);
+ whiteSpaceFilter);
+
m_dtms.add(dtm);
-
- if(DUMPTREE)
+
+ if (DUMPTREE)
{
System.out.println("Dumping DOM2DTM");
dtm.dumpDTM();
@@ -141,121 +147,187 @@
}
else
{
- boolean isSAXSource = (source instanceof SAXSource);
- boolean isStreamSource = (source instanceof StreamSource);
+ boolean isSAXSource = (null != source) ? (source instanceof SAXSource) : true;
+ boolean isStreamSource = (null != source) ? (source instanceof StreamSource) : false;
if (isSAXSource || isStreamSource)
{
- XMLReader reader = getXMLReader(source);
-
- // transformer.setIsTransformDone(false);
- InputSource xmlSource = SAXSource.sourceToInputSource(source);
- String urlOfSource = xmlSource.getSystemId();
+ XMLReader reader;
+ InputSource xmlSource;
- if (null != urlOfSource)
+ if (null == source)
{
- try
- {
- urlOfSource = SystemIDResolver.getAbsoluteURI(urlOfSource);
- }
- catch (Exception e)
- {
+ xmlSource = null;
+ reader = null;
+ }
+ else
+ {
+ reader = getXMLReader(source);
+ xmlSource = SAXSource.sourceToInputSource(source);
- // %REVIEW% Is there a better way to send a warning?
- System.err.println("Can not absolutize URL: " + urlOfSource);
- }
+ String urlOfSource = xmlSource.getSystemId();
- xmlSource.setSystemId(urlOfSource);
- }
+ if (null != urlOfSource)
+ {
+ try
+ {
+ urlOfSource = SystemIDResolver.getAbsoluteURI(urlOfSource);
+ }
+ catch (Exception e)
+ {
+
+ // %REVIEW% Is there a better way to send a warning?
+ System.err.println("Can not absolutize URL: " + urlOfSource);
+ }
- try
- {
- reader.setFeature("http://apache.org/xml/features/validation/dynamic",
- true);
+ xmlSource.setSystemId(urlOfSource);
+ }
}
- catch (org.xml.sax.SAXException se) {}
// Create the basic SAX2DTM.
- SAX2DTM dtm = new SAX2DTM(this,
- source,
- documentID,
- whiteSpaceFilter);
-
+ SAX2DTM dtm = new SAX2DTM(this, source, documentID, whiteSpaceFilter);
+
// Go ahead and add the DTM to the lookup table. This needs to be
// done before any parsing occurs.
m_dtms.add(dtm);
-
- // Create a CoroutineManager to manage the coordination between the
- // parser and the transformation. This will "throttle" between
- // the parser and the calling application.
- CoroutineManager coroutineManager=new CoroutineManager();
-
- // Create an CoRoutine ID for the transformation.
- int appCoroutine = coroutineManager.co_joinCoroutineSet(-1);
- // System.out.println("appCoroutine (mgr): "+appCoroutine);
-
- // %TBD% Test for a Xerces Parser, and create a
- // CoroutineSAXParser_Xerces to avoid threading.
-
- // Create a CoroutineSAXParser that will run on the secondary thread.
- CoroutineSAXParser coParser=new CoroutineSAXParser(coroutineManager, appCoroutine, reader);
-
- // Have the DTM set itself up as the CoroutineSAXParser's listener.
- dtm.setCoroutineParser(coParser, appCoroutine);
-
- // Get the parser's CoRoutine ID.
- int parserCoroutine = coParser.getParserCoroutineID();
- // System.out.println("parserCoroutine (mgr): "+parserCoroutine);
-
-
- // %TBD% It's probably OK to have these bypass the CoRoutine stuff??
- // Or maybe not?
- // ... Depends on how broken will things get if they occur at the same
- // time that someone is trying to read the DTM model. I'd suggest that
- // we instead extend CoroutineParser to handle these, and let it
- // pass the registration through to the reader if that's the Right Thng
- reader.setDTDHandler(dtm);
- reader.setErrorHandler(dtm);
-
- try
+
+ if (incremental)
{
- // This is a strange way to start the parse.
- // %REVIEW% Consider making coParser just be a throttling filter
- Object gotMore = coParser.doParse(xmlSource, appCoroutine);
- if( gotMore instanceof Exception)
+
+ // Create a CoroutineManager to manage the coordination between the
+ // parser and the transformation. This will "throttle" between
+ // the parser and the calling application.
+ CoroutineManager coroutineManager = new CoroutineManager();
+
+ // Create an CoRoutine ID for the transformation.
+ int appCoroutine = coroutineManager.co_joinCoroutineSet(-1);
+ CoroutineParser coParser;
+
+ // %TBD%
+ // if(reader instanceof org.apache.xerces.parsers.SAXParser)
+ // {
+ // // CoroutineSAXParser_Xerces to avoid threading.
+ // System.out.println("Creating a CoroutineSAXParser_Xerces");
+ // coParser =
+ // new CoroutineSAXParser_Xerces(coroutineManager, appCoroutine,
+ // (org.apache.xerces.parsers.SAXParser)reader);
+ // }
+ // else
+ {
+
+ // Create a CoroutineSAXParser that will run on the secondary thread.
+ coParser = new CoroutineSAXParser(coroutineManager, appCoroutine,
+ reader);
+ }
+
+ // Have the DTM set itself up as the CoroutineSAXParser's listener.
+ dtm.setCoroutineParser(coParser, appCoroutine);
+
+ // Get the parser's CoRoutine ID.
+ int parserCoroutine = coParser.getParserCoroutineID();
+
+ // System.out.println("parserCoroutine (mgr): "+parserCoroutine);
+ // %TBD% It's probably OK to have these bypass the CoRoutine stuff??
+ // Or maybe not?
+ // ... Depends on how broken will things get if they occur at the same
+ // time that someone is trying to read the DTM model. I'd suggest that
+ // we instead extend CoroutineParser to handle these, and let it
+ // pass the registration through to the reader if that's the Right Thng
+ reader.setDTDHandler(dtm);
+ reader.setErrorHandler(dtm);
+
+ if (null == xmlSource)
{
+
+ // Then the user will construct it themselves.
+ return dtm;
+ }
+
+ try
+ {
+
+ // %REVIEW% Consider making coParser just be a throttling filter
+ Object gotMore = coParser.doParse(xmlSource, appCoroutine);
+
+ if (gotMore instanceof Exception)
+ {
+ dtm.clearCoRoutine();
+
+ throw ((Exception) gotMore);
+ }
+ else if (gotMore != Boolean.TRUE)
+ {
+
+ // %REVIEW% Consider having coParser self-terminate at end of file.
+ dtm.clearCoRoutine();
+ }
+ }
+ catch (RuntimeException re)
+ {
+
+ // coroutineManager.co_exit(appCoroutine);
dtm.clearCoRoutine();
- throw ((Exception)gotMore);
+
+ throw re;
}
- else if (gotMore != Boolean.TRUE)
+ catch (Exception e)
{
- // This is a strange way to terminate the parser.
- // %REVIEW% Consider having coParser self-terminate at end of file.
+
+ // coroutineManager.co_exit(appCoroutine);
dtm.clearCoRoutine();
+
+ throw new org.apache.xml.utils.WrappedRuntimeException(e);
}
- }
- catch(RuntimeException re)
- {
- // coroutineManager.co_exit(appCoroutine);
- dtm.clearCoRoutine();
- throw re;
- }
- catch(Exception e)
- {
- // coroutineManager.co_exit(appCoroutine);
- dtm.clearCoRoutine();
- throw new org.apache.xml.utils.WrappedRuntimeException(e);
}
- finally
+ else
{
- // coroutineManager.co_exit(appCoroutine);
+ if(null == reader)
+ {
+ // Then the user will construct it themselves.
+ return dtm;
+ }
+
+ // not incremental
+ reader.setContentHandler(dtm);
+ reader.setDTDHandler(dtm);
+ reader.setErrorHandler(dtm);
+
+ try
+ {
+ reader.setProperty(
+ "http://xml.org/sax/properties/lexical-handler", dtm);
+ }
+ catch (SAXNotRecognizedException e){}
+ catch (SAXNotSupportedException e){}
+
+ try
+ {
+ reader.parse(xmlSource);
+ }
+ catch (RuntimeException re)
+ {
+
+ // coroutineManager.co_exit(appCoroutine);
+ dtm.clearCoRoutine();
+
+ throw re;
+ }
+ catch (Exception e)
+ {
+
+ // coroutineManager.co_exit(appCoroutine);
+ dtm.clearCoRoutine();
+
+ throw new org.apache.xml.utils.WrappedRuntimeException(e);
+ }
}
- if(DUMPTREE)
+ if (DUMPTREE)
{
System.out.println("Dumping SAX2DOM");
dtm.dumpDTM();
}
+
return dtm;
}
else
@@ -328,6 +400,7 @@
// What can we do?
// TODO: User diagnostics.
}
+
try
{
reader.setFeature("http://apache.org/xml/features/validation/dynamic",
@@ -399,9 +472,10 @@
*/
public boolean release(DTM dtm, boolean shouldHardDelete)
{
- if(dtm instanceof SAX2DTM)
+
+ if (dtm instanceof SAX2DTM)
{
- ((SAX2DTM)dtm).clearCoRoutine();
+ ((SAX2DTM) dtm).clearCoRoutine();
}
int i = getDTMIdentity(dtm);
@@ -435,7 +509,7 @@
Document doc = db.newDocument();
Node df = doc.createDocumentFragment();
- return getDTM(new DOMSource(df), true, null);
+ return getDTM(new DOMSource(df), true, null, false);
}
catch (Exception e)
{
1.1.2.5 +25 -7 xml-xalan/java/src/org/apache/xml/dtm/Attic/DTMTreeWalker.java
Index: DTMTreeWalker.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/Attic/DTMTreeWalker.java,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -u -r1.1.2.4 -r1.1.2.5
--- DTMTreeWalker.java 2001/05/14 23:04:02 1.1.2.4
+++ DTMTreeWalker.java 2001/05/16 05:33:20 1.1.2.5
@@ -271,27 +271,45 @@
this.m_contentHandler.startDocument();
break;
case DTM.ELEMENT_NODE :
+ DTM dtm = m_dtm;
- for (int nsn = m_dtm.getFirstNamespaceNode(node, true); DTM.NULL != nsn;
- nsn = m_dtm.getNextNamespaceNode(node, nsn, true))
+ for (int nsn = dtm.getFirstNamespaceNode(node, true); DTM.NULL != nsn;
+ nsn = dtm.getNextNamespaceNode(node, nsn, true))
{
- // String prefix = m_dtm.getPrefix(nsn);
- String prefix = m_dtm.getNodeNameX(nsn);
+ // String prefix = dtm.getPrefix(nsn);
+ String prefix = dtm.getNodeNameX(nsn);
this.m_contentHandler.startPrefixMapping(prefix,
- m_dtm.getStringValue(nsn));
+ dtm.getStringValue(nsn));
}
// System.out.println("m_dh.getNamespaceOfNode(node): "+m_dh.getNamespaceOfNode(node));
// System.out.println("m_dh.getLocalNameOfNode(node): "+m_dh.getLocalNameOfNode(node));
- String ns = m_dtm.getNamespaceURI(node);
+ String ns = dtm.getNamespaceURI(node);
if(null == ns)
ns = "";
+
+ // %OPT% !!
+ org.xml.sax.helpers.AttributesImpl attrs =
+ new org.xml.sax.helpers.AttributesImpl();
+
+ for (int i = dtm.getFirstAttribute(node);
+ i != DTM.NULL;
+ i = dtm.getNextAttribute(i))
+ {
+ attrs.addAttribute(dtm.getNamespaceURI(i),
+ dtm.getLocalName(i),
+ dtm.getNodeName(i),
+ "CDATA",
+ dtm.getNodeValue(i));
+ }
+
+
this.m_contentHandler.startElement(ns,
m_dtm.getLocalName(node),
m_dtm.getNodeName(node),
- null /* %TBD% new AttList(atts, m_dh) */);
+ attrs);
break;
case DTM.PROCESSING_INSTRUCTION_NODE :
{
No revision
No revision
1.1.2.13 +61 -0 xml-xalan/java/src/org/apache/xml/dtm/dom2dtm/Attic/DOM2DTM.java
Index: DOM2DTM.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/dom2dtm/Attic/DOM2DTM.java,v
retrieving revision 1.1.2.12
retrieving revision 1.1.2.13
diff -u -r1.1.2.12 -r1.1.2.13
--- DOM2DTM.java 2001/05/15 06:31:43 1.1.2.12
+++ DOM2DTM.java 2001/05/16 05:33:21 1.1.2.13
@@ -1120,6 +1120,67 @@
{
return null;
}
+
+ /**
+ * Return this DTM's lexical handler.
+ *
+ * %REVIEW% Should this return null if constrution already done/begun?
+ *
+ * @return null if this model doesn't respond to lexical SAX events,
+ * "this" if the DTM object has a built-in SAX ContentHandler,
+ * the CoroutineParser if we're bound to one and should receive
+ * the SAX stream via it for incremental build purposes...
+ */
+ public org.xml.sax.ext.LexicalHandler getLexicalHandler()
+ {
+
+ return null;
+ }
+
+
+ /**
+ * Return this DTM's EntityResolver.
+ *
+ * @return null if this model doesn't respond to SAX entity ref events.
+ */
+ public org.xml.sax.EntityResolver getEntityResolver()
+ {
+
+ return null;
+ }
+
+ /**
+ * Return this DTM's DTDHandler.
+ *
+ * @return null if this model doesn't respond to SAX dtd events.
+ */
+ public org.xml.sax.DTDHandler getDTDHandler()
+ {
+
+ return null;
+ }
+
+ /**
+ * Return this DTM's ErrorHandler.
+ *
+ * @return null if this model doesn't respond to SAX error events.
+ */
+ public org.xml.sax.ErrorHandler getErrorHandler()
+ {
+
+ return null;
+ }
+
+ /**
+ * Return this DTM's DeclHandler.
+ *
+ * @return null if this model doesn't respond to SAX Decl events.
+ */
+ public org.xml.sax.ext.DeclHandler getDeclHandler()
+ {
+
+ return null;
+ }
/** @return true iff we're building this model incrementally (eg
* we're partnered with a CoroutineParser) and thus require that the
1.1.2.4 +1 -1 xml-xalan/java/src/org/apache/xml/dtm/dom2dtm/Attic/UnitTest.java
Index: UnitTest.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/dom2dtm/Attic/UnitTest.java,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -r1.1.2.3 -r1.1.2.4
--- UnitTest.java 2001/05/06 02:09:46 1.1.2.3
+++ UnitTest.java 2001/05/16 05:33:21 1.1.2.4
@@ -122,7 +122,7 @@
Document doc = db.parse(new InputSource(sr));
DTMManager dtmMgr = DTMManager.newInstance();
- DTM dtm = dtmMgr.getDTM(new DOMSource(doc), true, null);
+ DTM dtm = dtmMgr.getDTM(new DOMSource(doc), true, null, true);
int docHandle = dtm.getDocument();
outputChildren(docHandle, dtm, 0);
No revision
No revision
1.1.2.11 +68 -3 xml-xalan/java/src/org/apache/xml/dtm/sax2dtm/Attic/SAX2DTM.java
Index: SAX2DTM.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/sax2dtm/Attic/SAX2DTM.java,v
retrieving revision 1.1.2.10
retrieving revision 1.1.2.11
diff -u -r1.1.2.10 -r1.1.2.11
--- SAX2DTM.java 2001/05/15 18:12:28 1.1.2.10
+++ SAX2DTM.java 2001/05/16 05:33:22 1.1.2.11
@@ -316,7 +316,7 @@
//coroutineParser.setDTDHandler(this);
//coroutineParser.setDeclHandler(this);
}
-
+
/**
* getContentHandler returns "our SAX builder" -- the thing that
* someone else should send SAX events to in order to extend this
@@ -329,7 +329,7 @@
* the CoroutineParser if we're bound to one and should receive
* the SAX stream via it for incremental build purposes...
*/
- public org.xml.sax.ContentHandler getContentHandler()
+ public ContentHandler getContentHandler()
{
if (m_coroutineParser instanceof CoroutineSAXParser)
@@ -337,7 +337,71 @@
else
return this;
}
+
+ /**
+ * Return this DTM's lexical handler.
+ *
+ * %REVIEW% Should this return null if constrution already done/begun?
+ *
+ * @return null if this model doesn't respond to lexical SAX events,
+ * "this" if the DTM object has a built-in SAX ContentHandler,
+ * the CoroutineParser if we're bound to one and should receive
+ * the SAX stream via it for incremental build purposes...
+ */
+ public LexicalHandler getLexicalHandler()
+ {
+
+ if (m_coroutineParser instanceof CoroutineSAXParser)
+ return (LexicalHandler) m_coroutineParser;
+ else
+ return this;
+ }
+
+ /**
+ * Return this DTM's EntityResolver.
+ *
+ * @return null if this model doesn't respond to SAX entity ref events.
+ */
+ public EntityResolver getEntityResolver()
+ {
+
+ return this;
+ }
+
+ /**
+ * Return this DTM's DTDHandler.
+ *
+ * @return null if this model doesn't respond to SAX dtd events.
+ */
+ public DTDHandler getDTDHandler()
+ {
+
+ return this;
+ }
+
+ /**
+ * Return this DTM's ErrorHandler.
+ *
+ * @return null if this model doesn't respond to SAX error events.
+ */
+ public ErrorHandler getErrorHandler()
+ {
+
+ return this;
+ }
+
+ /**
+ * Return this DTM's DeclHandler.
+ *
+ * @return null if this model doesn't respond to SAX Decl events.
+ */
+ public DeclHandler getDeclHandler()
+ {
+ return this;
+ }
+
+
/**
* @return true iff we're building this model incrementally (eg
* we're partnered with a CoroutineParser) and thus require that the
@@ -596,8 +660,9 @@
{
treeWalker = new DTMTreeWalker();
}
-
+
treeWalker.setcontentHandler(ch);
+ treeWalker.setDTM(this);
try
{
No revision
No revision
1.7.2.2 +2 -9 xml-xalan/java/src/org/apache/xml/utils/TreeWalker.java
Index: TreeWalker.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/utils/TreeWalker.java,v
retrieving revision 1.7.2.1
retrieving revision 1.7.2.2
diff -u -r1.7.2.1 -r1.7.2.2
--- TreeWalker.java 2001/04/17 15:55:03 1.7.2.1
+++ TreeWalker.java 2001/05/16 05:33:22 1.7.2.2
@@ -223,15 +223,8 @@
private final void dispatachChars(Node node)
throws org.xml.sax.SAXException
{
- if(node.isSupported(org.apache.xalan.stree.SaxEventDispatch.SUPPORTSINTERFACE, "1.0"))
- {
- ((org.apache.xalan.stree.SaxEventDispatch)node).dispatchCharactersEvent(m_contentHandler);
- }
- else
- {
- String data = ((Text) node).getData();
- this.m_contentHandler.characters(data.toCharArray(), 0, data.length());
- }
+ String data = ((Text) node).getData();
+ this.m_contentHandler.characters(data.toCharArray(), 0, data.length());
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org