You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by cu...@apache.org on 2001/06/21 21:19:52 UTC
cvs commit: xml-xalan/test/java/src/org/apache/qetest/xslwrapper TraxSystemIdWrapper.java TransformWrapperFactory.properties TraxDOMWrapper.java TraxFileWrapper.java TraxSAXWrapper.java
curcuru 01/06/21 12:19:52
Modified: test/java/src/org/apache/qetest QetestUtils.java
test/java/src/org/apache/qetest/xsl
PerfEverythingTestlet.java PerfPreloadTestlet.java
PerformanceTestlet.java StylesheetDatalet.java
StylesheetErrorTestlet.java StylesheetTestlet.java
ThreadedStylesheetTestlet.java
test/java/src/org/apache/qetest/xslwrapper
TransformWrapperFactory.properties
TraxDOMWrapper.java TraxFileWrapper.java
TraxSAXWrapper.java
Added: test/java/src/org/apache/qetest/xslwrapper
TraxSystemIdWrapper.java
Log:
Update Testlets, et.al. and TransformWrapper subclasses to properly
pass local path/filename references around: previously, the code had
not matched it's javadoc, now it should.
Most StylesheetTestletDriver-related classes should manipulate and
pass local path/filenames; TransformWrapper subclasses are responsible
for translating these into URLs as needed.
Revision Changes Path
1.5 +23 -7 xml-xalan/test/java/src/org/apache/qetest/QetestUtils.java
Index: QetestUtils.java
===================================================================
RCS file: /home/cvs/xml-xalan/test/java/src/org/apache/qetest/QetestUtils.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- QetestUtils.java 2001/03/15 22:25:11 1.4
+++ QetestUtils.java 2001/06/21 19:19:28 1.5
@@ -64,7 +64,7 @@
* Static utility class for both general-purpose testing methods
* and a few XML-specific methods.
* @author shane_curcuru@lotus.com
- * @version $Id: QetestUtils.java,v 1.4 2001/03/15 22:25:11 curcuru Exp $
+ * @version $Id: QetestUtils.java,v 1.5 2001/06/21 19:19:28 curcuru Exp $
*/
public abstract class QetestUtils
{
@@ -81,11 +81,14 @@
* flavors of URLs at all.
*
* If the name is null, return null.
- * If the name starts with file:///, we just return that.
+ * If the name starts with a common URI scheme (namely the ones
+ * found in the examples of RFC2396), then simply return the
+ * name as-is (the assumption is that it's already a URL)
* Otherwise we attempt (cheaply) to convert to a file:/// URL.
*
* @param String local path\filename of a file
- * @return a file:/// URL, or null if error
+ * @return a file:/// URL, the same string if it appears to
+ * already be a URL, or null if error
*/
public static String filenameToURL(String filename)
{
@@ -93,9 +96,15 @@
if (null == filename)
return null;
- // Don't translate a string that already looks like
- // a file: URL
- if (filename.startsWith("file:///"))
+ // Don't translate a string that already looks like a URL
+ if (filename.startsWith("file:")
+ || filename.startsWith("http:")
+ || filename.startsWith("ftp:")
+ || filename.startsWith("gopher:")
+ || filename.startsWith("mailto:")
+ || filename.startsWith("news:")
+ || filename.startsWith("telnet:")
+ )
return filename;
File f = new File(filename);
@@ -117,7 +126,14 @@
tmp = tmp.replace('\\', '/');
}
// Note the presumption that it's a file reference
- return "file:///" + tmp;
+ // Attempt to not add too many extra slashes on the
+ // front if it already starts with a slash
+ //@todo evaluate if this is really correct!
+ if (filename.startsWith("/"))
+ return "file://" + tmp;
+ else
+ return "file:///" + tmp;
+
}
1.6 +4 -10 xml-xalan/test/java/src/org/apache/qetest/xsl/PerfEverythingTestlet.java
Index: PerfEverythingTestlet.java
===================================================================
RCS file: /home/cvs/xml-xalan/test/java/src/org/apache/qetest/xsl/PerfEverythingTestlet.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- PerfEverythingTestlet.java 2001/03/16 21:30:22 1.5
+++ PerfEverythingTestlet.java 2001/06/21 19:19:31 1.6
@@ -81,7 +81,7 @@
* purposes, we really need to do it all here.
*
* @author Shane_Curcuru@lotus.com
- * @version $Id: PerfEverythingTestlet.java,v 1.5 2001/03/16 21:30:22 curcuru Exp $
+ * @version $Id: PerfEverythingTestlet.java,v 1.6 2001/06/21 19:19:31 curcuru Exp $
*/
public class PerfEverythingTestlet extends TestletImpl
{
@@ -214,17 +214,11 @@
// Test our supplied file in multiple ways, logging performance data
try
{
- // Setup: Store local copies of XSL, XML references for
- // potential change to URLs
+ // Store local copies of XSL, XML references to avoid
+ // potential for changing datalet
String inputName = datalet.inputName;
String xmlName = datalet.xmlName;
- if (datalet.useURL)
- {
- // inputName may not exist if it's an embedded test
- if (null != inputName)
- inputName = QetestUtils.filenameToURL(inputName);
- xmlName = QetestUtils.filenameToURL(xmlName);
- }
+
logger.logMsg(Logger.TRACEMSG, "executing with: inputName=" + inputName
+ " xmlName=" + xmlName + " outputName=" + datalet.outputName
+ " goldName=" + datalet.goldName + " flavor=" + datalet.flavor
1.3 +3 -10 xml-xalan/test/java/src/org/apache/qetest/xsl/PerfPreloadTestlet.java
Index: PerfPreloadTestlet.java
===================================================================
RCS file: /home/cvs/xml-xalan/test/java/src/org/apache/qetest/xsl/PerfPreloadTestlet.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PerfPreloadTestlet.java 2001/03/02 20:11:43 1.2
+++ PerfPreloadTestlet.java 2001/06/21 19:19:33 1.3
@@ -72,7 +72,7 @@
* precompiled/prebuilt stylesheets.
*
* @author Shane_Curcuru@lotus.com
- * @version $Id: PerfPreloadTestlet.java,v 1.2 2001/03/02 20:11:43 curcuru Exp $
+ * @version $Id: PerfPreloadTestlet.java,v 1.3 2001/06/21 19:19:33 curcuru Exp $
*/
public class PerfPreloadTestlet extends TestletImpl
{
@@ -156,17 +156,10 @@
}
catch (Exception e) { /* no-op, leave as default */ }
- // Store local copies of XSL, XML references for
- // potential change to URLs
+ // Store local copies of XSL, XML references to avoid
+ // potential for changing datalet
String inputName = datalet.inputName;
String xmlName = datalet.xmlName;
- if (datalet.useURL)
- {
- // inputName may not exist if it's an embedded test
- if (null != inputName)
- inputName = QetestUtils.filenameToURL(inputName);
- xmlName = QetestUtils.filenameToURL(xmlName);
- }
// Create a new ProcessorWrapper of appropriate flavor
ProcessorWrapper processorWrapper = ProcessorWrapper.getWrapper(datalet.flavor);
1.5 +4 -10 xml-xalan/test/java/src/org/apache/qetest/xsl/PerformanceTestlet.java
Index: PerformanceTestlet.java
===================================================================
RCS file: /home/cvs/xml-xalan/test/java/src/org/apache/qetest/xsl/PerformanceTestlet.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- PerformanceTestlet.java 2001/03/02 20:11:40 1.4
+++ PerformanceTestlet.java 2001/06/21 19:19:33 1.5
@@ -71,7 +71,7 @@
* Testlet to capture basic timing performance data.
*
* @author Shane_Curcuru@lotus.com
- * @version $Id: PerformanceTestlet.java,v 1.4 2001/03/02 20:11:40 curcuru Exp $
+ * @version $Id: PerformanceTestlet.java,v 1.5 2001/06/21 19:19:33 curcuru Exp $
*/
public class PerformanceTestlet extends TestletImpl
{
@@ -163,17 +163,11 @@
return;
}
- // Store local copies of XSL, XML references for
- // potential change to URLs
+ // Store local copies of XSL, XML references to avoid
+ // potential for changing datalet
String inputName = datalet.inputName;
String xmlName = datalet.xmlName;
- if (datalet.useURL)
- {
- // inputName may not exist if it's an embedded test
- if (null != inputName)
- inputName = QetestUtils.filenameToURL(inputName);
- xmlName = QetestUtils.filenameToURL(xmlName);
- }
+
logger.logMsg(Logger.TRACEMSG, "executing with: inputName=" + inputName
+ " xmlName=" + xmlName + " outputName=" + datalet.outputName
+ " goldName=" + datalet.goldName + " flavor=" + datalet.flavor
1.4 +1 -10 xml-xalan/test/java/src/org/apache/qetest/xsl/StylesheetDatalet.java
Index: StylesheetDatalet.java
===================================================================
RCS file: /home/cvs/xml-xalan/test/java/src/org/apache/qetest/xsl/StylesheetDatalet.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- StylesheetDatalet.java 2001/06/15 17:47:13 1.3
+++ StylesheetDatalet.java 2001/06/21 19:19:34 1.4
@@ -72,7 +72,7 @@
* Datalet for conformance testing of xsl stylesheet files.
* Should serve as a base class for other XSLT related Datalets.
* @author Shane_Curcuru@lotus.com
- * @version $Id: StylesheetDatalet.java,v 1.3 2001/06/15 17:47:13 curcuru Exp $
+ * @version $Id: StylesheetDatalet.java,v 1.4 2001/06/21 19:19:34 curcuru Exp $
*/
public class StylesheetDatalet implements Datalet
{
@@ -90,15 +90,6 @@
/** Flavor of a ProcessorWrapper to use; default:trax. */
public String flavor = "trax"; //@todo should be ProcessorWrapper.DEFAULT_FLAVOR
-
- /**
- * If we should force any local path\filenames to URLs.
- * Note: This is not really the best place for this, but
- * since it works with Xerces and Crimson and Xalan, it's
- * good enough for now.
- * Not currently settable by user; default:true
- */
- public boolean useURL = true;
/**
* Generic placeholder for any additional options.
1.2 +3 -11 xml-xalan/test/java/src/org/apache/qetest/xsl/StylesheetErrorTestlet.java
Index: StylesheetErrorTestlet.java
===================================================================
RCS file: /home/cvs/xml-xalan/test/java/src/org/apache/qetest/xsl/StylesheetErrorTestlet.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- StylesheetErrorTestlet.java 2001/05/15 20:09:11 1.1
+++ StylesheetErrorTestlet.java 2001/06/21 19:19:35 1.2
@@ -102,7 +102,7 @@
* produce an output file (that's the subject of another test...)
*
* @author Shane_Curcuru@lotus.com
- * @version $Id: StylesheetErrorTestlet.java,v 1.1 2001/05/15 20:09:11 curcuru Exp $
+ * @version $Id: StylesheetErrorTestlet.java,v 1.2 2001/06/21 19:19:35 curcuru Exp $
*/
public class StylesheetErrorTestlet extends TestletImpl
{
@@ -194,18 +194,10 @@
// Read in expectedExecption from datalet or stylesheet file
Vector expectedException = getExpectedException(datalet);
- // Store local copies of XSL, XML references for
- // potential change to URLs
+ // Store local copies of XSL, XML references to avoid
+ // potential for changing datalet
String inputName = datalet.inputName;
String xmlName = datalet.xmlName;
- if (datalet.useURL)
- {
- // inputName may not exist if it's an embedded test
- if (null != inputName)
- inputName = QetestUtils.filenameToURL(inputName);
- if (null != xmlName)
- xmlName = QetestUtils.filenameToURL(xmlName);
- }
//@todo Should we log a custom logElement here instead?
// Be sure to log everything before we start the test!
1.3 +3 -10 xml-xalan/test/java/src/org/apache/qetest/xsl/StylesheetTestlet.java
Index: StylesheetTestlet.java
===================================================================
RCS file: /home/cvs/xml-xalan/test/java/src/org/apache/qetest/xsl/StylesheetTestlet.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- StylesheetTestlet.java 2001/03/16 17:00:18 1.2
+++ StylesheetTestlet.java 2001/06/21 19:19:36 1.3
@@ -89,7 +89,7 @@
* as different processing models, like SAX, DOM or Streams).
*
* @author Shane_Curcuru@lotus.com
- * @version $Id: StylesheetTestlet.java,v 1.2 2001/03/16 17:00:18 curcuru Exp $
+ * @version $Id: StylesheetTestlet.java,v 1.3 2001/06/21 19:19:36 curcuru Exp $
*/
public class StylesheetTestlet extends TestletImpl
{
@@ -175,17 +175,10 @@
// Test our supplied input file, and compare with gold
try
{
- // Store local copies of XSL, XML references for
- // potential change to URLs
+ // Store local copies of XSL, XML references to avoid
+ // potential for changing datalet
String inputName = datalet.inputName;
String xmlName = datalet.xmlName;
- if (datalet.useURL)
- {
- // inputName may not exist if it's an embedded test
- if (null != inputName)
- inputName = QetestUtils.filenameToURL(inputName);
- xmlName = QetestUtils.filenameToURL(xmlName);
- }
//@todo Should we log a custom logElement here instead?
logger.logMsg(Logger.TRACEMSG, "executing with: inputName=" + inputName
1.2 +5 -16 xml-xalan/test/java/src/org/apache/qetest/xsl/ThreadedStylesheetTestlet.java
Index: ThreadedStylesheetTestlet.java
===================================================================
RCS file: /home/cvs/xml-xalan/test/java/src/org/apache/qetest/xsl/ThreadedStylesheetTestlet.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ThreadedStylesheetTestlet.java 2001/06/15 17:48:03 1.1
+++ ThreadedStylesheetTestlet.java 2001/06/21 19:19:37 1.2
@@ -91,7 +91,7 @@
* of calling execute(). @todo find a better way to integrate!
*
* @author Shane_Curcuru@lotus.com
- * @version $Id: ThreadedStylesheetTestlet.java,v 1.1 2001/06/15 17:48:03 curcuru Exp $
+ * @version $Id: ThreadedStylesheetTestlet.java,v 1.2 2001/06/21 19:19:37 curcuru Exp $
*/
public class ThreadedStylesheetTestlet
extends TestletImpl
@@ -320,13 +320,9 @@
// just go ahead and ask it to transform
try
{
- // Store local copies of XSL, XML references for
- // potential change to URLs
+ // Store local copies of XSL, XML references to avoid
+ // potential for changing datalet
String xmlName = datalet.xmlName;
- if (datalet.useURL)
- {
- xmlName = QetestUtils.filenameToURL(xmlName);
- }
//@todo Should we log a custom logElement here instead?
logger.logMsg(Logger.TRACEMSG, "About to test shared Templates: "
@@ -402,17 +398,10 @@
// Test our supplied input file, and compare with gold
try
{
- // Store local copies of XSL, XML references for
- // potential change to URLs
+ // Store local copies of XSL, XML references to avoid
+ // potential for changing datalet
String inputName = datalet.inputName;
String xmlName = datalet.xmlName;
- if (datalet.useURL)
- {
- // inputName may not exist if it's an embedded test
- if (null != inputName)
- inputName = QetestUtils.filenameToURL(inputName);
- xmlName = QetestUtils.filenameToURL(xmlName);
- }
//@todo Should we log a custom logElement here instead?
logger.logMsg(Logger.TRACEMSG, "About to test: inputName=" + inputName
1.3 +5 -2 xml-xalan/test/java/src/org/apache/qetest/xslwrapper/TransformWrapperFactory.properties
Index: TransformWrapperFactory.properties
===================================================================
RCS file: /home/cvs/xml-xalan/test/java/src/org/apache/qetest/xslwrapper/TransformWrapperFactory.properties,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TransformWrapperFactory.properties 2001/04/27 20:11:20 1.2
+++ TransformWrapperFactory.properties 2001/06/21 19:19:44 1.3
@@ -5,11 +5,14 @@
# Default for Xalan2 and TrAX is the TraxFileWrapper, which
# does transforms from StreamSource(URL)
-xalan2=org.apache.qetest.xslwrapper.TraxFileWrapper
-trax=org.apache.qetest.xslwrapper.TraxFileWrapper
+xalan2=org.apache.qetest.xslwrapper.TraxSystemIdWrapper
+trax=org.apache.qetest.xslwrapper.TraxSystemIdWrapper
# Other TrAX wrappers use the same TrAX APIs but in
# different models - streams, doms, sax, etc.
+# Note that you must set the appropriate Java system property to switch
+# between different javax.xml.transform.TransformerFactory implementations
+trax.systemId=org.apache.qetest.xslwrapper.TraxSystemIdWrapper
trax.file=org.apache.qetest.xslwrapper.TraxFileWrapper
trax.stream=org.apache.qetest.xslwrapper.TraxStreamWrapper
trax.dom=org.apache.qetest.xslwrapper.TraxDOMWrapper
1.2 +18 -11 xml-xalan/test/java/src/org/apache/qetest/xslwrapper/TraxDOMWrapper.java
Index: TraxDOMWrapper.java
===================================================================
RCS file: /home/cvs/xml-xalan/test/java/src/org/apache/qetest/xslwrapper/TraxDOMWrapper.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TraxDOMWrapper.java 2001/03/16 16:59:44 1.1
+++ TraxDOMWrapper.java 2001/06/21 19:19:45 1.2
@@ -62,6 +62,7 @@
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
@@ -96,7 +97,7 @@
* //@todo add in checks for factory.getFeature(DOMSource.FEATURE)
*
* @author Shane Curcuru
- * @version $Id: TraxDOMWrapper.java,v 1.1 2001/03/16 16:59:44 curcuru Exp $
+ * @version $Id: TraxDOMWrapper.java,v 1.2 2001/06/21 19:19:45 curcuru Exp $
*/
public class TraxDOMWrapper extends TransformWrapperHelper
{
@@ -171,6 +172,12 @@
//@todo do we need to do any other cleanup?
reset(false);
factory = TransformerFactory.newInstance();
+ // Verify the factory supports DOM!
+ if (!(factory.getFeature(DOMSource.FEATURE)
+ && factory.getFeature(DOMResult.FEATURE)))
+ {
+ throw new TransformerConfigurationException("TraxDOMWrapper.newProcessor: factory does not support DOM!");
+ }
return (Object)factory;
}
@@ -212,12 +219,12 @@
// Timed: read xsl into a DOM
startTime = System.currentTimeMillis();
- Node xslNode = docBuilder.parse(new InputSource(xslName));
+ Node xslNode = docBuilder.parse(new InputSource(QetestUtils.filenameToURL(xslName)));
xslRead = System.currentTimeMillis() - startTime;
// Untimed: create DOMSource and setSystemId
DOMSource xslSource = new DOMSource(xslNode);
- xslSource.setSystemId(xslName);
+ xslSource.setSystemId(QetestUtils.filenameToURL(xslName));
// Timed: build Transformer from DOMSource
startTime = System.currentTimeMillis();
@@ -226,12 +233,12 @@
// Timed: read xml into a DOM
startTime = System.currentTimeMillis();
- Node xmlNode = docBuilder.parse(new InputSource(xmlName));
+ Node xmlNode = docBuilder.parse(new InputSource(QetestUtils.filenameToURL(xmlName)));
xmlRead = System.currentTimeMillis() - startTime;
// Untimed: create DOMSource and setSystemId
DOMSource xmlSource = new DOMSource(xmlNode);
- xmlSource.setSystemId(xmlName);
+ xmlSource.setSystemId(QetestUtils.filenameToURL(xmlName));
// Untimed: create DOMResult
Document outNode = docBuilder.newDocument();
@@ -308,12 +315,12 @@
// Timed: read xsl into a DOM
startTime = System.currentTimeMillis();
- Node xslNode = docBuilder.parse(new InputSource(xslName));
+ Node xslNode = docBuilder.parse(new InputSource(QetestUtils.filenameToURL(xslName)));
xslRead = System.currentTimeMillis() - startTime;
// Untimed: create DOMSource and setSystemId
DOMSource xslSource = new DOMSource(xslNode);
- xslSource.setSystemId(xslName);
+ xslSource.setSystemId(QetestUtils.filenameToURL(xslName));
// Timed: build Templates from DOMSource
startTime = System.currentTimeMillis();
@@ -375,12 +382,12 @@
// Timed: read xml into a DOM
startTime = System.currentTimeMillis();
- Node xmlNode = docBuilder.parse(new InputSource(xmlName));
+ Node xmlNode = docBuilder.parse(new InputSource(QetestUtils.filenameToURL(xmlName)));
xmlRead = System.currentTimeMillis() - startTime;
// Untimed: create DOMSource and setSystemId
DOMSource xmlSource = new DOMSource(xmlNode);
- xmlSource.setSystemId(xmlName);
+ xmlSource.setSystemId(QetestUtils.filenameToURL(xmlName));
// Untimed: create DOMResult
Document outNode = docBuilder.newDocument();
@@ -454,12 +461,12 @@
// Timed: read xml into a DOM
startTime = System.currentTimeMillis();
- Node xmlNode = docBuilder.parse(new InputSource(xmlName));
+ Node xmlNode = docBuilder.parse(new InputSource(QetestUtils.filenameToURL(xmlName)));
xmlRead = System.currentTimeMillis() - startTime;
// Untimed: create DOMSource and setSystemId
DOMSource xmlSource = new DOMSource(xmlNode);
- xmlSource.setSystemId(xmlName);
+ xmlSource.setSystemId(QetestUtils.filenameToURL(xmlName));
// Timed: readxsl from the xml document
startTime = System.currentTimeMillis();
1.2 +23 -9 xml-xalan/test/java/src/org/apache/qetest/xslwrapper/TraxFileWrapper.java
Index: TraxFileWrapper.java
===================================================================
RCS file: /home/cvs/xml-xalan/test/java/src/org/apache/qetest/xslwrapper/TraxFileWrapper.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TraxFileWrapper.java 2001/03/16 16:59:44 1.1
+++ TraxFileWrapper.java 2001/06/21 19:19:46 1.2
@@ -60,10 +60,12 @@
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
+import java.io.File;
import java.util.Hashtable;
import java.util.Properties;
@@ -71,13 +73,17 @@
* Implementation of TransformWrapper that uses the TrAX API and
* uses files for it's sources.
*
+ * This is the second most common usage:
+ * transformer = factory.newTransformer(new StreamSource(new File(xslName)));
+ * transformer.transform(new StreamSource(new File(xmlName)), new StreamResult(resultFileName));
+ *
* <b>Important!</b> The underlying System property of
* javax.xml.transform.TransformerFactory will determine the actual
* TrAX implementation used. This value will be reported out in
* our getProcessorInfo() method.
*
* @author Shane Curcuru
- * @version $Id: TraxFileWrapper.java,v 1.1 2001/03/16 16:59:44 curcuru Exp $
+ * @version $Id: TraxFileWrapper.java,v 1.2 2001/06/21 19:19:46 curcuru Exp $
*/
public class TraxFileWrapper extends TransformWrapperHelper
{
@@ -107,7 +113,7 @@
*/
public String getDescription()
{
- return "Uses TrAX to perform transforms from StreamSource(systemId)";
+ return "Uses TrAX to perform transforms from StreamSource(new File(filename))";
}
@@ -123,7 +129,7 @@
public Properties getProcessorInfo()
{
Properties p = TraxWrapperUtils.getTraxInfo();
- p.put("traxwrapper.method", "dom");
+ p.put("traxwrapper.method", "file");
p.put("traxwrapper.desc", getDescription());
return p;
}
@@ -152,6 +158,12 @@
//@todo do we need to do any other cleanup?
reset(false);
factory = TransformerFactory.newInstance();
+ // Verify the factory supports Streams!
+ if (!(factory.getFeature(StreamSource.FEATURE)
+ && factory.getFeature(StreamResult.FEATURE)))
+ {
+ throw new TransformerConfigurationException("TraxFileWrapper.newProcessor: factory does not support Streams!");
+ }
return (Object)factory;
}
@@ -186,7 +198,7 @@
// Timed: read/build xsl from a URL
startTime = System.currentTimeMillis();
- Transformer transformer = factory.newTransformer(new StreamSource(xslName));
+ Transformer transformer = factory.newTransformer(new StreamSource(new File(xslName)));
xslBuild = System.currentTimeMillis() - startTime;
// Untimed: Apply any parameters needed
@@ -194,7 +206,7 @@
// Timed: read/build xml, transform, and write results
startTime = System.currentTimeMillis();
- transformer.transform(new StreamSource(xmlName), new StreamResult(resultName));
+ transformer.transform(new StreamSource(new File(xmlName)), new StreamResult(resultName));
transform = System.currentTimeMillis() - startTime;
long[] times = getTimeArray();
@@ -239,7 +251,7 @@
// Timed: read/build xsl from a URL
startTime = System.currentTimeMillis();
- builtTemplates = factory.newTemplates(new StreamSource(xslName));
+ builtTemplates = factory.newTemplates(new StreamSource(new File(xslName)));
xslBuild = System.currentTimeMillis() - startTime;
m_stylesheetReady = true;
@@ -291,7 +303,8 @@
// Timed: read/build xml, transform, and write results
startTime = System.currentTimeMillis();
- transformer.transform(new StreamSource(xmlName), new StreamResult(resultName));
+ transformer.transform(new StreamSource(new File(xmlName)),
+ new StreamResult(resultName));
transform = System.currentTimeMillis() - startTime;
long[] times = getTimeArray();
@@ -334,7 +347,7 @@
// Timed: readxsl from the xml document
startTime = System.currentTimeMillis();
- Source xslSource = factory.getAssociatedStylesheet(new StreamSource(xmlName),
+ Source xslSource = factory.getAssociatedStylesheet(new StreamSource(new File(xmlName)),
null, null, null);
xslRead = System.currentTimeMillis() - startTime;
@@ -348,7 +361,8 @@
// Timed: read/build xml, transform, and write results
startTime = System.currentTimeMillis();
- transformer.transform(new StreamSource(xmlName), new StreamResult(resultName));
+ transformer.transform(new StreamSource(new File(xmlName)),
+ new StreamResult(resultName));
transform = System.currentTimeMillis() - startTime;
long[] times = getTimeArray();
1.2 +11 -15 xml-xalan/test/java/src/org/apache/qetest/xslwrapper/TraxSAXWrapper.java
Index: TraxSAXWrapper.java
===================================================================
RCS file: /home/cvs/xml-xalan/test/java/src/org/apache/qetest/xslwrapper/TraxSAXWrapper.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TraxSAXWrapper.java 2001/06/01 15:19:45 1.1
+++ TraxSAXWrapper.java 2001/06/21 19:19:46 1.2
@@ -90,12 +90,8 @@
* Implementation of TransformWrapper that uses the TrAX API and
* uses SAXSource/SAXResult whenever possible.
*
- * <p>This implementation separates the process of reading xml and xsl
- * files from disk into byte arrays out from the time processing of
- * a new StreamSource(byte[]) takes to build a stylesheet.
- * It also separates the time of performing the transformation
- * to a StreamResult(byte[]) from the time spent simply sending
- * the byte[] through a FileOutputStream to disk.</p>
+ * <p>This implementation uses SAX to build the stylesheet and
+ * to perform the transformation.</p>
*
* <p><b>Important!</b> The underlying System property of
* javax.xml.transform.TransformerFactory will determine the actual
@@ -103,7 +99,7 @@
* our getProcessorInfo() method.</p>
*
* @author Shane Curcuru
- * @version $Id: TraxSAXWrapper.java,v 1.1 2001/06/01 15:19:45 curcuru Exp $
+ * @version $Id: TraxSAXWrapper.java,v 1.2 2001/06/21 19:19:46 curcuru Exp $
*/
public class TraxSAXWrapper extends TransformWrapperHelper
{
@@ -135,11 +131,11 @@
/**
* Get a general description of this wrapper itself.
*
- * @return Uses TrAX to perform transforms from StreamSource(systemId)
+ * @return Uses TrAX to perform transforms from SAXSource(systemId)
*/
public String getDescription()
{
- return "Uses TrAX to perform transforms from StreamSource(stream)";
+ return "Uses TrAX to perform transforms from SAXSource(stream)";
}
@@ -246,7 +242,7 @@
// Timed: read/build Templates from StreamSource
startTime = System.currentTimeMillis();
- xslReader.parse(xslName);
+ xslReader.parse(QetestUtils.filenameToURL(xslName));
xslBuild = System.currentTimeMillis() - startTime;
// Get the Templates object from the ContentHandler.
@@ -258,7 +254,7 @@
// Create a ContentHandler to handle parsing of the XML
TransformerHandler stylesheetHandler = saxFactory.newTransformerHandler(templates);
// Also set systemId to the stylesheet
- stylesheetHandler.setSystemId(xslName);
+ stylesheetHandler.setSystemId(QetestUtils.filenameToURL(xslName));
// Apply any parameters needed
applyParameters(stylesheetHandler.getTransformer());
@@ -315,7 +311,7 @@
// Timed: Parse the XML input document and do transform
startTime = System.currentTimeMillis();
- xmlReader.parse(xmlName);
+ xmlReader.parse(QetestUtils.filenameToURL(xmlName));
transform = System.currentTimeMillis() - startTime;
// Timed: writeResults from the byte array
@@ -377,11 +373,11 @@
// Timed: read/build Templates from StreamSource
startTime = System.currentTimeMillis();
- xslReader.parse(xslName);
+ xslReader.parse(QetestUtils.filenameToURL(xslName));
xslBuild = System.currentTimeMillis() - startTime;
// Also set systemId to the stylesheet
- templatesHandler.setSystemId(xslName);
+ templatesHandler.setSystemId(QetestUtils.filenameToURL(xslName));
// Get the Templates object from the ContentHandler.
builtTemplates = templatesHandler.getTemplates();
@@ -494,7 +490,7 @@
// Timed: Parse the XML input document and do transform
startTime = System.currentTimeMillis();
- xmlReader.parse(xmlName);
+ xmlReader.parse(QetestUtils.filenameToURL(xmlName));
transform = System.currentTimeMillis() - startTime;
// Timed: writeResults from the byte array
1.1 xml-xalan/test/java/src/org/apache/qetest/xslwrapper/TraxSystemIdWrapper.java
Index: TraxSystemIdWrapper.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001 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 apache@apache.org.
*
* 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.xslwrapper;
import org.apache.qetest.QetestUtils;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import java.util.Hashtable;
import java.util.Properties;
/**
* Implementation of TransformWrapper that uses the TrAX API and
* uses systemId URL's for it's sources.
*
* This is the most common usage:
* transformer = factory.newTransformer(new StreamSource(xslURL));
* transformer.transform(new StreamSource(xmlURL), new StreamResult(resultFileName));
*
* <b>Important!</b> The underlying System property of
* javax.xml.transform.TransformerFactory will determine the actual
* TrAX implementation used. This value will be reported out in
* our getProcessorInfo() method.
*
* @author Shane Curcuru
* @version $Id: TraxSystemIdWrapper.java,v 1.1 2001/06/21 19:19:48 curcuru Exp $
*/
public class TraxSystemIdWrapper extends TransformWrapperHelper
{
/**
* TransformerFactory to use; constructed in newProcessor().
*/
protected TransformerFactory factory = null;
/**
* Templates to use for buildStylesheet().
*/
protected Templates builtTemplates = null;
/**
* Cached copy of newProcessor() Hashtable.
*/
protected Hashtable newProcessorOpts = null;
/**
* Get a general description of this wrapper itself.
*
* @return Uses TrAX to perform transforms from StreamSource(systemId)
*/
public String getDescription()
{
return "Uses TrAX to perform transforms from StreamSource(systemId)";
}
/**
* Get a specific description of the wrappered processor.
*
* @return specific description of the underlying processor or
* transformer implementation: this should include both the
* general product name, as well as specific version info. If
* possible, should be implemented without actively creating
* an underlying processor.
*/
public Properties getProcessorInfo()
{
Properties p = TraxWrapperUtils.getTraxInfo();
p.put("traxwrapper.method", "systemId");
p.put("traxwrapper.desc", getDescription());
return p;
}
/**
* Actually create/initialize an underlying processor or factory.
*
* For TrAX/javax.xml.transform implementations, this creates
* a new TransformerFactory. For Xalan-J 1.x this creates an
* XSLTProcessor. Other implmentations may or may not actually
* do any work in this method.
*
* @param options Hashtable of options, unused.
*
* @return (Object)getProcessor() as a side-effect, this will
* be null if there was any problem creating the processor OR
* if the underlying implementation doesn't use this
*
* @throws Exception covers any underlying exceptions thrown
* by the actual implementation
*/
public Object newProcessor(Hashtable options) throws Exception
{
newProcessorOpts = options;
//@todo do we need to do any other cleanup?
reset(false);
factory = TransformerFactory.newInstance();
// Verify the factory supports Streams!
if (!(factory.getFeature(StreamSource.FEATURE)
&& factory.getFeature(StreamResult.FEATURE)))
{
throw new TransformerConfigurationException("TraxSystemIdWrapper.newProcessor: factory does not support Streams!");
}
return (Object)factory;
}
/**
* Transform supplied xmlName file with the stylesheet in the
* xslName file into a resultName file.
*
* Names are assumed to be local path\filename references, and
* will be converted to URLs as needed for any underlying
* processor implementation.
*
* @param xmlName local path\filename of XML file to transform
* @param xslName local path\filename of XSL stylesheet to use
* @param resultName local path\filename to put result in
*
* @return array of longs denoting timing of only these parts of
* our operation: IDX_OVERALL, IDX_XSLBUILD, IDX_TRANSFORM
*
* @throws Exception any underlying exceptions from the
* wrappered processor are simply allowed to propagate; throws
* a RuntimeException if any other problems prevent us from
* actually completing the operation
*/
public long[] transform(String xmlName, String xslName, String resultName)
throws Exception
{
preventFootShooting();
long startTime = 0;
long xslBuild = 0;
long transform = 0;
// Timed: read/build xsl from a URL
startTime = System.currentTimeMillis();
Transformer transformer = factory.newTransformer(
new StreamSource(QetestUtils.filenameToURL(xslName)));
xslBuild = System.currentTimeMillis() - startTime;
// Untimed: Apply any parameters needed
applyParameters(transformer);
// Timed: read/build xml, transform, and write results
startTime = System.currentTimeMillis();
transformer.transform(new StreamSource(QetestUtils.filenameToURL(xmlName)),
new StreamResult(resultName));
transform = System.currentTimeMillis() - startTime;
long[] times = getTimeArray();
times[IDX_OVERALL] = xslBuild + transform;
times[IDX_XSLBUILD] = xslBuild;
times[IDX_TRANSFORM] = transform;
return times;
}
/**
* Pre-build/pre-compile a stylesheet.
*
* Although the actual mechanics are implementation-dependent,
* most processors have some method of pre-setting up the data
* needed by the stylesheet itself for later use in transforms.
* In TrAX/javax.xml.transform, this equates to creating a
* Templates object.
*
* Sets isStylesheetReady() to true if it succeeds. Users can
* then call transformWithStylesheet(xmlName, resultName) to
* actually perform a transformation with this pre-built
* stylesheet.
*
* @param xslName local path\filename of XSL stylesheet to use
*
* @return array of longs denoting timing of only these parts of
* our operation: IDX_OVERALL, IDX_XSLBUILD
*
* @throws Exception any underlying exceptions from the
* wrappered processor are simply allowed to propagate; throws
* a RuntimeException if any other problems prevent us from
* actually completing the operation
*
* @see #transformWithStylesheet(String xmlName, String resultName)
*/
public long[] buildStylesheet(String xslName) throws Exception
{
preventFootShooting();
long startTime = 0;
long xslBuild = 0;
// Timed: read/build xsl from a URL
startTime = System.currentTimeMillis();
builtTemplates = factory.newTemplates(
new StreamSource(QetestUtils.filenameToURL(xslName)));
xslBuild = System.currentTimeMillis() - startTime;
m_stylesheetReady = true;
long[] times = getTimeArray();
times[IDX_OVERALL] = xslBuild;
times[IDX_XSLBUILD] = xslBuild;
return times;
}
/**
* Transform supplied xmlName file with a pre-built/pre-compiled
* stylesheet into a resultName file.
*
* User must have called buildStylesheet(xslName) beforehand,
* obviously.
* Names are assumed to be local path\filename references, and
* will be converted to URLs as needed.
*
* @param xmlName local path\filename of XML file to transform
* @param resultName local path\filename to put result in
*
* @return array of longs denoting timing of only these parts of
* our operation: IDX_OVERALL, IDX_XSLBUILD, IDX_TRANSFORM
*
* @throws Exception any underlying exceptions from the
* wrappered processor are simply allowed to propagate; throws
* a RuntimeException if any other problems prevent us from
* actually completing the operation; throws an
* IllegalStateException if isStylesheetReady() == false.
*
* @see #buildStylesheet(String xslName)
*/
public long[] transformWithStylesheet(String xmlName, String resultName)
throws Exception
{
if (!isStylesheetReady())
throw new IllegalStateException("transformWithStylesheet() when isStylesheetReady() == false");
preventFootShooting();
long startTime = 0;
long transform = 0;
// UNTimed: get Transformer from Templates
Transformer transformer = builtTemplates.newTransformer();
// Untimed: Apply any parameters needed
applyParameters(transformer);
// Timed: read/build xml, transform, and write results
startTime = System.currentTimeMillis();
transformer.transform(new StreamSource(QetestUtils.filenameToURL(xmlName)),
new StreamResult(resultName));
transform = System.currentTimeMillis() - startTime;
long[] times = getTimeArray();
times[IDX_OVERALL] = transform;
times[IDX_TRANSFORM] = transform;
return times;
}
/**
* Transform supplied xmlName file with a stylesheet found in an
* xml-stylesheet PI into a resultName file.
*
* Names are assumed to be local path\filename references, and
* will be converted to URLs as needed. Implementations will
* use whatever facilities exist in their wrappered processor
* to fetch and build the stylesheet to use for the transform.
*
* @param xmlName local path\filename of XML file to transform
* @param resultName local path\filename to put result in
*
* @return array of longs denoting timing of only these parts of
* our operation: IDX_OVERALL, IDX_XSLREAD (time to find XSL
* reference from the xml-stylesheet PI), IDX_XSLBUILD, (time
* to then build the Transformer therefrom), IDX_TRANSFORM
*
* @throws Exception any underlying exceptions from the
* wrappered processor are simply allowed to propagate; throws
* a RuntimeException if any other problems prevent us from
* actually completing the operation
*/
public long[] transformEmbedded(String xmlName, String resultName)
throws Exception
{
preventFootShooting();
long startTime = 0;
long xslRead = 0;
long xslBuild = 0;
long transform = 0;
// Timed: readxsl from the xml document
startTime = System.currentTimeMillis();
Source xslSource = factory.getAssociatedStylesheet(new StreamSource(QetestUtils.filenameToURL(xmlName)),
null, null, null);
xslRead = System.currentTimeMillis() - startTime;
// Timed: build xsl from a URL
startTime = System.currentTimeMillis();
Transformer transformer = factory.newTransformer(xslSource);
xslBuild = System.currentTimeMillis() - startTime;
// Untimed: Apply any parameters needed
applyParameters(transformer);
// Timed: read/build xml, transform, and write results
startTime = System.currentTimeMillis();
transformer.transform(new StreamSource(QetestUtils.filenameToURL(xmlName)),
new StreamResult(resultName));
transform = System.currentTimeMillis() - startTime;
long[] times = getTimeArray();
times[IDX_OVERALL] = xslRead + xslBuild + transform;
times[IDX_XSLREAD] = xslRead;
times[IDX_XSLBUILD] = xslBuild;
times[IDX_TRANSFORM] = transform;
return times;
}
/**
* Reset our parameters and wrapper state, and optionally
* force creation of a new underlying processor implementation.
*
* This always clears our built stylesheet and any parameters
* that have been set. If newProcessor is true, also forces a
* re-creation of our underlying processor as if by calling
* newProcessor().
*
* @param newProcessor if we should reset our underlying
* processor implementation as well
*/
public void reset(boolean newProcessor)
{
super.reset(newProcessor); // clears indent and parameters
m_stylesheetReady = false;
builtTemplates = null;
if (newProcessor)
{
try
{
newProcessor(newProcessorOpts);
}
catch (Exception e)
{
//@todo Hmm: what should we do here?
}
}
}
/**
* Apply a single parameter to a Transformer.
*
* Overridden to take a Transformer and call setParameter().
*
* @param passThru to be passed to each applyParameter() method
* call - for TrAX, you might pass a Transformer object.
* @param namespace for the parameter, may be null
* @param name for the parameter, should not be null
* @param value for the parameter, may be null
*/
protected void applyParameter(Object passThru, String namespace,
String name, Object value)
{
try
{
Transformer t = (Transformer)passThru;
// Munge the namespace into the name per
// javax.xml.transform.Transformer.setParameter()
if (null != namespace)
{
name = "{" + namespace + "}" + name;
}
t.setParameter(name, value);
}
catch (Exception e)
{
throw new IllegalArgumentException("applyParameter threw: " + e.toString());
}
}
/**
* Ensure newProcessor has been called when needed.
*
* Prevent users from shooting themselves in the foot by
* calling a transform* API before newProcessor().
*
* (Sorry, I couldn't resist)
*/
public void preventFootShooting() throws Exception
{
if (null == factory)
newProcessor(newProcessorOpts);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org