]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Removed the non-File constructors from the InputHandler subclasses in favor
authorGlen Mazza <gmazza@apache.org>
Sun, 25 Jul 2004 01:47:47 +0000 (01:47 +0000)
committerGlen Mazza <gmazza@apache.org>
Sun, 25 Jul 2004 01:47:47 +0000 (01:47 +0000)
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

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197838 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/apps/FOFileHandler.java
src/java/org/apache/fop/apps/InputHandler.java
src/java/org/apache/fop/apps/XSLTInputHandler.java
src/java/org/apache/fop/tools/TestConverter.java
test/java/org/apache/fop/BasicDriverTestCase.java

index 30bc4195c342c193aacbc03630ce1f3fcfa4d076..b159e5086a0c3ae29cd8fb2de7b1d58bb68343fb 100644 (file)
@@ -20,35 +20,31 @@ 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.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();
@@ -57,24 +53,6 @@ public class FOFileHandler extends InputHandler {
         }
     }
 
-    /**
-     * 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)
      */
@@ -90,14 +68,11 @@ public class FOFileHandler extends InputHandler {
             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);
index a172ec4438a90a7560c259abda2405c0e5aa6231..e094168ed37eb67eaa34db697e48847fe9e08231 100644 (file)
 
 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 abstract class InputHandler {
      */
     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");
-        }
-    }
 }
index 243181ac12c320169132ccc6efca42d4527f314d..f30ecc9e5cec7f11173e050da9ce78fdd12266ae 100644 (file)
@@ -23,13 +23,12 @@ import java.io.File;
 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 @@ public class XSLTInputHandler extends InputHandler {
      * @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) {
@@ -63,47 +62,6 @@ public class XSLTInputHandler extends InputHandler {
         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());
-    }
-
     /**
      * @see org.apache.fop.apps.InputHandler#render(Fop)
      */
index 3b331b48915da68f9e4225b74677f8a09b64ae6b..66f7b36f2f0d620e429a1e92ca8c97dac6579d47 100644 (file)
@@ -300,7 +300,7 @@ public class TestConverter {
             } else {
                 inputHandler = new XSLTInputHandler(xmlFile,
                                                     new File(baseDir + "/"
-                                                             + xsl));
+                                                             + xsl), null);
             }
 
             FOUserAgent userAgent = new FOUserAgent();
index 48c8678da281330ee606f8680cf071eda9988409..d1c2f2d9eca7df37535c4367087cbff3f77d69d3 100644 (file)
@@ -151,7 +151,7 @@ public class BasicDriverTestCase extends AbstractFOPTestCase {
         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);