You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by sb...@apache.org on 2001/01/09 06:43:38 UTC

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

sboag       01/01/08 21:43:38

  Modified:    test/java/src/org/apache/qetest/xslwrapper
                        ProcessorWrapper.properties TraxWrapper.java
  Log:
  Set up trax.saxpipes test.
  Perform the transform from multiple pipes.
       The transform goes from:
       xmlReader->identityTransform(pipe1)->identityTransform(pipe2)
             ->conformanceTestTranform(pipe3)->identityTransform(pipe4)
             ->serializer
  
  This causes 11 failures in the conformance test, mainly due to ID
  attributes not being identified through the pipe, but at least
  one having a problem with a namespace copy.  I'm not sure I
  can resolve all these by release, but I should try and resolve
  most of them.
  
  Revision  Changes    Path
  1.3       +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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ProcessorWrapper.properties	2000/12/21 15:22:45	1.2
  +++ ProcessorWrapper.properties	2001/01/09 05:43:38	1.3
  @@ -11,6 +11,7 @@
   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
  +trax.saxpipes=org.apache.qetest.xslwrapper.TraxWrapper;trax.wrapper.type=sax-pipes
   
   # Wrappers implemented for comparison purposes
   lotusxsl=org.apache.qetest.xslwrapper.LotusXSLWrapper
  
  
  
  1.10      +144 -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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TraxWrapper.java	2001/01/03 10:21:37	1.9
  +++ TraxWrapper.java	2001/01/09 05:43:38	1.10
  @@ -74,6 +74,7 @@
   import java.io.ObjectOutputStream;
   import java.io.OutputStream;
   import java.io.IOException;
  +import java.io.StringReader;
   
   // Needed SAX and DOM classes
   import org.xml.sax.InputSource;
  @@ -107,7 +108,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.9 2001/01/03 10:21:37 sboag Exp $
  + * @version $Id: TraxWrapper.java,v 1.10 2001/01/09 05:43:38 sboag Exp $
    */
   public class TraxWrapper extends ProcessorWrapper
   {
  @@ -182,6 +183,12 @@
   
       /** NEEDSDOC Field AS_XML_FILTER_TYPE          */
       public static final int SCOTT_TYPE = 8;
  +    
  +    /** NEEDSDOC Field SAX_TO_SAX          */
  +    public static final String SAX_PIPES = "sax-pipes";
  +
  +    /** NEEDSDOC Field SAX_TO_SAX_TYPE          */
  +    public static final int SAX_PIPES_TYPE = 9;
   
       /** NEEDSDOC Field DEFAULT_TRANSFORM          */
       public static final String DEFAULT_TRANSFORM = FILE_TO_FILE;
  @@ -207,6 +214,7 @@
           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));
  +        typeMap.put(SAX_PIPES, new Integer(SAX_PIPES_TYPE));
       }
       ;
   
  @@ -385,6 +393,10 @@
               xmlTime = processSAXToSAX(xmlSource, xslStylesheet, resultStream);
               break;
   
  +        case SAX_PIPES_TYPE :
  +            xmlTime = processPipes(xmlSource, xslStylesheet, resultStream);
  +            break;
  +
           case SCOTT_TYPE :
               xmlTime = processScott(xmlSource, xslStylesheet, resultStream);
               break;
  @@ -571,6 +583,137 @@
   
           return (endTime - startTime);
       }
  +    
  +    /**
  +     * Perform the transform from multiple pipes.
  +     * The transform goes from:
  +     * xmlReader->identityTransform(pipe1)->identityTransform(pipe2)
  +     *       ->conformanceTestTranform(pipe3)->identityTransform(pipe4)
  +     *       ->serializer
  +     * @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 processPipes(String xmlSource, 
  +                                   String xslStylesheet, 
  +                                   OutputStream resultStream)
  +                throws java.lang.Exception  // Cover all exceptions
  +    {
  +      
  +        if (!(processor.getFeature(SAXSource.FEATURE) 
  +              && processor.getFeature(SAXResult.FEATURE)))
  +        {
  +            // If SAX is not supported in either input (Sources)
  +            //  or output (Results), then bail
  +            return ERROR;
  +        }
  +        long endTime = 0;
  +        long startTime = System.currentTimeMillis();
  +
  +        // Mostly copied from samples\SAX2SAX
  +        // Cast the TransformerFactory.
  +        SAXTransformerFactory stf = 
  +                              ((SAXTransformerFactory) processor);
  +
  +        /** The identity transform string, for support of newTransformerHandler()
  +         *  and newTransformer().  */
  +        final String identityTransform =
  +          "<xsl:stylesheet " + "xmlns:xsl='http://www.w3.org/1999/XSL/Transform' "
  +          + "version='1.0'>" + "<xsl:template match='/|node()'>"
  +          + "<xsl:copy-of select='.'/>" + "</xsl:template>" + "</xsl:stylesheet>";
  +      
  +        StringReader reader = new StringReader(identityTransform);
  +        Templates identityTemplate = stf.newTemplates(new StreamSource(reader));
  +
  +        // Create a ContentHandler to handle parsing of the xsl
  +        TemplatesHandler templatesHandler = stf.newTemplatesHandler();
  +
  +        // Create an XMLReader and set its ContentHandler.
  +        XMLReader xslReader = XMLReaderFactory.createXMLReader();
  +        xslReader.setContentHandler(templatesHandler);
  +
  +        // Parse the stylesheet.                       
  +        xslReader.parse(xslStylesheet);
  +        // @todo Do we need to set systemID at all?
  +
  +        //Get the Templates object from the ContentHandler.
  +        Templates templates = templatesHandler.getTemplates();
  +        
  +        // Get the outputProperties from the stylesheet, so 
  +        //  we can later use them for the serialization
  +        Properties xslOutputProps = templates.getOutputProperties();
  +
  +        // Create Pipe 1
  +        // Create a ContentHandler to handle parsing of the XML
  +        TransformerHandler pipe1 = stf.newTransformerHandler(identityTemplate);
  +
  +        // Use a new XMLReader to parse the XML document
  +        XMLReader xmlReader = XMLReaderFactory.createXMLReader();
  +        xmlReader.setContentHandler(pipe1); 
  +
  +        // Set the ContentHandler to also function as LexicalHandler,
  +        // includes "lexical" events (e.g., comments and CDATA). 
  +        xmlReader.setProperty(
  +                "http://xml.org/sax/properties/lexical-handler", 
  +                pipe1);
  +        xmlReader.setProperty("http://xml.org/sax/properties/declaration-handler",
  +                           pipe1);
  +        
  +        // These two lines were added by sb.
  +        xmlReader.setDTDHandler(pipe1);
  +        pipe1.setSystemId(xmlSource);
  +        
  +        try
  +        {
  +          xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes",
  +                            true);
  +          xmlReader.setFeature("http://apache.org/xml/features/validation/dynamic",
  +                            true);
  +        }
  +        catch (org.xml.sax.SAXException se)
  +        {
  +          // We don't care.
  +        }
  +        
  +        // Create pipe 2
  +        TransformerHandler pipe2 = stf.newTransformerHandler(identityTemplate);
  +        pipe1.setResult(new SAXResult(pipe2));
  +
  +        // Create pipe 3
  +        TransformerHandler pipe3 = stf.newTransformerHandler(templates);
  +        pipe2.setResult(new SAXResult(pipe3));
  +        
  +        // Create pipe 4
  +        TransformerHandler pipe4 = stf.newTransformerHandler(identityTemplate);
  +        pipe3.setResult(new SAXResult(pipe4));
  +
  +        // Create a 'pipe'-like identity transformer, so we can 
  +        //  easily get our results serialized to disk
  +        TransformerHandler serializingHandler = stf.newTransformerHandler();
  +        // Set the stylesheet's output properties into the output 
  +        //  via it's Transformer
  +        serializingHandler.getTransformer().setOutputProperties(xslOutputProps);
  +        // Set the output to be our given resultStream
  +        serializingHandler.setResult(new StreamResult(resultStream));
  +
  +        // Create a SAXResult dumping into our 'pipe' serializer
  +        SAXResult saxResult = new SAXResult(serializingHandler);
  +        saxResult.setLexicalHandler(serializingHandler);
  +
  +        // Set the original stylesheet to dump into our result
  +        pipe4.setResult(saxResult);
  +
  +        // Parse the XML input document.
  +        xmlReader.parse(xmlSource);
  +
  +        // Stop timing now
  +        endTime = System.currentTimeMillis();
  +
  +        return (endTime - startTime);
  +    }
  +
   
       protected String objectFilename = "TEMP-FILE-TraxWrapper.ser";
       /**