xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerem...@apache.org
Subject svn commit: r747010 - in /xmlgraphics/fop/trunk: src/java/org/apache/fop/render/ src/java/org/apache/fop/render/afp/ src/java/org/apache/fop/render/bitmap/ src/java/org/apache/fop/render/pcl/ src/java/org/apache/fop/render/pdf/ src/java/org/apache/fop/...
Date Mon, 23 Feb 2009 13:25:09 GMT
Author: jeremias
Date: Mon Feb 23 13:25:08 2009
New Revision: 747010

URL: http://svn.apache.org/viewvc?rev=747010&view=rev
Log:
";mode=painter" MIME suffix removed from all new IFDocumentHandler implementations.
Changed RendererFactory to prefer IFDocumentHandler over Renderer if available.
A setting on RendererFactory allows to to prefer Renderer over IFDocumentHandler if necessary
for compatibility. (not yet tied into CLI or configuration)

Added:
    xmlgraphics/fop/trunk/test/java/org/apache/fop/render/RendererFactoryTest.java   (with
props)
Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/RendererFactory.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPDocumentHandlerMaker.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandlerMaker.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLDocumentHandlerMaker.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFDocumentHandlerMaker.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSDocumentHandlerMaker.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/RendererFactory.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/RendererFactory.java?rev=747010&r1=747009&r2=747010&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/RendererFactory.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/RendererFactory.java Mon Feb 23 13:25:08
2009
@@ -51,6 +51,8 @@
     private Map eventHandlerMakerMapping = new java.util.HashMap();
     private Map documentHandlerMakerMapping = new java.util.HashMap();
 
+    private boolean rendererPreferred = false;
+
     /**
      * Main constructor.
      */
@@ -61,6 +63,26 @@
     }
 
     /**
+     * Controls whether a {@link Renderer} is preferred over a {@link IFDocumentHandler}
if
+     * both are available for the same MIME type.
+     * @param value true to prefer the {@link Renderer},
+     *                  false to prefer the {@link IFDocumentHandler}.
+     */
+    public void setRendererPreferred(boolean value) {
+        this.rendererPreferred = value;
+    }
+
+    /**
+     * Indicates whether a {@link Renderer} is preferred over a {@link IFDocumentHandler}
if
+     * both are available for the same MIME type.
+     * @return true if the {@link Renderer} is preferred,
+     *                  false if the {@link IFDocumentHandler} is preferred.
+     */
+    public boolean isRendererPreferred() {
+        return this.rendererPreferred;
+    }
+
+    /**
      * Add a new RendererMaker. If another maker has already been registered for a
      * particular MIME type, this call overwrites the existing one.
      * @param maker the RendererMaker
@@ -236,27 +258,54 @@
         } else if (userAgent.getRendererOverride() != null) {
             return userAgent.getRendererOverride();
         } else {
-            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);
+            Renderer renderer;
+            if (isRendererPreferred()) {
+                //Try renderer first
+                renderer = tryRendererMaker(userAgent, outputFormat);
+                if (renderer == null) {
+                    renderer = tryIFDocumentHandlerMaker(userAgent, outputFormat);
                 }
-                return rend;
             } else {
-                AbstractIFDocumentHandlerMaker documentHandlerMaker
-                    = getDocumentHandlerMaker(outputFormat);
-                if (documentHandlerMaker != null) {
-                    IFDocumentHandler documentHandler = createDocumentHandler(
-                            userAgent, outputFormat);
-                    return createRendererForDocumentHandler(documentHandler);
-                } else {
-                    throw new UnsupportedOperationException(
-                            "No renderer for the requested format available: " + outputFormat);
+                //Try document handler first
+                renderer = tryIFDocumentHandlerMaker(userAgent, outputFormat);
+                if (renderer == null) {
+                    renderer = tryRendererMaker(userAgent, outputFormat);
                 }
             }
+            if (renderer == null) {
+                throw new UnsupportedOperationException(
+                        "No renderer for the requested format available: " + outputFormat);
+            }
+            return renderer;
+        }
+    }
+
+    private Renderer tryIFDocumentHandlerMaker(FOUserAgent userAgent, String outputFormat)
+            throws FOPException {
+        AbstractIFDocumentHandlerMaker documentHandlerMaker
+            = getDocumentHandlerMaker(outputFormat);
+        if (documentHandlerMaker != null) {
+            IFDocumentHandler documentHandler = createDocumentHandler(
+                    userAgent, outputFormat);
+            return createRendererForDocumentHandler(documentHandler);
+        } else {
+            return null;
+        }
+    }
+
+    private Renderer tryRendererMaker(FOUserAgent userAgent, String outputFormat)
+                throws FOPException {
+        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);
+            }
+            return rend;
+        } else {
+            return null;
         }
     }
 
@@ -327,6 +376,9 @@
      */
     public IFDocumentHandler createDocumentHandler(FOUserAgent userAgent, String outputFormat)
                     throws FOPException {
+        if (userAgent.getDocumentHandlerOverride() != null) {
+            return userAgent.getDocumentHandlerOverride();
+        }
         AbstractIFDocumentHandlerMaker maker = getDocumentHandlerMaker(outputFormat);
         if (maker == null) {
             throw new UnsupportedOperationException(

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPDocumentHandlerMaker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPDocumentHandlerMaker.java?rev=747010&r1=747009&r2=747010&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPDocumentHandlerMaker.java
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPDocumentHandlerMaker.java
Mon Feb 23 13:25:08 2009
@@ -30,9 +30,8 @@
  */
 public class AFPDocumentHandlerMaker extends AbstractIFDocumentHandlerMaker {
 
-    //TODO Revert to normal MIME after stabilization!
     private static final String[] MIMES = new String[]
-                              {MimeConstants.MIME_AFP + ";mode=painter"};
+                              {MimeConstants.MIME_AFP};
 
     /** {@inheritDoc} */
     public IFDocumentHandler makeIFDocumentHandler(FOUserAgent ua) {

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandlerMaker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandlerMaker.java?rev=747010&r1=747009&r2=747010&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandlerMaker.java
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandlerMaker.java
Mon Feb 23 13:25:08 2009
@@ -30,8 +30,7 @@
  */
 public class TIFFDocumentHandlerMaker extends AbstractIFDocumentHandlerMaker {
 
-    //TODO Revert to normal MIME after stabilization!
-    private static final String[] MIMES = new String[] {MimeConstants.MIME_TIFF + ";mode=painter"};
+    private static final String[] MIMES = new String[] {MimeConstants.MIME_TIFF};
 
     /** {@inheritDoc} */
     public IFDocumentHandler makeIFDocumentHandler(FOUserAgent ua) {

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLDocumentHandlerMaker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLDocumentHandlerMaker.java?rev=747010&r1=747009&r2=747010&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLDocumentHandlerMaker.java
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLDocumentHandlerMaker.java
Mon Feb 23 13:25:08 2009
@@ -30,8 +30,7 @@
  */
 public class PCLDocumentHandlerMaker extends AbstractIFDocumentHandlerMaker {
 
-    //TODO Revert to normal MIME after stabilization!
-    private static final String[] MIMES = new String[] {MimeConstants.MIME_PCL + ";mode=painter"};
+    private static final String[] MIMES = new String[] {MimeConstants.MIME_PCL};
 
     /** {@inheritDoc} */
     public IFDocumentHandler makeIFDocumentHandler(FOUserAgent ua) {

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFDocumentHandlerMaker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFDocumentHandlerMaker.java?rev=747010&r1=747009&r2=747010&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFDocumentHandlerMaker.java
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFDocumentHandlerMaker.java
Mon Feb 23 13:25:08 2009
@@ -30,8 +30,7 @@
  */
 public class PDFDocumentHandlerMaker extends AbstractIFDocumentHandlerMaker {
 
-    //TODO Revert to normal MIME after stabilization!
-    private static final String[] MIMES = new String[] {MimeConstants.MIME_PDF + ";mode=painter"};
+    private static final String[] MIMES = new String[] {MimeConstants.MIME_PDF};
 
     /** {@inheritDoc} */
     public IFDocumentHandler makeIFDocumentHandler(FOUserAgent ua) {

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSDocumentHandlerMaker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSDocumentHandlerMaker.java?rev=747010&r1=747009&r2=747010&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSDocumentHandlerMaker.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSDocumentHandlerMaker.java Mon
Feb 23 13:25:08 2009
@@ -30,9 +30,8 @@
  */
 public class PSDocumentHandlerMaker extends AbstractIFDocumentHandlerMaker {
 
-    //TODO Revert to normal MIME after stabilization!
     private static final String[] MIMES = new String[]
-                              {MimeConstants.MIME_POSTSCRIPT + ";mode=painter"};
+                              {MimeConstants.MIME_POSTSCRIPT};
 
     /** {@inheritDoc} */
     public IFDocumentHandler makeIFDocumentHandler(FOUserAgent ua) {

Added: xmlgraphics/fop/trunk/test/java/org/apache/fop/render/RendererFactoryTest.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/render/RendererFactoryTest.java?rev=747010&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/render/RendererFactoryTest.java (added)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/render/RendererFactoryTest.java Mon Feb
23 13:25:08 2009
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.render;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.io.output.NullOutputStream;
+
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.FopFactory;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.area.AreaTreeHandler;
+import org.apache.fop.fo.FOEventHandler;
+import org.apache.fop.render.intermediate.IFContext;
+import org.apache.fop.render.intermediate.IFDocumentHandler;
+import org.apache.fop.render.intermediate.IFRenderer;
+import org.apache.fop.render.pdf.PDFDocumentHandler;
+import org.apache.fop.render.pdf.PDFRenderer;
+import org.apache.fop.render.rtf.RTFHandler;
+
+/**
+ * Tests for {@link RendererFactory}.
+ */
+public class RendererFactoryTest extends TestCase {
+
+    public void testDocumentHandlerLevel() throws Exception {
+        FopFactory fopFactory = FopFactory.newInstance();
+        RendererFactory factory = fopFactory.getRendererFactory();
+        FOUserAgent ua;
+        IFDocumentHandler handler;
+        IFDocumentHandler overrideHandler;
+
+        ua = fopFactory.newFOUserAgent();
+        handler = factory.createDocumentHandler(ua, MimeConstants.MIME_PDF);
+        assertTrue(handler instanceof PDFDocumentHandler);
+
+        ua = fopFactory.newFOUserAgent();
+        overrideHandler = new PDFDocumentHandler();
+        overrideHandler.setContext(new IFContext(ua));
+        ua.setDocumentHandlerOverride(overrideHandler);
+        handler = factory.createDocumentHandler(ua, null);
+        assertTrue(handler == overrideHandler);
+
+        ua = fopFactory.newFOUserAgent();
+        try {
+            handler = factory.createDocumentHandler(ua, "invalid/format");
+            fail("Expected UnsupportedOperationException");
+        } catch (UnsupportedOperationException uoe) {
+            //expected
+        }
+    }
+
+    public void testRendererLevel() throws Exception {
+        FopFactory fopFactory = FopFactory.newInstance();
+        RendererFactory factory = fopFactory.getRendererFactory();
+        FOUserAgent ua;
+        Renderer renderer;
+        Renderer overrideRenderer;
+
+        ua = fopFactory.newFOUserAgent();
+        renderer = factory.createRenderer(ua, MimeConstants.MIME_PDF);
+        assertTrue(renderer instanceof IFRenderer);
+
+        factory.setRendererPreferred(true); //Test legacy setting
+        ua = fopFactory.newFOUserAgent();
+        renderer = factory.createRenderer(ua, MimeConstants.MIME_PDF);
+        assertTrue(renderer instanceof PDFRenderer);
+
+        ua = fopFactory.newFOUserAgent();
+        renderer = factory.createRenderer(ua, MimeConstants.MIME_FOP_IF);
+        assertTrue(renderer instanceof IFRenderer);
+
+        factory.setRendererPreferred(false);
+        ua = fopFactory.newFOUserAgent();
+        overrideRenderer = new PDFRenderer();
+        overrideRenderer.setUserAgent(ua);
+        ua.setRendererOverride(overrideRenderer);
+        renderer = factory.createRenderer(ua, null);
+        assertTrue(renderer == overrideRenderer);
+
+        ua = fopFactory.newFOUserAgent();
+        IFDocumentHandler overrideHandler;
+        overrideHandler = new PDFDocumentHandler();
+        overrideHandler.setContext(new IFContext(ua));
+        ua.setDocumentHandlerOverride(overrideHandler);
+        renderer = factory.createRenderer(ua, null);
+        assertTrue(renderer instanceof IFRenderer);
+
+        ua = fopFactory.newFOUserAgent();
+        try {
+            renderer = factory.createRenderer(ua, "invalid/format");
+            fail("Expected UnsupportedOperationException");
+        } catch (UnsupportedOperationException uoe) {
+            //expected
+        }
+    }
+
+    public void testFOEventHandlerLevel() throws Exception {
+        FopFactory fopFactory = FopFactory.newInstance();
+        RendererFactory factory = fopFactory.getRendererFactory();
+        FOUserAgent ua;
+        FOEventHandler foEventHandler;
+        FOEventHandler overrideFOEventHandler;
+
+        ua = fopFactory.newFOUserAgent();
+        foEventHandler = factory.createFOEventHandler(
+                ua, MimeConstants.MIME_PDF, new NullOutputStream());
+        assertTrue(foEventHandler instanceof AreaTreeHandler);
+
+        ua = fopFactory.newFOUserAgent();
+        foEventHandler = factory.createFOEventHandler(
+                ua, MimeConstants.MIME_RTF, new NullOutputStream());
+        assertTrue(foEventHandler instanceof RTFHandler);
+
+        ua = fopFactory.newFOUserAgent();
+        try {
+            foEventHandler = factory.createFOEventHandler(
+                    ua, "invalid/format", new NullOutputStream());
+            fail("Expected UnsupportedOperationException");
+        } catch (UnsupportedOperationException uoe) {
+            //expected
+        }
+
+        ua = fopFactory.newFOUserAgent();
+        try {
+            foEventHandler = factory.createFOEventHandler(
+                    ua, MimeConstants.MIME_PDF, null);
+            fail("Expected FOPException because of missing OutputStream");
+        } catch (FOPException fe) {
+            //expected
+        }
+
+        ua = fopFactory.newFOUserAgent();
+        overrideFOEventHandler = new RTFHandler(ua, new NullOutputStream());
+        ua.setFOEventHandlerOverride(overrideFOEventHandler);
+        foEventHandler = factory.createFOEventHandler(
+                ua, null, null);
+        assertTrue(foEventHandler == overrideFOEventHandler);
+    }
+
+}

Propchange: xmlgraphics/fop/trunk/test/java/org/apache/fop/render/RendererFactoryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/trunk/test/java/org/apache/fop/render/RendererFactoryTest.java
------------------------------------------------------------------------------
    svn:keywords = Id



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org


Mime
View raw message