diff options
30 files changed, 169 insertions, 113 deletions
diff --git a/examples/embedding/java/embedding/ExampleFO2JPSPrint.java b/examples/embedding/java/embedding/ExampleFO2JPSPrint.java index 1e0ec4853..4f18b71ab 100644 --- a/examples/embedding/java/embedding/ExampleFO2JPSPrint.java +++ b/examples/embedding/java/embedding/ExampleFO2JPSPrint.java @@ -85,7 +85,8 @@ 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(userAgent); + PageableRenderer renderer = new PageableRenderer(); + renderer.setUserAgent(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 289f7d074..adec1b08c 100644 --- a/examples/embedding/java/embedding/atxml/ExampleConcat.java +++ b/examples/embedding/java/embedding/atxml/ExampleConcat.java @@ -93,7 +93,8 @@ public class ExampleConcat { userAgent, MimeConstants.MIME_PDF); //Create the XMLRenderer to create the area tree XML - XMLRenderer xmlRenderer = new XMLRenderer(userAgent); + XMLRenderer xmlRenderer = new XMLRenderer(); + xmlRenderer.setUserAgent(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 845c11a0d..0d4c3790c 100644 --- a/src/java/org/apache/fop/cli/CommandLineOptions.java +++ b/src/java/org/apache/fop/cli/CommandLineOptions.java @@ -203,14 +203,17 @@ public class CommandLineOptions { System.err.println("Couldn't set system look & feel!"); } - AWTRenderer renderer = new AWTRenderer(foUserAgent, inputHandler, true, true); + AWTRenderer renderer = new AWTRenderer(true); + renderer.setRenderable(inputHandler); //set before user agent! + renderer.setUserAgent(foUserAgent); 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(foUserAgent); + XMLRenderer xmlRenderer = new XMLRenderer(); + xmlRenderer.setUserAgent(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 83d3d84a2..45a02a977 100644 --- a/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java +++ b/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java @@ -34,7 +34,6 @@ 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; @@ -57,10 +56,6 @@ 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 659748df9..7ff236d16 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; - /** - * - * @param userAgent the user agent that contains configuration details. This cannot be null. - */ - public AbstractRenderer(FOUserAgent userAgent) { - this.userAgent = userAgent; + /** {@inheritDoc} */ + public void setUserAgent(FOUserAgent agent) { + userAgent = agent; } /** {@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 05e9cb7af..be3ace016 100644 --- a/src/java/org/apache/fop/render/PrintRenderer.java +++ b/src/java/org/apache/fop/render/PrintRenderer.java @@ -27,7 +27,6 @@ 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; @@ -43,10 +42,6 @@ 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 5f5596dfb..76f245251 100644 --- a/src/java/org/apache/fop/render/Renderer.java +++ b/src/java/org/apache/fop/render/Renderer.java @@ -82,6 +82,13 @@ public interface Renderer { 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 3ceb27a8e..bc598450f 100644 --- a/src/java/org/apache/fop/render/RendererFactory.java +++ b/src/java/org/apache/fop/render/RendererFactory.java @@ -299,6 +299,7 @@ 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); @@ -310,7 +311,8 @@ public class RendererFactory { } private Renderer createRendererForDocumentHandler(IFDocumentHandler documentHandler) { - IFRenderer rend = new IFRenderer(documentHandler.getContext().getUserAgent()); + IFRenderer rend = new IFRenderer(); + rend.setUserAgent(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 c36655204..99dece24a 100644 --- a/src/java/org/apache/fop/render/awt/AWTRenderer.java +++ b/src/java/org/apache/fop/render/awt/AWTRenderer.java @@ -64,6 +64,18 @@ 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 */ @@ -72,36 +84,48 @@ public class AWTRenderer extends Java2DRenderer implements Pageable { /** * Creates a new AWTRenderer instance. - * - * @param userAgent the user agent that contains configuration data */ - public AWTRenderer(FOUserAgent userAgent) { - this(userAgent, null, false, false); + public AWTRenderer() { + this(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. - * @param show sets whether the preview dialog should be created and displayed when the - * rendering has finished. + * the main window of the application. */ - 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)); + 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)); } } /** + * 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} */ public void renderPage(PageViewport pageViewport) throws IOException { diff --git a/src/java/org/apache/fop/render/awt/AWTRendererMaker.java b/src/java/org/apache/fop/render/awt/AWTRendererMaker.java index d65a550d4..983b42e0c 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(ua); + return new AWTRenderer(); } /** {@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 c850c35e7..2303c0e8e 100644 --- a/src/java/org/apache/fop/render/awt/viewer/PreviewPanel.java +++ b/src/java/org/apache/fop/render/awt/viewer/PreviewPanel.java @@ -67,9 +67,12 @@ import org.apache.fop.render.awt.AWTRenderer; * </p> * <pre> * 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 1c6f2e33d..3733bf2f2 100644 --- a/src/java/org/apache/fop/render/bitmap/PNGRenderer.java +++ b/src/java/org/apache/fop/render/bitmap/PNGRenderer.java @@ -29,7 +29,6 @@ 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; @@ -41,10 +40,6 @@ 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 da19b2986..7d321791a 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(ua); + return new PNGRenderer(); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/bitmap/TIFFRenderer.java b/src/java/org/apache/fop/render/bitmap/TIFFRenderer.java index 0e2364d35..5a9cfa21b 100644 --- a/src/java/org/apache/fop/render/bitmap/TIFFRenderer.java +++ b/src/java/org/apache/fop/render/bitmap/TIFFRenderer.java @@ -83,11 +83,19 @@ public class TIFFRenderer extends Java2DRenderer implements TIFFConstants { } /** Creates TIFF renderer. */ - public TIFFRenderer(FOUserAgent userAgent) { - super(userAgent); + public TIFFRenderer() { 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 852e6ba04..e3c567995 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(userAgent); + return new TIFFRenderer(); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/intermediate/IFRenderer.java b/src/java/org/apache/fop/render/intermediate/IFRenderer.java index d5d5a154a..24a2e8a75 100644 --- a/src/java/org/apache/fop/render/intermediate/IFRenderer.java +++ b/src/java/org/apache/fop/render/intermediate/IFRenderer.java @@ -51,7 +51,6 @@ 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; @@ -71,10 +70,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; @@ -159,8 +158,7 @@ public class IFRenderer extends AbstractPathOrientedRenderer { /** * Main constructor */ - public IFRenderer(FOUserAgent userAgent) { - super(userAgent); + public IFRenderer() { } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java index 3c7006588..766aa081f 100644 --- a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java +++ b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java @@ -147,13 +147,15 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem private GeneralPath currentPath = null; /** Default constructor */ - public Java2DRenderer(FOUserAgent userAgent) { - super(userAgent); + public Java2DRenderer() { + } - // MH: necessary? the caller has access to FOUserAgent + /** {@inheritDoc} */ + public void setUserAgent(FOUserAgent foUserAgent) { + super.setUserAgent(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 08d5b0f04..89ab98071 100644 --- a/src/java/org/apache/fop/render/print/PageableRenderer.java +++ b/src/java/org/apache/fop/render/print/PageableRenderer.java @@ -73,11 +73,7 @@ public class PageableRenderer extends Java2DRenderer implements Pageable { /** * Creates a new PageableRenderer. */ - public PageableRenderer(FOUserAgent userAgent) { - super(userAgent); - Map rendererOptions = getUserAgent().getRendererOptions(); - processOptions(rendererOptions); - this.pageFilter = new DefaultPageFilter(); + public PageableRenderer() { } /** {@inheritDoc} */ @@ -85,6 +81,15 @@ 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 ea68bc9b2..2eb2b07a2 100644 --- a/src/java/org/apache/fop/render/print/PrintRenderer.java +++ b/src/java/org/apache/fop/render/print/PrintRenderer.java @@ -55,9 +55,19 @@ 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(FOUserAgent userAgent) { - super(userAgent); - setRendererOptions(); + 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); } private void initializePrinterJob() { @@ -75,8 +85,11 @@ public class PrintRenderer extends PageableRenderer { } } - private void setRendererOptions() { - Map rendererOptions = getUserAgent().getRendererOptions(); + /** {@inheritDoc} */ + public void setUserAgent(FOUserAgent agent) { + super.setUserAgent(agent); + + Map rendererOptions = agent.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 63444a628..21eb4717a 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(userAgent); + return new PrintRenderer(); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/txt/TXTRenderer.java b/src/java/org/apache/fop/render/txt/TXTRenderer.java index 74c5b84a8..386f95838 100644 --- a/src/java/org/apache/fop/render/txt/TXTRenderer.java +++ b/src/java/org/apache/fop/render/txt/TXTRenderer.java @@ -32,7 +32,6 @@ 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; @@ -111,8 +110,7 @@ public class TXTRenderer extends AbstractPathOrientedRenderer { /** * Constructs a newly allocated <code>TXTRenderer</code> object. */ - public TXTRenderer(FOUserAgent userAgent) { - super(userAgent); + public TXTRenderer() { } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/txt/TXTRendererMaker.java b/src/java/org/apache/fop/render/txt/TXTRendererMaker.java index 740866e0c..0db369ef2 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(userAgent); + return new TXTRenderer(); } /**{@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/xml/AbstractXMLRenderer.java b/src/java/org/apache/fop/render/xml/AbstractXMLRenderer.java index 9c938199f..497e3c047 100644 --- a/src/java/org/apache/fop/render/xml/AbstractXMLRenderer.java +++ b/src/java/org/apache/fop/render/xml/AbstractXMLRenderer.java @@ -29,15 +29,6 @@ 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; @@ -45,14 +36,16 @@ 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 3ae49b121..21d28042d 100644 --- a/src/java/org/apache/fop/render/xml/XMLRenderer.java +++ b/src/java/org/apache/fop/render/xml/XMLRenderer.java @@ -37,6 +37,7 @@ 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; @@ -74,11 +75,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; @@ -112,9 +113,20 @@ public class XMLRenderer extends AbstractXMLRenderer { private int pageSequenceIndex; - public XMLRenderer(FOUserAgent userAgent) { - super(userAgent); + /** + * Creates a new XML renderer. + */ + public XMLRenderer() { 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 f54c74b32..8526daa2a 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(userAgent); + return new XMLRenderer(); } /**{@inheritDoc} */ diff --git a/src/sandbox/org/apache/fop/render/svg/SVGRenderer.java b/src/sandbox/org/apache/fop/render/svg/SVGRenderer.java index 246062a32..63f486c07 100644 --- a/src/sandbox/org/apache/fop/render/svg/SVGRenderer.java +++ b/src/sandbox/org/apache/fop/render/svg/SVGRenderer.java @@ -26,22 +26,19 @@ 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; /** * <p> @@ -70,8 +67,8 @@ public class SVGRenderer extends Java2DRenderer { /** Helper class for generating multiple files */ private MultiFileRenderingUtil multiFileUtil; - public SVGRenderer(FOUserAgent userAgent) { - super(userAgent); + /** Default constructor. */ + public SVGRenderer() { } /** {@inheritDoc} */ diff --git a/src/sandbox/org/apache/fop/render/svg/SVGRendererMaker.java b/src/sandbox/org/apache/fop/render/svg/SVGRendererMaker.java index 892d01711..f0da974e6 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(ua); + return new SVGRenderer(); } /** {@inheritDoc} */ diff --git a/test/java/org/apache/fop/URIResolutionTestCase.java b/test/java/org/apache/fop/URIResolutionTestCase.java index 490486158..97d1c9c25 100644 --- a/test/java/org/apache/fop/URIResolutionTestCase.java +++ b/test/java/org/apache/fop/URIResolutionTestCase.java @@ -39,21 +39,19 @@ 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. @@ -162,7 +160,8 @@ public class URIResolutionTestCase extends AbstractFOPTest { TransformerHandler athandler = tfactory.newTransformerHandler(); athandler.setResult(domres); - XMLRenderer atrenderer = new XMLRenderer(ua); + XMLRenderer atrenderer = new XMLRenderer(); + atrenderer.setUserAgent(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 1f8abb9be..a0de2e8ab 100644 --- a/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java +++ b/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java @@ -97,9 +97,10 @@ public class AreaTreeParserTestCase extends AbstractIntermediateTest { Renderer targetRenderer = userAgent.getRendererFactory().createRenderer( userAgent, getTargetMIME()); - XMLRenderer renderer = new XMLRenderer(userAgent); + XMLRenderer renderer = new XMLRenderer(); renderer.mimicRenderer(targetRenderer); renderer.setContentHandler(handler); + renderer.setUserAgent(userAgent); userAgent.setRendererOverride(renderer); @@ -130,10 +131,12 @@ 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.setContentHandler(handler); + renderer.setUserAgent(userAgent); 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 6a0d424e9..46908a448 100644 --- a/test/java/org/apache/fop/layoutengine/LayoutEngineTestCase.java +++ b/test/java/org/apache/fop/layoutengine/LayoutEngineTestCase.java @@ -150,7 +150,8 @@ public class LayoutEngineTestCase { ua.getEventBroadcaster().addEventListener( new ConsoleEventListenerForTests(testFile.getName(), EventSeverity.WARN)); - XMLRenderer atrenderer = new XMLRenderer(ua); + XMLRenderer atrenderer = new XMLRenderer(); + atrenderer.setUserAgent(ua); atrenderer.setContentHandler(athandler); ua.setRendererOverride(atrenderer); fop = effFactory.newFop(ua); @@ -207,7 +208,8 @@ public class LayoutEngineTestCase { ua.getEventBroadcaster().addEventListener( new ConsoleEventListenerForTests(testFile.getName(), EventSeverity.WARN)); - IFRenderer ifRenderer = new IFRenderer(ua); + IFRenderer ifRenderer = new IFRenderer(); + ifRenderer.setUserAgent(ua); IFSerializer serializer = new IFSerializer(); serializer.setContext(new IFContext(ua)); |