[ofbiz-framework] branch trunk updated: Improved: Open Screen file from browser (OFBIZ-12038)

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: Open Screen file from browser (OFBIZ-12038)

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 cbbcb14  Improved: Open Screen file from browser (OFBIZ-12038)
cbbcb14 is described below

commit cbbcb1411906294b9aad2afe6c0900a3b6398aaa
Author: James Yong <[hidden email]>
AuthorDate: Sat Oct 10 18:06:14 2020 +0800

    Improved: Open Screen file from browser (OFBIZ-12038)
   
    Refactoring
---
 .../org/apache/ofbiz/widget/model/HtmlWidget.java  | 10 ++--
 .../widget/renderer/html/HtmlWidgetRenderer.java   | 66 +++++++++++++---------
 .../renderer/macro/MacroScreenViewHandler.java     | 13 +++--
 3 files changed, 53 insertions(+), 36 deletions(-)

diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/HtmlWidget.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/HtmlWidget.java
index 4dd8d43..516b69b 100644
--- a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/HtmlWidget.java
+++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/HtmlWidget.java
@@ -168,12 +168,10 @@ public class HtmlWidget extends ModelScreenWidget {
                 if (insertWidgetBoundaryComments) {
                     writer.append(HtmlWidgetRenderer.buildBoundaryComment("Begin", "Template", location));
                 }
-                HttpServletRequest request = ((HttpServletRequest) context.get("request"));
-                if (!location.endsWith(".fo.ftl") && request != null) {
-                    String contextPath = request.getContextPath();
-                    writer.append(HtmlWidgetRenderer.beginNamedBorder("Template", location, contextPath));
+                if (!location.endsWith(".fo.ftl") && HtmlWidgetRenderer.NAMED_BORDER_TYPE != ModelWidget.NamedBorderType.NONE) {
+                    HttpServletRequest request = ((HttpServletRequest) context.get("request"));
+                    writer.append(HtmlWidgetRenderer.beginNamedBorder("Template", location, request.getContextPath()));
                 }
-
                 Template template = null;
                 if (location.endsWith(".fo.ftl")) { // FOP can't render correctly escaped characters
                     template = FreeMarkerWorker.getTemplate(location);
@@ -182,7 +180,7 @@ public class HtmlWidget extends ModelScreenWidget {
                 }
                 FreeMarkerWorker.renderTemplate(template, context, writer);
 
-                if (!location.endsWith(".fo.ftl") && request != null) {
+                if (!location.endsWith(".fo.ftl") && HtmlWidgetRenderer.NAMED_BORDER_TYPE != ModelWidget.NamedBorderType.NONE) {
                     writer.append(HtmlWidgetRenderer.endNamedBorder("Template", location));
                 }
                 if (insertWidgetBoundaryComments) {
diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlWidgetRenderer.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlWidgetRenderer.java
index cc9e226..fd78801 100644
--- a/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlWidgetRenderer.java
+++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlWidgetRenderer.java
@@ -40,6 +40,11 @@ public class HtmlWidgetRenderer {
     public static final String WHITE_SPACE = "\r\n";
 
     /**
+     * Store property value of widget.dev.namedBorder
+     */
+    public static final ModelWidget.NamedBorderType NAMED_BORDER_TYPE = ModelWidget.widgetNamedBorderType();
+
+    /**
      * Sets widget comments enabled.
      * @param widgetCommentsEnabled the widget comments enabled
      */
@@ -49,8 +54,6 @@ public class HtmlWidgetRenderer {
 
     private boolean widgetCommentsEnabled = false;
 
-    private static ModelWidget.NamedBorderType namedBorderType = ModelWidget.widgetNamedBorderType();
-
     /**
      * Is widget comments enabled boolean.
      * @return the boolean
@@ -77,37 +80,48 @@ public class HtmlWidgetRenderer {
         return "<!-- " + boundaryType + " " + widgetType + " " + widgetName + " -->" + WHITE_SPACE;
     }
 
+    /**
+     * Always check the following condition is true before running the method:
+     * HtmlWidgetRenderer.namedBorderType != ModelWidget.NamedBorderType.NONE
+     * @param widgetType
+     * @param location
+     * @param contextPath
+     * @return
+     */
     public static String beginNamedBorder(String widgetType, String location, String contextPath) {
-        if (namedBorderType != ModelWidget.NamedBorderType.NONE) {
-            List<String> themeBasePathsToExempt = UtilHtml.getVisualThemeFolderNamesToExempt();
-            if (!themeBasePathsToExempt.stream().anyMatch(location::contains)) {
-                String fileName = location.substring(location.lastIndexOf("/") + 1);
-                switch (namedBorderType) {
-                case SOURCE:
-                    return "<div class='info-container'><span class='info-overlay-item info-cursor-none' data-source='"
-                            + location + "' data-target='" + contextPath
-                            + (SeoConfigUtil.isCategoryUrlEnabled(contextPath) ? "" : "/control")
-                            + "/openSourceFile'>"
-                            + fileName
-                            + "</span>";
-                case LABEL:
-                    return "<div class='info-container'><span class='info-overlay-item'>"
-                            + fileName
-                            + "</span>";
-                default:
-                    return "";
-                }
+        List<String> themeBasePathsToExempt = UtilHtml.getVisualThemeFolderNamesToExempt();
+        if (!themeBasePathsToExempt.stream().anyMatch(location::contains)) {
+            String fileName = location.substring(location.lastIndexOf("/") + 1);
+            switch (NAMED_BORDER_TYPE) {
+            case SOURCE:
+                return "<div class='info-container'><span class='info-overlay-item info-cursor-none' data-source='"
+                        + location + "' data-target='" + contextPath
+                        + (SeoConfigUtil.isCategoryUrlEnabled(contextPath) ? "" : "/control")
+                        + "/openSourceFile'>"
+                        + fileName
+                        + "</span>";
+            case LABEL:
+                return "<div class='info-container'><span class='info-overlay-item'>"
+                        + fileName
+                        + "</span>";
+            default:
+                return "";
             }
         }
         return "";
     }
 
+    /**
+     * Always check the following condition is true before running the method:
+     * HtmlWidgetRenderer.namedBorderType != ModelWidget.NamedBorderType.NONE
+     * @param widgetType
+     * @param location
+     * @return
+     */
     public static String endNamedBorder(String widgetType, String location) {
-        if (namedBorderType != ModelWidget.NamedBorderType.NONE) {
-            List<String> themeBasePathsToExempt = UtilHtml.getVisualThemeFolderNamesToExempt();
-            if (!themeBasePathsToExempt.stream().anyMatch(location::contains)) {
-                return "</div>";
-            }
+        List<String> themeBasePathsToExempt = UtilHtml.getVisualThemeFolderNamesToExempt();
+        if (!themeBasePathsToExempt.stream().anyMatch(location::contains)) {
+            return "</div>";
         }
         return "";
     }
diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroScreenViewHandler.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroScreenViewHandler.java
index 77fb023..fd09b24 100644
--- a/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroScreenViewHandler.java
+++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroScreenViewHandler.java
@@ -36,6 +36,7 @@ import org.apache.ofbiz.base.util.collections.MapStack;
 import org.apache.ofbiz.webapp.view.AbstractViewHandler;
 import org.apache.ofbiz.webapp.view.ViewHandlerException;
 import org.apache.ofbiz.widget.model.ModelTheme;
+import org.apache.ofbiz.widget.model.ModelWidget;
 import org.apache.ofbiz.widget.renderer.FormStringRenderer;
 import org.apache.ofbiz.widget.renderer.MenuStringRenderer;
 import org.apache.ofbiz.widget.renderer.ScreenRenderer;
@@ -114,11 +115,15 @@ public class MacroScreenViewHandler extends AbstractViewHandler {
             context.put("screens", screens);
             context.put("simpleEncoder", UtilCodec.getEncoder(visualTheme.getModelTheme().getEncoder(getName())));
             screenStringRenderer.renderScreenBegin(writer, context);
-            // render start of named border for screen
-            writer.append(HtmlWidgetRenderer.beginNamedBorder("Screen", page, request.getContextPath()));
+            if (HtmlWidgetRenderer.NAMED_BORDER_TYPE != ModelWidget.NamedBorderType.NONE) {
+                // render start of named border for screen
+                writer.append(HtmlWidgetRenderer.beginNamedBorder("Screen", page, request.getContextPath()));
+            }
             screens.render(page);
-            // render end of named border for screen
-            writer.append(HtmlWidgetRenderer.endNamedBorder("Screen", page));
+            if (HtmlWidgetRenderer.NAMED_BORDER_TYPE != ModelWidget.NamedBorderType.NONE) {
+                // render end of named border for screen
+                writer.append(HtmlWidgetRenderer.endNamedBorder("Screen", page));
+            }
             screenStringRenderer.renderScreenEnd(writer, context);
             writer.flush();
         } catch (TemplateException e) {