]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Attaching the ImageFactory to the FopFactory. To have a cache effect between multiple...
authorJeremias Maerki <jeremias@apache.org>
Tue, 14 Feb 2006 10:02:11 +0000 (10:02 +0000)
committerJeremias Maerki <jeremias@apache.org>
Tue, 14 Feb 2006 10:02:11 +0000 (10:02 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_API_Finalization@377680 13f79535-47bb-0310-9956-ffa450edef68

12 files changed:
src/java/org/apache/fop/apps/FopFactory.java
src/java/org/apache/fop/area/AreaTreeParser.java
src/java/org/apache/fop/fo/FOTreeBuilder.java
src/java/org/apache/fop/fo/flow/ExternalGraphic.java
src/java/org/apache/fop/fo/properties/CommonBorderPaddingBackground.java
src/java/org/apache/fop/image/ImageFactory.java
src/java/org/apache/fop/image/ImageLoader.java
src/java/org/apache/fop/render/java2d/Java2DRenderer.java
src/java/org/apache/fop/render/pdf/PDFRenderer.java
src/java/org/apache/fop/render/ps/PSRenderer.java
src/java/org/apache/fop/render/rtf/RTFHandler.java
test/java/org/apache/fop/URIResolutionTestCase.java

index 1b1a9e3ff5bd9599364a3eabd095c4a881a5274c..75d2902b98b892b99b4431a755f4a85dea06a920 100644 (file)
@@ -31,6 +31,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.fop.fo.ElementMapping;
 import org.apache.fop.fo.ElementMappingRegistry;
+import org.apache.fop.image.ImageFactory;
 import org.apache.fop.layoutmgr.LayoutManagerMaker;
 import org.apache.fop.render.RendererFactory;
 import org.apache.fop.render.XMLHandlerRegistry;
@@ -67,6 +68,8 @@ public class FopFactory {
     private ContentHandlerFactoryRegistry contentHandlerFactoryRegistry 
                 = new ContentHandlerFactoryRegistry();
     
+    private ImageFactory imageFactory = new ImageFactory();
+
     /** user configuration */
     private Configuration userConfig = null;
 
@@ -190,6 +193,11 @@ public class FopFactory {
         return this.contentHandlerFactoryRegistry;
     }
 
+    /** @return the image factory */
+    public ImageFactory getImageFactory() {
+        return this.imageFactory;
+    }
+
     /**
      * Add the element mapping with the given class name.
      * @param elementMapping the class name representing the element mapping.
index e81896a3e7ad87a3c7ff93b0131922cd45a5d703..5c3acfd51baf14f491ab7b83bf64a663360e01bf 100644 (file)
@@ -896,7 +896,7 @@ public class AreaTreeParser {
                             if (url != null) {
                                 bkg.setURL(url);
                                 
-                                ImageFactory fact = ImageFactory.getInstance();
+                                ImageFactory fact = userAgent.getFactory().getImageFactory();
                                 FopImage img = fact.getImage(url, userAgent);
                                 if (img == null) {
                                     log.error("Background image not available: " + url);
index 34ad4337519d5b1cd453cdd6fb28a54834529d47..5894202d2d456931305e104fe3ae81ef4d10ca15 100644 (file)
@@ -168,7 +168,8 @@ public class FOTreeBuilder extends DefaultHandler {
         foEventHandler.endDocument();
         
         //Notify the image factory that this user agent has expired.
-        ImageFactory.getInstance().removeContext(this.userAgent);
+        ImageFactory imageFactory = userAgent.getFactory().getImageFactory();
+        imageFactory.removeContext(this.userAgent);
     }
 
     /**
index 35bd47360311572d56c4724c4024e50c2d24038a..d80cbe8684df1fdbb73f83de8f4cdae0422e6923 100644 (file)
@@ -19,6 +19,7 @@
 package org.apache.fop.fo.flow;
 
 import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.fo.FONode;
 import org.apache.fop.fo.PropertyList;
 import org.apache.fop.fo.ValidationException;
@@ -60,8 +61,9 @@ public class ExternalGraphic extends AbstractGraphics {
         
         //Additional processing: preload image
         url = ImageFactory.getURL(getSrc());
-        ImageFactory fact = ImageFactory.getInstance();
-        fopimage = fact.getImage(url, getUserAgent());
+        FOUserAgent userAgent = getUserAgent();
+        ImageFactory fact = userAgent.getFactory().getImageFactory();
+        fopimage = fact.getImage(url, userAgent);
         if (fopimage == null) {
             getLogger().error("Image not available: " + getSrc());
         } else {
index 83214a5ab5856806e5a12552bd82ff6b16b494c7..54501d91c3d2e329c5546aa6e418dddc3c50ec0b 100755 (executable)
@@ -18,6 +18,7 @@
 
 package org.apache.fop.fo.properties;
 
+import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.datatypes.ColorType;
 import org.apache.fop.datatypes.Length;
 import org.apache.fop.datatypes.PercentBaseContext;
@@ -158,8 +159,9 @@ public class CommonBorderPaddingBackground implements Cloneable {
             
             //Additional processing: preload image
             String url = ImageFactory.getURL(backgroundImage);
-            ImageFactory fact = ImageFactory.getInstance();
-            fopimage = fact.getImage(url, fobj.getUserAgent());
+            FOUserAgent userAgent = fobj.getUserAgent();
+            ImageFactory fact = userAgent.getFactory().getImageFactory();
+            fopimage = fact.getImage(url, userAgent);
             if (fopimage == null) {
                 fobj.getLogger().error("Background image not available: " + backgroundImage);
             } else {
index e41ceb8582b789502c5fc2de32869745ce4f4da0..d9aafc418922f43f43284733be4d24b81bba6d87 100644 (file)
@@ -50,13 +50,13 @@ public final class ImageFactory {
      */
     protected static Log log = LogFactory.getLog(FopImage.class);
     
-    private static ImageFactory factory = new ImageFactory();
+    //private static ImageFactory factory = new ImageFactory();
 
     private HashMap imageMimeTypes = new HashMap();
     
     private ImageCache cache = new ContextImageCache(true);
 
-    private ImageFactory() {
+    public ImageFactory() {
         /* @todo The mappings set up below of image mime types to implementing
          * classes should be made externally configurable
          */
@@ -123,15 +123,6 @@ public final class ImageFactory {
         imt.addProvider(emfImage);
     }
 
-    /**
-     * Get static image factory instance.
-     *
-     * @return the image factory instance
-     */
-    public static ImageFactory getInstance() {
-        return factory;
-    }
-
     /**
      * Get the url string from a wrapped url.
      *
index ad22c6c2b5fbd2aa045afb757fc6c19f20bb56c1..f26088a01afd6b4d269babcd48b0055dd72f76f1 100644 (file)
@@ -51,7 +51,8 @@ class ImageLoader {
         if (!valid || image != null) {
             return image;
         }
-        image = ImageFactory.getInstance().loadImage(url, userAgent);
+        ImageFactory imageFactory = userAgent.getFactory().getImageFactory();
+        image = imageFactory.loadImage(url, userAgent);
         if (image == null) {
             cache.invalidateImage(url, userAgent);
             valid = false;
index 5255c7727b3867e30bcd11f2c2996daad3d8079f..225ccdb35b4ddc74a5419519a24601bd1f73ac81 100644 (file)
@@ -1058,7 +1058,7 @@ public abstract class Java2DRenderer extends AbstractRenderer implements Printab
         int y = currentBPPosition;
         String url = ImageFactory.getURL(pUrl);
 
-        ImageFactory fact = ImageFactory.getInstance();
+        ImageFactory fact = userAgent.getFactory().getImageFactory();
         FopImage fopimage = fact.getImage(url, userAgent);
 
         if (fopimage == null) {
index ab2ae245b9653873790220c1e3802034d130e3d4..f3a5d3e269980ffb664938e377c8a19c326f7009 100644 (file)
@@ -1251,7 +1251,7 @@ public class PDFRenderer extends AbstractPathOrientedRenderer {
         }
 
         url = ImageFactory.getURL(url);
-        ImageFactory fact = ImageFactory.getInstance();
+        ImageFactory fact = userAgent.getFactory().getImageFactory();
         FopImage fopimage = fact.getImage(url, userAgent);
         if (fopimage == null) {
             return;
index b786a49627c33348b11a6b5da63b6704973ebe53..8eb3bf19aa98921029f334dda3a4160aa7743153 100644 (file)
@@ -268,7 +268,7 @@ public class PSRenderer extends AbstractPathOrientedRenderer implements ImageAda
     protected void drawImage(String url, Rectangle2D pos) {
         endTextObject();
         url = ImageFactory.getURL(url);
-        ImageFactory fact = ImageFactory.getInstance();
+        ImageFactory fact = userAgent.getFactory().getImageFactory();
         FopImage fopimage = fact.getImage(url, userAgent);
         if (fopimage == null) {
             return;
index 931baeb63146bc3191e31900451c9226c5d19b23..525d01d7c2cdfb1a695c312881349a7687b96475 100644 (file)
@@ -1102,8 +1102,9 @@ public class RTFHandler extends FOEventHandler {
             String url = eg.getURL();
 
             //set image data
-            ImageFactory fact = ImageFactory.getInstance();
-            FopImage fopimage = fact.getImage(url, eg.getUserAgent());
+            FOUserAgent userAgent = eg.getUserAgent();
+            ImageFactory fact = userAgent.getFactory().getImageFactory();
+            FopImage fopimage = fact.getImage(url, userAgent);
             if (fopimage == null) {
                 log.error("Image could not be found: " + url);
                 return;
index 7eb79ec38bffe71468660de611e42bffaec1789d..0779bda29ad45fe71115be64bb6a0acd6fdd7c2b 100644 (file)
@@ -79,12 +79,13 @@ public class URIResolutionTestCase extends AbstractFOPTestCase {
     }
     
     private void innerTestFO1(boolean withStream) throws Exception {
+        FOUserAgent ua = new FOUserAgent();
+
         //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());