Author: lehmi
Date: Fri Jan 31 07:21:13 2025
New Revision: 1923473

URL: http://svn.apache.org/viewvc?rev=1923473&view=rev
Log:
PDFBOX-5943: extend interface to support the removal of cached resources

Modified:
    
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/DefaultResourceCache.java
    
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/ResourceCache.java

Modified: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/DefaultResourceCache.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/DefaultResourceCache.java?rev=1923473&r1=1923472&r2=1923473&view=diff
==============================================================================
--- 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/DefaultResourceCache.java
 (original)
+++ 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/DefaultResourceCache.java
 Fri Jan 31 07:21:13 2025
@@ -62,11 +62,7 @@ public class DefaultResourceCache implem
     public PDFont getFont(COSObject indirect)
     {
         SoftReference<PDFont> font = fonts.get(indirect);
-        if (font != null)
-        {
-            return font.get();
-        }
-        return null;
+        return font != null ? font.get() : null;
     }
 
     @Override
@@ -76,14 +72,17 @@ public class DefaultResourceCache implem
     }
 
     @Override
+    public PDFont removeFont(COSObject indirect)
+    {
+        SoftReference<PDFont> font = fonts.remove(indirect);
+        return font != null ? font.get() : null;
+    }
+
+    @Override
     public PDColorSpace getColorSpace(COSObject indirect)
     {
         SoftReference<PDColorSpace> colorSpace = colorSpaces.get(indirect);
-        if (colorSpace != null)
-        {
-            return colorSpace.get();
-        }
-        return null;
+        return colorSpace != null ? colorSpace.get() : null;
     }
 
     @Override
@@ -93,14 +92,17 @@ public class DefaultResourceCache implem
     }
 
     @Override
+    public PDColorSpace removeColorSpace(COSObject indirect)
+    {
+        SoftReference<PDColorSpace> colorSpace = colorSpaces.remove(indirect);
+        return colorSpace != null ? colorSpace.get() : null;
+    }
+
+    @Override
     public PDExtendedGraphicsState getExtGState(COSObject indirect)
     {
         SoftReference<PDExtendedGraphicsState> extGState = 
extGStates.get(indirect);
-        if (extGState != null)
-        {
-            return extGState.get();
-        }
-        return null;
+        return extGState != null ? extGState.get() : null;
     }
 
     @Override
@@ -110,14 +112,17 @@ public class DefaultResourceCache implem
     }
 
     @Override
+    public PDExtendedGraphicsState removeExtState(COSObject indirect)
+    {
+        SoftReference<PDExtendedGraphicsState> extGState = 
extGStates.remove(indirect);
+        return extGState != null ? extGState.get() : null;
+    }
+
+    @Override
     public PDShading getShading(COSObject indirect)
     {
         SoftReference<PDShading> shading = shadings.get(indirect);
-        if (shading != null)
-        {
-            return shading.get();
-        }
-        return null;
+        return shading != null ? shading.get() : null;
     }
 
     @Override
@@ -127,14 +132,17 @@ public class DefaultResourceCache implem
     }
 
     @Override
+    public PDShading removeShading(COSObject indirect)
+    {
+        SoftReference<PDShading> shading = shadings.remove(indirect);
+        return shading != null ? shading.get() : null;
+    }
+
+    @Override
     public PDAbstractPattern getPattern(COSObject indirect)
     {
         SoftReference<PDAbstractPattern> pattern = patterns.get(indirect);
-        if (pattern != null)
-        {
-            return pattern.get();
-        }
-        return null;
+        return pattern != null ? pattern.get() : null;
     }
 
     @Override
@@ -144,14 +152,17 @@ public class DefaultResourceCache implem
     }
     
     @Override
+    public PDAbstractPattern removePattern(COSObject indirect)
+    {
+        SoftReference<PDAbstractPattern> pattern = patterns.remove(indirect);
+        return pattern != null ? pattern.get() : null;
+    }
+
+    @Override
     public PDPropertyList getProperties(COSObject indirect)
     {
         SoftReference<PDPropertyList> propertyList = properties.get(indirect);
-        if (propertyList != null)
-        {
-            return propertyList.get();
-        }
-        return null;
+        return propertyList != null ? propertyList.get() : null;
     }
 
     @Override
@@ -161,14 +172,17 @@ public class DefaultResourceCache implem
     }
 
     @Override
+    public PDPropertyList removeProperties(COSObject indirect)
+    {
+        SoftReference<PDPropertyList> propertyList = 
properties.remove(indirect);
+        return propertyList != null ? propertyList.get() : null;
+    }
+
+    @Override
     public PDXObject getXObject(COSObject indirect)
     {
         SoftReference<PDXObject> xobject = xobjects.get(indirect);
-        if (xobject != null)
-        {
-            return xobject.get();
-        }
-        return null;
+        return xobject != null ? xobject.get() : null;
     }
 
     @Override
@@ -176,4 +190,11 @@ public class DefaultResourceCache implem
     {
         xobjects.put(indirect, new SoftReference<>(xobject));
     }
+
+    @Override
+    public PDXObject removeXObject(COSObject indirect)
+    {
+        SoftReference<PDXObject> xobject = xobjects.remove(indirect);
+        return xobject != null ? xobject.get() : null;
+    }
 }

Modified: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/ResourceCache.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/ResourceCache.java?rev=1923473&r1=1923472&r2=1923473&view=diff
==============================================================================
--- 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/ResourceCache.java 
(original)
+++ 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/ResourceCache.java 
Fri Jan 31 07:21:13 2025
@@ -144,4 +144,68 @@ public interface ResourceCache
      * @param xobject the XObject to be cached
      */
     void put(COSObject indirect, PDXObject xobject);
+
+    /**
+     * Removes the given indirect color space resource from the cache.
+     * 
+     * @param indirect the indirect reference of the color space to be removed
+     * 
+     * @return the removed resource if present
+     */
+    PDColorSpace removeColorSpace(COSObject indirect);
+
+    /**
+     * Removes the given indirect extended graphics state resource from the 
cache.
+     * 
+     * @param indirect the indirect reference of the extended graphics state 
to be removed
+     * 
+     * @return the removed resource if present
+     */
+    PDExtendedGraphicsState removeExtState(COSObject indirect);
+
+    /**
+     * Removes the given indirect font resource from the cache.
+     * 
+     * @param indirect the indirect reference of the font to be removed
+     * 
+     * @return the removed resource if present
+     */
+    PDFont removeFont(COSObject indirect);
+
+    /**
+     * Removes the given indirect shading resource from the cache.
+     * 
+     * @param indirect the indirect reference of the shading to be removed
+     * 
+     * @return the removed resource if present
+     */
+    PDShading removeShading(COSObject indirect);
+
+    /**
+     * Removes the given indirect pattern resource from the cache.
+     * 
+     * @param indirect the indirect reference of the pattern to be removed
+     * 
+     * @return the removed resource if present
+     */
+    PDAbstractPattern removePattern(COSObject indirect);
+
+    /**
+     * Removes the given indirect property list resource from the cache.
+     * 
+     * @param indirect the indirect reference of the property list to be 
removed
+     * 
+     * @return the removed resource if present
+     */
+    PDPropertyList removeProperties(COSObject indirect);
+
+    /**
+     * Removes the given indirect XObject resource from the cache.
+     * 
+     * @param indirect the indirect reference of the XObject to be removed
+     * 
+     * @return the removed resource if present
+     */
+    PDXObject removeXObject(COSObject indirect);
+
 }


Reply via email to