diff --git a/src/main/java/org/codelibs/fess/taglib/FessFunctions.java b/src/main/java/org/codelibs/fess/taglib/FessFunctions.java index da960a21c..571c89b0c 100644 --- a/src/main/java/org/codelibs/fess/taglib/FessFunctions.java +++ b/src/main/java/org/codelibs/fess/taglib/FessFunctions.java @@ -17,6 +17,9 @@ package org.codelibs.fess.taglib; import java.io.File; import java.math.RoundingMode; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.text.DecimalFormat; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -28,6 +31,8 @@ import java.util.Enumeration; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; @@ -40,14 +45,38 @@ import org.codelibs.fess.helper.ViewHelper; import org.codelibs.fess.util.ComponentUtil; import org.lastaflute.di.util.LdiURLUtil; import org.lastaflute.web.util.LaRequestUtil; +import org.lastaflute.web.util.LaResponseUtil; import org.lastaflute.web.util.LaServletContextUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; public class FessFunctions { + private static final Logger logger = LoggerFactory.getLogger(FessFunctions.class); private static final String GEO_PREFIX = "geo."; private static final String FACET_PREFIX = "facet."; + private static LoadingCache resourceHashCache = CacheBuilder.newBuilder().maximumSize(1000) + .expireAfterWrite(10, TimeUnit.MINUTES).build(new CacheLoader() { + @Override + public Long load(String key) throws Exception { + try { + final Path path = Paths.get(LaServletContextUtil.getServletContext().getRealPath(key)); + if (Files.exists(path)) { + return Files.getLastModifiedTime(path).toMillis(); + } + } catch (Exception e) { + logger.debug("Failed to access " + key, e); + } + return 0L; + } + }); + protected FessFunctions() { // nothing } @@ -231,4 +260,29 @@ public class FessFunctions { return file.exists(); } + public static String url(String input) { + if (input == null) { + String msg = "The argument 'input' should not be null."; + throw new IllegalArgumentException(msg); + } + if (!input.startsWith("/")) { + String msg = "The argument 'input' should start with slash '/': " + input; + throw new IllegalArgumentException(msg); + } + final String contextPath = LaRequestUtil.getRequest().getContextPath(); + final StringBuilder sb = new StringBuilder(); + if (contextPath.length() > 1) { + sb.append(contextPath); + } + sb.append(input); + if (input.indexOf('?') == -1) { + try { + final String t = resourceHashCache.get(input).toString(); + sb.append("?t=").append(t); + } catch (ExecutionException e) { + logger.debug("Failed to access " + input, e); + } + } + return LaResponseUtil.getResponse().encodeURL(sb.toString()); + } } diff --git a/src/main/webapp/WEB-INF/fe.tld b/src/main/webapp/WEB-INF/fe.tld index 9b2b5fe6c..01b330959 100644 --- a/src/main/webapp/WEB-INF/fe.tld +++ b/src/main/webapp/WEB-INF/fe.tld @@ -203,4 +203,11 @@ + + Calculates URL. + url + org.codelibs.fess.taglib.FessFunctions + java.lang.String url(java.lang.String) + <a href="${f:url(param:info)}" ... + diff --git a/src/main/webapp/WEB-INF/orig/view/error/badRequest.jsp b/src/main/webapp/WEB-INF/orig/view/error/badRequest.jsp index 12c2080c5..578ccfaf2 100644 --- a/src/main/webapp/WEB-INF/orig/view/error/badRequest.jsp +++ b/src/main/webapp/WEB-INF/orig/view/error/badRequest.jsp @@ -7,11 +7,11 @@ <la:message key="labels.system_error_title" /> - - - @@ -31,10 +31,10 @@ - - - + src="${fe:url('/js/jquery-2.2.4.min.js')}"> + + + <% }catch(Exception e){ session.invalidate();}%> diff --git a/src/main/webapp/WEB-INF/orig/view/error/error.jsp b/src/main/webapp/WEB-INF/orig/view/error/error.jsp index 6fb1f40ac..51586360d 100644 --- a/src/main/webapp/WEB-INF/orig/view/error/error.jsp +++ b/src/main/webapp/WEB-INF/orig/view/error/error.jsp @@ -6,11 +6,11 @@ <la:message key="labels.system_error_title" /> - - - @@ -35,9 +35,9 @@ - - - + src="${fe:url('/js/jquery-2.2.4.min.js')}"> + + + diff --git a/src/main/webapp/WEB-INF/orig/view/error/header.jsp b/src/main/webapp/WEB-INF/orig/view/error/header.jsp index 3893304d3..e4769467d 100755 --- a/src/main/webapp/WEB-INF/orig/view/error/header.jsp +++ b/src/main/webapp/WEB-INF/orig/view/error/header.jsp @@ -4,7 +4,7 @@ ${fe:facetForm()}${fe:geoForm()}