svn commit: r1817684 - /ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/

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

svn commit: r1817684 - /ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/

mbrohl
Author: mbrohl
Date: Sun Dec 10 10:10:52 2017
New Revision: 1817684

URL: http://svn.apache.org/viewvc?rev=1817684&view=rev
Log:
Improved: Fixing defects reported by FindBugs, package
org.apache.ofbiz.content.webapp.ftl.
(OFBIZ-9815)

Instead of just setting the locale to null I've added functionality to
retrieve the locale from the context map and set a default if there is
no locale provided.

Thanks Julian Leichert for reporting and providing the patch.

Modified:
    ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/CheckPermissionTransform.java
    ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/EditRenderSubContentCacheTransform.java
    ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/InjectNodeTrailCsvTransform.java
    ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/LimitedSubContentCacheTransform.java
    ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/LoopSubContentTransform.java
    ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/RenderContentAsText.java
    ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/RenderSubContentCacheTransform.java
    ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/TraverseSubContentCacheTransform.java
    ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/WrapSubContentCacheTransform.java

Modified: ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/CheckPermissionTransform.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/CheckPermissionTransform.java?rev=1817684&r1=1817683&r2=1817684&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/CheckPermissionTransform.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/CheckPermissionTransform.java Sun Dec 10 10:10:52 2017
@@ -53,7 +53,7 @@ public class CheckPermissionTransform im
 
     public static final String module = CheckPermissionTransform.class.getName();
 
-    public static final String [] saveKeyNames = {"globalNodeTrail", "nodeTrail", "mode", "purposeTypeId", "statusId", "entityOperation", "targetOperation" };
+    static final String [] saveKeyNames = {"globalNodeTrail", "nodeTrail", "mode", "purposeTypeId", "statusId", "entityOperation", "targetOperation" };
     public static final String [] removeKeyNames = {};
 
     /**

Modified: ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/EditRenderSubContentCacheTransform.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/EditRenderSubContentCacheTransform.java?rev=1817684&r1=1817683&r2=1817684&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/EditRenderSubContentCacheTransform.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/EditRenderSubContentCacheTransform.java Sun Dec 10 10:10:52 2017
@@ -24,6 +24,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Map.Entry;
 
 import javax.servlet.http.HttpServletRequest;
 
@@ -49,7 +50,7 @@ import freemarker.template.TemplateTrans
 public class EditRenderSubContentCacheTransform implements TemplateTransformModel {
 
     public static final String module = EditRenderSubContentCacheTransform.class.getName();
-    public static final String [] saveKeyNames = {"contentId", "subContentId", "subDataResourceTypeId", "mimeTypeId", "whenMap", "locale",  "wrapTemplateId", "encloseWrapText", "nullThruDatesOnly"};
+    static final String [] saveKeyNames = {"contentId", "subContentId", "subDataResourceTypeId", "mimeTypeId", "whenMap", "locale",  "wrapTemplateId", "encloseWrapText", "nullThruDatesOnly"};
 
     /**
      * @deprecated use FreeMarkerWorker.getWrappedObject()
@@ -159,14 +160,17 @@ public class EditRenderSubContentCacheTr
 
                     templateRoot.put("context", templateCtx);
                     if (Debug.verboseOn()) {
-                        for (Object ky : templateCtx.keySet()) {
-                            Object val = templateCtx.get(ky);
+                        for (Entry<String, Object> ky : templateCtx.entrySet()) {
+                            Object val = ky.getValue();;
                             Debug.logVerbose("context key: " + ky + " val: " + val, module);
                         }
                     }
 
-                    String mimeTypeId = (String)templateCtx.get("mimeTypeId");
-                    Locale locale = null;
+                    String mimeTypeId = (String) templateCtx.get("mimeTypeId");
+                    Locale locale = (Locale) templateCtx.get("locale");
+                    if (locale == null) {
+                        locale = Locale.getDefault();
+                    }
                     try {
                         ContentWorker.renderContentAsText(dispatcher, wrapTemplateId, out, templateRoot, locale, mimeTypeId, null, null, true);
                     } catch (IOException e) {

Modified: ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/InjectNodeTrailCsvTransform.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/InjectNodeTrailCsvTransform.java?rev=1817684&r1=1817683&r2=1817684&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/InjectNodeTrailCsvTransform.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/InjectNodeTrailCsvTransform.java Sun Dec 10 10:10:52 2017
@@ -46,8 +46,8 @@ public class InjectNodeTrailCsvTransform
 
     public static final String module = InjectNodeTrailCsvTransform.class.getName();
 
-    public static final String [] saveKeyNames = {"nodeTrailCsv","globalNodeTrail", "nodeTrail"};
-    public static final String [] removeKeyNames = {"nodeTrailCsv"};
+    static final String[] saveKeyNames = { "nodeTrailCsv", "globalNodeTrail", "nodeTrail" };
+    static final String[] removeKeyNames = { "nodeTrailCsv" };
 
     /**
      * @deprecated use FreeMarkerWorker.getWrappedObject()
@@ -136,7 +136,7 @@ public class InjectNodeTrailCsvTransform
                     // Build nodeTrail if one does not exist
                     if (UtilValidate.isNotEmpty(passedCsv)) {
                         csvTrail = passedCsv;
-                        int lastComma = passedCsv.lastIndexOf(",");
+                        int lastComma = passedCsv.lastIndexOf(',');
                         String lastPassedContentId = null;
                         if (lastComma >= 0) {
                             lastPassedContentId = passedCsv.substring(lastComma + 1);

Modified: ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/LimitedSubContentCacheTransform.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/LimitedSubContentCacheTransform.java?rev=1817684&r1=1817683&r2=1817684&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/LimitedSubContentCacheTransform.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/LimitedSubContentCacheTransform.java Sun Dec 10 10:10:52 2017
@@ -56,8 +56,11 @@ public class LimitedSubContentCacheTrans
 
     public static final String module = LimitedSubContentCacheTransform.class.getName();
 
-    public static final String [] upSaveKeyNames = {"globalNodeTrail"};
-    public static final String [] saveKeyNames = {"contentId", "subContentId", "entityList", "entityIndex", "subDataResourceTypeId", "mimeTypeId", "whenMap", "locale",  "entityList", "viewSize", "viewIndex", "highIndex", "lowIndex", "listSize", "wrapTemplateId", "encloseWrapText", "nullThruDatesOnly", "globalNodeTrail", "outputIndex"};
+    static final String[] upSaveKeyNames = { "globalNodeTrail" };
+    static final String[] saveKeyNames = { "contentId", "subContentId", "entityList", "entityIndex",
+            "subDataResourceTypeId", "mimeTypeId", "whenMap", "locale", "entityList", "viewSize", "viewIndex",
+            "highIndex", "lowIndex", "listSize", "wrapTemplateId", "encloseWrapText", "nullThruDatesOnly",
+            "globalNodeTrail", "outputIndex" };
 
     /**
      * @deprecated use FreeMarkerWorker.getWrappedObject()
@@ -221,12 +224,7 @@ public class LimitedSubContentCacheTrans
                 String mimeTypeId = ContentWorker.getMimeTypeId(delegator, view, ctx);
                 Map<String, Object> trailNode = ContentWorker.makeNode(view);
                 Map<String, Object> whenMap = UtilGenerics.checkMap(ctx.get("whenMap"));
-                Locale locale = (Locale) ctx.get("locale");
-                if (locale == null) {
-                    locale = Locale.getDefault();
-                }
-                GenericValue assocContent = null;
-                ContentWorker.checkConditions(delegator, trailNode, assocContent, whenMap);
+                ContentWorker.checkConditions(delegator, trailNode, null, whenMap);
                 Boolean isReturnBeforeObj = (Boolean) trailNode.get("isReturnBefore");
                 Boolean isPickObj = (Boolean) trailNode.get("isPick");
                 Boolean isFollowObj = (Boolean) trailNode.get("isFollow");

Modified: ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/LoopSubContentTransform.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/LoopSubContentTransform.java?rev=1817684&r1=1817683&r2=1817684&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/LoopSubContentTransform.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/LoopSubContentTransform.java Sun Dec 10 10:10:52 2017
@@ -53,8 +53,8 @@ public class LoopSubContentTransform imp
 
     public static final String module = LoopSubContentTransform.class.getName();
 
-    public static final String[] saveKeyNames = {"contentId", "subContentId", "mimeType", "subContentDataResourceView", "wrapTemplateId", "contentTemplateId"};
-    public static final String[] removeKeyNames = {"wrapTemplateId", "entityList", "entityIndex", "textData", "dataResourceId","drDataResourceId", "subContentIdSub", "parentContent", "wrappedFTL"};
+    static final String[] saveKeyNames = {"contentId", "subContentId", "mimeType", "subContentDataResourceView", "wrapTemplateId", "contentTemplateId"};
+    static final String[] removeKeyNames = {"wrapTemplateId", "entityList", "entityIndex", "textData", "dataResourceId","drDataResourceId", "subContentIdSub", "parentContent", "wrappedFTL"};
 
     /**
      * @deprecated use FreeMarkerWorker.getWrappedObject()

Modified: ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/RenderContentAsText.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/RenderContentAsText.java?rev=1817684&r1=1817683&r2=1817684&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/RenderContentAsText.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/RenderContentAsText.java Sun Dec 10 10:10:52 2017
@@ -52,8 +52,8 @@ import freemarker.template.TemplateTrans
 public class RenderContentAsText implements TemplateTransformModel {
 
     public static final String module = RenderContentAsText.class.getName();
-    public static final String [] upSaveKeyNames = {"globalNodeTrail"};
-    public static final String [] saveKeyNames = {"contentId", "subContentId", "subDataResourceTypeId", "mimeTypeId", "whenMap", "locale",  "wrapTemplateId", "encloseWrapText", "nullThruDatesOnly", "globalNodeTrail"};
+    static final String [] upSaveKeyNames = {"globalNodeTrail"};
+    static final String [] saveKeyNames = {"contentId", "subContentId", "subDataResourceTypeId", "mimeTypeId", "whenMap", "locale",  "wrapTemplateId", "encloseWrapText", "nullThruDatesOnly", "globalNodeTrail"};
 
     @SuppressWarnings("unchecked")
     public Writer getWriter(final Writer out, Map args) {

Modified: ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/RenderSubContentCacheTransform.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/RenderSubContentCacheTransform.java?rev=1817684&r1=1817683&r2=1817684&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/RenderSubContentCacheTransform.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/RenderSubContentCacheTransform.java Sun Dec 10 10:10:52 2017
@@ -52,7 +52,7 @@ import freemarker.template.TemplateTrans
 public class RenderSubContentCacheTransform implements TemplateTransformModel {
 
     public static final String module = RenderSubContentCacheTransform.class.getName();
-    public static final String [] upSaveKeyNames = {"globalNodeTrail"};
+    static final String[] upSaveKeyNames = { "globalNodeTrail" };
 
     @SuppressWarnings("unchecked")
     public Writer getWriter(final Writer out, Map args) {

Modified: ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/TraverseSubContentCacheTransform.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/TraverseSubContentCacheTransform.java?rev=1817684&r1=1817683&r2=1817684&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/TraverseSubContentCacheTransform.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/TraverseSubContentCacheTransform.java Sun Dec 10 10:10:52 2017
@@ -49,8 +49,8 @@ import freemarker.template.TransformCont
 public class TraverseSubContentCacheTransform implements TemplateTransformModel {
 
     public static final String module = TraverseSubContentCacheTransform.class.getName();
-    public static final String [] upSaveKeyNames = {"globalNodeTrail"};
-    public static final String [] saveKeyNames = {"contentId", "subContentId", "subDataResourceTypeId", "mimeTypeId", "whenMap", "locale",  "wrapTemplateId", "encloseWrapText", "nullThruDatesOnly", "globalNodeTrail"};
+    static final String [] upSaveKeyNames = {"globalNodeTrail"};
+    static final String [] saveKeyNames = {"contentId", "subContentId", "subDataResourceTypeId", "mimeTypeId", "whenMap", "locale",  "wrapTemplateId", "encloseWrapText", "nullThruDatesOnly", "globalNodeTrail"};
 
     /**
      * @deprecated use FreeMarkerWorker.getWrappedObject()
@@ -229,6 +229,7 @@ public class TraverseSubContentCacheTran
                     contentIdStart = (String)ndStart.get("contentId");
                 } else {
                     globalNodeTrail = new LinkedList<Map<String,? extends Object>>();
+                    contentIdStart = "";
                 }
                 boolean bIdEnd = UtilValidate.isNotEmpty(contentIdEnd);
                 boolean bIdStart = UtilValidate.isNotEmpty(contentIdStart);

Modified: ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/WrapSubContentCacheTransform.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/WrapSubContentCacheTransform.java?rev=1817684&r1=1817683&r2=1817684&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/WrapSubContentCacheTransform.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/webapp/ftl/WrapSubContentCacheTransform.java Sun Dec 10 10:10:52 2017
@@ -49,8 +49,8 @@ import freemarker.template.TemplateTrans
 public class WrapSubContentCacheTransform implements TemplateTransformModel {
 
     public static final String module = WrapSubContentCacheTransform.class.getName();
-    public static final String [] upSaveKeyNames = {"globalNodeTrail"};
-    public static final String [] saveKeyNames = {"contentId", "subContentId", "subDataResourceTypeId", "mimeTypeId", "whenMap", "locale",  "wrapTemplateId", "encloseWrapText", "nullThruDatesOnly"};
+    static final String [] upSaveKeyNames = {"globalNodeTrail"};
+    static final String [] saveKeyNames = {"contentId", "subContentId", "subDataResourceTypeId", "mimeTypeId", "whenMap", "locale",  "wrapTemplateId", "encloseWrapText", "nullThruDatesOnly"};
 
     /**
      * @deprecated use FreeMarkerWorker.getWrappedObject()
@@ -170,8 +170,13 @@ public class WrapSubContentCacheTransfor
 
                     templateRoot.put("context", templateCtx);
 
-                    String mimeTypeId = (String)templateCtx.get("mimeTypeId");
-                    Locale locale = null;
+                    String mimeTypeId = (String) templateCtx.get("mimeTypeId");
+                    
+                    Locale locale = (Locale) templateCtx.get("locale");
+                    if (locale == null) {
+                        locale = Locale.getDefault();
+                    }
+                    
                     try {
                         ContentWorker.renderContentAsText(dispatcher, wrapTemplateId, out, templateRoot, locale, mimeTypeId, null, null, true);
                     } catch (IOException e) {