Ver código fonte

fix #888 add max window height

Shinsuke Sugaya 8 anos atrás
pai
commit
00aa905473

+ 173 - 3
src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java

@@ -31,7 +31,7 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
     /** The key of the configuration. e.g. http://localhost:9201 */
     String ELASTICSEARCH_HTTP_URL = "elasticsearch.http.url";
 
-    /** The key of the configuration. e.g. true */
+    /** The key of the configuration. e.g. false */
     String ELASTICSEARCH_TRANSPORT_SNIFF = "elasticsearch.transport.sniff";
 
     /** The key of the configuration. e.g. 1m */
@@ -687,6 +687,27 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
     /** The key of the configuration. e.g. true */
     String THUMBNAIL_HTML_PHANTOMJS_ENABLED = "thumbnail.html.phantomjs.enabled";
 
+    /** The key of the configuration. e.g. 20000 */
+    String THUMBNAIL_HTML_PHANTOMJS_MAX_HEIGHT = "thumbnail.html.phantomjs.max.height";
+
+    /** The key of the configuration. e.g. 600000 */
+    String THUMBNAIL_HTML_PHANTOMJS_KEEP_ALIVE = "thumbnail.html.phantomjs.keep.alive";
+
+    /** The key of the configuration. e.g. 1200 */
+    String THUMBNAIL_HTML_PHANTOMJS_WINDOW_WIDTH = "thumbnail.html.phantomjs.window.width";
+
+    /** The key of the configuration. e.g. 800 */
+    String THUMBNAIL_HTML_PHANTOMJS_WINDOW_HEIGHT = "thumbnail.html.phantomjs.window.height";
+
+    /** The key of the configuration. e.g. 160 */
+    String THUMBNAIL_HTML_PHANTOMJS_THUMBNAIL_WIDTH = "thumbnail.html.phantomjs.thumbnail.width";
+
+    /** The key of the configuration. e.g. 160 */
+    String THUMBNAIL_HTML_PHANTOMJS_THUMBNAIL_HEIGHT = "thumbnail.html.phantomjs.thumbnail.height";
+
+    /** The key of the configuration. e.g. png */
+    String THUMBNAIL_HTML_PHANTOMJS_FORMAT = "thumbnail.html.phantomjs.format";
+
     /** The key of the configuration. e.g. all */
     String THUMBNAIL_GENERATOR_TARGETS = "thumbnail.generator.targets";
 
@@ -1142,14 +1163,14 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
 
     /**
      * Get the value for the key 'elasticsearch.transport.sniff'. <br>
-     * The value is, e.g. true <br>
+     * The value is, e.g. false <br>
      * @return The value of found property. (NotNull: if not found, exception but basically no way)
      */
     String getElasticsearchTransportSniff();
 
     /**
      * Is the property for the key 'elasticsearch.transport.sniff' true? <br>
-     * The value is, e.g. true <br>
+     * The value is, e.g. false <br>
      * @return The determination, true or false. (if not found, exception but basically no way)
      */
     boolean isElasticsearchTransportSniff();
@@ -3345,6 +3366,103 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
      */
     boolean isThumbnailHtmlPhantomjsEnabled();
 
+    /**
+     * Get the value for the key 'thumbnail.html.phantomjs.max.height'. <br>
+     * The value is, e.g. 20000 <br>
+     * @return The value of found property. (NotNull: if not found, exception but basically no way)
+     */
+    String getThumbnailHtmlPhantomjsMaxHeight();
+
+    /**
+     * Get the value for the key 'thumbnail.html.phantomjs.max.height' as {@link Integer}. <br>
+     * The value is, e.g. 20000 <br>
+     * @return The value of found property. (NotNull: if not found, exception but basically no way)
+     * @throws NumberFormatException When the property is not integer.
+     */
+    Integer getThumbnailHtmlPhantomjsMaxHeightAsInteger();
+
+    /**
+     * Get the value for the key 'thumbnail.html.phantomjs.keep.alive'. <br>
+     * The value is, e.g. 600000 <br>
+     * @return The value of found property. (NotNull: if not found, exception but basically no way)
+     */
+    String getThumbnailHtmlPhantomjsKeepAlive();
+
+    /**
+     * Get the value for the key 'thumbnail.html.phantomjs.keep.alive' as {@link Integer}. <br>
+     * The value is, e.g. 600000 <br>
+     * @return The value of found property. (NotNull: if not found, exception but basically no way)
+     * @throws NumberFormatException When the property is not integer.
+     */
+    Integer getThumbnailHtmlPhantomjsKeepAliveAsInteger();
+
+    /**
+     * Get the value for the key 'thumbnail.html.phantomjs.window.width'. <br>
+     * The value is, e.g. 1200 <br>
+     * @return The value of found property. (NotNull: if not found, exception but basically no way)
+     */
+    String getThumbnailHtmlPhantomjsWindowWidth();
+
+    /**
+     * Get the value for the key 'thumbnail.html.phantomjs.window.width' as {@link Integer}. <br>
+     * The value is, e.g. 1200 <br>
+     * @return The value of found property. (NotNull: if not found, exception but basically no way)
+     * @throws NumberFormatException When the property is not integer.
+     */
+    Integer getThumbnailHtmlPhantomjsWindowWidthAsInteger();
+
+    /**
+     * Get the value for the key 'thumbnail.html.phantomjs.window.height'. <br>
+     * The value is, e.g. 800 <br>
+     * @return The value of found property. (NotNull: if not found, exception but basically no way)
+     */
+    String getThumbnailHtmlPhantomjsWindowHeight();
+
+    /**
+     * Get the value for the key 'thumbnail.html.phantomjs.window.height' as {@link Integer}. <br>
+     * The value is, e.g. 800 <br>
+     * @return The value of found property. (NotNull: if not found, exception but basically no way)
+     * @throws NumberFormatException When the property is not integer.
+     */
+    Integer getThumbnailHtmlPhantomjsWindowHeightAsInteger();
+
+    /**
+     * Get the value for the key 'thumbnail.html.phantomjs.thumbnail.width'. <br>
+     * The value is, e.g. 160 <br>
+     * @return The value of found property. (NotNull: if not found, exception but basically no way)
+     */
+    String getThumbnailHtmlPhantomjsThumbnailWidth();
+
+    /**
+     * Get the value for the key 'thumbnail.html.phantomjs.thumbnail.width' as {@link Integer}. <br>
+     * The value is, e.g. 160 <br>
+     * @return The value of found property. (NotNull: if not found, exception but basically no way)
+     * @throws NumberFormatException When the property is not integer.
+     */
+    Integer getThumbnailHtmlPhantomjsThumbnailWidthAsInteger();
+
+    /**
+     * Get the value for the key 'thumbnail.html.phantomjs.thumbnail.height'. <br>
+     * The value is, e.g. 160 <br>
+     * @return The value of found property. (NotNull: if not found, exception but basically no way)
+     */
+    String getThumbnailHtmlPhantomjsThumbnailHeight();
+
+    /**
+     * Get the value for the key 'thumbnail.html.phantomjs.thumbnail.height' as {@link Integer}. <br>
+     * The value is, e.g. 160 <br>
+     * @return The value of found property. (NotNull: if not found, exception but basically no way)
+     * @throws NumberFormatException When the property is not integer.
+     */
+    Integer getThumbnailHtmlPhantomjsThumbnailHeightAsInteger();
+
+    /**
+     * Get the value for the key 'thumbnail.html.phantomjs.format'. <br>
+     * The value is, e.g. png <br>
+     * @return The value of found property. (NotNull: if not found, exception but basically no way)
+     */
+    String getThumbnailHtmlPhantomjsFormat();
+
     /**
      * Get the value for the key 'thumbnail.generator.targets'. <br>
      * The value is, e.g. all <br>
@@ -5702,6 +5820,58 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
             return is(FessConfig.THUMBNAIL_HTML_PHANTOMJS_ENABLED);
         }
 
+        public String getThumbnailHtmlPhantomjsMaxHeight() {
+            return get(FessConfig.THUMBNAIL_HTML_PHANTOMJS_MAX_HEIGHT);
+        }
+
+        public Integer getThumbnailHtmlPhantomjsMaxHeightAsInteger() {
+            return getAsInteger(FessConfig.THUMBNAIL_HTML_PHANTOMJS_MAX_HEIGHT);
+        }
+
+        public String getThumbnailHtmlPhantomjsKeepAlive() {
+            return get(FessConfig.THUMBNAIL_HTML_PHANTOMJS_KEEP_ALIVE);
+        }
+
+        public Integer getThumbnailHtmlPhantomjsKeepAliveAsInteger() {
+            return getAsInteger(FessConfig.THUMBNAIL_HTML_PHANTOMJS_KEEP_ALIVE);
+        }
+
+        public String getThumbnailHtmlPhantomjsWindowWidth() {
+            return get(FessConfig.THUMBNAIL_HTML_PHANTOMJS_WINDOW_WIDTH);
+        }
+
+        public Integer getThumbnailHtmlPhantomjsWindowWidthAsInteger() {
+            return getAsInteger(FessConfig.THUMBNAIL_HTML_PHANTOMJS_WINDOW_WIDTH);
+        }
+
+        public String getThumbnailHtmlPhantomjsWindowHeight() {
+            return get(FessConfig.THUMBNAIL_HTML_PHANTOMJS_WINDOW_HEIGHT);
+        }
+
+        public Integer getThumbnailHtmlPhantomjsWindowHeightAsInteger() {
+            return getAsInteger(FessConfig.THUMBNAIL_HTML_PHANTOMJS_WINDOW_HEIGHT);
+        }
+
+        public String getThumbnailHtmlPhantomjsThumbnailWidth() {
+            return get(FessConfig.THUMBNAIL_HTML_PHANTOMJS_THUMBNAIL_WIDTH);
+        }
+
+        public Integer getThumbnailHtmlPhantomjsThumbnailWidthAsInteger() {
+            return getAsInteger(FessConfig.THUMBNAIL_HTML_PHANTOMJS_THUMBNAIL_WIDTH);
+        }
+
+        public String getThumbnailHtmlPhantomjsThumbnailHeight() {
+            return get(FessConfig.THUMBNAIL_HTML_PHANTOMJS_THUMBNAIL_HEIGHT);
+        }
+
+        public Integer getThumbnailHtmlPhantomjsThumbnailHeightAsInteger() {
+            return getAsInteger(FessConfig.THUMBNAIL_HTML_PHANTOMJS_THUMBNAIL_HEIGHT);
+        }
+
+        public String getThumbnailHtmlPhantomjsFormat() {
+            return get(FessConfig.THUMBNAIL_HTML_PHANTOMJS_FORMAT);
+        }
+
         public String getThumbnailGeneratorTargets() {
             return get(FessConfig.THUMBNAIL_GENERATOR_TARGETS);
         }

+ 26 - 46
src/main/java/org/codelibs/fess/thumbnail/impl/WebDriverGenerator.java

@@ -31,8 +31,10 @@ import javax.imageio.stream.ImageInputStream;
 
 import org.codelibs.fess.mylasta.direction.FessConfig;
 import org.codelibs.fess.util.ComponentUtil;
+import org.openqa.selenium.By;
 import org.openqa.selenium.Capabilities;
 import org.openqa.selenium.Dimension;
+import org.openqa.selenium.JavascriptExecutor;
 import org.openqa.selenium.OutputType;
 import org.openqa.selenium.Proxy;
 import org.openqa.selenium.TakesScreenshot;
@@ -58,18 +60,6 @@ public class WebDriverGenerator extends BaseThumbnailGenerator {
 
     protected Capabilities webDriverCapabilities;
 
-    protected int windowWidth = 1200;
-
-    protected int windowHeight = 800;
-
-    protected int thumbnailWidth = 160;
-
-    protected int thumbnailHeight = 160;
-
-    protected String imageFormatName = "png";
-
-    protected long keepAlive = 10 * 60 * 1000L;
-
     protected long previousCheckTime = 0;
 
     @PostConstruct
@@ -95,7 +85,13 @@ public class WebDriverGenerator extends BaseThumbnailGenerator {
                     webDriver = new PhantomJSDriver(createDriverService(webDriverCapabilities), webDriverCapabilities);
                 }
             }
-            webDriver.manage().window().setSize(new Dimension(windowWidth, windowHeight));
+            final FessConfig fessConfig = ComponentUtil.getFessConfig();
+            webDriver
+                    .manage()
+                    .window()
+                    .setSize(
+                            new Dimension(fessConfig.getThumbnailHtmlPhantomjsWindowWidthAsInteger(), fessConfig
+                                    .getThumbnailHtmlPhantomjsWindowHeightAsInteger()));
             previousCheckTime = ComponentUtil.getSystemHelper().getCurrentTimeAsLong();
         } catch (final Exception e) {
             if (logger.isDebugEnabled()) {
@@ -143,9 +139,17 @@ public class WebDriverGenerator extends BaseThumbnailGenerator {
         }
 
         if (webDriver instanceof TakesScreenshot) {
+            final FessConfig fessConfig = ComponentUtil.getFessConfig();
             synchronized (this) {
                 try {
                     webDriver.get(url);
+                    if (webDriver instanceof JavascriptExecutor) {
+                        Dimension dim = webDriver.findElement(By.tagName("body")).getSize();
+                        if (dim.height >= fessConfig.getThumbnailHtmlPhantomjsMaxHeightAsInteger()) {
+                            logger.warn("Skpped Thumbnail generation " + dim + " for " + url);
+                            return false;
+                        }
+                    }
                     final File thumbnail = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE);
                     convert(thumbnail, outputFile);
                     return true;
@@ -156,7 +160,7 @@ public class WebDriverGenerator extends BaseThumbnailGenerator {
                     previousCheckTime = 0;
                 } finally {
                     final long now = ComponentUtil.getSystemHelper().getCurrentTimeAsLong();
-                    if (now - previousCheckTime > keepAlive) {
+                    if (now - previousCheckTime > fessConfig.getThumbnailHtmlPhantomjsKeepAliveAsInteger().longValue()) {
                         destroy();
                         startWebDriver();
                     }
@@ -177,6 +181,7 @@ public class WebDriverGenerator extends BaseThumbnailGenerator {
     }
 
     protected void convert(final File inputFile, final File outputFile) {
+        final FessConfig fessConfig = ComponentUtil.getFessConfig();
         try (ImageInputStream input = ImageIO.createImageInputStream(inputFile)) {
             final Iterator<ImageReader> readers = ImageIO.getImageReaders(input);
             if (readers.hasNext()) {
@@ -184,12 +189,15 @@ public class WebDriverGenerator extends BaseThumbnailGenerator {
                 try {
                     reader.setInput(input);
                     final ImageReadParam param = reader.getDefaultReadParam();
-                    final int samplingWidth = reader.getWidth(0) / thumbnailWidth;
-                    final int samplingHeight = reader.getHeight(0) / thumbnailHeight;
+                    final int samplingWidth = reader.getWidth(0) / fessConfig.getThumbnailHtmlPhantomjsThumbnailWidthAsInteger();
+                    final int samplingHeight = reader.getHeight(0) / fessConfig.getThumbnailHtmlPhantomjsThumbnailHeightAsInteger();
                     param.setSourceSubsampling(samplingWidth, samplingHeight, 0, 0);
-                    param.setSourceRegion(new Rectangle(windowWidth, thumbnailHeight * reader.getHeight(0) / thumbnailWidth));
+                    param.setSourceRegion(new Rectangle(fessConfig.getThumbnailHtmlPhantomjsWindowWidthAsInteger(), fessConfig
+                            .getThumbnailHtmlPhantomjsThumbnailHeightAsInteger()
+                            * reader.getHeight(0)
+                            / fessConfig.getThumbnailHtmlPhantomjsThumbnailWidthAsInteger()));
                     final BufferedImage image = reader.read(0, param);
-                    ImageIO.write(image, imageFormatName, outputFile);
+                    ImageIO.write(image, fessConfig.getThumbnailHtmlPhantomjsFormat(), outputFile);
                     image.flush();
                 } finally {
                     reader.dispose();
@@ -266,32 +274,4 @@ public class WebDriverGenerator extends BaseThumbnailGenerator {
         this.webDriverCapabilities = webDriverCapabilities;
     }
 
-    public void setWindowWidth(final int windowWidth) {
-        this.windowWidth = windowWidth;
-    }
-
-    public void setWindowHeight(final int windowHeight) {
-        this.windowHeight = windowHeight;
-    }
-
-    public void setThumbnailWidth(final int thumbnailWidth) {
-        this.thumbnailWidth = thumbnailWidth;
-    }
-
-    public void setImageFormatName(final String imageFormatName) {
-        this.imageFormatName = imageFormatName;
-    }
-
-    public void setThumbnailHeight(final int thumbnailHeight) {
-        this.thumbnailHeight = thumbnailHeight;
-    }
-
-    @Deprecated
-    public void setUnreachableCheckInterval(final long keepAlive) {
-        this.keepAlive = keepAlive;
-    }
-
-    public void setKeepAlive(long keepAlive) {
-        this.keepAlive = keepAlive;
-    }
 }

+ 7 - 0
src/main/resources/fess_config.properties

@@ -363,6 +363,13 @@ paging.search.page.size=20
 paging.search.page.max.size=100
 
 thumbnail.html.phantomjs.enabled=true
+thumbnail.html.phantomjs.max.height=20000
+thumbnail.html.phantomjs.keep.alive=600000
+thumbnail.html.phantomjs.window.width=1200
+thumbnail.html.phantomjs.window.height=800
+thumbnail.html.phantomjs.thumbnail.width=160
+thumbnail.html.phantomjs.thumbnail.height=160
+thumbnail.html.phantomjs.format=png
 thumbnail.generator.targets=all
 thumbnail.crawler.enabled=false