From 499ce535625915cb4bf2e00b1801e4a6c3dd04b8 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Tue, 24 Jan 2006 14:21:46 +0000 Subject: [PATCH] Command-line support for the intermediate format: Use "-atin" to specify an area tree XML file. Refactoring of the InputHandler to accomodate the IF as input format and to make responsibilities clearer in general. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@371922 13f79535-47bb-0310-9956-ffa450edef68 --- .../content/xdocs/trunk/intermediate.xml | 5 + .../content/xdocs/trunk/running.xml | 6 +- .../apache/fop/cli/AreaTreeInputHandler.java | 86 +++++++++++ .../apache/fop/cli/CommandLineOptions.java | 140 ++++++++++++++---- src/java/org/apache/fop/cli/InputHandler.java | 25 +++- src/java/org/apache/fop/cli/Main.java | 32 ++-- src/java/org/apache/fop/fo/Constants.java | 25 ++-- .../fop/render/awt/viewer/PreviewPanel.java | 9 +- .../fop/render/awt/viewer/Renderable.java | 10 +- .../org/apache/fop/tools/TestConverter.java | 4 +- .../org/apache/fop/tools/anttasks/Fop.java | 5 +- .../org/apache/fop/BasicDriverTestCase.java | 4 +- 12 files changed, 255 insertions(+), 96 deletions(-) create mode 100644 src/java/org/apache/fop/cli/AreaTreeInputHandler.java diff --git a/src/documentation/content/xdocs/trunk/intermediate.xml b/src/documentation/content/xdocs/trunk/intermediate.xml index e80925faa..360766241 100644 --- a/src/documentation/content/xdocs/trunk/intermediate.xml +++ b/src/documentation/content/xdocs/trunk/intermediate.xml @@ -101,6 +101,11 @@ try { endDocument() on the AreaTreeModel. This lets the Renderer know that the processing is now finished.

+

+ The intermediate format can also be used from the command-line + by using the "-atin" parameter for specifying the area tree XML as input file. You can also + specify a "mimic renderer" by inserting a MIME type between "-at" and the output file. +

Concatenating Documents

diff --git a/src/documentation/content/xdocs/trunk/running.xml b/src/documentation/content/xdocs/trunk/running.xml index 182756359..302f2efe4 100644 --- a/src/documentation/content/xdocs/trunk/running.xml +++ b/src/documentation/content/xdocs/trunk/running.xml @@ -128,7 +128,7 @@ Fop [options] [-fo|-xml] infile [-xsl file] [-awt|-pdf|-mif|-rtf|-tiff|-png|-pcl -fo infile xsl:fo input file -xml infile xml input file, must be used together with -xsl -xsl stylesheet xslt stylesheet - + -atin infile area tree input file -param name value to use for parameter in xslt stylesheet (repeat '-param name value' for each parameter) @@ -144,7 +144,9 @@ Fop [options] [-fo|-xml] infile [-xsl file] [-awt|-pdf|-mif|-rtf|-tiff|-png|-pcl -ps outfile input will be rendered as PostScript file (outfile req'd) -txt outfile input will be rendered as text file (outfile req'd) -svg outfile input will be rendered as an svg slides file (outfile req'd) - -at outfile representation of area tree as XML (outfile req'd) + -at [mime] out representation of area tree as XML (outfile req'd) + specify optional mime output to allow AT to be converted + to final format later -print input file will be rendered and sent to the printer see options with "-print help" -out mime outfile input will be rendered using the given MIME type diff --git a/src/java/org/apache/fop/cli/AreaTreeInputHandler.java b/src/java/org/apache/fop/cli/AreaTreeInputHandler.java new file mode 100644 index 000000000..a8e83c87f --- /dev/null +++ b/src/java/org/apache/fop/cli/AreaTreeInputHandler.java @@ -0,0 +1,86 @@ +/* + * Copyright 2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.cli; + +import java.io.File; +import java.io.OutputStream; +import java.util.Vector; + +import javax.xml.transform.Result; +import javax.xml.transform.sax.SAXResult; + +import org.apache.fop.apps.FOPException; +import org.apache.fop.apps.FOUserAgent; +import org.apache.fop.area.AreaTreeModel; +import org.apache.fop.area.AreaTreeParser; +import org.apache.fop.area.RenderPagesModel; +import org.apache.fop.fonts.FontInfo; +import org.xml.sax.SAXException; + +/** + * InputHandler for the area tree XML (intermediate format) as input. + */ +public class AreaTreeInputHandler extends InputHandler { + + /** + * Constructor for XML->XSLT->area tree XML input + * @param xmlfile XML file + * @param xsltfile XSLT file + * @param params Vector of command-line parameters (name, value, + * name, value, ...) for XSL stylesheet, null if none + */ + public AreaTreeInputHandler(File xmlfile, File xsltfile, Vector params) { + super(xmlfile, xsltfile, params); + } + + /** + * Constructor for area tree XML input + * @param atfile the file to read the area tree document. + */ + public AreaTreeInputHandler(File atfile) { + super(atfile); + } + + /** @see org.apache.fop.cli.InputHandler */ + public void renderTo(FOUserAgent userAgent, String outputFormat, OutputStream out) + throws FOPException { + FontInfo fontInfo = new FontInfo(); + FOUserAgent effUserAgent = userAgent; + if (effUserAgent == null) { + effUserAgent = new FOUserAgent(); + } + AreaTreeModel treeModel = new RenderPagesModel(userAgent, + outputFormat, fontInfo, out); + + //Iterate over all intermediate files + AreaTreeParser parser = new AreaTreeParser(); + + // Resulting SAX events (the generated FO) must be piped through to FOP + Result res = new SAXResult(parser.getContentHandler(treeModel, userAgent)); + + transformTo(res); + + try { + treeModel.endDocument(); + } catch (SAXException e) { + throw new FOPException(e); + } + } + +} diff --git a/src/java/org/apache/fop/cli/CommandLineOptions.java b/src/java/org/apache/fop/cli/CommandLineOptions.java index c1c069b39..cc52dea05 100644 --- a/src/java/org/apache/fop/cli/CommandLineOptions.java +++ b/src/java/org/apache/fop/cli/CommandLineOptions.java @@ -1,12 +1,12 @@ -/* - * Copyright 1999-2005 The Apache Software Foundation. - * +/* + * Copyright 1999-2006 The Apache Software Foundation. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -29,10 +29,11 @@ import org.apache.fop.Version; import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.MimeConstants; -import org.apache.fop.fo.Constants; import org.apache.fop.pdf.PDFEncryptionManager; import org.apache.fop.pdf.PDFEncryptionParams; import org.apache.fop.render.awt.AWTRenderer; +import org.apache.fop.render.Renderer; +import org.apache.fop.render.xml.XMLRenderer; import org.apache.fop.util.CommandLineLogger; // commons logging @@ -52,11 +53,24 @@ import org.apache.avalon.framework.configuration.ConfigurationException; /** * Options parses the commandline arguments */ -public class CommandLineOptions implements Constants { +public class CommandLineOptions { /** Used to indicate that only the result of the XSL transformation should be output */ public static final int RENDER_NONE = -1; - + + /* These following constants are used to describe the input (either .FO, .XML/.XSL or + * intermediate format) + */ + + /** (input) not set */ + public static final int NOT_SET = 0; + /** input: fo file */ + public static final int FO_INPUT = 1; + /** input: xml+xsl file */ + public static final int XSLT_INPUT = 2; + /** input: Area Tree XML file */ + public static final int AREATREE_INPUT = 3; + /* show configuration information */ private Boolean showConfiguration = Boolean.FALSE; /* for area tree XML output, only down to block area level */ @@ -69,6 +83,8 @@ public class CommandLineOptions implements Constants { private File xsltfile = null; /* xml file (xslt transformation as input) */ private File xmlfile = null; + /* area tree input file */ + private File areatreefile = null; /* output file */ private File outfile = null; /* input mode */ @@ -77,30 +93,32 @@ public class CommandLineOptions implements Constants { private String outputmode = null; private FOUserAgent foUserAgent; - + private InputHandler inputHandler; - + private Log log; private Vector xsltParams = null; - + + private String mimicRenderer = null; + /** * Construct a command line option object. */ public CommandLineOptions() { LogFactory logFactory = LogFactory.getFactory(); - + // Enable the simple command line logging when no other logger is // defined. if (System.getProperty("org.apache.commons.logging.Log") == null) { - logFactory.setAttribute("org.apache.commons.logging.Log", + logFactory.setAttribute("org.apache.commons.logging.Log", CommandLineLogger.class.getName()); setLogLevel("info"); } log = LogFactory.getLog("FOP"); } - + /** * Parse the command line arguments. * @param args the command line arguments. @@ -108,12 +126,12 @@ public class CommandLineOptions implements Constants { * @throws FileNotFoundException if an input file wasn't found * @throws IOException if the the configuration file could not be loaded */ - public void parse(String[] args) + public void parse(String[] args) throws FOPException, IOException { boolean optionsParsed = true; - + foUserAgent = new FOUserAgent(); - + try { optionsParsed = parseOptions(args); if (optionsParsed) { @@ -132,14 +150,27 @@ public class CommandLineOptions implements Constants { printUsage(); throw e; } - + inputHandler = createInputHandler(); - + if (outputmode.equals(MimeConstants.MIME_FOP_AWT_PREVIEW)) { AWTRenderer renderer = new AWTRenderer(); renderer.setRenderable(inputHandler); //set before user agent! renderer.setUserAgent(foUserAgent); foUserAgent.setRendererOverride(renderer); + } else if (outputmode.equals(MimeConstants.MIME_FOP_AREA_TREE) + && mimicRenderer != null) { + // render from FO to Intermediate Format + Renderer targetRenderer = foUserAgent.getRendererFactory().createRenderer( + foUserAgent, mimicRenderer); + XMLRenderer xmlRenderer = new XMLRenderer(); + xmlRenderer.setUserAgent(foUserAgent); + + //Tell the XMLRenderer to mimic the target renderer + xmlRenderer.mimicRenderer(targetRenderer); + + //Make sure the prepared XMLRenderer is used + foUserAgent.setRendererOverride(xmlRenderer); } } @@ -149,7 +180,7 @@ public class CommandLineOptions implements Constants { public InputHandler getInputHandler() { return inputHandler; } - + /** * Get the logger. * @return the logger @@ -165,7 +196,7 @@ public class CommandLineOptions implements Constants { xsltParams.addElement(name); xsltParams.addElement(value); } - + /** * parses the commandline arguments * @return true if parse was successful and processing can continue, false @@ -197,6 +228,8 @@ public class CommandLineOptions implements Constants { i = i + parseXSLInputOption(args, i); } else if (args[i].equals("-xml")) { i = i + parseXMLInputOption(args, i); + } else if (args[i].equals("-atin")) { + i = i + parseAreaTreeInputOption(args, i); } else if (args[i].equals("-awt")) { i = i + parseAWTOutputOption(args, i); } else if (args[i].equals("-pdf")) { @@ -508,9 +541,27 @@ public class CommandLineOptions implements Constants { if ((i + 1 == args.length) || (args[i + 1].charAt(0) == '-')) { throw new FOPException("you must specify the area-tree output file"); - } else { + } else if ((i + 2 == args.length) + || (args[i + 2].charAt(0) == '-')) { + // only output file is specified outfile = new File(args[i + 1]); return 1; + } else { + // mimic format and output file have been specified + mimicRenderer = args[i + 1]; + outfile = new File(args[i + 2]); + return 2; + } + } + + private int parseAreaTreeInputOption(String[] args, int i) throws FOPException { + inputmode = AREATREE_INPUT; + if ((i + 1 == args.length) + || (args[i + 1].charAt(0) == '-')) { + throw new FOPException("you must specify the Area Tree file for the '-atin' option"); + } else { + areatreefile = new File(args[i + 1]); + return 1; } } @@ -524,7 +575,7 @@ public class CommandLineOptions implements Constants { } return foUserAgent.getPDFEncryptionParams(); } - + private int parsePDFOwnerPassword(String[] args, int i) throws FOPException { if ((i + 1 == args.length) || (args[i + 1].charAt(0) == '-')) { @@ -575,7 +626,7 @@ public class CommandLineOptions implements Constants { ((CommandLineLogger) log).setLogLevel(level); } } - + /** * checks whether all necessary information has been given in a consistent way */ @@ -588,10 +639,10 @@ public class CommandLineOptions implements Constants { throw new FOPException("No output file specified"); } - if ((outputmode.equals(MimeConstants.MIME_FOP_AWT_PREVIEW) - || outputmode.equals(MimeConstants.MIME_FOP_PRINT)) + if ((outputmode.equals(MimeConstants.MIME_FOP_AWT_PREVIEW) + || outputmode.equals(MimeConstants.MIME_FOP_PRINT)) && outfile != null) { - throw new FOPException("Output file may not be specified " + throw new FOPException("Output file may not be specified " + "for AWT or PRINT output"); } @@ -640,7 +691,24 @@ public class CommandLineOptions implements Constants { + fofile.getAbsolutePath() + " not found "); } - + } else if (inputmode == AREATREE_INPUT) { + if (outputmode.equals(MimeConstants.MIME_XSL_FO)) { + throw new FOPException( + "FO output mode is only available if you use -xml and -xsl"); + } else if (outputmode.equals(MimeConstants.MIME_FOP_AREA_TREE)) { + throw new FOPException( + "Area Tree Output is not available if Area Tree is used as input!"); + } + if (xmlfile != null || xsltfile != null) { + log.warn("area tree input mode, but xmlfile or xslt file are set:"); + log.error("xml file: " + xmlfile.toString()); + log.error("xslt file: " + xsltfile.toString()); + } + if (!areatreefile.exists()) { + throw new FileNotFoundException("Error: area tree file " + + areatreefile.getAbsolutePath() + + " not found "); + } } } // end checkSettings @@ -690,6 +758,8 @@ public class CommandLineOptions implements Constants { switch (inputmode) { case FO_INPUT: return new InputHandler(fofile); + case AREATREE_INPUT: + return new AreaTreeInputHandler(areatreefile); case XSLT_INPUT: return new InputHandler(xmlfile, xsltfile, xsltParams); default: @@ -774,7 +844,7 @@ public class CommandLineOptions implements Constants { public static void printUsage() { System.err.println( "\nUSAGE\nFop [options] [-fo|-xml] infile [-xsl file] " - + "[-awt|-pdf|-mif|-rtf|-tiff|-png|-pcl|-ps|-txt|-at|-print] \n" + + "[-awt|-pdf|-mif|-rtf|-tiff|-png|-pcl|-ps|-txt|-at [mime]|-print] \n" + " [OPTIONS] \n" + " -d debug mode \n" + " -x dump configuration settings \n" @@ -795,9 +865,10 @@ public class CommandLineOptions implements Constants { + " infile xsl:fo input file (the same as the next) \n" + " -fo infile xsl:fo input file \n" + " -xml infile xml input file, must be used together with -xsl \n" + + " -atin infile area tree input file \n" + " -xsl stylesheet xslt stylesheet \n \n" + " -param name value to use for parameter in xslt stylesheet\n" - + " (repeat '-param name value' for each parameter)\n \n" + + " (repeat '-param name value' for each parameter)\n \n" + " [OUTPUT] \n" + " outfile input will be rendered as pdf file into outfile \n" + " -pdf outfile input will be rendered as pdf file (outfile req'd) \n" @@ -810,7 +881,9 @@ public class CommandLineOptions implements Constants { + " -ps outfile input will be rendered as PostScript file (outfile req'd) \n" + " -txt outfile input will be rendered as text file (outfile req'd) \n" + " -svg outfile input will be rendered as an svg slides file (outfile req'd) \n" - + " -at outfile representation of area tree as XML (outfile req'd) \n" + + " -at [mime] out representation of area tree as XML (outfile req'd) \n" + + " specify optional mime output to allow AT to be converted\n" + + " to final format later\n" + " -print input file will be rendered and sent to the printer \n" + " see options with \"-print help\" \n" + " -out mime outfile input will be rendered using the given MIME type\n" @@ -878,6 +951,9 @@ public class CommandLineOptions implements Constants { } } else if (MimeConstants.MIME_FOP_AREA_TREE.equals(outputmode)) { log.info("area tree"); + if (mimicRenderer != null) { + log.info("mimic renderer: " + mimicRenderer); + } log.info("output file: " + outfile.toString()); } else { log.info(outputmode); @@ -885,7 +961,7 @@ public class CommandLineOptions implements Constants { } log.info("OPTIONS"); - + if (userConfigFile != null) { log.info("user configuration file: " + userConfigFile.toString()); diff --git a/src/java/org/apache/fop/cli/InputHandler.java b/src/java/org/apache/fop/cli/InputHandler.java index 53e4649f1..554f5d572 100644 --- a/src/java/org/apache/fop/cli/InputHandler.java +++ b/src/java/org/apache/fop/cli/InputHandler.java @@ -37,6 +37,7 @@ import javax.xml.transform.stream.StreamSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.fop.apps.FOPException; +import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.Fop; import org.apache.fop.render.awt.viewer.Renderable; @@ -77,10 +78,18 @@ public class InputHandler implements ErrorListener, Renderable { /** * Generate a document, given an initialized Fop object - * @param fop -- Fop object + * @param userAgent the user agent + * @param outputFormat the output format to generate (MIME type, see MimeConstants) + * @param out the output stream to write the generated output to (may be null if not applicable) * @throws FOPException in case of an error during processing */ - public void render(Fop fop) throws FOPException { + public void renderTo(FOUserAgent userAgent, String outputFormat, OutputStream out) + throws FOPException { + + Fop fop = new Fop(outputFormat, userAgent); + if (out != null) { + fop.setOutputStream(out); + } // if base URL was not explicitly set in FOUserAgent, obtain here if (fop.getUserAgent().getBaseURL() == null) { @@ -101,6 +110,11 @@ public class InputHandler implements ErrorListener, Renderable { transformTo(res); } + /** @see org.apache.fop.render.awt.viewer.Renderable */ + public void renderTo(FOUserAgent userAgent, String outputFormat) throws FOPException { + renderTo(userAgent, outputFormat, null); + } + /** * In contrast to render(Fop) this method only performs the XSLT stage and saves the * intermediate XSL-FO file to the output file. @@ -112,7 +126,12 @@ public class InputHandler implements ErrorListener, Renderable { transformTo(res); } - private void transformTo(Result result) throws FOPException { + /** + * Transforms the input document to the input format expected by FOP using XSLT. + * @param result the Result object where the result of the XSL transformation is sent to + * @throws FOPException in case of an error during processing + */ + protected void transformTo(Result result) throws FOPException { try { // Setup XSLT TransformerFactory factory = TransformerFactory.newInstance(); diff --git a/src/java/org/apache/fop/cli/Main.java b/src/java/org/apache/fop/cli/Main.java index 5f979bfa0..c4a627f48 100644 --- a/src/java/org/apache/fop/cli/Main.java +++ b/src/java/org/apache/fop/cli/Main.java @@ -18,17 +18,16 @@ package org.apache.fop.cli; -import java.io.BufferedOutputStream; import java.io.File; import java.io.FileFilter; -import java.io.FileOutputStream; +import java.io.OutputStream; import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URL; import java.util.List; +import org.apache.commons.io.IOUtils; import org.apache.fop.apps.FOUserAgent; -import org.apache.fop.apps.Fop; import org.apache.fop.apps.MimeConstants; /** @@ -141,37 +140,28 @@ public class Main { //System.out.println("static CL: " + Fop.class.getClassLoader().toString()); CommandLineOptions options = null; FOUserAgent foUserAgent = null; - BufferedOutputStream bos = null; + OutputStream out = null; try { options = new CommandLineOptions(); options.parse(args); - foUserAgent = options.getFOUserAgent(); - Fop fop = null; + foUserAgent = options.getFOUserAgent(); String outputFormat = options.getOutputFormat(); - if (!MimeConstants.MIME_XSL_FO.equals(outputFormat)) { - fop = new Fop(outputFormat, foUserAgent); - } try { if (options.getOutputFile() != null) { - bos = new BufferedOutputStream(new FileOutputStream( - options.getOutputFile())); - if (fop != null) { - fop.setOutputStream(bos); - foUserAgent.setOutputFile(options.getOutputFile()); - } + out = new java.io.BufferedOutputStream( + new java.io.FileOutputStream(options.getOutputFile())); + foUserAgent.setOutputFile(options.getOutputFile()); } - if (fop != null) { - options.getInputHandler().render(fop); + if (!MimeConstants.MIME_XSL_FO.equals(outputFormat)) { + options.getInputHandler().renderTo(foUserAgent, outputFormat, out); } else { - options.getInputHandler().transformTo(bos); + options.getInputHandler().transformTo(out); } } finally { - if (bos != null) { - bos.close(); - } + IOUtils.closeQuietly(out); } // System.exit(0) called to close AWT/SVG-created threads, if any. diff --git a/src/java/org/apache/fop/fo/Constants.java b/src/java/org/apache/fop/fo/Constants.java index c751d11aa..db12b5cb8 100644 --- a/src/java/org/apache/fop/fo/Constants.java +++ b/src/java/org/apache/fop/fo/Constants.java @@ -1,12 +1,12 @@ /* * Copyright 1999-2005 The Apache Software Foundation. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -30,15 +30,8 @@ package org.apache.fop.fo; */ public interface Constants { - /* These constants are used by apps.CommandLineOptions - to describe the input (either .FO or .XML/.XSL) */ - - /** (input) not set */ + /** not set */ int NOT_SET = 0; - /** input: fo file */ - int FO_INPUT = 1; - /** input: xml+xsl file */ - int XSLT_INPUT = 2; // element constants /** FObj base class */ @@ -165,26 +158,26 @@ public interface Constants { int FO_PAGE_SEQUENCE_WRAPPER = 60; /** Number of FO element constants defined */ int FRM_OBJ_COUNT = 60; - + // Masks - /** + /** * For compound properties the property constant value is shifted by this amount. * The low order bits hold the constant for the component property. */ int COMPOUND_SHIFT = 9; - /** + /** * Mask that when applied to a compound property returns the constant of * the component property. */ int PROPERTY_MASK = (1 << COMPOUND_SHIFT) - 1; - /** + /** * Mask that when applied to a compound property returns the constant of * the compound property. */ int COMPOUND_MASK = ~PROPERTY_MASK; /** Number of compund properties defined */ int COMPOUND_COUNT = 11; - + // property constants /** Property constant */ int PR_ABSOLUTE_POSITION = 1; diff --git a/src/java/org/apache/fop/render/awt/viewer/PreviewPanel.java b/src/java/org/apache/fop/render/awt/viewer/PreviewPanel.java index f2a94eb29..aedcf801f 100644 --- a/src/java/org/apache/fop/render/awt/viewer/PreviewPanel.java +++ b/src/java/org/apache/fop/render/awt/viewer/PreviewPanel.java @@ -35,7 +35,6 @@ import javax.swing.JViewport; import javax.swing.SwingUtilities; import javax.swing.border.EmptyBorder; -import org.apache.fop.apps.Fop; import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.MimeConstants; @@ -135,9 +134,6 @@ public class PreviewPanel extends JPanel { /** Asynchronous reloader thread, used when reload() method is called. */ private Reloader reloader; - /** The Fop object used for refreshing/reloading the view */ - protected Fop fop; - /** * Allows any mouse drag on the page area to scroll the display window. */ @@ -303,9 +299,6 @@ public class PreviewPanel extends JPanel { return; } - //Always recreate the Fop instance. It is a use-once only. - fop = new Fop(MimeConstants.MIME_FOP_AWT_PREVIEW, foUserAgent); - pagePanels = null; int savedCurrentPage = currentPage; @@ -341,7 +334,7 @@ public class PreviewPanel extends JPanel { try { if (renderable != null) { renderer.clearViewportList(); - renderable.render(fop); + renderable.renderTo(foUserAgent, MimeConstants.MIME_FOP_AWT_PREVIEW); } } catch (FOPException e) { e.printStackTrace(); diff --git a/src/java/org/apache/fop/render/awt/viewer/Renderable.java b/src/java/org/apache/fop/render/awt/viewer/Renderable.java index dc25243ee..9b069a231 100644 --- a/src/java/org/apache/fop/render/awt/viewer/Renderable.java +++ b/src/java/org/apache/fop/render/awt/viewer/Renderable.java @@ -1,5 +1,5 @@ /* - * Copyright 2005 The Apache Software Foundation. + * Copyright 2005-2006 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,7 @@ package org.apache.fop.render.awt.viewer; import org.apache.fop.apps.FOPException; -import org.apache.fop.apps.Fop; +import org.apache.fop.apps.FOUserAgent; /** * The interface is used by the AWT preview dialog to reload a document. @@ -28,9 +28,11 @@ public interface Renderable { /** * Renders the pre-setup document. - * @param fop the Fop instance to do the FO processing with + * @param userAgent the user agent + * @param outputFormat the output format to generate (MIME type, see MimeConstants) * @exception FOPException if the FO processing fails */ - void render(Fop fop) throws FOPException; + void renderTo(FOUserAgent userAgent, String outputFormat) + throws FOPException; } diff --git a/src/java/org/apache/fop/tools/TestConverter.java b/src/java/org/apache/fop/tools/TestConverter.java index 27176b47e..6d4800a86 100644 --- a/src/java/org/apache/fop/tools/TestConverter.java +++ b/src/java/org/apache/fop/tools/TestConverter.java @@ -286,7 +286,6 @@ public class TestConverter { FOUserAgent userAgent = new FOUserAgent(); userAgent.setBaseURL(baseURL); - Fop fop = new Fop(outputFormat, userAgent); userAgent.getRendererOptions().put("fineDetail", new Boolean(false)); userAgent.getRendererOptions().put("consistentOutput", new Boolean(true)); @@ -302,9 +301,8 @@ public class TestConverter { outputFile.getParentFile().mkdirs(); OutputStream outStream = new java.io.BufferedOutputStream( new java.io.FileOutputStream(outputFile)); - fop.setOutputStream(outStream); logger.debug("ddir:" + destdir + " on:" + outputFile.getName()); - inputHandler.render(fop); + inputHandler.renderTo(userAgent, outputFormat, outStream); outStream.close(); // check difference diff --git a/src/java/org/apache/fop/tools/anttasks/Fop.java b/src/java/org/apache/fop/tools/anttasks/Fop.java index af1496df2..10badfefa 100644 --- a/src/java/org/apache/fop/tools/anttasks/Fop.java +++ b/src/java/org/apache/fop/tools/anttasks/Fop.java @@ -538,10 +538,7 @@ class FOPTaskStarter { try { FOUserAgent userAgent = new FOUserAgent(); userAgent.setBaseURL(this.baseURL); - org.apache.fop.apps.Fop fop = new org.apache.fop.apps.Fop( - outputFormat, userAgent); - fop.setOutputStream(out); - inputHandler.render(fop); + inputHandler.renderTo(userAgent, outputFormat, out); } catch (Exception ex) { throw new BuildException(ex); } finally { diff --git a/test/java/org/apache/fop/BasicDriverTestCase.java b/test/java/org/apache/fop/BasicDriverTestCase.java index 100f1eaeb..c74ecaad9 100644 --- a/test/java/org/apache/fop/BasicDriverTestCase.java +++ b/test/java/org/apache/fop/BasicDriverTestCase.java @@ -110,11 +110,9 @@ public class BasicDriverTestCase extends AbstractFOPTestCase { File xmlFile = new File(getBaseDir(), "test/xml/1.xml"); File xsltFile = new File(getBaseDir(), "test/xsl/doc.xsl"); ByteArrayOutputStream baout = new ByteArrayOutputStream(); - Fop fop = new Fop(MimeConstants.MIME_PDF); - fop.setOutputStream(baout); InputHandler handler = new InputHandler(xmlFile, xsltFile, null); - handler.render(fop); + handler.renderTo(null, MimeConstants.MIME_PDF, baout); assertTrue("Generated PDF has zero length", baout.size() > 0); } -- 2.39.5