diff --git a/pom.xml b/pom.xml
index aba49b34..1478d8c3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -14,7 +14,7 @@
UTF-8
- 0.4.1
+ 0.4.2-SNAPSHOT
0.0.3
0.0.5
diff --git a/src/main/java/eu/transkribus/core/io/util/ImgFileFilter.java b/src/main/java/eu/transkribus/core/io/util/ImgFileFilter.java
index 777e3fb2..785be14c 100644
--- a/src/main/java/eu/transkribus/core/io/util/ImgFileFilter.java
+++ b/src/main/java/eu/transkribus/core/io/util/ImgFileFilter.java
@@ -14,6 +14,6 @@ public boolean accept(File pathname) {
final String mime = MimeTypes.getMimeType(FilenameUtils.getExtension(pathname.getName()));
//is allowed mimetype and not starts with ".", which may occur on mac
//FIXME pathname.isFile() does not have to be checked here?
- return pathname.isFile() && !pathname.getName().startsWith(".") && ImgPriority.priorities.containsKey(mime);
+ return pathname.isFile() && !pathname.getName().startsWith(".") && ImgPriority.containsMimeType(mime);
}
}
diff --git a/src/main/java/eu/transkribus/core/io/util/ImgFilenameFilter.java b/src/main/java/eu/transkribus/core/io/util/ImgFilenameFilter.java
index 839d8bcb..91ec251f 100644
--- a/src/main/java/eu/transkribus/core/io/util/ImgFilenameFilter.java
+++ b/src/main/java/eu/transkribus/core/io/util/ImgFilenameFilter.java
@@ -12,7 +12,7 @@ public class ImgFilenameFilter implements FilenameFilter {
public boolean accept(File dir, String name) {
final String mime = MimeTypes.getMimeType(FilenameUtils.getExtension(name));
//is allowed mimetype and not starts with ".", which may occur on mac
- return !name.startsWith(".") && ImgPriority.priorities.containsKey(mime);
+ return !name.startsWith(".") && ImgPriority.containsMimeType(mime);
}
}
diff --git a/src/main/java/eu/transkribus/core/io/util/ImgPriority.java b/src/main/java/eu/transkribus/core/io/util/ImgPriority.java
index 49073657..5709c8f6 100644
--- a/src/main/java/eu/transkribus/core/io/util/ImgPriority.java
+++ b/src/main/java/eu/transkribus/core/io/util/ImgPriority.java
@@ -1,15 +1,21 @@
package eu.transkribus.core.io.util;
import java.io.File;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.apache.commons.io.FilenameUtils;
import org.dea.fimagestore.core.util.MimeTypes;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class ImgPriority {
+ private static final Logger logger = LoggerFactory.getLogger(ImgPriority.class);
+
// this map will be used to prioritize different images for one page on the path
- public static Map priorities = new HashMap<>();
+ private static Map priorities = new HashMap<>();
static {
//jpg > tif/tiff
@@ -22,4 +28,24 @@ public static Integer getPriority(File f) {
final String mime = MimeTypes.getMimeType(FilenameUtils.getExtension(f.getName()));
return priorities.get(mime);
}
+
+ public static boolean containsMimeType(final String mimeType) {
+ return priorities.containsKey(mimeType);
+ }
+
+ public static List getAllowedFilenameExtensions() {
+ List exts = new ArrayList<>(ImgPriority.priorities.size() * 2);
+ for(String mimeType : ImgPriority.priorities.keySet()) {
+ List extsForType = MimeTypes.lookupExtensions(mimeType);
+ if(extsForType.isEmpty()) {
+ logger.error("Reverse lookup of registered mimetype failed: " + mimeType);
+ continue;
+ }
+ for(String ext : extsForType) {
+ exts.add(ext.toLowerCase());
+ exts.add(ext.toUpperCase());
+ }
+ }
+ return exts;
+ }
}
diff --git a/src/test/java/eu/transkribus/core/io/util/ImgPriorityTest.java b/src/test/java/eu/transkribus/core/io/util/ImgPriorityTest.java
new file mode 100644
index 00000000..efab7d30
--- /dev/null
+++ b/src/test/java/eu/transkribus/core/io/util/ImgPriorityTest.java
@@ -0,0 +1,22 @@
+package eu.transkribus.core.io.util;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ImgPriorityTest {
+ private static final Logger logger = LoggerFactory.getLogger(ImgPriorityTest.class);
+
+ @Test
+ public void testGetAllowedFilenameExtensions() {
+ List exts = ImgPriority.getAllowedFilenameExtensions();
+ Assert.assertNotNull(exts);
+ logger.debug("Collected allowed file extensions: " + exts.stream().collect(Collectors.joining(", ")));
+ Assert.assertFalse(exts.isEmpty());
+ }
+
+}