gmazza      2004/07/19 20:39:24

  Modified:    src/java/org/apache/fop/apps Driver.java FOFileHandler.java
                        Fop.java InputHandler.java XSLTInputHandler.java
               src/java/org/apache/fop/render/awt/viewer PreviewDialog.java
               src/java/org/apache/fop/tools TestConverter.java
               src/java/org/apache/fop/tools/anttasks Fop.java
               test/java/org/apache/fop BasicDriverTestCase.java
                        GenericFOPTestCase.java
  Log:
  1.)  render() methods moved from Driver to XSLTInputHandler and FOFileHandler.
  
  2.)  -param command line switch implemented for xml->xslt->pdf processes
  
  Revision  Changes    Path
  1.92      +1 -55     xml-fop/src/java/org/apache/fop/apps/Driver.java
  
  Index: Driver.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/Driver.java,v
  retrieving revision 1.91
  retrieving revision 1.92
  diff -u -r1.91 -r1.92
  --- Driver.java       19 Jul 2004 22:46:14 -0000      1.91
  +++ Driver.java       20 Jul 2004 03:39:24 -0000      1.92
  @@ -19,13 +19,9 @@
   package org.apache.fop.apps;
   
   // Java
  -import java.io.IOException;
   import java.io.OutputStream;
   
   // XML
  -import org.xml.sax.InputSource;
  -import org.xml.sax.SAXException;
  -import org.xml.sax.XMLReader;
   import org.xml.sax.helpers.DefaultHandler;
      
   // FOP
  @@ -137,55 +133,5 @@
        */
       public DefaultHandler getDefaultHandler() throws FOPException {
           return new FOTreeBuilder(renderType, foUserAgent, stream);
  -    }
  -
  -    /**
  -     * Render the FO document read by a SAX Parser from an InputHandler
  -     * @param inputHandler the input handler containing the source and
  -     * parser information.
  -     * @throws FOPException if anything goes wrong.
  -     */
  -    public synchronized void render(InputHandler inputHandler)
  -                throws FOPException {
  -        XMLReader parser = inputHandler.getParser();
  -        foUserAgent.setBaseURL(inputHandler.getBaseURL());
  -        render(parser, inputHandler.getInputSource());
  -    }
  -
  -    /**
  -     * This is the main render() method. The other render() methods are for
  -     * convenience, and normalize to this form, then run this.
  -     * Renders the FO document read by a SAX Parser from an InputSource.
  -     * For versions not needing an FO Tree (e.g., Alt-Design), override this.
  -     *
  -     * @param parser the SAX parser.
  -     * @param source the input source the parser reads from.
  -     * @throws FOPException if anything goes wrong.
  -     */
  -    public synchronized void render(XMLReader parser, InputSource source)
  -                throws FOPException {
  -        parser.setContentHandler(getDefaultHandler());
  -
  -        try {
  -            /**
  -             The following statement triggers virtually all of the processing
  -             for this document. The SAX parser fires events that are handled by
  -             the appropriate InputHandler object, which means that you will need
  -             to look in those objects to see where FOP picks up control of
  -             processing again. For Structure Renderers (e.g. MIF & RTF), the SAX
  -             events are handled directly. For Layout Renderers (e.g. PDF &
  -             PostScript), an Area Tree is managed by the AreaTreeHandler.
  -             */
  -            parser.parse(source);
  -        } catch (SAXException e) {
  -            if (e.getException() instanceof FOPException) {
  -                // Undo exception tunneling.
  -                throw (FOPException)e.getException();
  -            } else {
  -                throw new FOPException(e);
  -            }
  -        } catch (IOException e) {
  -            throw new FOPException(e);
  -        }
       }
   }
  
  
  
  1.5       +40 -13    xml-fop/src/java/org/apache/fop/apps/FOFileHandler.java
  
  Index: FOFileHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/FOFileHandler.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- FOFileHandler.java        16 Mar 2004 22:17:09 -0000      1.4
  +++ FOFileHandler.java        20 Jul 2004 03:39:24 -0000      1.5
  @@ -15,21 +15,27 @@
    */
   
   /* $Id$ */
  - 
  +
   package org.apache.fop.apps;
   
  +// Java
  +import java.io.File;
  +import java.net.URL;
  +
   // Imported SAX classes
   import org.xml.sax.InputSource;
  -import org.xml.sax.XMLReader;
   import org.xml.sax.SAXException;
  -import org.xml.sax.SAXNotSupportedException;
  +import org.xml.sax.XMLReader;
   
  -// java
  +//JAXP
   import javax.xml.parsers.SAXParserFactory;
   import javax.xml.parsers.ParserConfigurationException;
  -import java.io.File;
  -import java.net.URL;
  -
  +import javax.xml.transform.Transformer;
  +import javax.xml.transform.TransformerFactory;
  +import javax.xml.transform.Source;
  +import javax.xml.transform.Result;
  +import javax.xml.transform.sax.SAXSource;
  +import javax.xml.transform.sax.SAXResult;
   
   /**
    * Manages input if it is an XSL-FO file.
  @@ -72,12 +78,34 @@
       }
   
       /**
  -     * @see org.apache.fop.apps.InputHandler#getParser()
  +     * @see org.apache.fop.apps.InputHandler#render(Driver)
        */
  -    public XMLReader getParser() throws FOPException {
  -        return createParser();
  -    }
  +    public void render(Driver driver) throws FOPException {
   
  +        // temporary until baseURL removed from inputHandler objects
  +        if (driver.getUserAgent().getBaseURL() == null) {
  +            driver.getUserAgent().setBaseURL(getBaseURL());
  +        }
  +
  +        try {
  +            // Setup JAXP using identity transformer (no stylesheet here)
  +            TransformerFactory factory = TransformerFactory.newInstance();
  +            Transformer transformer = factory.newTransformer();
  +            
  +            // Setup input stream
  +            Source src = new SAXSource(getInputSource());
  +
  +            // Resulting SAX events (the generated FO) must be piped through to FOP
  +            Result res = new SAXResult(driver.getDefaultHandler());
  +            
  +            // Start XSLT transformation and FOP processing
  +            transformer.transform(src, res);
  +
  +        } catch (Exception e) {
  +            throw new FOPException(e);
  +        }
  +    }
  +    
       /**
        * Creates <code>XMLReader</code> object using default
        * <code>SAXParserFactory</code>
  @@ -109,4 +137,3 @@
           }
       }
   }
  -
  
  
  
  1.18      +2 -2      xml-fop/src/java/org/apache/fop/apps/Fop.java
  
  Index: Fop.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/Fop.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- Fop.java  19 Jul 2004 05:33:34 -0000      1.17
  +++ Fop.java  20 Jul 2004 03:39:24 -0000      1.18
  @@ -52,7 +52,7 @@
                           options.getOutputFile()));
                       driver.setOutputStream(bos);
                   }
  -                driver.render(foUserAgent.getInputHandler());
  +                foUserAgent.getInputHandler().render(driver);
                } finally {
                    if (bos != null) {
                        bos.close();
  
  
  
  1.12      +5 -13     xml-fop/src/java/org/apache/fop/apps/InputHandler.java
  
  Index: InputHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/InputHandler.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- InputHandler.java 4 Apr 2004 11:12:28 -0000       1.11
  +++ InputHandler.java 20 Jul 2004 03:39:24 -0000      1.12
  @@ -33,12 +33,6 @@
    */
   public abstract class InputHandler {
   
  -    /**
  -     * Get the input source associated with this input handler.
  -     * @return the input source
  -     */
  -    public abstract InputSource getInputSource();
  -
       protected String baseURL = null;
       
       /**
  @@ -50,11 +44,11 @@
       }
   
       /**
  -     * Get the SAX parser associated with this input handler.
  -     * @return the SAX parser
  -     * @throws FOPException in case of an error determining the SAX parser
  +     * Generate a document, given an initialized Driver object
  +     * @param driver -- Driver object
  +     * @throws FOPException in case of an error during processing
        */
  -    public abstract XMLReader getParser() throws FOPException;
  +    public void render(Driver driver) throws FOPException {}
   
       /**
        * Creates an InputSource from a URL.
  @@ -86,6 +80,4 @@
               throw new RuntimeException("unexpected MalformedURLException");
           }
       }
  -
   }
  -
  
  
  
  1.15      +28 -74    xml-fop/src/java/org/apache/fop/apps/XSLTInputHandler.java
  
  Index: XSLTInputHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/XSLTInputHandler.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- XSLTInputHandler.java     25 Jun 2004 23:35:00 -0000      1.14
  +++ XSLTInputHandler.java     20 Jul 2004 03:39:24 -0000      1.15
  @@ -28,23 +28,20 @@
   import javax.xml.transform.TransformerFactory;
   import javax.xml.transform.stream.StreamSource;
   import javax.xml.transform.sax.SAXResult;
  -import javax.xml.transform.sax.SAXSource;
  -import javax.xml.transform.sax.SAXTransformerFactory;
  +import javax.xml.transform.stream.StreamSource;
  +import javax.xml.transform.Result;
   
   // Imported SAX classes
   import org.xml.sax.InputSource;
  -import org.xml.sax.XMLReader;
  -import org.xml.sax.XMLFilter;
   
   /**
    * XSLTInputHandler basically takes an XML file and transforms it with an XSLT
    * file and the resulting XSL-FO document is input for FOP.
    */
   public class XSLTInputHandler extends InputHandler {
  -
       private StreamSource xmlSource;
       private Source xsltSource;
  -    private Vector xsltParams = null; // not yet implemented
  +    private Vector xsltParams = null;
       
       /**
        * Constructor for files as input
  @@ -108,80 +105,37 @@
       }
   
       /**
  -     * @see org.apache.fop.apps.InputHandler#getInputSource()
  +     * @see org.apache.fop.apps.InputHandler#render(Driver)
        */
  -    public InputSource getInputSource() {
  -        InputSource is = new InputSource();
  -        is.setByteStream(xmlSource.getInputStream());
  -        is.setSystemId(xmlSource.getSystemId());
  -        return is;
  -    }
  +    public void render(Driver driver) 
  +        throws FOPException {
   
  -    /**
  -     * Overwrites this method of the super class and returns an XMLFilter 
  -     * instead of a simple XMLReader which allows chaining of transformations.
  -     * @see org.apache.fop.apps.InputHandler#getParser()
  -     */
  -    public XMLReader getParser() throws FOPException {
  -        return getXMLFilter(xsltSource, xsltParams);
  -    }
  +        // temporary until baseURL removed from inputHandler objects
  +        if (driver.getUserAgent().getBaseURL() == null) {
  +            driver.getUserAgent().setBaseURL(getBaseURL());
  +        }
   
  -    /**
  -     * Creates from the transformer an instance of an XMLFilter which
  -     * then can be used in a chain with the XMLReader passed to Driver. This way
  -     * during the conversion of the xml file + xslt stylesheet the resulting
  -     * data is fed into Fop. This should help to avoid memory problems
  -     * @param xsltSource An xslt stylesheet
  -     * @return an XMLFilter which can be chained together with other 
  -     * XMLReaders or XMLFilters
  -     * @throws FOPException if setting up the XMLFilter fails
  -     */
  -    public static XMLFilter getXMLFilter(Source xsltSource, Vector inParams) throws 
FOPException {
           try {
  -            // Instantiate  a TransformerFactory.
  -            TransformerFactory tFactory = TransformerFactory.newInstance();
  -            // Determine whether the TransformerFactory supports The use of 
SAXSource
  -            // and SAXResult
  -            if (tFactory.getFeature(SAXSource.FEATURE)
  -                    && tFactory.getFeature(SAXResult.FEATURE)) {
  -                // Cast the TransformerFactory to SAXTransformerFactory.
  -                SAXTransformerFactory saxTFactory =
  -                    ((SAXTransformerFactory)tFactory);
  -                // Create an XMLFilter for each stylesheet.
  -                XMLFilter xmlfilter =
  -                    saxTFactory.newXMLFilter(xsltSource);
  -                    
  -/*              if (inParams != null) { 
  -                    // parameters currently not settable with an XMLFilter
  -                    for (int i = 0; i < nParams; i += 2) {
  -                        // setParameter() method doesn't exist
  -                        xmlfilter.setParameter((String) inParams.elementAt(i),
  -                            (String) inParams.elementAt(i + 1));
  -                    }
  +            // Setup XSLT
  +            TransformerFactory factory = TransformerFactory.newInstance();
  +            Transformer transformer = factory.newTransformer(xsltSource);
  +            
  +            // Set the value of parameters, if any, defined for stylesheet
  +            if (xsltParams != null) { 
  +                for (int i = 0; i < xsltParams.size(); i += 2) {
  +                    transformer.setParameter((String) xsltParams.elementAt(i),
  +                        (String) xsltParams.elementAt(i + 1));
                   }
  -*/                  
  -                
  -                // Create an XMLReader.
  -                XMLReader parser = FOFileHandler.createParser();
  -                if (parser == null) {
  -                    throw new FOPException("Unable to create SAX parser");
  -                }
  -
  -                // xmlFilter1 uses the XMLReader as its reader.
  -                xmlfilter.setParent(parser);
  -                return xmlfilter;
  -            } else {
  -                throw new FOPException("Your parser doesn't support the "
  -                        + "features SAXSource and SAXResult."
  -                        + "\nMake sure you are using an XSLT engine which "
  -                        + "supports TrAX");
               }
  -        } catch (FOPException fe) {
  -            throw fe;
  -        } catch (Exception ex) {
  -            throw new FOPException(ex);
  +
  +            // Resulting SAX events (the generated FO) must be piped through to FOP
  +            Result res = new SAXResult(driver.getDefaultHandler());
  +
  +            // Start XSLT transformation and FOP processing
  +            transformer.transform(xmlSource, res);
  +
  +        } catch (Exception e) {
  +            throw new FOPException(e);
           }
       }
  -
   }
  -
  
  
  
  1.6       +2 -2      
xml-fop/src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java
  
  Index: PreviewDialog.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- PreviewDialog.java        19 Jul 2004 05:33:34 -0000      1.5
  +++ PreviewDialog.java        20 Jul 2004 03:39:24 -0000      1.6
  @@ -394,7 +394,7 @@
   
               try {
                   setStatus(translator.getString("Status.Build.FO.tree"));
  -                driver.render(foUserAgent.getInputHandler());
  +                foUserAgent.getInputHandler().render(driver);
                   setStatus(translator.getString("Status.Show"));
               } catch (FOPException e) {
                   reportException(e);
  
  
  
  1.18      +1 -1      xml-fop/src/java/org/apache/fop/tools/TestConverter.java
  
  Index: TestConverter.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/tools/TestConverter.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- TestConverter.java        19 Jul 2004 05:33:34 -0000      1.17
  +++ TestConverter.java        20 Jul 2004 03:39:24 -0000      1.18
  @@ -326,7 +326,7 @@
               driver.setOutputStream(outStream);
               logger.debug("ddir:" + destdir + " on:" + 
                                 outputFile.getName());
  -            driver.render(inputHandler);
  +            inputHandler.render(driver);
               outStream.close();
   
               // check difference
  
  
  
  1.17      +1 -1      xml-fop/src/java/org/apache/fop/tools/anttasks/Fop.java
  
  Index: Fop.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/tools/anttasks/Fop.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- Fop.java  19 Jul 2004 05:33:34 -0000      1.16
  +++ Fop.java  20 Jul 2004 03:39:24 -0000      1.17
  @@ -535,7 +535,7 @@
               userAgent.setBaseURL(this.baseURL);
               Driver driver = new Driver(renderer, userAgent);
               driver.setOutputStream(out);
  -            driver.render(inputHandler);
  +            inputHandler.render(driver);
           } catch (Exception ex) {
               throw new BuildException(ex);
           } finally {
  
  
  
  1.11      +2 -21     xml-fop/test/java/org/apache/fop/BasicDriverTestCase.java
  
  Index: BasicDriverTestCase.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/test/java/org/apache/fop/BasicDriverTestCase.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- BasicDriverTestCase.java  19 Jul 2004 22:46:14 -0000      1.10
  +++ BasicDriverTestCase.java  20 Jul 2004 03:39:24 -0000      1.11
  @@ -84,25 +84,6 @@
       }
   
       /**
  -     * Tests Driver with XMLReader, InputSource and OutputStream.
  -     * @throws Exception if anything fails
  -     */
  -    public void testFO2PDFWithXMLReader() throws Exception {
  -        File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo");
  -        ByteArrayOutputStream baout = new ByteArrayOutputStream();
  -        Driver driver = new Driver(Driver.RENDER_PDF);
  -
  -        driver.setOutputStream(baout);
  -        SAXParserFactory factory = SAXParserFactory.newInstance();
  -        factory.setNamespaceAware(true);
  -        factory.setValidating(false);
  -        SAXParser parser = factory.newSAXParser();
  -        driver.render(parser.getXMLReader(),
  -            new InputSource(foFile.toURL().toExternalForm()));
  -        assertTrue("Generated PDF has zero length", baout.size() > 0);
  -    }
  -
  -    /**
        * Tests Driver with JAXP and OutputStream generating PDF.
        * @throws Exception if anything fails
        */
  @@ -171,7 +152,7 @@
           driver.setOutputStream(baout);
           
           InputHandler handler = new XSLTInputHandler(xmlFile, xsltFile);
  -        driver.render(handler);
  +        handler.render(driver);
           
           assertTrue("Generated PDF has zero length", baout.size() > 0);
       }
  
  
  
  1.6       +3 -2      xml-fop/test/java/org/apache/fop/GenericFOPTestCase.java
  
  Index: GenericFOPTestCase.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/test/java/org/apache/fop/GenericFOPTestCase.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- GenericFOPTestCase.java   19 Jul 2004 05:33:35 -0000      1.5
  +++ GenericFOPTestCase.java   20 Jul 2004 03:39:24 -0000      1.6
  @@ -123,7 +123,8 @@
           InputSource source = new InputSource(new StringReader(fo));
           DigestFilter filter = new DigestFilter("MD5");
           filter.setParent(parserFactory.newSAXParser().getXMLReader());
  -        driver.render(filter, source);
  +        filter.setContentHandler(driver.getDefaultHandler());
  +        filter.parse(source);
           String digestInActual = digestToString(filter.getDigestValue());
           if (!digestIn.equals(digestInActual)) {
               fail("input MD5: was " + digestInActual + ", expected " + digestIn);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to