gmazza      2004/07/24 18:47:47

  Modified:    src/java/org/apache/fop/apps FOFileHandler.java
                        InputHandler.java XSLTInputHandler.java
               src/java/org/apache/fop/tools TestConverter.java
               test/java/org/apache/fop BasicDriverTestCase.java
  Log:
  Removed the non-File constructors from the InputHandler subclasses in favor
  of JAXP (for embedded use), and standardized FOFileHandler to use a
  StreamSource (like XSLTInputHandler).  Currently, command Line usage
  works only with files, but We may need to expand the constructors here
  somewhat again should we provide other input options from the command line.
  other options
  
  Revision  Changes    Path
  1.8       +11 -36    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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- FOFileHandler.java        24 Jul 2004 05:47:44 -0000      1.7
  +++ FOFileHandler.java        25 Jul 2004 01:47:47 -0000      1.8
  @@ -20,35 +20,31 @@
   
   // Java
   import java.io.File;
  -import java.net.URL;
  -
  -// Imported SAX classes
  -import org.xml.sax.InputSource;
  -import org.xml.sax.SAXException;
  -import org.xml.sax.XMLReader;
   
   // JAXP
  +import javax.xml.transform.Result;
  +import javax.xml.transform.Source;
   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;
  +import javax.xml.transform.stream.StreamSource;
  +
  +// Imported SAX classes
  +import org.xml.sax.InputSource;
   
   /**
    * Manages input if it is an XSL-FO file.
    */
   public class FOFileHandler extends InputHandler {
  -    
  -    private File fofile = null;
  -    private URL foURL = null;
  +    private StreamSource fofile = null;
   
       /**
        * Create a FOFileHandler for a file.
        * @param fofile the file to read the FO document.
        */
       public FOFileHandler(File fofile) {
  -        this.fofile = fofile;
  +        this.fofile  = new StreamSource(fofile);
  +
           try {
               baseURL =
                   new 
File(fofile.getAbsolutePath()).getParentFile().toURL().toExternalForm();
  @@ -58,24 +54,6 @@
       }
   
       /**
  -     * Create a FOFileHandler for an URL.
  -     * @param url the URL to read the FO document.
  -     */
  -    public FOFileHandler(URL url) {
  -        this.foURL = url;
  -    }
  -
  -    /**
  -     * @see org.apache.fop.apps.InputHandler#getInputSource()
  -     */
  -    public InputSource getInputSource () {
  -        if (fofile != null) {
  -            return super.fileInputSource(fofile);
  -        }
  -        return super.urlInputSource(foURL);
  -    }
  -
  -    /**
        * @see org.apache.fop.apps.InputHandler#render(Fop)
        */
       public void render(Fop fop) throws FOPException {
  @@ -90,14 +68,11 @@
               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(fop.getDefaultHandler());
               
               // Start XSLT transformation and FOP processing
  -            transformer.transform(src, res);
  +            transformer.transform(fofile, res);
   
           } catch (Exception e) {
               throw new FOPException(e);
  
  
  
  1.14      +1 -41     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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- InputHandler.java 24 Jul 2004 05:47:45 -0000      1.13
  +++ InputHandler.java 25 Jul 2004 01:47:47 -0000      1.14
  @@ -18,18 +18,8 @@
   
   package org.apache.fop.apps;
   
  -// SAX
  -import org.xml.sax.InputSource;
  -import org.xml.sax.XMLReader;
  -
  -// Java
  -import java.net.URL;
  -import java.io.File;
  -
   /**
    * Abstract super class for input handlers.
  - * Should be used to abstract the various possibilities on how input
  - * can be provided to FOP (but actually isn't).
    */
   public abstract class InputHandler {
   
  @@ -50,34 +40,4 @@
        */
       public void render(Fop fop) throws FOPException {}
   
  -    /**
  -     * Creates an InputSource from a URL.
  -     * @param url URL to use
  -     * @return the newly created InputSource
  -     */
  -    public static InputSource urlInputSource(URL url) {
  -        return new InputSource(url.toString());
  -    }
  -
  -    /**
  -     * Creates an <code>InputSource</code> from a <code>File</code>
  -     * @param file the <code>File</code>
  -     * @return the <code>InputSource</code> created
  -     */
  -    public static InputSource fileInputSource(File file) {
  -        /* this code adapted from James Clark's in XT */
  -        String path = file.getAbsolutePath();
  -        String fSep = System.getProperty("file.separator");
  -        if (fSep != null && fSep.length() == 1) {
  -            path = path.replace(fSep.charAt(0), '/');
  -        }
  -        if (path.length() > 0 && path.charAt(0) != '/') {
  -            path = '/' + path;
  -        }
  -        try {
  -            return new InputSource(new URL("file", null, path).toString());
  -        } catch (java.net.MalformedURLException e) {
  -            throw new RuntimeException("unexpected MalformedURLException");
  -        }
  -    }
   }
  
  
  
  1.17      +2 -44     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.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- XSLTInputHandler.java     24 Jul 2004 05:47:45 -0000      1.16
  +++ XSLTInputHandler.java     25 Jul 2004 01:47:47 -0000      1.17
  @@ -23,13 +23,12 @@
   import java.util.Vector;
   
   // Imported TraX classes
  +import javax.xml.transform.Result;
   import javax.xml.transform.Source;
   import javax.xml.transform.Transformer;
   import javax.xml.transform.TransformerFactory;
  -import javax.xml.transform.stream.StreamSource;
   import javax.xml.transform.sax.SAXResult;
   import javax.xml.transform.stream.StreamSource;
  -import javax.xml.transform.Result;
   
   // Imported SAX classes
   import org.xml.sax.InputSource;
  @@ -48,7 +47,7 @@
        * @param xmlfile XML file
        * @param xsltfile XSLT file
        * @param params Vector of command-line parameters (name, value, 
  -     *      name, value, ...) for XSL stylesheet
  +     *      name, value, ...) for XSL stylesheet, null if none
        * @throws FOPException if initializing the Transformer fails
        */
       public XSLTInputHandler(File xmlfile, File xsltfile, Vector params) {
  @@ -61,47 +60,6 @@
               baseURL = "";
           }
           xsltParams = params;
  -    }
  -
  -    /**
  -     * Constructor for files as input
  -     * @param xmlfile XML file
  -     * @param xsltfile XSLT file
  -     * @throws FOPException if initializing the Transformer fails
  -     */
  -    public XSLTInputHandler(File xmlfile, File xsltfile) {
  -        this.xmlSource  = new StreamSource(xmlfile);
  -        this.xsltSource = new StreamSource(xsltfile);
  -        try {
  -            baseURL =
  -                new 
File(xmlfile.getAbsolutePath()).getParentFile().toURL().toExternalForm();
  -        } catch (Exception e) {
  -            baseURL = "";
  -        }
  -    }
  -
  -    /**
  -     * Constructor with URIs/URLs as input.
  -     * @param xmlURL XML URL
  -     * @param xsltURL XSLT URL
  -     * @throws FOPException if initializing the Transformer fails
  -     */
  -    public XSLTInputHandler(String xmlURL, String xsltURL) {
  -        this.xmlSource  = new StreamSource(xmlURL);
  -        this.xsltSource = new StreamSource(xsltURL);
  -    }
  -
  -    /**
  -     * Constructor with InputSources as input.
  -     * @param xmlSource XML InputSource
  -     * @param xsltSource XSLT InputSource
  -     * @throws FOPException if initializing the Transformer fails
  -     */
  -    public XSLTInputHandler(InputSource xmlSource, InputSource xsltSource) {
  -        this.xmlSource  = new StreamSource(xmlSource.getByteStream(),
  -                                           xmlSource.getSystemId());
  -        this.xsltSource = new StreamSource(xsltSource.getByteStream(),
  -                                           xsltSource.getSystemId());
       }
   
       /**
  
  
  
  1.20      +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.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- TestConverter.java        24 Jul 2004 05:47:45 -0000      1.19
  +++ TestConverter.java        25 Jul 2004 01:47:47 -0000      1.20
  @@ -300,7 +300,7 @@
               } else {
                   inputHandler = new XSLTInputHandler(xmlFile,
                                                       new File(baseDir + "/"
  -                                                             + xsl));
  +                                                             + xsl), null);
               }
   
               FOUserAgent userAgent = new FOUserAgent();
  
  
  
  1.13      +2 -2      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.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- BasicDriverTestCase.java  24 Jul 2004 05:47:45 -0000      1.12
  +++ BasicDriverTestCase.java  25 Jul 2004 01:47:47 -0000      1.13
  @@ -151,7 +151,7 @@
           Fop fop = new Fop(Fop.RENDER_PDF);
           fop.setOutputStream(baout);
           
  -        InputHandler handler = new XSLTInputHandler(xmlFile, xsltFile);
  +        InputHandler handler = new XSLTInputHandler(xmlFile, xsltFile, null);
           handler.render(fop);
           
           assertTrue("Generated PDF has zero length", baout.size() > 0);
  
  
  

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

Reply via email to