Author: lehmi
Date: Wed Apr 16 06:16:59 2025
New Revision: 1925104

URL: http://svn.apache.org/viewvc?rev=1925104&view=rev
Log:
PDFBOX-4668: add a ResourceCacheFactory to configure what kind of cache to be 
used for resources while processing a pdf

Added:
    
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/DefaultResourceCacheCreateImpl.java
   (with props)
    
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/ResourceCacheCreateFunction.java
   (with props)
    
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/ResourceCacheFactory.java
   (with props)
Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java

Added: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/DefaultResourceCacheCreateImpl.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/DefaultResourceCacheCreateImpl.java?rev=1925104&view=auto
==============================================================================
--- 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/DefaultResourceCacheCreateImpl.java
 (added)
+++ 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/DefaultResourceCacheCreateImpl.java
 Wed Apr 16 06:16:59 2025
@@ -0,0 +1,53 @@
+/*
+ * 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.
+ */
+
+package org.apache.pdfbox.pdmodel;
+
+/**
+ * Implementation of the functional interface ResourceCacheCreateFunction to 
create an instance of a
+ * DefaultResourceCache.
+ */
+public class DefaultResourceCacheCreateImpl implements 
ResourceCacheCreateFunction
+{
+    private final boolean stableCacheEnabled;
+
+    /**
+     * Default constructor.
+     */
+    public DefaultResourceCacheCreateImpl()
+    {
+        this(true);
+    }
+
+    /**
+     * Constructor providing a parameter to enable/disable the stable object 
cache.
+     * 
+     * @param enableStableCache enables/disables the stable object cache
+     * 
+     */
+    public DefaultResourceCacheCreateImpl(boolean enableStableCache)
+    {
+        stableCacheEnabled = enableStableCache;
+    }
+
+    @Override
+    public ResourceCache create()
+    {
+        return new DefaultResourceCache(stableCacheEnabled);
+    }
+}
+

Propchange: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/DefaultResourceCacheCreateImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java?rev=1925104&r1=1925103&r2=1925104&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java 
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java 
Wed Apr 16 06:16:59 2025
@@ -147,7 +147,7 @@ public class PDDocument implements Close
     private SigningSupport signingSupport;
 
     // document-wide cached resources
-    private ResourceCache resourceCache = new DefaultResourceCache();
+    private ResourceCache resourceCache = 
ResourceCacheFactory.createResourceCache();
 
     // to make sure only one signature is added
     private boolean signatureAdded = false;

Added: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/ResourceCacheCreateFunction.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/ResourceCacheCreateFunction.java?rev=1925104&view=auto
==============================================================================
--- 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/ResourceCacheCreateFunction.java
 (added)
+++ 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/ResourceCacheCreateFunction.java
 Wed Apr 16 06:16:59 2025
@@ -0,0 +1,33 @@
+/*
+ * 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.
+ */
+
+package org.apache.pdfbox.pdmodel;
+
+/**
+ * Functional interface to be used to create an instance of a resource cache.
+ */
+@FunctionalInterface
+public interface ResourceCacheCreateFunction
+{
+    /**
+     * Creates an instance of a ResourceCache.
+     *
+     * @return the resource cache.
+     */
+    ResourceCache create();
+}
+

Propchange: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/ResourceCacheCreateFunction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/ResourceCacheFactory.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/ResourceCacheFactory.java?rev=1925104&view=auto
==============================================================================
--- 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/ResourceCacheFactory.java
 (added)
+++ 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/ResourceCacheFactory.java
 Wed Apr 16 06:16:59 2025
@@ -0,0 +1,69 @@
+/*
+ * 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.
+ */
+
+package org.apache.pdfbox.pdmodel;
+
+/**
+ * Factory which provides a function to create an instance of a ResourceCache 
to be used to cache resources while
+ * processing a pdf.
+ * 
+ * A DefaultResourceCache is used as default implementation. I can be replaced 
with an individual implementation.
+ * 
+ * Setting the function to null disables the cache.
+ */
+public class ResourceCacheFactory
+{
+    private static ResourceCacheCreateFunction resourceCacheCreateFunction = 
null;
+
+    /**
+     * Constructor.
+     */
+    private ResourceCacheFactory()
+    {
+        setResourceCacheCreateFunction(new DefaultResourceCacheCreateImpl());
+    }
+    
+    /**
+     * Use the given function to create an instance of a resource cache. 
Caching is disabled if a null value is
+     * provided.
+     */
+    public static void 
setResourceCacheCreateFunction(ResourceCacheCreateFunction function)
+    {
+        resourceCacheCreateFunction = function;
+    }
+
+    /**
+     * Get the current function to be used to create an instance of a resource 
cache.
+     * 
+     * @return the current function or null.
+     */
+    public static ResourceCacheCreateFunction getResourceCacheCreateFunction()
+    {
+        return resourceCacheCreateFunction;
+    }
+
+    /**
+     * Create an instance of a resource cache using the provided function. 
Returns null if the function is set to null.
+     * 
+     * @return an instance of a resource cache.
+     */
+    public static ResourceCache createResourceCache()
+    {
+        return resourceCacheCreateFunction != null ? 
resourceCacheCreateFunction.create() : null;
+    }
+    
+}

Propchange: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/ResourceCacheFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to