Selaa lähdekoodia

fix #1175 modify condition checks

Shinsuke Sugaya 8 vuotta sitten
vanhempi
commit
093521b12e

+ 20 - 0
src/main/assemblies/files/generate-thumbnail

@@ -5,13 +5,29 @@ URL=$2
 OUTPUT_FILE=$3
 IMAGE_SIZE=100x100!
 
+check_command() {
+  CMD=$1
+  CMD_PATH=`which $CMD`
+  if [ ! -e "$CMD_PATH" ] ; then
+    echo "$CMD does not exist."
+    exit 1
+  fi
+}
+
 if [ x"$CMD_TYPE" = "xmsoffice" ] ; then
+  check_command convert
+  check_command unoconv
   TARGET_FILE=`echo $URL | sed -e "s#^file:/*#/#g"`
   TMP_FILE=/tmp/thumbnail.$$.pdf
   unoconv -e PageRange=1-1 -o $TMP_FILE -f pdf $TARGET_FILE
+  if [ ! -f $TMP_FILE ] ; then
+    echo "unoconv does not work."
+    exit 1
+  fi
   convert -thumbnail $IMAGE_SIZE ${TMP_FILE}[0] $OUTPUT_FILE
   rm $TMP_FILE
 elif [ x"$CMD_TYPE" = "xpdf" ] ; then
+  check_command convert
   TARGET_FILE=`echo $URL | sed -e "s#^file:/*#/#g"`
   convert -thumbnail $IMAGE_SIZE ${TARGET_FILE}[0] $OUTPUT_FILE
 else
@@ -19,3 +35,7 @@ else
   exit 1
 fi
 
+if [ ! -f $OUTPUT_FILE ] ; then
+  echo "Thumbnail is not created."
+  exit 1
+fi

+ 9 - 4
src/main/java/org/codelibs/fess/thumbnail/impl/BaseThumbnailGenerator.java

@@ -60,7 +60,12 @@ public abstract class BaseThumbnailGenerator implements ThumbnailGenerator {
     protected int maxRedirectCount = 10;
 
     public void addCondition(final String key, final String regex) {
-        conditionMap.put(key, regex);
+        final String value = conditionMap.get(key);
+        if (StringUtil.isBlank(value)) {
+            conditionMap.put(key, regex);
+        } else {
+            conditionMap.put(key, value + "|" + regex);
+        }
     }
 
     @Override
@@ -70,11 +75,11 @@ public abstract class BaseThumbnailGenerator implements ThumbnailGenerator {
         }
         for (final Map.Entry<String, String> entry : conditionMap.entrySet()) {
             final Object value = docMap.get(entry.getKey());
-            if (value instanceof String && !((String) value).matches(entry.getValue())) {
-                return false;
+            if (value instanceof String && ((String) value).matches(entry.getValue())) {
+                return true;
             }
         }
-        return true;
+        return false;
     }
 
     @Override

+ 0 - 4
src/main/resources/fess_thumbnail.xml

@@ -31,10 +31,6 @@
 		<property name="generatorList">
 			["${path}/generate-thumbnail"]
 		</property>
-		<postConstruct name="addCondition">
-			<arg>"mimetype"</arg>
-			<arg>"text/html"</arg>
-		</postConstruct>
 		<postConstruct name="addCondition">
 			<arg>"mimetype"</arg>
 			<arg>"application/vnd.openxmlformats-officedocument.wordprocessingml.document"</arg>

+ 0 - 4
src/main/webapp/WEB-INF/crawler/resources/crawler_thumbnail.xml

@@ -25,10 +25,6 @@
 		<property name="generatorList">
 			["${path}/generate-thumbnail"]
 		</property>
-		<postConstruct name="addCondition">
-			<arg>"mimetype"</arg>
-			<arg>"text/html"</arg>
-		</postConstruct>
 		<postConstruct name="addCondition">
 			<arg>"mimetype"</arg>
 			<arg>"application/vnd.openxmlformats-officedocument.wordprocessingml.document"</arg>