From 1351bab5738277f96d0db633bc34b1c3752571d8 Mon Sep 17 00:00:00 2001 From: Glen Mazza Date: Sun, 25 Jul 2004 01:47:47 +0000 Subject: [PATCH] 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 git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197838 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/fop/apps/FOFileHandler.java | 45 ++++-------------- .../org/apache/fop/apps/InputHandler.java | 40 ---------------- .../org/apache/fop/apps/XSLTInputHandler.java | 46 +------------------ .../org/apache/fop/tools/TestConverter.java | 2 +- .../org/apache/fop/BasicDriverTestCase.java | 2 +- 5 files changed, 14 insertions(+), 121 deletions(-) diff --git a/src/java/org/apache/fop/apps/FOFileHandler.java b/src/java/org/apache/fop/apps/FOFileHandler.java index 30bc4195c..b159e5086 100644 --- a/src/java/org/apache/fop/apps/FOFileHandler.java +++ b/src/java/org/apache/fop/apps/FOFileHandler.java @@ -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); diff --git a/src/java/org/apache/fop/apps/InputHandler.java b/src/java/org/apache/fop/apps/InputHandler.java index a172ec443..e094168ed 100644 --- a/src/java/org/apache/fop/apps/InputHandler.java +++ b/src/java/org/apache/fop/apps/InputHandler.java @@ -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 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 InputSource from a File - * @param file the File - * @return the InputSource 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"); - } - } } diff --git a/src/java/org/apache/fop/apps/XSLTInputHandler.java b/src/java/org/apache/fop/apps/XSLTInputHandler.java index 243181ac1..f30ecc9e5 100644 --- a/src/java/org/apache/fop/apps/XSLTInputHandler.java +++ b/src/java/org/apache/fop/apps/XSLTInputHandler.java @@ -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) */ diff --git a/src/java/org/apache/fop/tools/TestConverter.java b/src/java/org/apache/fop/tools/TestConverter.java index 3b331b489..66f7b36f2 100644 --- a/src/java/org/apache/fop/tools/TestConverter.java +++ b/src/java/org/apache/fop/tools/TestConverter.java @@ -300,7 +300,7 @@ public class TestConverter { } else { inputHandler = new XSLTInputHandler(xmlFile, new File(baseDir + "/" - + xsl)); + + xsl), null); } FOUserAgent userAgent = new FOUserAgent(); diff --git a/test/java/org/apache/fop/BasicDriverTestCase.java b/test/java/org/apache/fop/BasicDriverTestCase.java index 48c8678da..d1c2f2d9e 100644 --- a/test/java/org/apache/fop/BasicDriverTestCase.java +++ b/test/java/org/apache/fop/BasicDriverTestCase.java @@ -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); -- 2.39.5