From 1351bab5738277f96d0db633bc34b1c3752571d8 Mon Sep 17 00:00:00 2001 From: Glen Mazza Date: Sun, 25 Jul 2004 01:47:47 +0000 Subject: 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 --- src/java/org/apache/fop/apps/FOFileHandler.java | 45 +++++---------------- src/java/org/apache/fop/apps/InputHandler.java | 40 ------------------- src/java/org/apache/fop/apps/XSLTInputHandler.java | 46 +--------------------- 3 files changed, 12 insertions(+), 119 deletions(-) (limited to 'src/java/org/apache/fop/apps') 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) */ -- cgit v1.2.3