[ofbiz-framework] branch trunk updated: Improved: Headerize external script in multi-block html template (OFBIZ-11741)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[ofbiz-framework] branch trunk updated: Improved: Headerize external script in multi-block html template (OFBIZ-11741)

James Yong-2
This is an automated email from the ASF dual-hosted git repository.

jamesyong pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new d1a22a6  Improved: Headerize external script in multi-block html template (OFBIZ-11741)
d1a22a6 is described below

commit d1a22a6ba8456ea72167af922155882ffdecc183
Author: James Yong <[hidden email]>
AuthorDate: Sat May 30 14:32:38 2020 +0800

    Improved: Headerize external script in multi-block html template (OFBIZ-11741)
   
    Cleanup script cache when session ended
---
 .../org/apache/ofbiz/webapp/control/ControlEventListener.java |  6 ++++--
 .../apache/ofbiz/widget/model/MultiBlockHtmlTemplateUtil.java | 11 +++++++----
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ControlEventListener.java b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ControlEventListener.java
index 49f4f92..a188a14 100644
--- a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ControlEventListener.java
+++ b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ControlEventListener.java
@@ -26,7 +26,6 @@ import javax.servlet.http.HttpSession;
 import javax.servlet.http.HttpSessionEvent;
 import javax.servlet.http.HttpSessionListener;
 
-import org.apache.ofbiz.security.CsrfUtil;
 import org.apache.ofbiz.base.util.Debug;
 import org.apache.ofbiz.base.util.UtilDateTime;
 import org.apache.ofbiz.base.util.UtilGenerics;
@@ -38,6 +37,8 @@ import org.apache.ofbiz.entity.GenericValue;
 import org.apache.ofbiz.entity.serialize.XmlSerializer;
 import org.apache.ofbiz.entity.transaction.TransactionUtil;
 import org.apache.ofbiz.entity.util.EntityQuery;
+import org.apache.ofbiz.security.CsrfUtil;
+import org.apache.ofbiz.widget.model.MultiBlockHtmlTemplateUtil;
 
 /**
  * HttpSessionListener that gathers and tracks various information and statistics
@@ -73,6 +74,7 @@ public class ControlEventListener implements HttpSessionListener {
         HttpSession session = event.getSession();
 
         CsrfUtil.cleanupTokenMap(session);
+        MultiBlockHtmlTemplateUtil.cleanupScriptCache(session);
 
         // Finalize the Visit
         boolean beganTransaction = false;
@@ -141,7 +143,7 @@ public class ControlEventListener implements HttpSessionListener {
             Debug.logInfo("--------------------------------------------------------------------", MODULE);
             Debug.logInfo("Total Sessions : " + ControlEventListener.getTotalActiveSessions(), MODULE);
             Debug.logInfo("Total Active   : " + ControlEventListener.getTotalActiveSessions(), MODULE);
-            Debug.logInfo("Total Passive  : " + ControlEventListener.getTotalPassiveSessions(),  MODULE);
+            Debug.logInfo("Total Passive  : " + ControlEventListener.getTotalPassiveSessions(), MODULE);
             Debug.logInfo("** note : this session has been counted as destroyed.", MODULE);
             Debug.logInfo("--------------------------------------------------------------------", MODULE);
             if (visit != null) {
diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/MultiBlockHtmlTemplateUtil.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/MultiBlockHtmlTemplateUtil.java
index ee29af5..7404963 100644
--- a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/MultiBlockHtmlTemplateUtil.java
+++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/MultiBlockHtmlTemplateUtil.java
@@ -36,8 +36,7 @@ public final class MultiBlockHtmlTemplateUtil {
     public static final String MULTI_BLOCK_WRITER = "multiBlockWriter";
     private static final String HTML_LINKS_FOR_HEAD = "htmlLinksForHead";
     private static final String SCRIPT_LINKS_FOR_FOOT = "ScriptLinksForFoot";
-    private static int maxNumOfScriptInCache = 10;
-    private static int cacheSize = 100;
+    private static int maxScriptCacheSizePerSession = 10;
     // store inline script from freemarker template by user session
     private static LinkedHashMap<String, Map<String, String>> scriptCache =
             new LinkedHashMap<String, Map<String, String>>() {
@@ -180,7 +179,7 @@ public final class MultiBlockHtmlTemplateUtil {
     }
 
     /**
-     * get the script links for page footer. Also @see {@link ScriptTagsFooterTransform}
+     * get the script links for page footer. Also @see {@link org.apache.ofbiz.webapp.ftl.ScriptTagsFooterTransform}
      * @param request
      * @return
      */
@@ -204,7 +203,7 @@ public final class MultiBlockHtmlTemplateUtil {
             scriptMap = new LinkedHashMap<String, String>() {
                 private static final long serialVersionUID = 1L;
                 protected boolean removeEldestEntry(Map.Entry<String, String> eldest) {
-                    return size() > maxNumOfScriptInCache;
+                    return size() > maxScriptCacheSizePerSession;
                 }
             };
             scriptCache.put(sessionId, scriptMap);
@@ -225,4 +224,8 @@ public final class MultiBlockHtmlTemplateUtil {
         }
         return "";
     }
+
+    public static void cleanupScriptCache(HttpSession session) {
+        scriptCache.remove(session.getId());
+    }
 }