diff options
-rw-r--r-- | src/java/org/apache/fop/apps/FOFileHandler.java | 45 | ||||
-rw-r--r-- | src/java/org/apache/fop/apps/InputHandler.java | 40 | ||||
-rw-r--r-- | src/java/org/apache/fop/apps/XSLTInputHandler.java | 46 | ||||
-rw-r--r-- | src/java/org/apache/fop/tools/TestConverter.java | 2 | ||||
-rw-r--r-- | test/java/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(); @@ -58,24 +54,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) */ public void render(Fop fop) throws FOPException { @@ -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 <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"); - } - } } 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) { @@ -64,47 +63,6 @@ public class XSLTInputHandler extends InputHandler { } /** - * 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) */ public void render(Fop 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); |