jkesselm 2003/02/13 10:34:25
Modified: test/java/src/org/apache/qetest/dtm TestDTMIter.java
TestDTMIterator.java TestDTMTrav.java
TestDTMTraverser.java TimeDTMIterDeep.java
TimeDTMIterator.java TimeDTMTravDeep.java
TimeDTMTraverser.java
Added: test/java/src/org/apache/qetest/xdm TestXDMCurs.java
TestXDMCursor.java xdmWSStripper.java
Log:
NEW API UNDER DEVELOPMENT: eXtensible Data Model (XDM).
Axis and Sequence have been migrated into the XDM package.
New (primitive) unit tests for prototype XDM implementation.
Revision Changes Path
1.10 +2 -2 xml-xalan/test/java/src/org/apache/qetest/dtm/TestDTMIter.java
Index: TestDTMIter.java
===================================================================
RCS file: /home/cvs/xml-xalan/test/java/src/org/apache/qetest/dtm/TestDTMIter.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- TestDTMIter.java 31 Jan 2003 15:47:17 -0000 1.9
+++ TestDTMIter.java 13 Feb 2003 18:34:24 -0000 1.10
@@ -71,7 +71,7 @@
import org.apache.qetest.LinebyLineCheckService;
import org.apache.qetest.OutputNameManager;
import org.apache.qetest.xsl.XSLTestfileInfo;
-import org.apache.xml.dtm.Axis;
+import org.apache.xml.xdm.Axis;
import org.apache.xml.dtm.DTM;
import org.apache.xml.dtm.DTMAxisIterator;
import org.apache.xml.dtm.DTMManager;
1.9 +2 -2
xml-xalan/test/java/src/org/apache/qetest/dtm/TestDTMIterator.java
Index: TestDTMIterator.java
===================================================================
RCS file:
/home/cvs/xml-xalan/test/java/src/org/apache/qetest/dtm/TestDTMIterator.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- TestDTMIterator.java 31 Jan 2003 15:47:17 -0000 1.8
+++ TestDTMIterator.java 13 Feb 2003 18:34:24 -0000 1.9
@@ -61,7 +61,7 @@
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
-import org.apache.xml.dtm.Axis;
+import org.apache.xml.xdm.Axis;
import org.apache.xml.dtm.DTM;
import org.apache.xml.dtm.DTMAxisIterator;
import org.apache.xml.dtm.DTMManager;
@@ -360,4 +360,4 @@
}
}
-}
\ No newline at end of file
+}
1.6 +2 -2 xml-xalan/test/java/src/org/apache/qetest/dtm/TestDTMTrav.java
Index: TestDTMTrav.java
===================================================================
RCS file: /home/cvs/xml-xalan/test/java/src/org/apache/qetest/dtm/TestDTMTrav.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TestDTMTrav.java 31 Jan 2003 15:47:17 -0000 1.5
+++ TestDTMTrav.java 13 Feb 2003 18:34:24 -0000 1.6
@@ -70,7 +70,7 @@
import org.apache.qetest.FileBasedTest;
import org.apache.qetest.OutputNameManager;
import org.apache.qetest.xsl.XSLTestfileInfo;
-import org.apache.xml.dtm.Axis;
+import org.apache.xml.xdm.Axis;
import org.apache.xml.dtm.DTM;
import org.apache.xml.dtm.DTMAxisTraverser;
import org.apache.xml.dtm.DTMManager;
1.10 +2 -2
xml-xalan/test/java/src/org/apache/qetest/dtm/TestDTMTraverser.java
Index: TestDTMTraverser.java
===================================================================
RCS file:
/home/cvs/xml-xalan/test/java/src/org/apache/qetest/dtm/TestDTMTraverser.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- TestDTMTraverser.java 31 Jan 2003 15:47:17 -0000 1.9
+++ TestDTMTraverser.java 13 Feb 2003 18:34:24 -0000 1.10
@@ -61,7 +61,7 @@
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
-import org.apache.xml.dtm.Axis;
+import org.apache.xml.xdm.Axis;
import org.apache.xml.dtm.DTM;
import org.apache.xml.dtm.DTMAxisTraverser;
import org.apache.xml.dtm.DTMManager;
@@ -383,4 +383,4 @@
}
}
-}
\ No newline at end of file
+}
1.6 +1 -1
xml-xalan/test/java/src/org/apache/qetest/dtm/TimeDTMIterDeep.java
Index: TimeDTMIterDeep.java
===================================================================
RCS file:
/home/cvs/xml-xalan/test/java/src/org/apache/qetest/dtm/TimeDTMIterDeep.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TimeDTMIterDeep.java 31 Jan 2003 15:47:17 -0000 1.5
+++ TimeDTMIterDeep.java 13 Feb 2003 18:34:24 -0000 1.6
@@ -63,7 +63,7 @@
import org.apache.qetest.FileBasedTest;
import org.apache.qetest.OutputNameManager;
import org.apache.qetest.xsl.XSLTestfileInfo;
-import org.apache.xml.dtm.Axis;
+import org.apache.xml.xdm.Axis;
import org.apache.xml.dtm.DTM;
1.4 +1 -1
xml-xalan/test/java/src/org/apache/qetest/dtm/TimeDTMIterator.java
Index: TimeDTMIterator.java
===================================================================
RCS file:
/home/cvs/xml-xalan/test/java/src/org/apache/qetest/dtm/TimeDTMIterator.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TimeDTMIterator.java 31 Jan 2003 15:47:17 -0000 1.3
+++ TimeDTMIterator.java 13 Feb 2003 18:34:24 -0000 1.4
@@ -56,7 +56,7 @@
*/
package org.apache.qetest.dtm;
-import org.apache.xml.dtm.Axis;
+import org.apache.xml.xdm.Axis;
import org.apache.xml.dtm.DTM;
1.5 +2 -2
xml-xalan/test/java/src/org/apache/qetest/dtm/TimeDTMTravDeep.java
Index: TimeDTMTravDeep.java
===================================================================
RCS file:
/home/cvs/xml-xalan/test/java/src/org/apache/qetest/dtm/TimeDTMTravDeep.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TimeDTMTravDeep.java 31 Jan 2003 15:47:17 -0000 1.4
+++ TimeDTMTravDeep.java 13 Feb 2003 18:34:24 -0000 1.5
@@ -63,7 +63,7 @@
import org.apache.qetest.FileBasedTest;
import org.apache.qetest.OutputNameManager;
import org.apache.qetest.xsl.XSLTestfileInfo;
-import org.apache.xml.dtm.Axis;
+import org.apache.xml.xdm.Axis;
import org.apache.xml.dtm.DTM;
@@ -280,4 +280,4 @@
app.doMain(args);
}
-}
\ No newline at end of file
+}
1.5 +1 -1
xml-xalan/test/java/src/org/apache/qetest/dtm/TimeDTMTraverser.java
Index: TimeDTMTraverser.java
===================================================================
RCS file:
/home/cvs/xml-xalan/test/java/src/org/apache/qetest/dtm/TimeDTMTraverser.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TimeDTMTraverser.java 31 Jan 2003 15:47:17 -0000 1.4
+++ TimeDTMTraverser.java 13 Feb 2003 18:34:24 -0000 1.5
@@ -56,7 +56,7 @@
*/
package org.apache.qetest.dtm;
-import org.apache.xml.dtm.Axis;
+import org.apache.xml.xdm.Axis;
import org.apache.xml.dtm.DTM;
1.1 xml-xalan/test/java/src/org/apache/qetest/xdm/TestXDMCurs.java
Index: TestXDMCurs.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2000, Lotus
* Development Corporation., http://www.lotus.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* TestXDMCurs.java
*
*/
package org.apache.qetest.xdm;
// Support for test reporting and harness classes
import org.apache.qetest.*;
import org.apache.qetest.xsl.*;
// java classes
import java.io.File;
import java.io.StringReader;
import java.io.FileOutputStream;
import java.util.Properties;
// Needed SAX, DOM, JAXP, Xalan classes
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamSource;
import org.apache.xml.xdm.*;
import org.apache.xml.xdm.ref.*;
import org.apache.xpath.objects.XMLStringFactoryImpl;
//-------------------------------------------------------------------------
/**
* This test creates an XDM and then walks it with axisIterators
* for each axis within XPATH
* - execute 'build package.trax', 'traxapitest TestXDMCurs.java'
* - a bunch of convenience variables/initializers are included,
* use or delete as is useful
* @author Paul Dick
* @author Joe Kesselman (adapted from DTM to XDM)
* @version $Id: TestXDMCurs.java,v 1.1 2003/02/13 18:34:25 jkesselm Exp $
*/
public class TestXDMCurs extends FileBasedTest
{
/**
* Provides nextName(), currentName() functionality for tests
* that may produce any number of output files.
*/
protected OutputNameManager outNames;
/**
* Information about an xsl/xml file pair for transforming.
* Public members include inputName (for xsl); xmlName; goldName; etc.
* If you don't use an .xml file on disk, you don't actually need this.
*/
protected XSLTestfileInfo testFileInfo = new XSLTestfileInfo();
/** Subdirectory under test\tests\api for our xsl/xml files. */
public static final String XDM_SUBDIR = "xdm";
public static final String CURS_Prefix = "Curs_";
public static final String defaultSource=
"<?xml version=\"1.0\"?>\n"+
"<Document xmlns:d=\"www.d.com\" a1=\"hello\" a2=\"goodbye\">"+
"<!-- Default test document -->"+
"<?api a1=\"yes\" a2=\"no\"?>"+
"<A><!-- A Subtree --><B><C><D><E><F xmlns:f=\"www.f.com\" a1=\"down\"
a2=\"up\"/></E></D></C></B></A>"+
"<Aa/><Ab/><Ac><Ac1/></Ac>"+
"<Ad xmlns:Ad=\"www.Ad.com\" xmlns:y=\"www.y.com\"
xmlns:z=\"www.z.com\">"+
"<Ad1/></Ad>"+
"</Document>";
static final String[] TYPENAME=
{ "NULL",
"ELEMENT",
"ATTRIBUTE",
"TEXT",
"CDATA_SECTION",
"ENTITY_REFERENCE",
"ENTITY",
"PROCESSING_INSTRUCTION",
"COMMENT",
"DOCUMENT",
"DOCUMENT_TYPE",
"DOCUMENT_FRAGMENT",
"NOTATION",
"NAMESPACE"
};
private XDMCursor lastNode; // Set by first axis, used by subsequent axis.
private String lastName;
private XDMCursor lastNode2; // Set by DESCENDANTORSELF, used in 11 & 12
private String lastName2;
private XDMCursor ANode; // Used in testcase 7 - 10
private String ANodeName;
private static xdmWSStripper stripper = new xdmWSStripper();
/** Just initialize test name, comment, numTestCases. */
public TestXDMCurs()
{
numTestCases = 12;
testName = "TestXDMCurs";
testComment = "Function test of XDMCursors";
}
/**
* Initialize this test - Set names of xml/xsl test files,
* REPLACE_other_test_file_init.
*
* @param p Properties to initialize from (if needed)
* @return false if we should abort the test; true otherwise
*/
public boolean doTestFileInit(Properties p)
{
// Used for all tests; just dump files in xdm subdir
File outSubDir = new File(outputDir + File.separator + XDM_SUBDIR);
if (!outSubDir.mkdirs())
reporter.logWarningMsg("Could not create output dir: " + outSubDir);
// Initialize an output name manager to that dir with .out extension
outNames = new OutputNameManager(outputDir + File.separator + XDM_SUBDIR
+ File.separator + testName, ".out");
String testBasePath = inputDir
+ File.separator
+ XDM_SUBDIR
+ File.separator;
String goldBasePath = goldDir
+ File.separator
+ XDM_SUBDIR
+ File.separator
+ CURS_Prefix;
//testFileInfo.inputName = testBasePath + "REPLACE_xslxml_filename.xsl";
//testFileInfo.xmlName = testBasePath + "REPLACE_xslxml_filename.xml";
testFileInfo.goldName = goldBasePath;
return true;
}
/**
* Cleanup this test - REPLACE_other_test_file_cleanup.
*
* @param p Properties to initialize from (if needed)
* @return false if we should abort the test; true otherwise
*/
public boolean doTestFileClose(Properties p)
{
// Often will be a no-op
return true;
}
/**
* Create AxisCursor and walk CHILD axis.
* @return false if we should abort the test; true otherwise
*/
public boolean testCase1()
{
reporter.testCaseInit("Walk CHILD AxisCursor");
StringBuffer buf = new StringBuffer();
FileOutputStream fos = openFileStream(outNames.nextName());
String gold = testFileInfo.goldName + "testcase1.out";
// Create xdm and generate initial context
XDMCursor doc = generateXDM();
// Get various nodes to use as context nodes.
XDMCursor xdmRoot = doc; // #document
String xdmRootName = xdmRoot.getNodeName(); // Used for output
XDMCursor DNode = xdmRoot.getAxisCursor(Axis.CHILD); // <Document>
String DNodeName = DNode.getNodeName();
XDMCursor CNode = DNode.getAxisCursor(Axis.CHILD); // <Comment>
// Use the cursor as an iterator, pulling a SELF
// cursor off the PINode to save state.
XDMCursor cNodeSibs=CNode.getAxisCursor(Axis.FOLLOWINGSIBLING);
XDMCursor PINode = cNodeSibs.singleNode(); // <PI>
cNodeSibs.nextNode();
ANode = cNodeSibs; // <A>
String ANodeName = ANode.getNodeName();
// Get a Cursor for CHILD:: axis and query it's direction.
XDMCursor iter = DNode.getAxisCursor(Axis.CHILD);
lastNode=DNode.singleNode();
// scan the axis and write node info to output file
for (boolean more=!iter.isEmpty();
more;
more=iter.nextNode())
{
buf.append(getNodeInfo(iter, " "));
lastNode.setIterationRoot(iter,null); //
Setting this GLOBAL IS BAD, but easy. Investigate!!
}
lastName = lastNode.getNodeName();
// Write results and close output file.
writeClose(fos, buf);
// Verify results
LinebyLineCheckService myfilechecker = new LinebyLineCheckService();
myfilechecker.check(reporter, new File(outNames.currentName()),
new File(gold),
"Testcase1");
reporter.testCaseClose();
return true;
}
/**
* Create AxisCursor and walk PARENT axis.
* @return false if we should abort the test; true otherwise
*/
public boolean testCase2()
{
reporter.testCaseInit("Walk PARENT AxisCursor");
StringBuffer buf = new StringBuffer();
FileOutputStream fos = openFileStream(outNames.nextName());
String gold = testFileInfo.goldName + "testcase2.out";
// Get a Cursor for PARENT:: axis.
XDMCursor iter = lastNode.getAxisCursor(Axis.PARENT);
// scan the axis and write node info to output file
for (boolean more=!iter.isEmpty();
more;
more=iter.nextNode())
buf.append(getNodeInfo(iter, " "));
// Write results and close output file.
writeClose(fos, buf);
// Verify results
LinebyLineCheckService myfilechecker = new LinebyLineCheckService();
myfilechecker.check(reporter, new File(outNames.currentName()),
new File(gold),
"Testcase2");
reporter.testCaseClose();
return true;
}
/**
* Create AxisCursor and walk SELF axis.
* @return false if we should abort the test; true otherwise
*/
public boolean testCase3()
{
reporter.testCaseInit("Walk SELF AxisCursor");
StringBuffer buf = new StringBuffer();
FileOutputStream fos = openFileStream(outNames.nextName());
String gold = testFileInfo.goldName + "testcase3.out";
// Get a Cursor for CHILD:: axis.
XDMCursor iter = lastNode.getAxisCursor(Axis.SELF);
// scan the axis and write node info to output file
for (boolean more=!iter.isEmpty();
more;
more=iter.nextNode())
buf.append(getNodeInfo(iter, " "));
// Write results and close output file.
writeClose(fos, buf);
// Verify results
LinebyLineCheckService myfilechecker = new LinebyLineCheckService();
myfilechecker.check(reporter, new File(outNames.currentName()),
new File(gold),
"Testcase3");
reporter.testCaseClose();
return true;
}
/**
* Create AxisCursor and walk NAMESPACE axis.
* @return false if we should abort the test; true otherwise
*/
public boolean testCase4()
{
reporter.testCaseInit("Walk NAMESPACE AxisCursor");
StringBuffer buf = new StringBuffer();
FileOutputStream fos = openFileStream(outNames.nextName());
String gold = testFileInfo.goldName + "testcase4.out";
// Get a Cursor for NAMESPACE:: axis.
XDMCursor iter = lastNode.getAxisCursor(Axis.NAMESPACE);
// scan the axis and write node info to output file
for (boolean more=!iter.isEmpty();
more;
more=iter.nextNode())
buf.append(getNodeInfo(iter, " "));
// Write results and close output file.
writeClose(fos, buf);
// Verify results
LinebyLineCheckService myfilechecker = new LinebyLineCheckService();
myfilechecker.check(reporter, new File(outNames.currentName()),
new File(gold),
"Testcase4");
reporter.testCaseClose();
return true;
}
/**
* Create AxisCursor and walk PRECEDING axis.
* @return false if we should abort the test; true otherwise
*/
public boolean testCase5()
{
reporter.testCaseInit("Walk PRECEDING AxisCursor");
StringBuffer buf = new StringBuffer();
FileOutputStream fos = openFileStream(outNames.nextName());
String gold = testFileInfo.goldName + "testcase5.out";
// Get a Cursor for PRECEDING:: axis.
XDMCursor iter = lastNode.getAxisCursor(Axis.PRECEDING);
// scan the axis and write node info to output file
for (boolean more=!iter.isEmpty();
more;
more=iter.nextNode())
buf.append(getNodeInfo(iter, " "));
// Write results and close output file.
writeClose(fos, buf);
// Verify results
LinebyLineCheckService myfilechecker = new LinebyLineCheckService();
myfilechecker.check(reporter, new File(outNames.currentName()),
new File(gold),
"Testcase5");
reporter.testCaseClose();
return true;
}
/**
* Create AxisCursor and walk PRECEDINGSIBLING axis.
* @return false if we should abort the test; true otherwise
*/
public boolean testCase6()
{
reporter.testCaseInit("Walk PRECEDINGSIBLING AxisCursor");
StringBuffer buf = new StringBuffer();
FileOutputStream fos = openFileStream(outNames.nextName());
String gold = testFileInfo.goldName + "testcase6.out";
// Get a Cursor for PRECEDINGSIBLING:: axis.
XDMCursor iter = lastNode.getAxisCursor(Axis.PRECEDINGSIBLING);
// scan the axis and write node info to output file
for (boolean more=!iter.isEmpty();
more;
more=iter.nextNode())
buf.append(getNodeInfo(iter, " "));
// Write results and close output file.
writeClose(fos, buf);
// Verify results
LinebyLineCheckService myfilechecker = new LinebyLineCheckService();
myfilechecker.check(reporter, new File(outNames.currentName()),
new File(gold),
"Testcase6");
reporter.testCaseClose();
return true;
}
/**
* Create AxisCursor and walk FOLLOWING axis.
* @return false if we should abort the test; true otherwise
*/
public boolean testCase7()
{
reporter.testCaseInit("Walk FOLLOWING AxisCursor");
StringBuffer buf = new StringBuffer();
FileOutputStream fos = openFileStream(outNames.nextName());
String gold = testFileInfo.goldName + "testcase7.out";
// Get a Cursor for FOLLOWING:: axis.
XDMCursor iter = ANode.getAxisCursor(Axis.FOLLOWING);
// scan the axis and write node info to output file
for (boolean more=!iter.isEmpty();
more;
more=iter.nextNode())
buf.append(getNodeInfo(iter, " "));
// Write results and close output file.
writeClose(fos, buf);
// Verify results
LinebyLineCheckService myfilechecker = new LinebyLineCheckService();
myfilechecker.check(reporter, new File(outNames.currentName()),
new File(gold),
"Testcase7");
reporter.testCaseClose();
return true;
}
/**
* Create AxisCursor and walk FOLLOWINGSIBLING axis.
* @return false if we should abort the test; true otherwise
*/
public boolean testCase8()
{
reporter.testCaseInit("Walk FOLLOWINGSIBLING AxisCursor");
StringBuffer buf = new StringBuffer();
FileOutputStream fos = openFileStream(outNames.nextName());
String gold = testFileInfo.goldName + "testcase8.out";
// Get a Cursor for FOLLOWINGSIBLING:: axis.
XDMCursor iter = ANode.getAxisCursor(Axis.FOLLOWINGSIBLING);
// scan the axis and write node info to output file
for (boolean more=!iter.isEmpty();
more;
more=iter.nextNode())
{ buf.append(getNodeInfo(iter, " "));
//lastNode = itNode;
}
// Write results and close output file.
writeClose(fos, buf);
// Verify results
LinebyLineCheckService myfilechecker = new LinebyLineCheckService();
myfilechecker.check(reporter, new File(outNames.currentName()),
new File(gold),
"Testcase8");
reporter.testCaseClose();
return true;
}
/**
* Create AxisCursor and walk DESCENDANT axis.
* @return false if we should abort the test; true otherwise
*/
public boolean testCase9()
{
reporter.testCaseInit("Walk DESCENDANT AxisCursor");
StringBuffer buf = new StringBuffer();
FileOutputStream fos = openFileStream(outNames.nextName());
String gold = testFileInfo.goldName + "testcase9.out";
// Get a Cursor for DESCENDANT:: axis.
XDMCursor iter = ANode.getAxisCursor(Axis.DESCENDANT);
// scan the axis and write node info to output file
for (boolean more=!iter.isEmpty();
more;
more=iter.nextNode())
buf.append(getNodeInfo(iter, " "));
// Write results and close output file.
writeClose(fos, buf);
// Verify results
LinebyLineCheckService myfilechecker = new LinebyLineCheckService();
myfilechecker.check(reporter, new File(outNames.currentName()),
new File(gold),
"Testcase9");
reporter.testCaseClose();
return true;
}
/**
* Create AxisCursor and walk DESCENDANTORSELF axis.
* @return false if we should abort the test; true otherwise
*/
public boolean testCase10()
{
reporter.testCaseInit("Walk DESCENDANTORSELF AxisCursor");
StringBuffer buf = new StringBuffer();
FileOutputStream fos = openFileStream(outNames.nextName());
String gold = testFileInfo.goldName + "testcase10.out";
// Get a Cursor for DESCENDANTORSELF:: axis.
XDMCursor iter = ANode.getAxisCursor(Axis.DESCENDANTORSELF);
lastNode2=iter.singleNode();
// scan the axis and write node info to output file
for (boolean more=!iter.isEmpty();
more;
more=iter.nextNode())
{
buf.append(getNodeInfo(iter, " "));
lastNode2.setIterationRoot(iter,null);
}
// Write results and close output file.
writeClose(fos, buf);
// Verify results
LinebyLineCheckService myfilechecker = new LinebyLineCheckService();
myfilechecker.check(reporter, new File(outNames.currentName()),
new File(gold),
"Testcase10");
reporter.testCaseClose();
return true;
}
/**
* Create AxisCursor and walk ANCESTOR axis.
* @return false if we should abort the test; true otherwise
*/
public boolean testCase11()
{
reporter.testCaseInit("Walk ANCESTOR AxisCursor");
StringBuffer buf = new StringBuffer();
FileOutputStream fos = openFileStream(outNames.nextName());
String gold = testFileInfo.goldName + "testcase11.out";
// Get a Cursor for ANCESTOR:: axis.
lastName2 = lastNode2.getNodeName();
XDMCursor iter = lastNode2.getAxisCursor(Axis.ANCESTOR);
// scan the axis and write node info to output file
for (boolean more=!iter.isEmpty();
more;
more=iter.nextNode())
buf.append(getNodeInfo(iter, " "));
// Write results and close output file.
writeClose(fos, buf);
// Verify results
LinebyLineCheckService myfilechecker = new LinebyLineCheckService();
myfilechecker.check(reporter, new File(outNames.currentName()),
new File(gold),
"Testcase11");
reporter.testCaseClose();
return true;
}
/**
* Create AxisCursor and walk ANCESTORORSELF axis.
* @return false if we should abort the test; true otherwise
*/
public boolean testCase12()
{
reporter.testCaseInit("Walk ANCESTORORSELF AxisCursor");
StringBuffer buf = new StringBuffer();
FileOutputStream fos = openFileStream(outNames.nextName());
String gold = testFileInfo.goldName + "testcase12.out";
// Get a Cursor for ANCESTORORSELF:: axis.
XDMCursor iter = lastNode2.getAxisCursor(Axis.ANCESTORORSELF);
// scan the axis and write node info to output file
for (boolean more=!iter.isEmpty();
more;
more=iter.nextNode())
buf.append(getNodeInfo(iter, " "));
// Write results and close output file.
writeClose(fos, buf);
// Verify results
LinebyLineCheckService myfilechecker = new LinebyLineCheckService();
myfilechecker.check(reporter, new File(outNames.currentName()),
new File(gold),
"Testcase12");
reporter.testCaseClose();
return true;
}
public String usage()
{
return ("Common [optional] options supported by TestXDMCurs:\n"
+ "(Note: assumes inputDir=.\\tests\\api)\n");
}
FileOutputStream openFileStream(String name)
{
FileOutputStream fos = null;
try
{ fos = new FileOutputStream(name); }
catch (Exception e)
{ reporter.checkFail("Failure opening output file."); }
return fos;
}
// This routine generates a new root XDMCursor for each testcase
XDMCursor generateXDM()
{
// Create XDM and generate initial context
// %REVIEW% We'll need to generalize this.
Source source = new StreamSource(new StringReader(defaultSource));
XDMManager manager= new XDMManagerDTM().newInstance(new
XMLStringFactoryImpl());
XDMCursor xdm=manager.getXDM(source, true, stripper, false, true);
return xdm;
}
void writeClose(FileOutputStream fos, StringBuffer buf)
{
// Write results and close output file.
try
{
fos.write(buf.toString().getBytes());
fos.close();
}
catch (Exception e)
{ reporter.checkFail("Failure writing output."); }
}
String getNodeInfo(XDMCursor node, String indent)
{
// Formatting hack -- suppress quotes when value is null, to distinguish
// it from "null".
String buf = new String("null");
String value=node.getNodeValue();
String vq = (value==null) ? "" : "\"";
// Skip outputing of text nodes. In most cases they clutter the output,
// besides I'm only interested in the elemental structure of the xdm.
if( node.getNodeType() != node.TEXT_NODE )
{
// node.toString() does most of this better...
buf = new String(indent+
//nodeHandle+": "+
TYPENAME[node.getNodeType()]+" "+
node.getNodeName()+" "+
//" Level=" + xdm.getLevel(nodeHandle)+" "+
"\tValue=" + vq + value + vq + "\n"
);
}
return buf;
}
/**
* Main method to run test from the command line - can be left alone.
* @param args command line argument array
*/
public static void main(String[] args)
{
TestXDMCurs app = new TestXDMCurs();
app.doMain(args);
}
}
1.1 xml-xalan/test/java/src/org/apache/qetest/xdm/TestXDMCursor.java
Index: TestXDMCursor.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, Lotus
* Development Corporation., http://www.lotus.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.qetest.xdm;
import java.io.StringReader;
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamSource;
import org.apache.xpath.objects.XMLStringFactoryImpl;
//import org.apache.xml.dtm.*;
//import org.apache.xml.dtm.ref.*;
import org.apache.xml.xdm.*;
import org.apache.xml.xdm.ref.*;
/**
* Unit test for XDMCursor, currently hardwired to the initial DTM implementation
*
* Loads an XML document from a file (or, if no filename is supplied,
* an internal string), then dumps its contents.
*
* %REVIEW% Extend to test other XDMs, incremental, DOM view of the DTM,
* whitespace-filtered, indexed/nonindexed, ...
* */
public class TestXDMCursor {
public static void main(String argv[])
{
System.out.println("\nTestXDMCursor -- Initial unit test of singletons and
axes\n");
try
{
// Pick our input source
Source source=null;
if(argv.length<1)
{
String defaultSource=
"<?xml version=\"1.0\"?>\n"+
"<Document xmlns:d=\"www.d.com\" a1=\"hello\" a2=\"goodbye\">"+
"<!-- Default test document -->"+
"<?api a1=\"yes\" a2=\"no\"?>"+
"<A><!-- A Subtree --><B><C><D><E><F xmlns:f=\"www.f.com\" a1=\"down\"
a2=\"up\"/></E></D></C></B></A>"+
"<Aa/><Ab/><Ac><Ac1/></Ac>"+
"<Ad xmlns:Ad=\"www.Ad.com\" xmlns:y=\"www.y.com\"
xmlns:z=\"www.z.com\">"+
"<Ad1/></Ad>"+
"</Document>";
source=new StreamSource(new StringReader(defaultSource));
}
else if (argv.length>1 && "X".equalsIgnoreCase(argv[1]))
{
// XNI stream startup goes here
// Remember to perform Schema validation, to obtain PSVI
annotations
}
else
{
// Read from a URI via whatever mechanism the DTMManager
prefers
source=new StreamSource(argv[0]);
}
// Get a DTM manager, and ask it to load the DTM "uniquely",
// with no whitespace filtering, nonincremental, but _with_
// indexing (a fairly common case, and avoids the special
// mode used for RTF DTMs).
// For testing with some of David Marston's files I do want to strip
whitespace.
xdmWSStripper stripper = new xdmWSStripper();
XDMManager manager= new XDMManagerDTM().newInstance(new
XMLStringFactoryImpl());
XDMCursor doc=manager.getXDM(source, true, stripper, false, true);
// Get various nodes to use as context nodes.
//
// XDM supports only axis navigation, not tree navigation;
// the equivalent of getFirstChild() or getNextSibling() is
// to get the children/siblings cursor, which will be
// initialized to point to the first instance. Note that
// these remain mutable -- if you want to protect them you
// need to clone the axis cursor or make a SELF cursor
// to that node.
XDMCursor xdmRoot = doc; // #document
String xdmRootName = xdmRoot.getNodeName(); // Used for output
XDMCursor DNode = xdmRoot.getAxisCursor(Axis.CHILD); // <Document>
String DNodeName = DNode.getNodeName();
XDMCursor CNode = DNode.getAxisCursor(Axis.CHILD); // <Comment>
// Use the cursor as an iterator, pulling a SELF
// cursor off the PINode to save state.
XDMCursor cNodeSibs=CNode.getAxisCursor(Axis.FOLLOWINGSIBLING);
XDMCursor PINode = cNodeSibs.singleNode(); // <PI>
cNodeSibs.nextNode();
XDMCursor ANode = cNodeSibs; // <A>
String ANodeName = ANode.getNodeName();
// Get a Iterator for CHILD:: axis, starting from DNode
XDMCursor iter=DNode.getAxisCursor(Axis.CHILD);
// SELF cursor -- mutable, so we can reset it each time.
XDMCursor lastNode=iter.singleNode();
// isReverse not currently supported, so I'm changing this message:
System.out.println("#### CHILD from "+"<"+DNodeName+">, Doc-ordered:" +
iter.isDocOrdered());
// Iterate the axis and print out node info.
// Note the need to check isEmpty before starting the loop
// ... this is slightly ugly, but seems to be unavoidable
// in the general case.
//
// %REVIEW% I hate to say it, but having nextNode return
// an object rather than a boolean *may* have been
// suboptimal.
for (boolean more=!iter.isEmpty();
more;
more=iter.nextNode())
{ printNode(iter, " ");
lastNode.setIterationRoot(iter,null);
}
String lastNodeName = lastNode.getNodeName();
// Get iterator for PARENT:: Axis
iter = lastNode.getAxisCursor(Axis.PARENT);
// isReverse not currently supported, so I'm changing this message:
System.out.println("\n#### PARENT from "+"<"+lastNodeName+">, Doc-ordered:"
+ iter.isDocOrdered());
// Iterate the axis and print out node info.
for (boolean more=!iter.isEmpty();
more;
more=iter.nextNode())
{ printNode(iter, " ");
}
// Get iterator for SELF:: Axis
iter = lastNode.getAxisCursor(Axis.SELF);
// isReverse not currently supported, so I'm changing this message:
System.out.println("\n#### SELF from "+"<"+lastNodeName+">, Doc-ordered:" +
iter.isDocOrdered());
// Iterate the axis and print out node info.
for (boolean more=!iter.isEmpty();
more;
more=iter.nextNode())
{ printNode(iter, " ");
}
/**** Not Implemented?
// Get iterator for NAMESPACEDECLS:: Axis
iter = doc.getAxisIterator(Axis.NAMESPACEDECLS);
iter.setStartNode(lastNode);
System.out.println("\n#### NAMESPACEDECLS from "+"<"+lastNodeName+">,
Reverse Axis:" + iter.isReverse());
// Iterate the axis and print out node info.
for (int itNode = iter.next(); doc.NULL != itNode;
itNode = iter.next())
printNode(xdm, itNode, " ");
****/
// Get iterator for NAMESPACE:: Axis
iter = lastNode.getAxisCursor(Axis.NAMESPACE);
// isReverse not currently supported, so I'm changing this message:
System.out.println("\n#### NAMESPACE from "+"<"+lastNodeName+">,
Doc-ordered:" + iter.isDocOrdered());
// Iterate the axis and print out node info.
for (boolean more=!iter.isEmpty();
more;
more=iter.nextNode())
{ printNode(iter, " ");
}
// Get iterator for PRECEDING:: Axis
iter = lastNode.getAxisCursor(Axis.PRECEDING);
// isReverse not currently supported, so I'm changing this message:
System.out.println("\n#### PRECEDING from "+"<"+lastNodeName+">,
Doc-ordered:" + iter.isDocOrdered());
// Iterate the axis and print out node info.
for (boolean more=!iter.isEmpty();
more;
more=iter.nextNode())
{ printNode(iter, " ");
}
// Get iterator for PRECEDINGSIBLING:: Axis
iter = lastNode.getAxisCursor(Axis.PRECEDINGSIBLING);
// isReverse not currently supported, so I'm changing this message:
System.out.println("\n#### PRECEDINGSIBLING from "+"<"+lastNodeName+">,
Doc-ordered:" + iter.isDocOrdered());
// Iterate the axis and print out node info.
for (boolean more=!iter.isEmpty();
more;
more=iter.nextNode())
{ printNode(iter, " ");
}
// Get iterator for ATTRIBUTE:: Axis
iter = lastNode.getAxisCursor(Axis.ATTRIBUTE);
// isReverse not currently supported, so I'm changing this message:
System.out.println("\n#### ATTRIBUTE from "+"<"+lastNodeName+">,
Doc-ordered:" + iter.isDocOrdered());
// Iterate the axis and print out node info.
for (boolean more=!iter.isEmpty();
more;
more=iter.nextNode())
{ printNode(iter, " ");
}
// Get iterator for FOLLOWING:: Axis
iter = lastNode.getAxisCursor(Axis.FOLLOWING);
// isReverse not currently supported, so I'm changing this message:
System.out.println("\n#### FOLLOWING from "+"<"+lastNodeName+">,
Doc-ordered:" + iter.isDocOrdered());
// Iterate the axis and print out node info.
for (boolean more=!iter.isEmpty();
more;
more=iter.nextNode())
{ printNode(iter, " ");
}
// Get iterator for FOLLOWINGSIBLING:: Axis
iter = lastNode.getAxisCursor(Axis.FOLLOWINGSIBLING);
// isReverse not currently supported, so I'm changing this message:
System.out.println("\n#### FOLLOWINGSIBLING from "+"<"+lastNodeName+">,
Doc-ordered:" + iter.isDocOrdered());
// Iterate the axis and print out node info.
for (boolean more=!iter.isEmpty();
more;
more=iter.nextNode())
{ printNode(iter, " ");
}
// Get iterator for DESCENDANT:: Axis
iter = lastNode.getAxisCursor(Axis.DESCENDANT);
// isReverse not currently supported, so I'm changing this message:
System.out.println("\n#### DESCENDANT from "+"<"+lastNodeName+">,
Doc-ordered:" + iter.isDocOrdered());
// Iterate the axis and print out node info.
for (boolean more=!iter.isEmpty();
more;
more=iter.nextNode())
{ printNode(iter, " ");
}
// Get iterator for DESCENDANTORSELF:: Axis
iter = lastNode.getAxisCursor(Axis.DESCENDANTORSELF);
// isReverse not currently supported, so I'm changing this message:
System.out.println("\n#### DESCENDANTORSELF from "+"<"+lastNodeName+">,
Doc-ordered:" + iter.isDocOrdered());
// Iterate the axis and print out node info.
for (boolean more=!iter.isEmpty();
more;
more=iter.nextNode())
{ printNode(iter, " ");
lastNode.setIterationRoot(iter,null);
}
// %BUG% In DTM, uncommenting provoked Bugzilla 7885
//lastNode = iter.getLast();
lastNodeName = lastNode.getNodeName();
// %BUG% The output from Ancestor and Ancestor-or-self is the topic
// of Bugzilla 7886
// Get iterator for ANCESTOR:: Axis
iter = lastNode.getAxisCursor(Axis.ANCESTOR);
// isReverse not currently supported, so I'm changing this message:
System.out.println("\n#### ANCESTOR from "+"<"+lastNodeName+">,
Doc-ordered:" + iter.isDocOrdered());
// Iterate the axis and print out node info.
for (boolean more=!iter.isEmpty();
more;
more=iter.nextNode())
{ printNode(iter, " ");
}
// Get iterator for ANCESTORORSELF:: Axis
iter = lastNode.getAxisCursor(Axis.ANCESTORORSELF);
// isReverse not currently supported, so I'm changing this message:
System.out.println("\n#### ANCESTORORSELF from "+"<"+lastNodeName+">,
Doc-ordered:" + iter.isDocOrdered());
// Iterate the axis and print out node info.
for (boolean more=!iter.isEmpty();
more;
more=iter.nextNode())
{ printNode(iter, " ");
}
/**** Absolute axis (ALL, DESCENDANTSFROMROOT, or DESCENDANTSORSELFFROMROOT) not
implemented.
// Get iterator for ALL:: Axis
// of previous iterator, i.e. lastNode.
iter = doc.getAxisIterator(Axis.ALL);
iter.setStartNode(lastNode);
System.out.println("\n#### ALL from "+"<"+lastNodeName+">, Reverse Axis:" +
iter.isReverse());
// Iterate the axis and print out node info.
for (int itNode = iter.next(); doc.NULL != itNode;
itNode = iter.next())
printNode(xdm, itNode, " ");
****/
}
catch(Exception e)
{
e.printStackTrace();
}
}
static void printNode(XDMCursor node, String indent)
{
// Briefly display this node
// Don't bother displaying namespaces or attrs; we do that at the
// next level up.
// Skip outputing of text nodes. In most cases they clutter the output,
// besides I'm only interested in the elemental structure of the node.
if( node.getNodeType() != XDMCursor.TEXT_NODE )
{
System.out.println(indent+node.toString());
}
}
}
1.1 xml-xalan/test/java/src/org/apache/qetest/xdm/xdmWSStripper.java
Index: xdmWSStripper.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, Lotus
* Development Corporation., http://www.lotus.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.qetest.xdm;
import org.apache.xml.xdm.*;
/**
* Impl of XDMWSFilter
*
* Currently it always returns TRUE.
* TODO:
* Make into a more general purpose stripper.
*
**/
class xdmWSStripper implements XDMWSFilter {
void dtmWSStripper()
{ }
public short getShouldStripSpace(XDMCursor node)
{
return XDMWSFilter.STRIP;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]