diff --git a/src/main/java/org/codelibs/fess/crawler/transformer/FessXpathTransformer.java b/src/main/java/org/codelibs/fess/crawler/transformer/FessXpathTransformer.java
index f2b305e00..18b042259 100644
--- a/src/main/java/org/codelibs/fess/crawler/transformer/FessXpathTransformer.java
+++ b/src/main/java/org/codelibs/fess/crawler/transformer/FessXpathTransformer.java
@@ -714,12 +714,10 @@ public class FessXpathTransformer extends XpathTransformer implements FessTransf
for (int i = 0; i < imgNodeList.getLength(); i++) {
final Node imgNode = imgNodeList.item(i);
final NamedNodeMap attributes = imgNode.getAttributes();
- final Node heightAttr = attributes.getNamedItem("height");
- final Node widthAttr = attributes.getNamedItem("width");
- if (heightAttr != null && widthAttr != null) {
+ final Integer height = getAttributeAsInteger(attributes, "height");
+ final Integer width = getAttributeAsInteger(attributes, "width");
+ if (height != null && width != null) {
try {
- final int height = Integer.parseInt(heightAttr.getTextContent());
- final int width = Integer.parseInt(widthAttr.getTextContent());
if (fessConfig.validateThumbnailSize(width, height)) {
final Node srcNode = attributes.getNamedItem("src");
if (srcNode != null) {
@@ -756,6 +754,25 @@ public class FessXpathTransformer extends XpathTransformer implements FessTransf
return null;
}
+ protected Integer getAttributeAsInteger(final NamedNodeMap attributes, final String name) {
+ Node namedItem = attributes.getNamedItem(name);
+ if (namedItem == null) {
+ return null;
+ }
+ final String value = namedItem.getTextContent();
+ if (value == null) {
+ return null;
+ }
+ try {
+ return Integer.parseInt(value);
+ } catch (final NumberFormatException e) {
+ if (value.endsWith("%") || value.endsWith("px")) {
+ return null;
+ }
+ return 0;
+ }
+ }
+
protected URL getURL(final String currentUrl, final String url) throws MalformedURLException {
if (url != null) {
if (url.startsWith("://")) {
diff --git a/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java b/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java
index 842430bb8..06201ab16 100644
--- a/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java
+++ b/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java
@@ -771,7 +771,7 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
/** The key of the configuration. e.g. all */
String THUMBNAIL_GENERATOR_TARGETS = "thumbnail.generator.targets";
- /** The key of the configuration. e.g. false */
+ /** The key of the configuration. e.g. true */
String THUMBNAIL_CRAWLER_ENABLED = "thumbnail.crawler.enabled";
/** The key of the configuration. e.g. userCode */
@@ -3780,14 +3780,14 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
/**
* Get the value for the key 'thumbnail.crawler.enabled'.
- * The value is, e.g. false
+ * The value is, e.g. true
* @return The value of found property. (NotNull: if not found, exception but basically no way)
*/
String getThumbnailCrawlerEnabled();
/**
* Is the property for the key 'thumbnail.crawler.enabled' true?
- * The value is, e.g. false
+ * The value is, e.g. true
* @return The determination, true or false. (if not found, exception but basically no way)
*/
boolean isThumbnailCrawlerEnabled();
diff --git a/src/main/java/org/codelibs/fess/thumbnail/impl/HtmlTagBasedGenerator.java b/src/main/java/org/codelibs/fess/thumbnail/impl/HtmlTagBasedGenerator.java
index 07629fc0a..87b804185 100644
--- a/src/main/java/org/codelibs/fess/thumbnail/impl/HtmlTagBasedGenerator.java
+++ b/src/main/java/org/codelibs/fess/thumbnail/impl/HtmlTagBasedGenerator.java
@@ -79,18 +79,29 @@ public class HtmlTagBasedGenerator extends BaseThumbnailGenerator {
}
Curl.get(url).execute(con -> {
+ boolean created = false;
try (ImageInputStream input = ImageIO.createImageInputStream(con.getInputStream())) {
- saveImage(input, outputFile);
+ if (saveImage(input, outputFile)) {
+ created = true;
+ } else {
+ logger.warn("Failed to create a thumbnail for " + url);
+ }
} catch (final Throwable t) {
- logger.warn("Failed to convert " + url, t);
- updateThumbnailField(thumbnailId, url, StringUtil.EMPTY);
+ logger.warn("Failed to create a thumbnail for " + url, t);
+ } finally {
+ if (!created) {
+ updateThumbnailField(thumbnailId, url, StringUtil.EMPTY);
+ if (outputFile.exists() && !outputFile.delete()) {
+ logger.warn("Failed to delete " + outputFile.getAbsolutePath());
+ }
+ }
}
});
- return false;
+ return outputFile.exists();
}
- protected void saveImage(final ImageInputStream input, final File outputFile) throws IOException {
+ protected boolean saveImage(final ImageInputStream input, final File outputFile) throws IOException {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final Iterator readers = ImageIO.getImageReaders(input);
if (readers.hasNext()) {
@@ -114,10 +125,12 @@ public class HtmlTagBasedGenerator extends BaseThumbnailGenerator {
0, thumbnailWidth, thumbnailHeight, null);
ImageIO.write(thumbnail, fessConfig.getThumbnailHtmlImageFormat(), outputFile);
image.flush();
+ return true;
} finally {
reader.dispose();
}
}
+ return false;
}
}
diff --git a/src/main/resources/fess_config.properties b/src/main/resources/fess_config.properties
index a4b3a0bb7..c742b2718 100644
--- a/src/main/resources/fess_config.properties
+++ b/src/main/resources/fess_config.properties
@@ -393,7 +393,7 @@ thumbnail.html.image.thumbnail.width=100
thumbnail.html.image.thumbnail.height=100
thumbnail.html.image.format=png
thumbnail.generator.targets=all
-thumbnail.crawler.enabled=false
+thumbnail.crawler.enabled=true
# user
user.code.request.parameter=userCode
diff --git a/src/main/webapp/WEB-INF/crawler/resources/crawler_thumbnail.xml b/src/main/webapp/WEB-INF/crawler/resources/crawler_thumbnail.xml
index e7dbbe2a6..20bae9a41 100644
--- a/src/main/webapp/WEB-INF/crawler/resources/crawler_thumbnail.xml
+++ b/src/main/webapp/WEB-INF/crawler/resources/crawler_thumbnail.xml
@@ -6,57 +6,13 @@
htmlThumbnailGenerator
-
- msofficeThumbnailGenerator
-
-
+
"htmlThumbnailGenerator"
"mimetype"
"text/html"
-
- "msofficeThumbnailGenerator"
-
- "mimetype"
- "text/html"
-
-
- "mimetype"
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
-
-
-
- "mimetype"
- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
-
-
-
- "mimetype"
- "application/vnd.openxmlformats-officedocument.presentationml.presentation"
-
-
-
- "mimetype"
- "application/msword"
-
-
-
- "mimetype"
- "application/vnd.ms-excel"
-
-
-
- "mimetype"
- "application/vnd.ms-powerpoint"
-
-
-
- "mimetype"
- "application/rtf"
-
-
-
+
diff --git a/src/test/java/org/codelibs/fess/crawler/transformer/FessXpathTransformerTest.java b/src/test/java/org/codelibs/fess/crawler/transformer/FessXpathTransformerTest.java
index a68affe0e..1a229fe41 100644
--- a/src/test/java/org/codelibs/fess/crawler/transformer/FessXpathTransformerTest.java
+++ b/src/test/java/org/codelibs/fess/crawler/transformer/FessXpathTransformerTest.java
@@ -706,6 +706,14 @@ public class FessXpathTransformerTest extends UnitFessTestCase {
data = "
";
expected = "http://example/foo.jpg";
assertGetThumbnailUrl(data, expected);
+
+ data = "
";
+ expected = "http://example/foo.jpg";
+ assertGetThumbnailUrl(data, expected);
+
+ data = "
";
+ expected = "http://example/foo.jpg";
+ assertGetThumbnailUrl(data, expected);
}
private void assertGetThumbnailUrl(String data, String expected) throws Exception {