svn commit: r1818541 - in /ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html: HtmlMenuRenderer.java HtmlMenuRendererImage.java HtmlMenuWrapper.java HtmlMenuWrapperImage.java HtmlTreeRenderer.java

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

svn commit: r1818541 - in /ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html: HtmlMenuRenderer.java HtmlMenuRendererImage.java HtmlMenuWrapper.java HtmlMenuWrapperImage.java HtmlTreeRenderer.java

mbrohl
Author: mbrohl
Date: Mon Dec 18 09:35:36 2017
New Revision: 1818541

URL: http://svn.apache.org/viewvc?rev=1818541&view=rev
Log:
Improved: General refactoring and code improvements, package
org.apache.ofbiz.widget.renderer.html.
(OFBIZ-9933)

Thanks Dennis Balkir for reporting and providing the patches.

Modified:
    ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlMenuRenderer.java
    ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlMenuRendererImage.java
    ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlMenuWrapper.java
    ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlMenuWrapperImage.java
    ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlTreeRenderer.java

Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlMenuRenderer.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlMenuRenderer.java?rev=1818541&r1=1818540&r2=1818541&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlMenuRenderer.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlMenuRenderer.java Mon Dec 18 09:35:36 2017
@@ -32,7 +32,6 @@ import org.apache.ofbiz.base.util.String
 import org.apache.ofbiz.base.util.UtilCodec;
 import org.apache.ofbiz.base.util.UtilMisc;
 import org.apache.ofbiz.base.util.UtilValidate;
-import org.apache.ofbiz.entity.Delegator;
 import org.apache.ofbiz.entity.GenericValue;
 import org.apache.ofbiz.webapp.control.RequestHandler;
 import org.apache.ofbiz.webapp.taglib.ContentUrlTag;
@@ -69,7 +68,7 @@ public class HtmlMenuRenderer extends Ht
             HttpSession session = request.getSession();
             if (session != null) {
                 ctx = session.getServletContext();
-            }
+            }
             if (ctx == null) {
                 throw new RuntimeException("ctx is null. location:" + location);
             }
@@ -125,8 +124,9 @@ public class HtmlMenuRenderer extends Ht
     public void renderMenuItem(Appendable writer, Map<String, Object> context, ModelMenuItem menuItem) throws IOException {
         boolean hideThisItem = isHideIfSelected(menuItem, context);
 
-        if (hideThisItem)
+        if (hideThisItem) {
             return;
+        }
 
         String style = menuItem.getWidgetStyle();
 
@@ -249,7 +249,7 @@ public class HtmlMenuRenderer extends Ht
         if (UtilValidate.isNotEmpty(fillStyle)) {
             writer.append("<div class=\"").append(fillStyle).append("\">&nbsp;</div>");
         }
-        if (modelMenu.renderedMenuItemCount(context) > 0) {      
+        if (modelMenu.renderedMenuItemCount(context) > 0) {
             writer.append(" </ul>");
             appendWhitespace(writer);
             writer.append("</li>");
@@ -273,11 +273,9 @@ public class HtmlMenuRenderer extends Ht
     }
 
     public void renderFormatSimpleWrapperOpen(Appendable writer, Map<String, Object> context, ModelMenu modelMenu) throws IOException {
-        //appendWhitespace(writer);
     }
 
     public void renderFormatSimpleWrapperClose(Appendable writer, Map<String, Object> context, ModelMenu modelMenu) throws IOException {
-        //appendWhitespace(writer);
     }
 
     public void setRequest(HttpServletRequest request) {
@@ -314,18 +312,20 @@ public class HtmlMenuRenderer extends Ht
         GenericValue userLogin = (GenericValue)request.getSession().getAttribute("userLogin");
         userLoginIdAtPermGrant = getUserLoginIdAtPermGrant();
         String userLoginId = null;
-        if (userLogin != null)
+        if (userLogin != null) {
             userLoginId = userLogin.getString("userLoginId");
+        }
         if ((userLoginId == null && userLoginIdAtPermGrant != null)
            || (userLoginId != null && userLoginIdAtPermGrant == null)
            || ((userLoginId != null && userLoginIdAtPermGrant != null)
               && !userLoginId.equals(userLoginIdAtPermGrant))) {
             hasChanged = true;
         } else {
-            if (userLoginIdAtPermGrant != null)
-               hasChanged = true;
-            else
-               hasChanged = false;
+            if (userLoginIdAtPermGrant != null) {
+                hasChanged = true;
+            } else {
+                hasChanged = false;
+            }
 
             userLoginIdAtPermGrant = null;
         }

Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlMenuRendererImage.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlMenuRendererImage.java?rev=1818541&r1=1818540&r2=1818541&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlMenuRendererImage.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlMenuRendererImage.java Mon Dec 18 09:35:36 2017
@@ -52,7 +52,6 @@ public class HtmlMenuRendererImage exten
         String contentId = menuItem.getAssociatedContentId(context);
         Delegator delegator = (Delegator)request.getAttribute("delegator");
         GenericValue webSitePublishPoint = null;
-                //Debug.logInfo("in HtmlMenuRendererImage, contentId:" + contentId,"");
         try {
             if (WidgetContentWorker.getContentWorker() != null) {
                 webSitePublishPoint = WidgetContentWorker.getContentWorker().getWebSitePublishPointExt(delegator, contentId, false);
@@ -60,18 +59,17 @@ public class HtmlMenuRendererImage exten
                 Debug.logError("Not rendering image because can't get WebSitePublishPoint, not ContentWorker found.", module);
             }
         } catch (GenericEntityException e) {
-                //Debug.logInfo("in HtmlMenuRendererImage, GEException:" + e.getMessage(),"");
             throw new RuntimeException(e.getMessage());
         }
         String medallionLogoStr = webSitePublishPoint.getString("medallionLogo");
         StringWriter buf = new StringWriter();
         appendContentUrl(buf, medallionLogoStr);
         imgStr.append(buf.toString());
-                //Debug.logInfo("in HtmlMenuRendererImage, imgStr:" + imgStr,"");
         String cellWidth = menuItem.getCellWidth();
         imgStr.append("\"");
-        if (UtilValidate.isNotEmpty(cellWidth))
+        if (UtilValidate.isNotEmpty(cellWidth)) {
             imgStr.append(" width=\"").append(cellWidth).append("\" ");
+        }
 
         imgStr.append(" border=\"0\" />");
         return imgStr.toString();

Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlMenuWrapper.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlMenuWrapper.java?rev=1818541&r1=1818540&r2=1818541&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlMenuWrapper.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlMenuWrapper.java Mon Dec 18 09:35:36 2017
@@ -74,7 +74,7 @@ public class HtmlMenuWrapper {
 
         this.renderer = getMenuRenderer();
 
-        this.context = new HashMap<String, Object>();
+        this.context = new HashMap<>();
         Map<String, Object> parameterMap = UtilHttp.getParameterMap(request);
         context.put("parameters", parameterMap);
 
@@ -106,7 +106,9 @@ public class HtmlMenuWrapper {
         HttpServletRequest req = ((HtmlMenuRenderer)renderer).request;
         ServletContext ctx = (ServletContext) req.getAttribute("servletContext");
         if (ctx == null) {
-            if (Debug.infoOn()) Debug.logInfo("in renderMenuString, ctx is null(0)" , "");
+            if (Debug.infoOn()) {
+                Debug.logInfo("in renderMenuString, ctx is null(0)" , "");
+            }
         }
 
         Writer writer = new StringWriter();
@@ -115,7 +117,9 @@ public class HtmlMenuWrapper {
         HttpServletRequest req2 = ((HtmlMenuRenderer)renderer).request;
         ServletContext ctx2 = (ServletContext) req2.getAttribute("servletContext");
         if (ctx2 == null) {
-            if (Debug.infoOn()) Debug.logInfo("in renderMenuString, ctx is null(2)" , "");
+            if (Debug.infoOn()) {
+                Debug.logInfo("in renderMenuString, ctx is null(2)" , "");
+            }
         }
 
         return writer.toString();
@@ -152,7 +156,7 @@ public class HtmlMenuWrapper {
     public void putInContext(String menuItemName, String valueName,  Object value) {
         Map<String, Object> valueMap = UtilGenerics.toMap(context.get(menuItemName));
         if (valueMap == null) {
-            valueMap = new HashMap<String, Object>();
+            valueMap = new HashMap<>();
             context.put(menuItemName, valueMap);
         }
         valueMap.put(valueName, value);
@@ -165,7 +169,7 @@ public class HtmlMenuWrapper {
     public Object getFromContext(String menuItemName, String valueName) {
         Map<String, Object> valueMap = UtilGenerics.toMap(context.get(menuItemName));
         if (valueMap == null) {
-            valueMap = new HashMap<String, Object>();
+            valueMap = new HashMap<>();
             context.put(menuItemName, valueMap);
         }
         return valueMap.get(valueName);
@@ -215,18 +219,10 @@ public class HtmlMenuWrapper {
                 Class<?> cls = Class.forName("org.apache.ofbiz.widget.html." + menuWrapperClassName);
                 menuWrapper = (HtmlMenuWrapper)cls.newInstance();
                 menuWrapper.init(menuDefFile, menuName, request, response);
-            } catch (InstantiationException e) {
+            } catch (InstantiationException | IllegalAccessException | IOException | SAXException | ParserConfigurationException e) {
                 throw new RuntimeException(e.getMessage());
-            } catch (IllegalAccessException e2) {
-                throw new RuntimeException(e2.getMessage());
-            } catch (ClassNotFoundException e3) {
-                throw new RuntimeException("Class not found:" + e3.getMessage());
-            } catch (IOException e4) {
-                throw new RuntimeException(e4.getMessage());
-            } catch (SAXException e5) {
-                throw new RuntimeException(e5.getMessage());
-            } catch (ParserConfigurationException e6) {
-                throw new RuntimeException(e6.getMessage());
+            } catch (ClassNotFoundException e) {
+                throw new RuntimeException("Class not found:" + e.getMessage());
             }
         } else {
             menuWrapper.setRequest(request);

Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlMenuWrapperImage.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlMenuWrapperImage.java?rev=1818541&r1=1818540&r2=1818541&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlMenuWrapperImage.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlMenuWrapperImage.java Mon Dec 18 09:35:36 2017
@@ -58,19 +58,13 @@ public class HtmlMenuWrapperImage extend
             throws IOException, SAXException, ParserConfigurationException {
 
         super.init(resourceName, menuName, request, response);
-        //String pubPt = (String)request.getAttribute("pubPt");
-        //if (Debug.infoOn()) Debug.logInfo("in init, pubPt:" + pubPt, module);
-        Map<String, Object> dummyMap = new HashMap<String, Object>();
+        Map<String, Object> dummyMap = new HashMap<>();
         Delegator delegator = (Delegator)request.getAttribute("delegator");
-        //if (Debug.infoOn()) Debug.logInfo("in init, delegator:" + delegator, module);
         try {
             for (ModelMenuItem menuItem : modelMenu.getMenuItemList()) {
                String contentId = menuItem.getAssociatedContentId(dummyMap);
-               //if (Debug.infoOn()) Debug.logInfo("in init, contentId:" + contentId, module);
                GenericValue webSitePublishPoint = EntityQuery.use(delegator).from("WebSitePublishPoint").where("contentId", contentId).cache().queryOne();
                String menuItemName = menuItem.getName();
-               //if (Debug.infoOn()) Debug.logInfo("in init, menuItemName:" + menuItemName, module);
-               //if (Debug.infoOn()) Debug.logInfo("in init, webSitePublishPoint:" + webSitePublishPoint, module);
                putInContext(menuItemName, "WebSitePublishPoint", webSitePublishPoint);
             }
         } catch (GenericEntityException e) {

Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlTreeRenderer.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlTreeRenderer.java?rev=1818541&r1=1818540&r2=1818541&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlTreeRenderer.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlTreeRenderer.java Mon Dec 18 09:35:36 2017
@@ -28,7 +28,6 @@ import javax.servlet.http.HttpServletRes
 
 import org.apache.ofbiz.base.util.StringUtil;
 import org.apache.ofbiz.base.util.UtilGenerics;
-import org.apache.ofbiz.base.util.UtilProperties;
 import org.apache.ofbiz.base.util.UtilValidate;
 import org.apache.ofbiz.webapp.control.RequestHandler;
 import org.apache.ofbiz.webapp.taglib.ContentUrlTag;
@@ -91,7 +90,6 @@ public class HtmlTreeRenderer extends Ht
                 // Not on the trail
                 if (node.showPeers(depth, context)) {
                     context.put("processChildren", Boolean.FALSE);
-                    //expandCollapseLink.setText("&nbsp;+&nbsp;");
                     currentNodeTrailPiped = StringUtil.join(currentNodeTrail, "|");
                     StringBuilder target = new StringBuilder(node.getModelTree().getExpandCollapseRequest(context));
                     String trailName = node.getModelTree().getTrailName(context);
@@ -105,7 +103,6 @@ public class HtmlTreeRenderer extends Ht
                 }
             } else {
                 context.put("processChildren", Boolean.TRUE);
-                //expandCollapseLink.setText("&nbsp;-&nbsp;");
                 String lastContentId = currentNodeTrail.remove(currentNodeTrail.size() - 1);
                 currentNodeTrailPiped = StringUtil.join(currentNodeTrail, "|");
                 if (currentNodeTrailPiped == null) {