fix #1175 modify condition checks
This commit is contained in:
parent
9f1a4b07da
commit
093521b12e
4 changed files with 29 additions and 12 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Add table
Reference in a new issue