From: Mehdi Houshmand Date: Mon, 23 Jan 2012 16:15:23 +0000 (+0000) Subject: Moved the FOUserAgent into the constructor of the Renderers X-Git-Tag: fop-1_1rc1old~141 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fb20c15fa4aafcc71ddb7288d45d32db118a7d86;p=xmlgraphics-fop.git Moved the FOUserAgent into the constructor of the Renderers This breaks the public API but for good reasons: 1) the user-agent is essential for configuring the renderers 2) instantiation of the constructor is always followed by call to "setUserAgent()" (in the examples) 3) simplifies the API and reduces mutability of the Renderers git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1234877 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/examples/embedding/java/embedding/ExampleFO2JPSPrint.java b/examples/embedding/java/embedding/ExampleFO2JPSPrint.java index 4f18b71ab..1e0ec4853 100644 --- a/examples/embedding/java/embedding/ExampleFO2JPSPrint.java +++ b/examples/embedding/java/embedding/ExampleFO2JPSPrint.java @@ -85,8 +85,7 @@ public class ExampleFO2JPSPrint { //Set up a custom user agent so we can supply our own renderer instance FOUserAgent userAgent = fopFactory.newFOUserAgent(); - PageableRenderer renderer = new PageableRenderer(); - renderer.setUserAgent(userAgent); + PageableRenderer renderer = new PageableRenderer(userAgent); userAgent.setRendererOverride(renderer); // Construct FOP with desired output format diff --git a/examples/embedding/java/embedding/atxml/ExampleConcat.java b/examples/embedding/java/embedding/atxml/ExampleConcat.java index adec1b08c..289f7d074 100644 --- a/examples/embedding/java/embedding/atxml/ExampleConcat.java +++ b/examples/embedding/java/embedding/atxml/ExampleConcat.java @@ -93,8 +93,7 @@ public class ExampleConcat { userAgent, MimeConstants.MIME_PDF); //Create the XMLRenderer to create the area tree XML - XMLRenderer xmlRenderer = new XMLRenderer(); - xmlRenderer.setUserAgent(userAgent); + XMLRenderer xmlRenderer = new XMLRenderer(userAgent); //Tell the XMLRenderer to mimic the target renderer xmlRenderer.mimicRenderer(targetRenderer); diff --git a/src/java/org/apache/fop/cli/CommandLineOptions.java b/src/java/org/apache/fop/cli/CommandLineOptions.java index 0d4c3790c..845c11a0d 100644 --- a/src/java/org/apache/fop/cli/CommandLineOptions.java +++ b/src/java/org/apache/fop/cli/CommandLineOptions.java @@ -203,17 +203,14 @@ public class CommandLineOptions { System.err.println("Couldn't set system look & feel!"); } - AWTRenderer renderer = new AWTRenderer(true); - renderer.setRenderable(inputHandler); //set before user agent! - renderer.setUserAgent(foUserAgent); + AWTRenderer renderer = new AWTRenderer(foUserAgent, inputHandler, true, true); foUserAgent.setRendererOverride(renderer); } else if (MimeConstants.MIME_FOP_AREA_TREE.equals(outputmode) && mimicRenderer != null) { // render from FO to Intermediate Format Renderer targetRenderer = foUserAgent.getRendererFactory().createRenderer( foUserAgent, mimicRenderer); - XMLRenderer xmlRenderer = new XMLRenderer(); - xmlRenderer.setUserAgent(foUserAgent); + XMLRenderer xmlRenderer = new XMLRenderer(foUserAgent); //Tell the XMLRenderer to mimic the target renderer xmlRenderer.mimicRenderer(targetRenderer); diff --git a/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java b/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java index 45a02a977..83d3d84a2 100644 --- a/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java +++ b/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java @@ -34,6 +34,7 @@ import org.apache.xmlgraphics.image.loader.ImageSize; import org.apache.xmlgraphics.util.QName; import org.apache.xmlgraphics.util.UnitConv; +import org.apache.fop.apps.FOUserAgent; import org.apache.fop.area.Area; import org.apache.fop.area.Block; import org.apache.fop.area.BlockViewport; @@ -56,6 +57,10 @@ import org.apache.fop.traits.BorderProps; */ public abstract class AbstractPathOrientedRenderer extends PrintRenderer { + public AbstractPathOrientedRenderer(FOUserAgent userAgent) { + super(userAgent); + } + /** * Handle block traits. * The block could be any sort of block with any positioning diff --git a/src/java/org/apache/fop/render/AbstractRenderer.java b/src/java/org/apache/fop/render/AbstractRenderer.java index 7ff236d16..659748df9 100644 --- a/src/java/org/apache/fop/render/AbstractRenderer.java +++ b/src/java/org/apache/fop/render/AbstractRenderer.java @@ -61,11 +61,11 @@ import org.apache.fop.area.inline.Image; import org.apache.fop.area.inline.InlineArea; import org.apache.fop.area.inline.InlineBlockParent; import org.apache.fop.area.inline.InlineParent; +import org.apache.fop.area.inline.InlineViewport; import org.apache.fop.area.inline.Leader; import org.apache.fop.area.inline.Space; import org.apache.fop.area.inline.SpaceArea; import org.apache.fop.area.inline.TextArea; -import org.apache.fop.area.inline.InlineViewport; import org.apache.fop.area.inline.WordArea; import org.apache.fop.fo.Constants; import org.apache.fop.fonts.FontInfo; @@ -116,16 +116,16 @@ public abstract class AbstractRenderer /** {@inheritDoc} */ public abstract void setupFontInfo(FontInfo fontInfo) throws FOPException; - /** {@inheritDoc} */ - public void setUserAgent(FOUserAgent agent) { - userAgent = agent; + /** + * + * @param userAgent the user agent that contains configuration details. This cannot be null. + */ + public AbstractRenderer(FOUserAgent userAgent) { + this.userAgent = userAgent; } /** {@inheritDoc} */ public FOUserAgent getUserAgent() { - if (userAgent == null) { - throw new IllegalStateException("FOUserAgent has not been set on Renderer"); - } return userAgent; } diff --git a/src/java/org/apache/fop/render/PrintRenderer.java b/src/java/org/apache/fop/render/PrintRenderer.java index be3ace016..05e9cb7af 100644 --- a/src/java/org/apache/fop/render/PrintRenderer.java +++ b/src/java/org/apache/fop/render/PrintRenderer.java @@ -27,6 +27,7 @@ import java.util.Map; import org.w3c.dom.Document; import org.apache.fop.apps.FOPException; +import org.apache.fop.apps.FOUserAgent; import org.apache.fop.area.Area; import org.apache.fop.area.Trait; import org.apache.fop.fonts.CustomFontCollection; @@ -42,6 +43,10 @@ import org.apache.fop.fonts.base14.Base14FontCollection; /** Abstract base class of "Print" type renderers. */ public abstract class PrintRenderer extends AbstractRenderer { + public PrintRenderer(FOUserAgent userAgent) { + super(userAgent); + } + /** Font configuration */ protected FontInfo fontInfo; diff --git a/src/java/org/apache/fop/render/Renderer.java b/src/java/org/apache/fop/render/Renderer.java index 76f245251..5f5596dfb 100644 --- a/src/java/org/apache/fop/render/Renderer.java +++ b/src/java/org/apache/fop/render/Renderer.java @@ -81,13 +81,6 @@ public interface Renderer { void stopRenderer() throws IOException; - /** - * Set the User Agent. - * - * @param agent The User Agent - */ - void setUserAgent(FOUserAgent agent); - /** * Returns the associated user agent. * @return the user agent diff --git a/src/java/org/apache/fop/render/RendererFactory.java b/src/java/org/apache/fop/render/RendererFactory.java index bc598450f..3ceb27a8e 100644 --- a/src/java/org/apache/fop/render/RendererFactory.java +++ b/src/java/org/apache/fop/render/RendererFactory.java @@ -299,7 +299,6 @@ public class RendererFactory { AbstractRendererMaker maker = getRendererMaker(outputFormat); if (maker != null) { Renderer rend = maker.makeRenderer(userAgent); - rend.setUserAgent(userAgent); RendererConfigurator configurator = maker.getConfigurator(userAgent); if (configurator != null) { configurator.configure(rend); @@ -311,8 +310,7 @@ public class RendererFactory { } private Renderer createRendererForDocumentHandler(IFDocumentHandler documentHandler) { - IFRenderer rend = new IFRenderer(); - rend.setUserAgent(documentHandler.getContext().getUserAgent()); + IFRenderer rend = new IFRenderer(documentHandler.getContext().getUserAgent()); rend.setDocumentHandler(documentHandler); return rend; } diff --git a/src/java/org/apache/fop/render/awt/AWTRenderer.java b/src/java/org/apache/fop/render/awt/AWTRenderer.java index 99dece24a..c36655204 100644 --- a/src/java/org/apache/fop/render/awt/AWTRenderer.java +++ b/src/java/org/apache/fop/render/awt/AWTRenderer.java @@ -64,18 +64,6 @@ public class AWTRenderer extends Java2DRenderer implements Pageable { /** flag for debugging */ public boolean debug; // CSOK: VisibilityModifier - /** If true, preview dialog is shown. */ - public boolean dialogDisplay = true; // CSOK: VisibilityModifier - - /** true if the preview dialog should be the main window of the application */ - private boolean previewAsMainWindow; - - /** - * Renderable instance that can be used to reload and re-render a document after - * modifications. - */ - protected Renderable renderable; - /** * Will be notified when rendering progresses */ @@ -84,47 +72,35 @@ public class AWTRenderer extends Java2DRenderer implements Pageable { /** * Creates a new AWTRenderer instance. + * + * @param userAgent the user agent that contains configuration data */ - public AWTRenderer() { - this(false); + public AWTRenderer(FOUserAgent userAgent) { + this(userAgent, null, false, false); } /** * Creates a new AWTRenderer instance. + * + * @param userAgent the user agent that contains configuration data + * @param renderable a Renderable instance can be set so the Preview Dialog can enable the + * "Reload" button which causes the current document to be reprocessed and redisplayed. * @param previewAsMainWindow true if the preview dialog created by the renderer should be - * the main window of the application. + * the main window of the application. + * @param show sets whether the preview dialog should be created and displayed when the + * rendering has finished. */ - public AWTRenderer(boolean previewAsMainWindow) { - this.previewAsMainWindow = previewAsMainWindow; - } - - /** {@inheritDoc} */ - public void setUserAgent(FOUserAgent foUserAgent) { - super.setUserAgent(foUserAgent); - if (dialogDisplay) { - setStatusListener(PreviewDialog.createPreviewDialog(userAgent, this.renderable, - this.previewAsMainWindow)); + public AWTRenderer(FOUserAgent userAgent, Renderable renderable, boolean previewAsMainWindow, + boolean show) { + super(userAgent); + if (show) { + // MH: Not sure about this??? If show is false, there's no way for this class + // to create a preview dialog... Previously a "setUserAgent" could be called. + setStatusListener(PreviewDialog.createPreviewDialog(userAgent, renderable, + previewAsMainWindow)); } } - /** - * A Renderable instance can be set so the Preview Dialog can enable the "Reload" button - * which causes the current document to be reprocessed and redisplayed. - * @param renderable the Renderable instance. - */ - public void setRenderable(Renderable renderable) { - this.renderable = renderable; - } - - /** - * Sets whether the preview dialog should be created and displayed when - * the rendering is finished. - * @param show If false, preview dialog is not shown. True by default - */ - public void setPreviewDialogDisplayed(boolean show) { - dialogDisplay = show; - } - /** * {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/awt/AWTRendererMaker.java b/src/java/org/apache/fop/render/awt/AWTRendererMaker.java index 983b42e0c..d65a550d4 100644 --- a/src/java/org/apache/fop/render/awt/AWTRendererMaker.java +++ b/src/java/org/apache/fop/render/awt/AWTRendererMaker.java @@ -34,7 +34,7 @@ public class AWTRendererMaker extends AbstractRendererMaker { /** {@inheritDoc} */ public Renderer makeRenderer(FOUserAgent ua) { - return new AWTRenderer(); + return new AWTRenderer(ua); } /** {@inheritDoc} */ 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 2303c0e8e..c850c35e7 100644 --- a/src/java/org/apache/fop/render/awt/viewer/PreviewPanel.java +++ b/src/java/org/apache/fop/render/awt/viewer/PreviewPanel.java @@ -67,12 +67,9 @@ import org.apache.fop.render.awt.AWTRenderer; *

*
  * FopFactory fopFactory = FopFactory.newInstance();
- * AWTRenderer renderer = new AWTRenderer();
  * FOUserAgent agent = fopFactory.newFOUserAgent();
+ * AWTRenderer renderer = new AWTRenderer(agent);
  * agent.setRendererOverride(renderer);
- * renderer.setPreviewDialogDisplayed(false);
- * renderer.setUserAgent(agent);
- * renderer.setUserAgent(agent);
  * previewPanel = new PreviewPanel(agent, null, renderer);
  * previewPanel = new PreviewPanel(ua);
  * myGui.add(previewPanel);
diff --git a/src/java/org/apache/fop/render/bitmap/PNGRenderer.java b/src/java/org/apache/fop/render/bitmap/PNGRenderer.java
index 3733bf2f2..1c6f2e33d 100644
--- a/src/java/org/apache/fop/render/bitmap/PNGRenderer.java
+++ b/src/java/org/apache/fop/render/bitmap/PNGRenderer.java
@@ -29,6 +29,7 @@ import org.apache.xmlgraphics.image.writer.ImageWriter;
 import org.apache.xmlgraphics.image.writer.ImageWriterParams;
 import org.apache.xmlgraphics.image.writer.ImageWriterRegistry;
 
+import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.MimeConstants;
 import org.apache.fop.area.PageViewport;
 import org.apache.fop.render.java2d.Java2DRenderer;
@@ -40,6 +41,10 @@ import org.apache.fop.render.java2d.Java2DRenderer;
  */
 public class PNGRenderer extends Java2DRenderer {
 
+    public PNGRenderer(FOUserAgent userAgent) {
+        super(userAgent);
+    }
+
     /** The MIME type for png-Rendering */
     public static final String MIME_TYPE = MimeConstants.MIME_PNG;
 
diff --git a/src/java/org/apache/fop/render/bitmap/PNGRendererMaker.java b/src/java/org/apache/fop/render/bitmap/PNGRendererMaker.java
index 7d321791a..da19b2986 100644
--- a/src/java/org/apache/fop/render/bitmap/PNGRendererMaker.java
+++ b/src/java/org/apache/fop/render/bitmap/PNGRendererMaker.java
@@ -36,7 +36,7 @@ public class PNGRendererMaker extends AbstractRendererMaker {
 
     /** {@inheritDoc} */
     public Renderer makeRenderer(FOUserAgent ua) {
-        return new PNGRenderer();
+        return new PNGRenderer(ua);
     }
 
     /** {@inheritDoc} */
diff --git a/src/java/org/apache/fop/render/bitmap/TIFFRenderer.java b/src/java/org/apache/fop/render/bitmap/TIFFRenderer.java
index 5a9cfa21b..0e2364d35 100644
--- a/src/java/org/apache/fop/render/bitmap/TIFFRenderer.java
+++ b/src/java/org/apache/fop/render/bitmap/TIFFRenderer.java
@@ -83,19 +83,11 @@ public class TIFFRenderer extends Java2DRenderer implements TIFFConstants {
     }
 
     /** Creates TIFF renderer. */
-    public TIFFRenderer() {
+    public TIFFRenderer(FOUserAgent userAgent) {
+        super(userAgent);
         writerParams = new ImageWriterParams();
         writerParams.setCompressionMethod(COMPRESSION_PACKBITS);
-    }
-
-    /**
-     * {@inheritDoc}
-     *          org.apache.fop.apps.FOUserAgent)
-     */
-    public void setUserAgent(FOUserAgent foUserAgent) {
-        super.setUserAgent(foUserAgent);
 
-        //Set target resolution
         int dpi = Math.round(userAgent.getTargetResolution());
         writerParams.setResolution(dpi);
     }
diff --git a/src/java/org/apache/fop/render/bitmap/TIFFRendererMaker.java b/src/java/org/apache/fop/render/bitmap/TIFFRendererMaker.java
index e3c567995..852e6ba04 100644
--- a/src/java/org/apache/fop/render/bitmap/TIFFRendererMaker.java
+++ b/src/java/org/apache/fop/render/bitmap/TIFFRendererMaker.java
@@ -34,7 +34,7 @@ public class TIFFRendererMaker extends AbstractRendererMaker {
 
     /** {@inheritDoc} */
     public Renderer makeRenderer(FOUserAgent userAgent) {
-        return new TIFFRenderer();
+        return new TIFFRenderer(userAgent);
     }
 
     /** {@inheritDoc} */
diff --git a/src/java/org/apache/fop/render/intermediate/IFRenderer.java b/src/java/org/apache/fop/render/intermediate/IFRenderer.java
index 24a2e8a75..d5d5a154a 100644
--- a/src/java/org/apache/fop/render/intermediate/IFRenderer.java
+++ b/src/java/org/apache/fop/render/intermediate/IFRenderer.java
@@ -51,6 +51,7 @@ import org.apache.xmlgraphics.xmp.schemas.XMPBasicSchema;
 
 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.area.Area;
 import org.apache.fop.area.AreaTreeObject;
@@ -70,10 +71,10 @@ import org.apache.fop.area.inline.ForeignObject;
 import org.apache.fop.area.inline.Image;
 import org.apache.fop.area.inline.InlineArea;
 import org.apache.fop.area.inline.InlineParent;
+import org.apache.fop.area.inline.InlineViewport;
 import org.apache.fop.area.inline.Leader;
 import org.apache.fop.area.inline.SpaceArea;
 import org.apache.fop.area.inline.TextArea;
-import org.apache.fop.area.inline.InlineViewport;
 import org.apache.fop.area.inline.WordArea;
 import org.apache.fop.datatypes.URISpecification;
 import org.apache.fop.fo.extensions.ExtensionAttachment;
@@ -158,7 +159,8 @@ public class IFRenderer extends AbstractPathOrientedRenderer {
     /**
      * Main constructor
      */
-    public IFRenderer() {
+    public IFRenderer(FOUserAgent userAgent) {
+        super(userAgent);
     }
 
     /** {@inheritDoc} */
diff --git a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
index 766aa081f..3c7006588 100644
--- a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
+++ b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
@@ -147,15 +147,13 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem
     private GeneralPath currentPath = null;
 
     /** Default constructor */
-    public Java2DRenderer() {
-    }
+    public Java2DRenderer(FOUserAgent userAgent) {
+        super(userAgent);
 
-    /** {@inheritDoc} */
-    public void setUserAgent(FOUserAgent foUserAgent) {
-        super.setUserAgent(foUserAgent);
+        // MH: necessary? the caller has access to FOUserAgent
         userAgent.setRendererOverride(this); // for document regeneration
 
-        String s = (String)userAgent.getRendererOptions().get(JAVA2D_TRANSPARENT_PAGE_BACKGROUND);
+        String s = (String) userAgent.getRendererOptions().get(JAVA2D_TRANSPARENT_PAGE_BACKGROUND);
         if (s != null) {
             this.transparentPageBackground = "true".equalsIgnoreCase(s);
         }
diff --git a/src/java/org/apache/fop/render/print/PageableRenderer.java b/src/java/org/apache/fop/render/print/PageableRenderer.java
index 89ab98071..08d5b0f04 100644
--- a/src/java/org/apache/fop/render/print/PageableRenderer.java
+++ b/src/java/org/apache/fop/render/print/PageableRenderer.java
@@ -73,7 +73,11 @@ public class PageableRenderer extends Java2DRenderer implements Pageable {
     /**
      * Creates a new PageableRenderer.
      */
-    public PageableRenderer() {
+    public PageableRenderer(FOUserAgent userAgent) {
+        super(userAgent);
+        Map rendererOptions = getUserAgent().getRendererOptions();
+        processOptions(rendererOptions);
+        this.pageFilter = new DefaultPageFilter();
     }
 
     /** {@inheritDoc} */
@@ -81,15 +85,6 @@ public class PageableRenderer extends Java2DRenderer implements Pageable {
         return MimeConstants.MIME_FOP_PRINT;
     }
 
-    /** {@inheritDoc} */
-    public void setUserAgent(FOUserAgent agent) {
-        super.setUserAgent(agent);
-
-        Map rendererOptions = agent.getRendererOptions();
-        processOptions(rendererOptions);
-        this.pageFilter = new DefaultPageFilter();
-    }
-
     private void processOptions(Map rendererOptions) {
         Object o = rendererOptions.get(PageableRenderer.PAGES_MODE);
         if (o != null) {
diff --git a/src/java/org/apache/fop/render/print/PrintRenderer.java b/src/java/org/apache/fop/render/print/PrintRenderer.java
index 2eb2b07a2..ea68bc9b2 100644
--- a/src/java/org/apache/fop/render/print/PrintRenderer.java
+++ b/src/java/org/apache/fop/render/print/PrintRenderer.java
@@ -55,19 +55,9 @@ public class PrintRenderer extends PageableRenderer {
      * Creates a new PrintRenderer with the options set through the renderer options if a custom
      * PrinterJob is not given in FOUserAgent's renderer options.
      */
-    public PrintRenderer() {
-    }
-
-    /**
-     * Creates a new PrintRenderer and allows you to pass in a specific PrinterJob instance
-     * that this renderer should work with.
-     * @param printerJob the PrinterJob instance
-     * @deprecated Please use the rendering options on the user agent to pass in the PrinterJob!
-     */
-    public PrintRenderer(PrinterJob printerJob) {
-        this();
-        this.printerJob = printerJob;
-        printerJob.setPageable(this);
+    public PrintRenderer(FOUserAgent userAgent) {
+        super(userAgent);
+        setRendererOptions();
     }
 
     private void initializePrinterJob() {
@@ -85,11 +75,8 @@ public class PrintRenderer extends PageableRenderer {
         }
     }
 
-    /** {@inheritDoc} */
-    public void setUserAgent(FOUserAgent agent) {
-        super.setUserAgent(agent);
-
-        Map rendererOptions = agent.getRendererOptions();
+    private void setRendererOptions() {
+        Map rendererOptions = getUserAgent().getRendererOptions();
 
         Object printerJobO = rendererOptions.get(PrintRenderer.PRINTER_JOB);
         if (printerJobO != null) {
diff --git a/src/java/org/apache/fop/render/print/PrintRendererMaker.java b/src/java/org/apache/fop/render/print/PrintRendererMaker.java
index 21eb4717a..63444a628 100644
--- a/src/java/org/apache/fop/render/print/PrintRendererMaker.java
+++ b/src/java/org/apache/fop/render/print/PrintRendererMaker.java
@@ -35,7 +35,7 @@ public class PrintRendererMaker extends AbstractRendererMaker {
 
     /**{@inheritDoc} */
     public Renderer makeRenderer(FOUserAgent userAgent) {
-        return new PrintRenderer();
+        return new PrintRenderer(userAgent);
     }
 
     /** {@inheritDoc} */
diff --git a/src/java/org/apache/fop/render/txt/TXTRenderer.java b/src/java/org/apache/fop/render/txt/TXTRenderer.java
index 386f95838..74c5b84a8 100644
--- a/src/java/org/apache/fop/render/txt/TXTRenderer.java
+++ b/src/java/org/apache/fop/render/txt/TXTRenderer.java
@@ -32,6 +32,7 @@ import java.util.Map;
 import org.apache.xmlgraphics.util.UnitConv;
 
 import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.area.Area;
 import org.apache.fop.area.CTM;
 import org.apache.fop.area.PageViewport;
@@ -110,7 +111,8 @@ public class TXTRenderer extends AbstractPathOrientedRenderer {
     /**
      * Constructs a newly allocated TXTRenderer object.
      */
-    public TXTRenderer() {
+    public TXTRenderer(FOUserAgent userAgent) {
+        super(userAgent);
     }
 
     /** {@inheritDoc} */
diff --git a/src/java/org/apache/fop/render/txt/TXTRendererMaker.java b/src/java/org/apache/fop/render/txt/TXTRendererMaker.java
index 0db369ef2..740866e0c 100644
--- a/src/java/org/apache/fop/render/txt/TXTRendererMaker.java
+++ b/src/java/org/apache/fop/render/txt/TXTRendererMaker.java
@@ -34,7 +34,7 @@ public class TXTRendererMaker extends AbstractRendererMaker {
 
     /**{@inheritDoc} */
     public Renderer makeRenderer(FOUserAgent userAgent) {
-        return new TXTRenderer();
+        return new TXTRenderer(userAgent);
     }
 
     /**{@inheritDoc} */
diff --git a/src/java/org/apache/fop/render/xml/AbstractXMLRenderer.java b/src/java/org/apache/fop/render/xml/AbstractXMLRenderer.java
index 497e3c047..9c938199f 100644
--- a/src/java/org/apache/fop/render/xml/AbstractXMLRenderer.java
+++ b/src/java/org/apache/fop/render/xml/AbstractXMLRenderer.java
@@ -29,6 +29,15 @@ import javax.xml.transform.sax.SAXTransformerFactory;
 import javax.xml.transform.sax.TransformerHandler;
 import javax.xml.transform.stream.StreamResult;
 
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.ext.LexicalHandler;
+import org.xml.sax.helpers.AttributesImpl;
+
+import org.apache.xmlgraphics.util.QName;
+
+import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.area.BookmarkData;
 import org.apache.fop.area.OffDocumentExtensionAttachment;
 import org.apache.fop.area.OffDocumentItem;
@@ -36,16 +45,14 @@ import org.apache.fop.area.PageViewport;
 import org.apache.fop.fo.extensions.ExtensionAttachment;
 import org.apache.fop.render.PrintRenderer;
 import org.apache.fop.render.RendererContext;
-import org.apache.xmlgraphics.util.QName;
-import org.xml.sax.Attributes;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
-import org.xml.sax.ext.LexicalHandler;
-import org.xml.sax.helpers.AttributesImpl;
 
 /** Abstract xml renderer base class. */
 public abstract class AbstractXMLRenderer extends PrintRenderer {
 
+    public AbstractXMLRenderer(FOUserAgent userAgent) {
+        super(userAgent);
+    }
+
     /** Main namespace in use. */
     public static final String NS = "";
 
diff --git a/src/java/org/apache/fop/render/xml/XMLRenderer.java b/src/java/org/apache/fop/render/xml/XMLRenderer.java
index 21d28042d..3ae49b121 100644
--- a/src/java/org/apache/fop/render/xml/XMLRenderer.java
+++ b/src/java/org/apache/fop/render/xml/XMLRenderer.java
@@ -37,7 +37,6 @@ import javax.xml.transform.stream.StreamResult;
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
-
 import org.xml.sax.SAXException;
 
 import org.apache.xmlgraphics.util.QName;
@@ -75,11 +74,11 @@ import org.apache.fop.area.inline.Image;
 import org.apache.fop.area.inline.InlineArea;
 import org.apache.fop.area.inline.InlineBlockParent;
 import org.apache.fop.area.inline.InlineParent;
+import org.apache.fop.area.inline.InlineViewport;
 import org.apache.fop.area.inline.Leader;
 import org.apache.fop.area.inline.Space;
 import org.apache.fop.area.inline.SpaceArea;
 import org.apache.fop.area.inline.TextArea;
-import org.apache.fop.area.inline.InlineViewport;
 import org.apache.fop.area.inline.WordArea;
 import org.apache.fop.fo.Constants;
 import org.apache.fop.fo.extensions.ExtensionAttachment;
@@ -113,20 +112,9 @@ public class XMLRenderer extends AbstractXMLRenderer {
 
     private int pageSequenceIndex;
 
-    /**
-     * Creates a new XML renderer.
-     */
-    public XMLRenderer() {
+    public XMLRenderer(FOUserAgent userAgent) {
+        super(userAgent);
         context = new RendererContext(this, XML_MIME_TYPE);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void setUserAgent(FOUserAgent agent) {
-        super.setUserAgent(agent);
-
         XMLHandler xmlHandler = new XMLXMLHandler();
         userAgent.getXMLHandlerRegistry().addXMLHandler(xmlHandler);
         Boolean b = (Boolean)userAgent.getRendererOptions().get("compact-format");
diff --git a/src/java/org/apache/fop/render/xml/XMLRendererMaker.java b/src/java/org/apache/fop/render/xml/XMLRendererMaker.java
index 8526daa2a..f54c74b32 100644
--- a/src/java/org/apache/fop/render/xml/XMLRendererMaker.java
+++ b/src/java/org/apache/fop/render/xml/XMLRendererMaker.java
@@ -35,7 +35,7 @@ public class XMLRendererMaker extends AbstractRendererMaker {
 
     /**{@inheritDoc} */
     public Renderer makeRenderer(FOUserAgent userAgent) {
-        return new XMLRenderer();
+        return new XMLRenderer(userAgent);
     }
 
     /**{@inheritDoc} */
diff --git a/src/sandbox/org/apache/fop/render/svg/SVGRenderer.java b/src/sandbox/org/apache/fop/render/svg/SVGRenderer.java
index 63f486c07..246062a32 100644
--- a/src/sandbox/org/apache/fop/render/svg/SVGRenderer.java
+++ b/src/sandbox/org/apache/fop/render/svg/SVGRenderer.java
@@ -26,19 +26,22 @@ import java.io.IOException;
 import java.io.OutputStream;
 import java.io.Writer;
 
+import org.w3c.dom.DOMImplementation;
+import org.w3c.dom.Document;
+
 import org.apache.batik.dom.GenericDOMImplementation;
 import org.apache.batik.svggen.SVGGeneratorContext;
 import org.apache.batik.svggen.SVGGraphics2D;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+
+import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.MimeConstants;
 import org.apache.fop.area.PageViewport;
 import org.apache.fop.render.bitmap.MultiFileRenderingUtil;
 import org.apache.fop.render.java2d.Java2DGraphicsState;
 import org.apache.fop.render.java2d.Java2DRenderer;
-import org.w3c.dom.DOMImplementation;
-import org.w3c.dom.Document;
 
 /**
  * 

@@ -67,8 +70,8 @@ public class SVGRenderer extends Java2DRenderer { /** Helper class for generating multiple files */ private MultiFileRenderingUtil multiFileUtil; - /** Default constructor. */ - public SVGRenderer() { + public SVGRenderer(FOUserAgent userAgent) { + super(userAgent); } /** {@inheritDoc} */ diff --git a/src/sandbox/org/apache/fop/render/svg/SVGRendererMaker.java b/src/sandbox/org/apache/fop/render/svg/SVGRendererMaker.java index f0da974e6..892d01711 100644 --- a/src/sandbox/org/apache/fop/render/svg/SVGRendererMaker.java +++ b/src/sandbox/org/apache/fop/render/svg/SVGRendererMaker.java @@ -34,7 +34,7 @@ public class SVGRendererMaker extends AbstractRendererMaker { /** {@inheritDoc} */ public Renderer makeRenderer(FOUserAgent ua) { - return new SVGRenderer(); + return new SVGRenderer(ua); } /** {@inheritDoc} */ diff --git a/test/java/org/apache/fop/URIResolutionTestCase.java b/test/java/org/apache/fop/URIResolutionTestCase.java index 97d1c9c25..490486158 100644 --- a/test/java/org/apache/fop/URIResolutionTestCase.java +++ b/test/java/org/apache/fop/URIResolutionTestCase.java @@ -39,19 +39,21 @@ import javax.xml.transform.sax.TransformerHandler; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; +import org.junit.BeforeClass; +import org.junit.Test; +import org.w3c.dom.Document; + import org.apache.commons.io.IOUtils; import org.apache.commons.io.output.ByteArrayOutputStream; +import org.apache.xpath.XPathAPI; +import org.apache.xpath.objects.XObject; + 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.render.xml.XMLRenderer; -import org.apache.xpath.XPathAPI; -import org.apache.xpath.objects.XObject; -import org.junit.BeforeClass; -import org.junit.Test; -import org.w3c.dom.Document; /** * Tests URI resolution facilities. @@ -160,8 +162,7 @@ public class URIResolutionTestCase extends AbstractFOPTest { TransformerHandler athandler = tfactory.newTransformerHandler(); athandler.setResult(domres); - XMLRenderer atrenderer = new XMLRenderer(); - atrenderer.setUserAgent(ua); + XMLRenderer atrenderer = new XMLRenderer(ua); atrenderer.setContentHandler(athandler); ua.setRendererOverride(atrenderer); diff --git a/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java b/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java index a0de2e8ab..1f8abb9be 100644 --- a/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java +++ b/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java @@ -97,10 +97,9 @@ public class AreaTreeParserTestCase extends AbstractIntermediateTest { Renderer targetRenderer = userAgent.getRendererFactory().createRenderer( userAgent, getTargetMIME()); - XMLRenderer renderer = new XMLRenderer(); + XMLRenderer renderer = new XMLRenderer(userAgent); renderer.mimicRenderer(targetRenderer); renderer.setContentHandler(handler); - renderer.setUserAgent(userAgent); userAgent.setRendererOverride(renderer); @@ -131,12 +130,10 @@ public class AreaTreeParserTestCase extends AbstractIntermediateTest { TransformerHandler handler = testAssistant.getTransformerFactory().newTransformerHandler(); DOMResult domResult = new DOMResult(); handler.setResult(domResult); - XMLRenderer renderer = new XMLRenderer(); - renderer.setContentHandler(handler); - FOUserAgent userAgent = createUserAgent(); + XMLRenderer renderer = new XMLRenderer(userAgent); userAgent.setRendererOverride(renderer); - renderer.setUserAgent(userAgent); + renderer.setContentHandler(handler); FontInfo fontInfo = new FontInfo(); AreaTreeModel treeModel = new RenderPagesModel(userAgent, diff --git a/test/java/org/apache/fop/layoutengine/LayoutEngineTestCase.java b/test/java/org/apache/fop/layoutengine/LayoutEngineTestCase.java index 46908a448..6a0d424e9 100644 --- a/test/java/org/apache/fop/layoutengine/LayoutEngineTestCase.java +++ b/test/java/org/apache/fop/layoutengine/LayoutEngineTestCase.java @@ -150,8 +150,7 @@ public class LayoutEngineTestCase { ua.getEventBroadcaster().addEventListener( new ConsoleEventListenerForTests(testFile.getName(), EventSeverity.WARN)); - XMLRenderer atrenderer = new XMLRenderer(); - atrenderer.setUserAgent(ua); + XMLRenderer atrenderer = new XMLRenderer(ua); atrenderer.setContentHandler(athandler); ua.setRendererOverride(atrenderer); fop = effFactory.newFop(ua); @@ -208,8 +207,7 @@ public class LayoutEngineTestCase { ua.getEventBroadcaster().addEventListener( new ConsoleEventListenerForTests(testFile.getName(), EventSeverity.WARN)); - IFRenderer ifRenderer = new IFRenderer(); - ifRenderer.setUserAgent(ua); + IFRenderer ifRenderer = new IFRenderer(ua); IFSerializer serializer = new IFSerializer(); serializer.setContext(new IFContext(ua));