Author: centic
Date: Wed Dec  6 19:50:02 2023
New Revision: 1914407

URL: http://svn.apache.org/viewvc?rev=1914407&view=rev
Log:
Make sure OLE2ScratchpadExtractorFacory is sorted first

Otherwise order of found extractors would depend on jar-loading order
and thus might have unexpected side-effects and missing features in
text-extraction.

Modified:
    poi/trunk/poi/src/main/java/org/apache/poi/extractor/ExtractorFactory.java
    poi/trunk/poi/src/main/java/org/apache/poi/extractor/ExtractorProvider.java

Modified: 
poi/trunk/poi/src/main/java/org/apache/poi/extractor/ExtractorFactory.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/extractor/ExtractorFactory.java?rev=1914407&r1=1914406&r2=1914407&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/extractor/ExtractorFactory.java 
(original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/extractor/ExtractorFactory.java 
Wed Dec  6 19:50:02 2023
@@ -88,6 +88,21 @@ public final class ExtractorFactory {
     private ExtractorFactory() {
         ClassLoader cl = ExtractorFactory.class.getClassLoader();
         ServiceLoader.load(ExtractorProvider.class, cl).forEach(provider::add);
+
+        // loading of service-files is non-deterministic as it depends on 
order of loaded jars
+        // however we would like to "prefer" one Factory, so let's make sure 
the more
+        // powerful "ScratchpadProvider" is sorted first
+        provider.sort((o1, o2) -> {
+            if (o1.getClass() != o2.getClass()) {
+                if 
(o1.getClass().getSimpleName().equals("OLE2ScratchpadExtractorFactory")) {
+                    return -1;
+                } else if 
(o2.getClass().getSimpleName().equals("OLE2ScratchpadExtractorFactory")) {
+                    return 1;
+                }
+            }
+
+            return o1.getClass().getName().compareTo(o2.getClass().getName());
+        });
     }
 
     /**

Modified: 
poi/trunk/poi/src/main/java/org/apache/poi/extractor/ExtractorProvider.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/extractor/ExtractorProvider.java?rev=1914407&r1=1914406&r2=1914407&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/extractor/ExtractorProvider.java 
(original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/extractor/ExtractorProvider.java 
Wed Dec  6 19:50:02 2023
@@ -70,7 +70,8 @@ public interface ExtractorProvider {
      * @param dirs a list to be filled with directory references holding 
embedded
      * @param nonPOIFS a list to be filled with streams which aren't based on 
POIFS entries
      *
-     * @throws IOException when the format specific extraction fails because 
of invalid entires
+     * @throws IOException when the format specific extraction fails because 
of invalid entries
+     * @throws java.lang.IllegalArgumentException if implementations do not 
overwrite this method
      */
     default void identifyEmbeddedResources(POIOLE2TextExtractor ext, 
List<Entry> dirs, List<InputStream> nonPOIFS) throws IOException {
         throw new IllegalArgumentException("Error checking for Scratchpad 
embedded resources");



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to