xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sstei...@apache.org
Subject svn commit: r1713640 - in /xmlgraphics/fop-pdf-images/trunk: lib/fop.jar src/java/org/apache/fop/render/pdf/pdfbox/AbstractPDFBoxHandler.java test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java
Date Tue, 10 Nov 2015 14:09:12 GMT
Author: ssteiner
Date: Tue Nov 10 14:09:11 2015
New Revision: 1713640

URL: http://svn.apache.org/viewvc?rev=1713640&view=rev
Log:
FOP-2538: PDF to PDF OOM

Modified:
    xmlgraphics/fop-pdf-images/trunk/lib/fop.jar
    xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/AbstractPDFBoxHandler.java
    xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java

Modified: xmlgraphics/fop-pdf-images/trunk/lib/fop.jar
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/lib/fop.jar?rev=1713640&r1=1713639&r2=1713640&view=diff
==============================================================================
Binary files - no diff available.

Modified: xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/AbstractPDFBoxHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/AbstractPDFBoxHandler.java?rev=1713640&r1=1713639&r2=1713640&view=diff
==============================================================================
--- xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/AbstractPDFBoxHandler.java
(original)
+++ xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/AbstractPDFBoxHandler.java
Tue Nov 10 14:09:11 2015
@@ -22,16 +22,14 @@ package org.apache.fop.render.pdf.pdfbox
 import java.awt.Rectangle;
 import java.awt.geom.AffineTransform;
 import java.io.IOException;
-import java.util.Collections;
 import java.util.HashMap;
-import java.util.Locale;
 import java.util.Map;
-import java.util.WeakHashMap;
 
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDPage;
 
 import org.apache.xmlgraphics.image.loader.util.ImageUtil;
+import org.apache.xmlgraphics.image.loader.util.SoftMapCache;
 
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.events.EventBroadcaster;
@@ -43,7 +41,6 @@ import org.apache.fop.pdf.PDFResources;
 import org.apache.fop.pdf.PDFStructElem;
 import org.apache.fop.pdf.Version;
 import org.apache.fop.render.pdf.PDFLogicalStructureHandler;
-import org.apache.fop.render.pdf.pdfbox.Cache.ValueMaker;
 
 /**
  * Abstract base class for implementation of FOP's image handler interfaces (old and new)
@@ -52,22 +49,6 @@ import org.apache.fop.render.pdf.pdfbox.
  */
 public abstract class AbstractPDFBoxHandler {
 
-    private static final Cache.Type CACHE_TYPE = Cache.Type.valueOf(
-            System.getProperty("fop.pdfbox.doc-cache", Cache.Type.WEAK.name()).toUpperCase(Locale.ENGLISH));
-
-    private static Cache<String, Map<Object, Object>> createDocumentCache() {
-        return Cache.createCache(CACHE_TYPE);
-    }
-
-    private static final ValueMaker<Map<Object, Object>> MAP_MAKER = new ValueMaker<Map<Object,
Object>>() {
-        public Map<Object, Object> make() throws Exception {
-            return new HashMap<Object, Object>();
-        }
-    };
-
-    private static Map<Object, Cache<String, Map<Object, Object>>> objectCacheMap
-        = Collections.synchronizedMap(new WeakHashMap<Object, Cache<String, Map<Object,
Object>>>());
-
     protected String createStreamForPDF(ImagePDF image, PDFPage targetPage, FOUserAgent userAgent,
                                         AffineTransform at, FontInfo fontinfo, Rectangle
pos,
                                         Map<Integer, PDFArray> pageNumbers,
@@ -134,25 +115,13 @@ public abstract class AbstractPDFBoxHand
         return stream;
     }
 
-    private Map<Object, Object> getObjectCache(String originalImageUri,
-            Object documentScopedReference) {
-        String fileUri = getImagePath(originalImageUri);
-        try {
-            return getDocumentCache(documentScopedReference)
-                        .getValue(fileUri, MAP_MAKER);
-        } catch (Exception e) {
-            // We cannot recover from this
-            throw new RuntimeException(e);
-        }
-    }
-
-    private Cache<String, Map<Object, Object>> getDocumentCache(Object documentScopedReference)
{
-        Cache<String, Map<Object, Object>> documentCache = objectCacheMap.get(documentScopedReference);
-        if (documentCache == null) {
-            documentCache = createDocumentCache();
-            objectCacheMap.put(documentScopedReference, documentCache);
+    private Map<Object, Object> getObjectCache(String originalImageUri, FOUserAgent
userAgent) {
+        SoftMapCache objectCache = userAgent.getPDFObjectCache();
+        String path = getImagePath(originalImageUri);
+        if (objectCache.get(path) == null) {
+            objectCache.put(path, new HashMap<Object, Object>());
         }
-        return documentCache;
+        return (Map<Object, Object>) objectCache.get(path);
     }
 
     private String getImagePath(String originalImageUri) {

Modified: xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java?rev=1713640&r1=1713639&r2=1713640&view=diff
==============================================================================
--- xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java
(original)
+++ xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java
Tue Nov 10 14:09:11 2015
@@ -62,6 +62,7 @@ import org.apache.xmlgraphics.image.load
 import org.apache.xmlgraphics.image.loader.impl.DefaultImageContext;
 import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D;
 import org.apache.xmlgraphics.image.loader.impl.ImageRendered;
+import org.apache.xmlgraphics.image.loader.util.SoftMapCache;
 import org.apache.xmlgraphics.java2d.GeneralGraphics2DImagePainter;
 import org.apache.xmlgraphics.java2d.GraphicContext;
 import org.apache.xmlgraphics.ps.PSGenerator;
@@ -427,6 +428,7 @@ public class PDFBoxAdapterTestCase {
         PDFContentGenerator con = new PDFContentGenerator(pdfdoc, null, null);
         FOUserAgent mockedAgent = mock(FOUserAgent.class);
         when(mockedAgent.isAccessibilityEnabled()).thenReturn(false);
+        when(mockedAgent.getPDFObjectCache()).thenReturn(new SoftMapCache(true));
         PDFRenderingContext c = new PDFRenderingContext(mockedAgent, con, pdfpage, null);
         c.setPageNumbers(new HashMap<Integer, PDFArray>());
         new PDFBoxImageHandler().handleImage(c, img, new Rectangle());



---------------------------------------------------------------------
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