|
@@ -13,7 +13,7 @@
|
|
|
* either express or implied. See the License for the specific language
|
|
|
* governing permissions and limitations under the License.
|
|
|
*/
|
|
|
-package org.codelibs.fess.screenshot;
|
|
|
+package org.codelibs.fess.thumbnail;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.util.ArrayList;
|
|
@@ -40,10 +40,10 @@ import org.lastaflute.web.util.LaRequestUtil;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
-public class ScreenShotManager {
|
|
|
- private static final String DEFAULT_SCREENSHOT_DIR = "/WEB-INF/screenshots";
|
|
|
+public class ThumbnailManager {
|
|
|
+ private static final String DEFAULT_SCREENSHOT_DIR = "/WEB-INF/thumbnails";
|
|
|
|
|
|
- private static final Logger logger = LoggerFactory.getLogger(ScreenShotManager.class);
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(ThumbnailManager.class);
|
|
|
|
|
|
@Resource
|
|
|
protected ServletContext application;
|
|
@@ -52,25 +52,25 @@ public class ScreenShotManager {
|
|
|
|
|
|
public long shutdownTimeout = 5 * 60 * 1000L; // 5min
|
|
|
|
|
|
- public int screenShotPathCacheSize = 10;
|
|
|
+ public int thumbnailPathCacheSize = 10;
|
|
|
|
|
|
- private final List<ScreenShotGenerator> generatorList = new ArrayList<>();
|
|
|
+ private final List<ThumbnailGenerator> generatorList = new ArrayList<>();
|
|
|
|
|
|
public String imageExtention = "png";
|
|
|
|
|
|
public int splitSize = 5;
|
|
|
|
|
|
- private final BlockingQueue<ScreenShotTask> screenShotTaskQueue = new LinkedBlockingQueue<>();
|
|
|
+ private final BlockingQueue<ThumbnailTask> thumbnailTaskQueue = new LinkedBlockingQueue<>();
|
|
|
|
|
|
private boolean generating;
|
|
|
|
|
|
- private Thread screenshotGeneratorThread;
|
|
|
+ private Thread thumbnailGeneratorThread;
|
|
|
|
|
|
@PostConstruct
|
|
|
public void init() {
|
|
|
final String varPath = System.getProperty("fess.var.path");
|
|
|
if (varPath != null) {
|
|
|
- baseDir = new File(varPath, "screenshots");
|
|
|
+ baseDir = new File(varPath, "thumbnails");
|
|
|
} else {
|
|
|
final String path = application.getRealPath(DEFAULT_SCREENSHOT_DIR);
|
|
|
if (StringUtil.isNotBlank(path)) {
|
|
@@ -87,38 +87,38 @@ public class ScreenShotManager {
|
|
|
}
|
|
|
|
|
|
if (logger.isDebugEnabled()) {
|
|
|
- logger.debug("ScreenShot Directory: " + baseDir.getAbsolutePath());
|
|
|
+ logger.debug("Thumbnail Directory: " + baseDir.getAbsolutePath());
|
|
|
}
|
|
|
|
|
|
generating = true;
|
|
|
- screenshotGeneratorThread = new Thread((Runnable) () -> {
|
|
|
+ thumbnailGeneratorThread = new Thread((Runnable) () -> {
|
|
|
while (generating) {
|
|
|
try {
|
|
|
- screenShotTaskQueue.take().generate();
|
|
|
+ thumbnailTaskQueue.take().generate();
|
|
|
} catch (final InterruptedException e1) {
|
|
|
logger.debug("Interupted task.", e1);
|
|
|
} catch (final Exception e2) {
|
|
|
- logger.warn("Failed to generage a screenshot.", e2);
|
|
|
+ logger.warn("Failed to generage a thumbnail.", e2);
|
|
|
}
|
|
|
}
|
|
|
- }, "ScreenShotGenerator");
|
|
|
- screenshotGeneratorThread.start();
|
|
|
+ }, "ThumbnailGenerator");
|
|
|
+ thumbnailGeneratorThread.start();
|
|
|
}
|
|
|
|
|
|
@PreDestroy
|
|
|
public void destroy() {
|
|
|
generating = false;
|
|
|
- screenshotGeneratorThread.interrupt();
|
|
|
+ thumbnailGeneratorThread.interrupt();
|
|
|
}
|
|
|
|
|
|
public void generate(final Map<String, Object> docMap) {
|
|
|
final FessConfig fessConfig = ComponentUtil.getFessConfig();
|
|
|
- for (final ScreenShotGenerator generator : generatorList) {
|
|
|
+ for (final ThumbnailGenerator generator : generatorList) {
|
|
|
if (generator.isTarget(docMap)) {
|
|
|
final String url = DocumentUtil.getValue(docMap, fessConfig.getIndexFieldUrl(), String.class);
|
|
|
final String path = getImageFilename(docMap);
|
|
|
- if (!screenShotTaskQueue.offer(new ScreenShotTask(url, new File(baseDir, path), generator))) {
|
|
|
- logger.warn("Failed to offer a screenshot task: " + url + " -> " + path);
|
|
|
+ if (!thumbnailTaskQueue.offer(new ThumbnailTask(url, new File(baseDir, path), generator))) {
|
|
|
+ logger.warn("Failed to offer a thumbnail task: " + url + " -> " + path);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
@@ -144,20 +144,20 @@ public class ScreenShotManager {
|
|
|
final Map<String, String> dataMap = new HashMap<>(documentItems.size());
|
|
|
for (final Map<String, Object> docMap : documentItems) {
|
|
|
final String docid = (String) docMap.get(fessConfig.getIndexFieldDocId());
|
|
|
- final String screenShotPath = getImageFilename(docMap);
|
|
|
- if (StringUtil.isNotBlank(docid) && StringUtil.isNotBlank(screenShotPath)) {
|
|
|
- dataMap.put(docid, screenShotPath);
|
|
|
+ final String thumbnailPath = getImageFilename(docMap);
|
|
|
+ if (StringUtil.isNotBlank(docid) && StringUtil.isNotBlank(thumbnailPath)) {
|
|
|
+ dataMap.put(docid, thumbnailPath);
|
|
|
}
|
|
|
}
|
|
|
- final Map<String, Map<String, String>> screenShotPathCache = getScreenShotPathCache(LaRequestUtil.getRequest().getSession());
|
|
|
- screenShotPathCache.put(queryId, dataMap);
|
|
|
+ final Map<String, Map<String, String>> thumbnailPathCache = getThumbnailPathCache(LaRequestUtil.getRequest().getSession());
|
|
|
+ thumbnailPathCache.put(queryId, dataMap);
|
|
|
}
|
|
|
|
|
|
- public File getScreenShotFile(final String queryId, final String docId) {
|
|
|
+ public File getThumbnailFile(final String queryId, final String docId) {
|
|
|
final HttpSession session = LaRequestUtil.getRequest().getSession(false);
|
|
|
if (session != null) {
|
|
|
- final Map<String, Map<String, String>> screenShotPathCache = getScreenShotPathCache(session);
|
|
|
- final Map<String, String> dataMap = screenShotPathCache.get(queryId);
|
|
|
+ final Map<String, Map<String, String>> thumbnailPathCache = getThumbnailPathCache(session);
|
|
|
+ final Map<String, String> dataMap = thumbnailPathCache.get(queryId);
|
|
|
if (dataMap != null) {
|
|
|
final String path = dataMap.get(docId);
|
|
|
final File file = new File(baseDir, path);
|
|
@@ -169,29 +169,31 @@ public class ScreenShotManager {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- private Map<String, Map<String, String>> getScreenShotPathCache(final HttpSession session) {
|
|
|
+ private Map<String, Map<String, String>> getThumbnailPathCache(final HttpSession session) {
|
|
|
@SuppressWarnings("unchecked")
|
|
|
- Map<String, Map<String, String>> screenShotPathCache =
|
|
|
+ Map<String, Map<String, String>> thumbnailPathCache =
|
|
|
(Map<String, Map<String, String>>) session.getAttribute(Constants.SCREEN_SHOT_PATH_CACHE);
|
|
|
- if (screenShotPathCache == null) {
|
|
|
- screenShotPathCache = new LruHashMap<>(screenShotPathCacheSize);
|
|
|
- session.setAttribute(Constants.SCREEN_SHOT_PATH_CACHE, screenShotPathCache);
|
|
|
+ if (thumbnailPathCache == null) {
|
|
|
+ thumbnailPathCache = new LruHashMap<>(thumbnailPathCacheSize);
|
|
|
+ session.setAttribute(Constants.SCREEN_SHOT_PATH_CACHE, thumbnailPathCache);
|
|
|
}
|
|
|
- return screenShotPathCache;
|
|
|
+ return thumbnailPathCache;
|
|
|
}
|
|
|
|
|
|
- public void add(final ScreenShotGenerator generator) {
|
|
|
- generatorList.add(generator);
|
|
|
+ public void add(final ThumbnailGenerator generator) {
|
|
|
+ if (generator.isAvailable()) {
|
|
|
+ generatorList.add(generator);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- protected static class ScreenShotTask {
|
|
|
+ protected static class ThumbnailTask {
|
|
|
String url;
|
|
|
|
|
|
File outputFile;
|
|
|
|
|
|
- ScreenShotGenerator generator;
|
|
|
+ ThumbnailGenerator generator;
|
|
|
|
|
|
- protected ScreenShotTask(final String url, final File outputFile, final ScreenShotGenerator generator) {
|
|
|
+ protected ThumbnailTask(final String url, final File outputFile, final ThumbnailGenerator generator) {
|
|
|
this.url = url;
|
|
|
this.outputFile = outputFile;
|
|
|
this.generator = generator;
|
|
@@ -221,7 +223,7 @@ public class ScreenShotManager {
|
|
|
if (getClass() != obj.getClass()) {
|
|
|
return false;
|
|
|
}
|
|
|
- final ScreenShotTask other = (ScreenShotTask) obj;
|
|
|
+ final ThumbnailTask other = (ThumbnailTask) obj;
|
|
|
if (outputFile == null) {
|
|
|
if (other.outputFile != null) {
|
|
|
return false;
|