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

commit 5fca2ed58deb59d7eb2847810208f42cdc5f7a09
Author: James Yong <[hidden email]>
AuthorDate: Sat Oct 10 12:39:43 2020 +0800

    Improved: Open Screen file from browser (OFBIZ-12038)
   
    Refactoring
---
 .../org/apache/ofbiz/widget/model/HtmlWidget.java  | 17 +++----------
 .../widget/renderer/html/HtmlWidgetRenderer.java   | 29 ++++++++++++++--------
 .../renderer/macro/MacroScreenViewHandler.java     | 10 ++------
 3 files changed, 25 insertions(+), 31 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 65723ad..62d3158 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,18 +168,9 @@ public class HtmlWidget extends ModelScreenWidget {
                 if (insertWidgetBoundaryComments) {
                     writer.append(HtmlWidgetRenderer.buildBoundaryComment("Begin", "Template", location));
                 }
-                boolean insertWidgetNamedBorder = false;
-                NamedBorderType namedBorderType = null;
                 if (!location.endsWith(".fo.ftl")) {
-                    namedBorderType = ModelWidget.widgetNamedBorderType();
-                    if (namedBorderType != NamedBorderType.NONE) {
-                        insertWidgetNamedBorder = true;
-                    }
-                }
-                String contextPath = "";
-                if (insertWidgetNamedBorder) {
-                    contextPath = ((HttpServletRequest) context.get("request")).getContextPath();
-                    writer.append(HtmlWidgetRenderer.buildNamedBorder("Begin", "Template", location, namedBorderType, contextPath));
+                    String contextPath = ((HttpServletRequest) context.get("request")).getContextPath();
+                    writer.append(HtmlWidgetRenderer.beginNamedBorder("Template", location, contextPath));
                 }
 
                 Template template = null;
@@ -190,8 +181,8 @@ public class HtmlWidget extends ModelScreenWidget {
                 }
                 FreeMarkerWorker.renderTemplate(template, context, writer);
 
-                if (insertWidgetNamedBorder) {
-                    writer.append(HtmlWidgetRenderer.buildNamedBorder("End", "Template", location, namedBorderType, contextPath));
+                if (!location.endsWith(".fo.ftl")) {
+                    writer.append(HtmlWidgetRenderer.endNamedBorder("Template", location));
                 }
                 if (insertWidgetBoundaryComments) {
                     writer.append(HtmlWidgetRenderer.buildBoundaryComment("End", "Template", location));
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 74c2b9b..cc9e226 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
@@ -49,6 +49,8 @@ public class HtmlWidgetRenderer {
 
     private boolean widgetCommentsEnabled = false;
 
+    private static ModelWidget.NamedBorderType namedBorderType = ModelWidget.widgetNamedBorderType();
+
     /**
      * Is widget comments enabled boolean.
      * @return the boolean
@@ -75,17 +77,15 @@ public class HtmlWidgetRenderer {
         return "<!-- " + boundaryType + " " + widgetType + " " + widgetName + " -->" + WHITE_SPACE;
     }
 
-    public static String buildNamedBorder(String boundaryType, String widgetType, String widgetName,
-                                          ModelWidget.NamedBorderType namedBorderType, String contextPath) {
-        List<String> themeBasePathsToExempt = UtilHtml.getVisualThemeFolderNamesToExempt();
-        if (!themeBasePathsToExempt.stream().anyMatch(widgetName::contains)) {
-            // add additional visual label for non-theme ftl
-            if ("Begin".equals(boundaryType)) {
-                String fileName = widgetName.substring(widgetName.lastIndexOf("/") + 1);
+    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='"
-                            + widgetName + "' data-target='" + contextPath
+                            + location + "' data-target='" + contextPath
                             + (SeoConfigUtil.isCategoryUrlEnabled(contextPath) ? "" : "/control")
                             + "/openSourceFile'>"
                             + fileName
@@ -94,9 +94,18 @@ public class HtmlWidgetRenderer {
                     return "<div class='info-container'><span class='info-overlay-item'>"
                             + fileName
                             + "</span>";
-                default: return "";
+                default:
+                    return "";
                 }
-            } else if ("End".equals(boundaryType)) {
+            }
+        }
+        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>";
             }
         }
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 444eec2..77fb023 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,7 +36,6 @@ 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;
@@ -116,15 +115,10 @@ public class MacroScreenViewHandler extends AbstractViewHandler {
             context.put("simpleEncoder", UtilCodec.getEncoder(visualTheme.getModelTheme().getEncoder(getName())));
             screenStringRenderer.renderScreenBegin(writer, context);
             // render start of named border for screen
-            ModelWidget.NamedBorderType widgetNamedBorderType = ModelWidget.widgetNamedBorderType();
-            if (widgetNamedBorderType != ModelWidget.NamedBorderType.NONE) {
-                writer.append(HtmlWidgetRenderer.buildNamedBorder("Begin", "Screen", page, widgetNamedBorderType, request.getContextPath()));
-            }
+            writer.append(HtmlWidgetRenderer.beginNamedBorder("Screen", page, request.getContextPath()));
             screens.render(page);
             // render end of named border for screen
-            if (widgetNamedBorderType != ModelWidget.NamedBorderType.NONE) {
-                writer.append(HtmlWidgetRenderer.buildNamedBorder("End", "Screen", page, widgetNamedBorderType, request.getContextPath()));
-            }
+            writer.append(HtmlWidgetRenderer.endNamedBorder("Screen", page));
             screenStringRenderer.renderScreenEnd(writer, context);
             writer.flush();
         } catch (TemplateException e) {