diff options
author | Jeremias Maerki <jeremias@apache.org> | 2006-03-27 09:51:14 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2006-03-27 09:51:14 +0000 |
commit | 0a2d149c230858d311f6d4d776072704a0096ac2 (patch) | |
tree | 3dcbf5ed7be99ab2a93f5911ff2ff40e10364fc6 /test | |
parent | 60fc6535d1a4bb48faea00e1d4793d18bc0f7f98 (diff) | |
download | xmlgraphics-fop-0a2d149c230858d311f6d4d776072704a0096ac2.tar.gz xmlgraphics-fop-0a2d149c230858d311f6d4d776072704a0096ac2.zip |
Merged Temp_API_Finalization branch back into FOP Trunk:
Finalized API according to the plan in the Wiki: http://wiki.apache.org/xmlgraphics-fop/ApiDesign
In addition to that:
Deprecated the rest of the Fop constructors.
Refactored the FopServlet a bit to make it more versatile and still easy to understand. The FopPrintServlet is now a subclass of FopServlet.
Some further cleanup on the way.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@389086 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test')
9 files changed, 77 insertions, 57 deletions
diff --git a/test/java/org/apache/fop/BasicDriverTestCase.java b/test/java/org/apache/fop/BasicDriverTestCase.java index c74ecaad9..33bfb1841 100644 --- a/test/java/org/apache/fop/BasicDriverTestCase.java +++ b/test/java/org/apache/fop/BasicDriverTestCase.java @@ -1,5 +1,5 @@ /* - * 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. @@ -28,7 +28,9 @@ import javax.xml.transform.sax.SAXResult; import javax.xml.transform.stream.StreamSource; import org.apache.commons.io.output.ByteArrayOutputStream; +import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.Fop; +import org.apache.fop.apps.FopFactory; import org.apache.fop.apps.MimeConstants; import org.apache.fop.cli.InputHandler; @@ -38,6 +40,8 @@ import org.apache.fop.cli.InputHandler; */ public class BasicDriverTestCase extends AbstractFOPTestCase { + private FopFactory fopFactory = FopFactory.newInstance(); + /** * @see junit.framework.TestCase#TestCase(String) */ @@ -50,10 +54,10 @@ public class BasicDriverTestCase extends AbstractFOPTestCase { * @throws Exception if anything fails */ public void testFO2PDFWithJAXP() throws Exception { + FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo"); ByteArrayOutputStream baout = new ByteArrayOutputStream(); - Fop fop = new Fop(MimeConstants.MIME_PDF); - fop.setOutputStream(baout); + Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, baout); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); //Identity transf. @@ -69,10 +73,10 @@ public class BasicDriverTestCase extends AbstractFOPTestCase { * @throws Exception if anything fails */ public void testFO2PSWithJAXP() throws Exception { + FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo"); ByteArrayOutputStream baout = new ByteArrayOutputStream(); - Fop fop = new Fop(MimeConstants.MIME_POSTSCRIPT); - fop.setOutputStream(baout); + Fop fop = fopFactory.newFop(MimeConstants.MIME_POSTSCRIPT, foUserAgent, baout); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); //Identity transf. @@ -88,10 +92,10 @@ public class BasicDriverTestCase extends AbstractFOPTestCase { * @throws Exception if anything fails */ public void testFO2RTFWithJAXP() throws Exception { + FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo"); ByteArrayOutputStream baout = new ByteArrayOutputStream(); - Fop fop = new Fop(MimeConstants.MIME_RTF); - fop.setOutputStream(baout); + Fop fop = fopFactory.newFop(MimeConstants.MIME_RTF, foUserAgent, baout); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); //Identity transf. @@ -107,12 +111,13 @@ public class BasicDriverTestCase extends AbstractFOPTestCase { * @throws Exception if anything fails */ public void testFO2PDFWithXSLTInputHandler() throws Exception { + FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); File xmlFile = new File(getBaseDir(), "test/xml/1.xml"); File xsltFile = new File(getBaseDir(), "test/xsl/doc.xsl"); ByteArrayOutputStream baout = new ByteArrayOutputStream(); InputHandler handler = new InputHandler(xmlFile, xsltFile, null); - handler.renderTo(null, MimeConstants.MIME_PDF, baout); + handler.renderTo(foUserAgent, MimeConstants.MIME_PDF, baout); assertTrue("Generated PDF has zero length", baout.size() > 0); } diff --git a/test/java/org/apache/fop/GenericFOPTestCase.java b/test/java/org/apache/fop/GenericFOPTestCase.java index 7c8a65f4d..25f18b819 100644 --- a/test/java/org/apache/fop/GenericFOPTestCase.java +++ b/test/java/org/apache/fop/GenericFOPTestCase.java @@ -1,5 +1,5 @@ /* - * 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. @@ -32,6 +32,7 @@ import junit.framework.TestSuite; import org.apache.fop.apps.Fop; import org.apache.fop.apps.FOUserAgent; +import org.apache.fop.apps.FopFactory; import org.apache.fop.apps.MimeConstants; import org.apache.fop.util.DigestFilter; import org.xml.sax.InputSource; @@ -46,6 +47,9 @@ import org.xml.sax.InputSource; */ public final class GenericFOPTestCase extends TestCase { + // configure fopFactory as desired + private FopFactory fopFactory = FopFactory.newInstance(); + protected SAXParserFactory parserFactory; public static Test suite() { @@ -110,13 +114,12 @@ public final class GenericFOPTestCase extends TestCase { private void renderPDF(String fo, String digestIn, String digestOut) throws Exception { - FOUserAgent foUserAgent = new FOUserAgent(); + FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); foUserAgent.setCreationDate(new Date(10000)); MessageDigest outDigest = MessageDigest.getInstance("MD5"); DigestOutputStream out = new DigestOutputStream(new ByteArrayOutputStream(), outDigest); - Fop fop = new Fop(MimeConstants.MIME_PDF, foUserAgent); - fop.setOutputStream(out); + Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out); InputSource source = new InputSource(new StringReader(fo)); DigestFilter filter = new DigestFilter("MD5"); filter.setParent(parserFactory.newSAXParser().getXMLReader()); diff --git a/test/java/org/apache/fop/URIResolutionTestCase.java b/test/java/org/apache/fop/URIResolutionTestCase.java index 7eb79ec38..367275d8b 100644 --- a/test/java/org/apache/fop/URIResolutionTestCase.java +++ b/test/java/org/apache/fop/URIResolutionTestCase.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. @@ -40,8 +40,8 @@ import org.apache.commons.io.output.ByteArrayOutputStream; import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.Fop; +import org.apache.fop.apps.FopFactory; import org.apache.fop.apps.MimeConstants; -import org.apache.fop.image.ImageFactory; import org.apache.fop.render.xml.XMLRenderer; import org.apache.xpath.XPathAPI; import org.apache.xpath.objects.XObject; @@ -52,6 +52,9 @@ import org.w3c.dom.Document; */ public class URIResolutionTestCase extends AbstractFOPTestCase { + // configure fopFactory as desired + private FopFactory fopFactory = FopFactory.newInstance(); + private SAXTransformerFactory tfactory = (SAXTransformerFactory)SAXTransformerFactory.newInstance(); @@ -79,12 +82,13 @@ public class URIResolutionTestCase extends AbstractFOPTestCase { } private void innerTestFO1(boolean withStream) throws Exception { + FOUserAgent ua = fopFactory.newFOUserAgent(); + //Reset the image caches to force URI resolution! - ImageFactory.getInstance().clearCaches(); + ua.getFactory().getImageFactory().clearCaches(); File foFile = new File(getBaseDir(), "test/xml/uri-resolution1.fo"); - FOUserAgent ua = new FOUserAgent(); MyURIResolver resolver = new MyURIResolver(withStream); ua.setURIResolver(resolver); ua.setBaseURL(foFile.getParentFile().toURL().toString()); @@ -111,15 +115,14 @@ public class URIResolutionTestCase extends AbstractFOPTestCase { //TODO This will only work when we can do URI resolution inside Batik! File foFile = new File(getBaseDir(), "test/xml/uri-resolution2.fo"); - FOUserAgent ua = new FOUserAgent(); + FOUserAgent ua = fopFactory.newFOUserAgent(); MyURIResolver resolver = new MyURIResolver(false); ua.setURIResolver(resolver); ua.setBaseURL(foFile.getParentFile().toURL().toString()); - Fop fop = new Fop(MimeConstants.MIME_PDF, ua); - ByteArrayOutputStream baout = new ByteArrayOutputStream(); - fop.setOutputStream(baout); + + Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, ua, baout); Transformer transformer = tfactory.newTransformer(); //Identity transf. Source src = new StreamSource(foFile); @@ -156,7 +159,7 @@ public class URIResolutionTestCase extends AbstractFOPTestCase { atrenderer.setContentHandler(athandler); ua.setRendererOverride(atrenderer); - Fop fop = new Fop(MimeConstants.MIME_FOP_AREA_TREE, ua); + Fop fop = fopFactory.newFop(ua); Transformer transformer = tfactory.newTransformer(); //Identity transf. Source src = new StreamSource(fo); diff --git a/test/java/org/apache/fop/fotreetest/FOTreeTester.java b/test/java/org/apache/fop/fotreetest/FOTreeTester.java index 773593f09..323990303 100644 --- a/test/java/org/apache/fop/fotreetest/FOTreeTester.java +++ b/test/java/org/apache/fop/fotreetest/FOTreeTester.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. @@ -23,18 +23,12 @@ import java.util.List; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; -import javax.xml.transform.Source; -import javax.xml.transform.Transformer; -import javax.xml.transform.sax.SAXResult; -import javax.xml.transform.sax.SAXTransformerFactory; -import javax.xml.transform.stream.StreamSource; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.Fop; -import org.apache.fop.apps.MimeConstants; +import org.apache.fop.apps.FopFactory; import org.apache.fop.fotreetest.ext.TestElementMapping; -import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; import org.xml.sax.helpers.XMLFilterImpl; @@ -44,9 +38,6 @@ import org.xml.sax.helpers.XMLFilterImpl; */ public class FOTreeTester { - private SAXTransformerFactory tfactory - = (SAXTransformerFactory)SAXTransformerFactory.newInstance(); - /** * Runs a test. * @param testFile the test file. @@ -63,15 +54,17 @@ public class FOTreeTester { XMLReader reader = parser.getXMLReader(); //Setup FOP for area tree rendering - FOUserAgent ua = new FOUserAgent(); + FopFactory fopFactory = FopFactory.newInstance(); + fopFactory.addElementMapping(new TestElementMapping()); + + FOUserAgent ua = fopFactory.newFOUserAgent(); ua.setBaseURL(testFile.getParentFile().toURL().toString()); ua.setFOEventHandlerOverride(new DummyFOEventHandler(ua)); - ua.addElementMapping(new TestElementMapping()); //Used to set values in the user agent through processing instructions reader = new PIListener(reader, ua); - Fop fop = new Fop(MimeConstants.MIME_FOP_AREA_TREE, ua); + Fop fop = fopFactory.newFop(ua); reader.setContentHandler(fop.getDefaultHandler()); reader.setDTDHandler(fop.getDefaultHandler()); @@ -100,7 +93,7 @@ public class FOTreeTester { /** @see org.xml.sax.helpers.XMLFilterImpl */ public void processingInstruction(String target, String data) throws SAXException { if ("fop-useragent-break-indent-inheritance".equals(target)) { - userAgent.setBreakIndentInheritanceOnReferenceAreaBoundary( + userAgent.getFactory().setBreakIndentInheritanceOnReferenceAreaBoundary( Boolean.valueOf(data).booleanValue()); } super.processingInstruction(target, data); diff --git a/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java b/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java index 245dc25eb..be7f73e13 100644 --- a/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java +++ b/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java @@ -41,6 +41,7 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.io.output.ByteArrayOutputStream; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.Fop; +import org.apache.fop.apps.FopFactory; import org.apache.fop.apps.MimeConstants; import org.apache.fop.area.AreaTreeModel; import org.apache.fop.area.AreaTreeParser; @@ -58,6 +59,9 @@ import org.w3c.dom.Document; */ public class AreaTreeParserTestCase extends XMLTestCase { + // configure fopFactory as desired + private FopFactory fopFactory = FopFactory.newInstance(); + private static SAXTransformerFactory tFactory = (SAXTransformerFactory)SAXTransformerFactory.newInstance(); private static Templates stylesheet = null; @@ -162,7 +166,7 @@ public class AreaTreeParserTestCase extends XMLTestCase { } private FOUserAgent createUserAgent() { - FOUserAgent userAgent = new FOUserAgent(); + FOUserAgent userAgent = fopFactory.newFOUserAgent(); try { userAgent.setBaseURL(testDir.toURL().toExternalForm()); } catch (MalformedURLException e) { @@ -197,7 +201,7 @@ public class AreaTreeParserTestCase extends XMLTestCase { userAgent.setRendererOverride(renderer); - Fop fop = new Fop(MimeConstants.MIME_FOP_AREA_TREE, userAgent); + Fop fop = fopFactory.newFop(MimeConstants.MIME_FOP_AREA_TREE, userAgent); Result res = new SAXResult(fop.getDefaultHandler()); transformer.transform(src, res); diff --git a/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java b/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java index 7fd8fe4e4..f3262e881 100644 --- a/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java +++ b/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java @@ -21,7 +21,6 @@ package org.apache.fop.layoutengine; import java.io.File; import java.io.IOException; import java.lang.reflect.Constructor; -import java.net.MalformedURLException; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -43,11 +42,10 @@ import javax.xml.transform.sax.TransformerHandler; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; -import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.Fop; +import org.apache.fop.apps.FopFactory; import org.apache.fop.apps.FormattingResults; -import org.apache.fop.apps.MimeConstants; import org.apache.fop.layoutmgr.ElementListObserver; import org.apache.fop.render.xml.XMLRenderer; import org.apache.xpath.XPathAPI; @@ -56,7 +54,6 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import org.xml.sax.InputSource; import org.xml.sax.SAXException; /** @@ -67,6 +64,10 @@ public class LayoutEngineTester { private static final Map CHECK_CLASSES = new java.util.HashMap(); + // configure fopFactory as desired + private FopFactory fopFactory = FopFactory.newInstance(); + private FopFactory fopFactoryWithBase14Kerning = FopFactory.newInstance(); + private SAXTransformerFactory tfactory = (SAXTransformerFactory)SAXTransformerFactory.newInstance(); @@ -89,6 +90,8 @@ public class LayoutEngineTester { */ public LayoutEngineTester(File areaTreeBackupDir) { this.areaTreeBackupDir = areaTreeBackupDir; + fopFactory.setBase14KerningEnabled(false); + fopFactoryWithBase14Kerning.setBase14KerningEnabled(true); } private Templates getTestcase2FOStylesheet() throws TransformerConfigurationException { @@ -137,6 +140,7 @@ public class LayoutEngineTester { XObject xo = XPathAPI.eval(testDoc, "/testcase/cfg/base14kerning"); String s = xo.str(); boolean base14kerning = ("true".equalsIgnoreCase(s)); + FopFactory effFactory = (base14kerning ? fopFactoryWithBase14Kerning : fopFactory); //Setup Transformer to convert the testcase XML to XSL-FO Transformer transformer = getTestcase2FOStylesheet().newTransformer(); @@ -147,14 +151,13 @@ public class LayoutEngineTester { athandler.setResult(domres); //Setup FOP for area tree rendering - FOUserAgent ua = new FOUserAgent(); + FOUserAgent ua = effFactory.newFOUserAgent(); ua.setBaseURL(testFile.getParentFile().toURL().toString()); - ua.setBase14KerningEnabled(base14kerning); XMLRenderer atrenderer = new XMLRenderer(); atrenderer.setUserAgent(ua); atrenderer.setContentHandler(athandler); ua.setRendererOverride(atrenderer); - fop = new Fop(MimeConstants.MIME_FOP_AREA_TREE, ua); + fop = effFactory.newFop(ua); SAXResult fores = new SAXResult(fop.getDefaultHandler()); transformer.transform(src, fores); diff --git a/test/java/org/apache/fop/threading/FOProcessorImpl.java b/test/java/org/apache/fop/threading/FOProcessorImpl.java index 51c76584a..303cffd47 100644 --- a/test/java/org/apache/fop/threading/FOProcessorImpl.java +++ b/test/java/org/apache/fop/threading/FOProcessorImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2005 The Apache Software Foundation. + * Copyright 2004-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. @@ -35,14 +35,18 @@ import org.apache.avalon.framework.configuration.Configurable; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; +import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.Fop; import org.apache.fop.apps.FOPException; +import org.apache.fop.apps.FopFactory; import org.apache.fop.apps.MimeConstants; import org.apache.avalon.framework.activity.Initializable; public class FOProcessorImpl extends AbstractLogEnabled implements FOProcessor, Configurable, Initializable { + private FopFactory fopFactory = FopFactory.newInstance(); + private TransformerFactory factory = TransformerFactory.newInstance(); private String baseDir; private String fontBaseDir; private String userconfig; @@ -84,13 +88,12 @@ public class FOProcessorImpl extends AbstractLogEnabled public void process(InputStream in, Templates templates, OutputStream out) throws org.apache.fop.apps.FOPException, java.io.IOException { - Fop fop = new Fop(MimeConstants.MIME_PDF); - fop.setOutputStream(out); + FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); + Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out); try { Transformer transformer; if (templates == null) { - TransformerFactory factory = TransformerFactory.newInstance(); transformer = factory.newTransformer(); } else { transformer = templates.newTransformer(); diff --git a/test/java/org/apache/fop/visual/AbstractPSPDFBitmapProducer.java b/test/java/org/apache/fop/visual/AbstractPSPDFBitmapProducer.java index 8e893fea9..f26b2f9d9 100644 --- a/test/java/org/apache/fop/visual/AbstractPSPDFBitmapProducer.java +++ b/test/java/org/apache/fop/visual/AbstractPSPDFBitmapProducer.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. @@ -36,6 +36,7 @@ import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.commons.io.IOUtils; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.Fop; +import org.apache.fop.apps.FopFactory; /** * BitmapProducer implementation that uses the PS or PDF renderer and an external converter @@ -63,6 +64,9 @@ import org.apache.fop.apps.Fop; public abstract class AbstractPSPDFBitmapProducer extends AbstractBitmapProducer implements Configurable { + // configure fopFactory as desired + private FopFactory fopFactory = FopFactory.newInstance(); + private String converter; private boolean deleteTempFiles; @@ -106,7 +110,7 @@ public abstract class AbstractPSPDFBitmapProducer extends AbstractBitmapProducer /** @see org.apache.fop.visual.BitmapProducer */ public BufferedImage produce(File src, ProducerContext context) { try { - FOUserAgent userAgent = new FOUserAgent(); + FOUserAgent userAgent = fopFactory.newFOUserAgent(); userAgent.setTargetResolution(context.getTargetResolution()); userAgent.setBaseURL(src.getParentFile().toURL().toString()); @@ -118,8 +122,7 @@ public abstract class AbstractPSPDFBitmapProducer extends AbstractBitmapProducer OutputStream out = new FileOutputStream(tempOut); out = new BufferedOutputStream(out); try { - Fop fop = new Fop(getTargetFormat(), userAgent); - fop.setOutputStream(out); + Fop fop = fopFactory.newFop(getTargetFormat(), userAgent, out); SAXResult res = new SAXResult(fop.getDefaultHandler()); Transformer transformer = getTransformer(context); diff --git a/test/java/org/apache/fop/visual/BitmapProducerJava2D.java b/test/java/org/apache/fop/visual/BitmapProducerJava2D.java index 06f3b6b5e..060384447 100644 --- a/test/java/org/apache/fop/visual/BitmapProducerJava2D.java +++ b/test/java/org/apache/fop/visual/BitmapProducerJava2D.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. @@ -34,6 +34,7 @@ import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.commons.io.IOUtils; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.Fop; +import org.apache.fop.apps.FopFactory; import org.apache.fop.apps.MimeConstants; /** @@ -51,6 +52,9 @@ import org.apache.fop.apps.MimeConstants; */ public class BitmapProducerJava2D extends AbstractBitmapProducer implements Configurable { + // configure fopFactory as desired + private FopFactory fopFactory = FopFactory.newInstance(); + private boolean deleteTempFiles; /** @see org.apache.avalon.framework.configuration.Configurable */ @@ -61,7 +65,7 @@ public class BitmapProducerJava2D extends AbstractBitmapProducer implements Conf /** @see org.apache.fop.visual.BitmapProducer */ public BufferedImage produce(File src, ProducerContext context) { try { - FOUserAgent userAgent = new FOUserAgent(); + FOUserAgent userAgent = fopFactory.newFOUserAgent(); userAgent.setTargetResolution(context.getTargetResolution()); userAgent.setBaseURL(src.getParentFile().toURL().toString()); @@ -69,8 +73,7 @@ public class BitmapProducerJava2D extends AbstractBitmapProducer implements Conf OutputStream out = new FileOutputStream(outputFile); out = new BufferedOutputStream(out); try { - Fop fop = new Fop(MimeConstants.MIME_PNG, userAgent); - fop.setOutputStream(out); + Fop fop = fopFactory.newFop(MimeConstants.MIME_PNG, userAgent, out); SAXResult res = new SAXResult(fop.getDefaultHandler()); Transformer transformer = getTransformer(context); |