curcuru 00/12/12 08:00:30
Modified: test/java/src/org/apache/qetest/xslwrapper
LotusXSLWrapper.java ProcessorWrapper.java
TraxWrapper.java XalanWrapper.java
Log:
Implement new processEmbeddedToFile methods
Revision Changes Path
1.2 +19 -1
xml-xalan/test/java/src/org/apache/qetest/xslwrapper/LotusXSLWrapper.java
Index: LotusXSLWrapper.java
===================================================================
RCS file:
/home/cvs/xml-xalan/test/java/src/org/apache/qetest/xslwrapper/LotusXSLWrapper.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- LotusXSLWrapper.java 2000/11/01 23:27:00 1.1
+++ LotusXSLWrapper.java 2000/12/12 16:00:27 1.2
@@ -77,7 +77,7 @@
/**
* Implementation of a ProcessorWrapper for LotusXSL.
* @author Shane Curcuru
- * @version $Id: LotusXSLWrapper.java,v 1.1 2000/11/01 23:27:00 curcuru Exp $
+ * @version $Id: LotusXSLWrapper.java,v 1.2 2000/12/12 16:00:27 curcuru Exp $
*/
public class LotusXSLWrapper extends ProcessorWrapper
{
@@ -284,6 +284,24 @@
return (endTime - startTime);
}
+
+
+ /**
+ * Process xmlSource with embedded stylesheet to produce resultFile.
+ * <p>Wrappers will ask their processor to parse an XML file
+ * that presumably has an <?xml-stylesheet element in it.</p>
+ *
+ * @param xmlSource file name of source XML file
+ * @param resultFile file name of output file
+ * @return milliseconds process time took or ProcessorWrapper.ERROR
+ * @throws java.lang.Exception covers any underlying exceptions
+ */
+ public long processEmbeddedToFile(String xmlSource, String resultFile)
+ throws java.lang.Exception // should cover all exception cases
+ {
+ throw new RuntimeException("processEmbeddedToFile() not yet
implemented!");
+ }
+
/**
* Reset the state.
1.2 +84 -34
xml-xalan/test/java/src/org/apache/qetest/xslwrapper/ProcessorWrapper.java
Index: ProcessorWrapper.java
===================================================================
RCS file:
/home/cvs/xml-xalan/test/java/src/org/apache/qetest/xslwrapper/ProcessorWrapper.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ProcessorWrapper.java 2000/11/01 23:27:00 1.1
+++ ProcessorWrapper.java 2000/12/12 16:00:27 1.2
@@ -82,7 +82,7 @@
* timed in their implementations, and the ways that they are
* implementing the process (SAX, DOM, etc.)</p>
* @author Shane Curcuru
- * @version $Id: ProcessorWrapper.java,v 1.1 2000/11/01 23:27:00 curcuru Exp
$
+ * @version $Id: ProcessorWrapper.java,v 1.2 2000/12/12 16:00:27 curcuru Exp
$
*/
public abstract class ProcessorWrapper
{
@@ -97,13 +97,12 @@
* <p>May throw exceptions related to the creating of a new processor.
* Subclasses must set the value of (Object)p in this method and return
it.</p>
* <p>Note that not all processors may use liaisons in the same
manner.</p>
+ * //@todo revisit: see if liaisonClassName should be genericized
+ *
* @param liaisonClassName [optional] if non-null & non-blank,
* classname of an XML liaison
* @return (Object)processor as a side effect; null if error
- * @exception Exception may be thrown by underlying operation
- * @todo revisit: see if liaisonClassName should be genericized
- *
- * @throws java.lang.Exception
+ * @throws java.lang.Exception covers any underlying exceptions
*/
public abstract Object createNewProcessor(String liaisonClassName)
throws java.lang.Exception; // Cover all exception cases
@@ -119,8 +118,7 @@
/**
* Reference to actual current processor object.
- *
- * NEEDSDOC ($objectName$) @return
+ * @return underlying (Object)processor object
*/
public Object getProcessor()
{
@@ -132,15 +130,20 @@
/**
* If we think the current processor has a preprocessed stylesheet
ready.
- *
- * NEEDSDOC ($objectName$) @return
+ * @return true if ready to call processToFile(String xmlSource,
+ * String resultFile)
*/
public boolean getStylesheetReady()
{
return stylesheetReady;
}
- /** Return value when an error occours from process* methods. */
+ /**
+ * Return value when an error occours from process* methods.
+ * Most methods return either a long representing the milliseconds
+ * the 'interesting' portions of the operation took, or this
+ * ERROR constant if something went wrong.
+ */
public static final long ERROR = -1L;
//-----------------------------------------------------
@@ -148,17 +151,23 @@
//-----------------------------------------------------
/**
- * Process the xmlSource using the xslStylesheet to produce the
resultFile.
- * <p>May throw exceptions related to asking the processor to perform
the process.</p>
- * <p>Attempts to ask each processor to accomplish the task in the
simplest
- * and most obvious manner. Often copied from various processor's
samples.</p>
- * @param xmlSource name of source XML file
- * @param xslStylesheet name of stylesheet XSL file
- * @param resultFile name of output file
+ * Process xmlSource using xslStylesheet to produce resultFile.
+ * <p>Will throw any exceptions from the underlying processor
+ * as-is, so callers probably need to catch Exception, and then
+ * check whichever specific types of Exception they expect.</p>
+ * <p>Attempts to ask each processor to accomplish the task
+ * in the simplest and most obvious manner. Often copied from
+ * various processor's samples. Should only time data related
+ * to the basic act of processing the file, not time setting up
+ * local variables or processing the filenames. <b>Note:</b>
+ * the format of the filenames (absolute, relative, local, URI)
+ * is not necessarily defined.</p>
+ *
+ * @param xmlSource file name of source XML file
+ * @param xslStylesheet file name of stylesheet XSL file
+ * @param resultFile file name of output file
* @return milliseconds process time took or ProcessorWrapper.ERROR
- * @exception Exception may be thrown by underlying operation
- *
- * @throws java.lang.Exception
+ * @throws java.lang.Exception covers any underlying exceptions
*/
public abstract long processToFile(
String xmlSource, String xslStylesheet, String resultFile)
@@ -166,36 +175,66 @@
/**
* Preprocess a stylesheet and set it into the processor.
- * @param xslStylesheet name of stylesheet XSL file
- * @return milliseconds process time took or ProcessorWrapper.ERROR
- * @exception Exception may be thrown by underlying operation
+ * <p>Most XSLT processors offer some feature allowing you to
+ * parse and pre-process a stylesheet into a compact memory
+ * representation, which may then be used later to perform a
+ * process or transformation. Normal usage would be to call this
+ * method, then call processToFile(String xmlSource,
+ * String resultFile), and then validate the resultFile.</p>
*
- * @throws java.lang.Exception
+ * @param xslStylesheet file name of stylesheet XSL file
+ * @return milliseconds process time took or ProcessorWrapper.ERROR
+ * @throws java.lang.Exception covers any underlying exceptions
*/
public abstract long preProcessStylesheet(String xslStylesheet)
throws java.lang.Exception; // should cover all exception cases
/**
- * Process the xmlSource using a preProcessStylesheet to produce the
resultFile.
- * @param xmlSource name of source XML file
- * @param resultFile name of output file
- * @return milliseconds process time took or ProcessorWrapper.ERROR
- * @exception Exception may be thrown by underlying operation
+ * Process xmlSource using a preProcessStylesheet to produce resultFile.
+ * <p>Must call preProcessStylesheet(String xslStylesheet)
+ * before calling this method.</p>
*
- * @throws java.lang.Exception
+ * @param xmlSource file name of source XML file
+ * @param resultFile file name of output file
+ * @return milliseconds process time took or ProcessorWrapper.ERROR
+ * @throws java.lang.Exception covers any underlying exceptions
*/
public abstract long processToFile(String xmlSource, String resultFile)
throws java.lang.Exception; // should cover all exception cases
/**
+ * Process xmlSource with embedded stylesheet to produce resultFile.
+ * <p>Wrappers will ask their processor to parse an XML file
+ * that presumably has an <?xml-stylesheet element in it.</p>
+ *
+ * @param xmlSource file name of source XML file
+ * @param resultFile file name of output file
+ * @return milliseconds process time took or ProcessorWrapper.ERROR
+ * @throws java.lang.Exception covers any underlying exceptions
+ */
+ public abstract long processEmbeddedToFile(String xmlSource, String
resultFile)
+ throws java.lang.Exception; // should cover all exception cases
+
+ /**
* Set a String name=value param in the processor, if applicable.
+ * <p>The implementation is wrapper dependent, but generally
+ * wrappers should set any Params given immediately before
+ * performing any processing operations. Does not necessarily
+ * handle namespaces, nor non-String valued values.</p>
+ *
* @param key name of the param
- * @param expression value of the param
+ * @param expression value of the param, as a String
*/
public abstract void setStylesheetParam(String key, String expression);
/**
* Set a String namespace:name=value param in the processor, if
applicable.
+ * <p>The implementation is wrapper dependent, but generally
+ * wrappers should set any Params given immediately before
+ * performing any processing operations. Does not handle
+ * non-String valued values; if the processor does not obviously
+ * support namespaces, the namespace is ignored.</p>
+ *
* @param namespace of the param
* @param key name of the param
* @param expression value of the param
@@ -203,11 +242,19 @@
public abstract void setStylesheetParam(String namespace, String key,
String expression);
- /** Reset the state of the processor, if applicable. */
+ /**
+ * Reset the state of the processor, if applicable.
+ * <p>This implementation is wrapper dependent, but generally
+ * should be called before re-using the same wrapper to
+ * process additional files.</p>
+ */
public abstract void reset();
/**
* Set a diagnostics output PrintWriter, if applicable.
+ * <p>For processors that offer a simple diagnostics stream,
+ * this is passed in. Not (currently) used for tracing or
+ * advanced diagnostics features in some processors.</p>
* @param pw PrintWriter to dump diagnostic or error output
*/
public abstract void setDiagnosticsOutput(java.io.PrintWriter pw);
@@ -231,7 +278,9 @@
* so clients don't necessarily have to know the full classname.</p>
* <ul>Where:
* <li>key = String simple name = xalan|trax|etc...</li>
- * <li>value = String full classname</li>
+ * <li>Supports: See ProcessorWrapper.properties</li>
+ * <li>Or:</li>
+ * <li>value = String FQCN of wrapper implementation</li>
* <li>Or, optionally:</li>
* <li>value = String full classname;property=value</li>
* <li>Supports: See ProcessorWrapper.properties</li>
@@ -268,7 +317,8 @@
/**
* Accessor for our wrapperMapper.
*
- * NEEDSDOC ($objectName$) @return
+ * @return Properties block of wrapper implementations
+ * that we implicitly know about
*/
public static final Properties getDescriptions()
{
1.5 +69 -23
xml-xalan/test/java/src/org/apache/qetest/xslwrapper/TraxWrapper.java
Index: TraxWrapper.java
===================================================================
RCS file:
/home/cvs/xml-xalan/test/java/src/org/apache/qetest/xslwrapper/TraxWrapper.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TraxWrapper.java 2000/11/15 22:17:28 1.4
+++ TraxWrapper.java 2000/12/12 16:00:28 1.5
@@ -97,7 +97,7 @@
* @todo share constants between TraxWrapper, SaxonWrapper
* @todo document how we perform various types of transforms
* @author Shane Curcuru
- * @version $Id: TraxWrapper.java,v 1.4 2000/11/15 22:17:28 curcuru Exp $
+ * @version $Id: TraxWrapper.java,v 1.5 2000/12/12 16:00:28 curcuru Exp $
*/
public class TraxWrapper extends ProcessorWrapper
{
@@ -218,12 +218,11 @@
* property to the Xalan 2.x implementation. It also reads
* the "trax.wrapper.type" property to determine how we should
* perform transformations: eg, SAX2SAX, DOM2DOM, FILE2FILE, etc..</p>
+ *
* @param liaisonClassName [optional] if non-null & non-blank,
* classname of an XML liaison
* @return (Object)processor as a side effect; null if error
- * @exception Exception may be thrown by underlying operation
- *
- * @throws java.lang.Exception
+ * @throws java.lang.Exception covers any underlying exceptions
*/
public Object createNewProcessor(String liaisonClassName)
throws java.lang.Exception // Cover all exception cases
@@ -312,13 +311,12 @@
* and most obvious manner. Often copied from various processor's
samples.</p>
* <p>This also respects the "trax.wrapper.type" System property to
* support different types of transforms.</p>
+ *
* @param xmlSource name of source XML file
* @param xslStylesheet name of stylesheet XSL file
* @param resultFile name of output file, presumably XML
* @return milliseconds process time took
- * @exception Exception may be thrown by underlying operation
- *
- * @throws java.lang.Exception
+ * @throws java.lang.Exception covers any underlying exceptions
*/
public long processToFile(
String xmlSource, String xslStylesheet, String resultFile)
@@ -383,15 +381,14 @@
/**
* Perform the transform from a DOM to a DOM (then serialize).
- * @todo EVALUATE TIMING: right now, we time everything,
+ *
+ * //@todo EVALUATE TIMING: right now, we time everything,
* all DOM building and transforms (but not serialization)
* @param xmlSource name of source XML file
* @param xslStylesheet name of stylesheet XSL file
* @param resultFile name of output file, presumably XML
* @return milliseconds process time took
- * @exception Exception may be thrown by underlying operation
- *
- * @throws java.lang.Exception
+ * @throws java.lang.Exception covers any underlying exceptions
*/
protected long processDOMToDOM(
String xmlSource, String xslStylesheet, OutputStream
resultStream)
@@ -447,12 +444,11 @@
/**
* Preprocess a stylesheet and set it into the processor, based on
string inputs.
- * @todo Does NOT respect the "trax.wrapper.type" System property yet.
+ *
+ * //@todo Does NOT respect the "trax.wrapper.type" System property yet.
* @param xslStylesheet name of stylesheet XSL file
* @return milliseconds process time took or ProcessorWrapper.ERROR
- * @exception Exception may be thrown by underlying operation
- *
- * @throws java.lang.Exception
+ * @throws java.lang.Exception covers any underlying exceptions
*/
public long preProcessStylesheet(String xslStylesheet)
throws java.lang.Exception // should cover all exception cases
@@ -483,13 +479,12 @@
/**
* Process the xmlSource using the xslStylesheet to produce the
resultFile.
- * @todo Does NOT respect the "trax.wrapper.type" System property yet.
+ *
+ * //@todo Does NOT respect the "trax.wrapper.type" System property yet.
* @param xmlSource name of source XML file
* @param resultFile name of output file, presumably XML
* @return milliseconds process time took or ProcessorWrapper.ERROR
- * @exception Exception may be thrown by underlying operation
- *
- * @throws java.lang.Exception
+ * @throws java.lang.Exception covers any underlying exceptions
*/
public long processToFile(String xmlSource, String resultFile)
throws java.lang.Exception // should cover all exception cases
@@ -526,6 +521,57 @@
return (endTime - startTime);
}
+
+ /**
+ * Process xmlSource with embedded stylesheet to produce resultFile.
+ * <p>Wrappers will ask their processor to parse an XML file
+ * that presumably has an <?xml-stylesheet element in it.</p>
+ *
+ * @param xmlSource file name of source XML file
+ * @param resultFile file name of output file
+ * @return milliseconds process time took or ProcessorWrapper.ERROR
+ * @throws java.lang.Exception covers any underlying exceptions
+ */
+ public long processEmbeddedToFile(String xmlSource, String resultFile)
+ throws java.lang.Exception // should cover all exception cases
+ {
+ // Ensure we (apparently) have some processor
+ if (processor == null)
+ throw new java.lang.IllegalStateException(
+ "You must call createNewProcessor first!");
+
+ // Declare variables ahead of time to minimize latency
+ long startTime = 0;
+ long endTime = 0;
+ String media= null; // currently ignored
+ String title = null; // currently ignored
+ String charset = null; // currently ignored
+
+ // May throw IOException
+ FileOutputStream resultStream = new FileOutputStream(resultFile);
+
+ // Begin timing the whole process
+ startTime = System.currentTimeMillis();
+
+ // Get the xml-stylesheet and process it
+ Source stylesheetSource = processor.getAssociatedStylesheet(new
StreamSource(xmlSource),
+ media, title,
charset);
+
+ Transformer transformer = processor.newTransformer(stylesheetSource);
+
+ applyParams(transformer, params);
+
+ transformer.transform(new StreamSource(xmlSource), new
StreamResult(resultStream));
+
+ endTime = System.currentTimeMillis();
+
+ // Force output stream closed, just in case
+ resultStream.close();
+
+ return (endTime - startTime);
+ }
+
+
/**
* Reset the state.
*/
@@ -544,9 +590,9 @@
}
/**
- * Set diagnostics output PrintWriter.
+ * Set diagnostics output PrintWriter - not implemented.
*
- * NEEDSDOC @param pw
+ * @param pw ignored
*/
public void setDiagnosticsOutput(java.io.PrintWriter pw)
{
@@ -561,9 +607,9 @@
}
/**
- * Set the indent level of the processor.
+ * Set the indent level of the processor - not implemented.
*
- * NEEDSDOC @param i
+ * @param i ignored
*/
public void setIndent(int i)
{
1.2 +19 -1
xml-xalan/test/java/src/org/apache/qetest/xslwrapper/XalanWrapper.java
Index: XalanWrapper.java
===================================================================
RCS file:
/home/cvs/xml-xalan/test/java/src/org/apache/qetest/xslwrapper/XalanWrapper.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XalanWrapper.java 2000/11/01 23:27:00 1.1
+++ XalanWrapper.java 2000/12/12 16:00:28 1.2
@@ -77,7 +77,7 @@
* Implementation of a ProcessorWrapper for Xalan 1.x builds.
* <p>See TraxWrapper for a Xalan 2.x wrapper solution.</p>
* @author Shane Curcuru
- * @version $Id: XalanWrapper.java,v 1.1 2000/11/01 23:27:00 curcuru Exp $
+ * @version $Id: XalanWrapper.java,v 1.2 2000/12/12 16:00:28 curcuru Exp $
*/
public class XalanWrapper extends ProcessorWrapper
{
@@ -282,6 +282,24 @@
return (endTime - startTime);
}
+
+
+ /**
+ * Process xmlSource with embedded stylesheet to produce resultFile.
+ * <p>Wrappers will ask their processor to parse an XML file
+ * that presumably has an <?xml-stylesheet element in it.</p>
+ *
+ * @param xmlSource file name of source XML file
+ * @param resultFile file name of output file
+ * @return milliseconds process time took or ProcessorWrapper.ERROR
+ * @throws java.lang.Exception covers any underlying exceptions
+ */
+ public long processEmbeddedToFile(String xmlSource, String resultFile)
+ throws java.lang.Exception // should cover all exception cases
+ {
+ throw new RuntimeException("processEmbeddedToFile() not yet
implemented!");
+ }
+
/**
* Reset the state.