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...@locus.apache.org on 2000/12/21 16:22:47 UTC

cvs commit: xml-xalan/test/java/src/org/apache/qetest/xslwrapper ProcessorWrapper.properties TraxWrapper.java

curcuru     00/12/21 07:22:47

  Modified:    test/java/src/org/apache/qetest/xslwrapper
                        ProcessorWrapper.properties TraxWrapper.java
  Log:
  Implement -flavor trax.scott: simple stream transform where
  the Templates object is serialized - needs more updates, but should work
  
  Revision  Changes    Path
  1.2       +1 -0      xml-xalan/test/java/src/org/apache/qetest/xslwrapper/ProcessorWrapper.properties
  
  Index: ProcessorWrapper.properties
  ===================================================================
  RCS file: /home/cvs/xml-xalan/test/java/src/org/apache/qetest/xslwrapper/ProcessorWrapper.properties,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ProcessorWrapper.properties	2000/11/01 23:27:00	1.1
  +++ ProcessorWrapper.properties	2000/12/21 15:22:45	1.2
  @@ -10,6 +10,7 @@
   trax.s2t=org.apache.qetest.xslwrapper.TraxWrapper;trax.wrapper.type=sax-to-stream
   trax.d2d=org.apache.qetest.xslwrapper.TraxWrapper;trax.wrapper.type=dom-to-dom
   trax.filter=org.apache.qetest.xslwrapper.TraxWrapper;trax.wrapper.type=as-xml-filter
  +trax.scott=org.apache.qetest.xslwrapper.TraxWrapper;trax.wrapper.type=scott
   
   # Wrappers implemented for comparison purposes
   lotusxsl=org.apache.qetest.xslwrapper.LotusXSLWrapper
  
  
  
  1.7       +65 -1     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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TraxWrapper.java	2000/12/21 14:09:57	1.6
  +++ TraxWrapper.java	2000/12/21 15:22:45	1.7
  @@ -68,7 +68,10 @@
   
   import java.io.PrintWriter;  // currently only used in unimplemented setDiagnosticsOutput
   import java.io.ByteArrayOutputStream;
  +import java.io.FileInputStream;
   import java.io.FileOutputStream;
  +import java.io.ObjectInputStream;
  +import java.io.ObjectOutputStream;
   import java.io.OutputStream;
   import java.io.IOException;
   
  @@ -104,7 +107,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.6 2000/12/21 14:09:57 curcuru Exp $
  + * @version $Id: TraxWrapper.java,v 1.7 2000/12/21 15:22:45 curcuru Exp $
    */
   public class TraxWrapper extends ProcessorWrapper
   {
  @@ -174,6 +177,12 @@
       /** NEEDSDOC Field AS_XML_FILTER_TYPE          */
       public static final int AS_XML_FILTER_TYPE = 7;
   
  +    /** NEEDSDOC Field SCOTT          */
  +    public static final String SCOTT = "scott";
  +
  +    /** NEEDSDOC Field AS_XML_FILTER_TYPE          */
  +    public static final int SCOTT_TYPE = 8;
  +
       /** NEEDSDOC Field DEFAULT_TRANSFORM          */
       public static final String DEFAULT_TRANSFORM = FILE_TO_FILE;
   
  @@ -197,6 +206,7 @@
           typeMap.put(DOM_TO_STREAM, new Integer(DOM_TO_STREAM_TYPE));
           typeMap.put(STREAM_TO_DOM, new Integer(STREAM_TO_DOM_TYPE));
           typeMap.put(AS_XML_FILTER, new Integer(AS_XML_FILTER_TYPE));
  +        typeMap.put(SCOTT, new Integer(SCOTT_TYPE));
       }
       ;
   
  @@ -375,6 +385,9 @@
               xmlTime = processSAXToSAX(xmlSource, xslStylesheet, resultStream);
               break;
   
  +        case SCOTT_TYPE :
  +            xmlTime = processScott(xmlSource, xslStylesheet, resultStream);
  +            break;
           default :
               throw new java.lang.IllegalStateException("bad/unimplemented transformType("
                                                         + transformType
  @@ -530,6 +543,57 @@
   
           // Parse the XML input document.
           xmlReader.parse(xmlSource);
  +
  +        // Stop timing now
  +        endTime = System.currentTimeMillis();
  +
  +        return (endTime - startTime);
  +    }
  +
  +    protected String objectFilename = "TEMP-FILE-TraxWrapper.ser";
  +    /**
  +     * Perform the transform with Scott's example.
  +     * //@todo rename and reevaluate - I'm in a hurry today
  +     * //@todo EVALUATE TIMING: currently times entire process
  +     * @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
  +     * @throws java.lang.Exception covers any underlying exceptions
  +     */
  +    protected long processScott(String xmlSource, 
  +                                   String xslStylesheet, 
  +                                   OutputStream resultStream)
  +                throws java.lang.Exception  // Cover all exceptions
  +    {
  +        if (!(processor.getFeature(StreamSource.FEATURE) 
  +              && processor.getFeature(StreamResult.FEATURE)))
  +        {
  +            // If Stream is not supported in either input (Sources)
  +            //  or output (Results), then bail
  +            return ERROR;
  +        }
  +        long endTime = 0;
  +        long startTime = System.currentTimeMillis();
  +
  +        // Create templates normally
  +        Templates templates = processor.newTemplates(new StreamSource(xslStylesheet));
  +
  +        // Serialize the Templates to disk using normal Java methods
  +        // Note this needs more work to be robust - need to handle
  +        //  cleaning up previous files on disk, or maybe use a random
  +        //  name generator each time
  +        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(objectFilename));
  +        oos.writeObject(templates);
  +        oos.close();
  +
  +        // Deserialize the Templates to disk using normal Java methods
  +        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(objectFilename));
  +        Templates templates2 = (Templates)ois.readObject();
  +          
  +        // Use the transformer as normal to transform
  +        Transformer transformer = templates2.newTransformer();
  +        transformer.transform(new StreamSource(xmlSource), new StreamResult(resultStream));
   
           // Stop timing now
           endTime = System.currentTimeMillis();