You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by mb...@apache.org on 2017/10/07 16:06:24 UTC

svn commit: r1811439 - /ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlMenuRenderer.java

Author: mbrohl
Date: Sat Oct  7 16:06:24 2017
New Revision: 1811439

URL: http://svn.apache.org/viewvc?rev=1811439&view=rev
Log:
Improved: Fixing defects reported by FindBugs, package 
org.apache.ofbiz.widget.renderer.html.
(OFBIZ-9686)

I modified the class further by removing all commented out code.

Thanks Julian Leichert for reporting and providing the patch.

Modified:
    ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/html/HtmlMenuRenderer.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=1811439&r1=1811438&r2=1811439&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 Sat Oct  7 16:06:24 2017
@@ -66,51 +66,32 @@ public class HtmlMenuRenderer extends Ht
     public void appendOfbizUrl(Appendable writer, String location) throws IOException {
         ServletContext ctx = (ServletContext) request.getAttribute("servletContext");
         if (ctx == null) {
-            //if (Debug.infoOn()) Debug.logInfo("in appendOfbizUrl, ctx is null(0): buffer=" + buffer.toString() + " location:" + location, "");
             HttpSession session = request.getSession();
             if (session != null) {
                 ctx = session.getServletContext();
-            } else {
-                //if (Debug.infoOn()) Debug.logInfo("in appendOfbizUrl, session is null(1)", "");
-            }
+            } 
             if (ctx == null) {
                 throw new RuntimeException("ctx is null. location:" + location);
             }
-                //if (Debug.infoOn()) Debug.logInfo("in appendOfbizUrl, ctx is NOT null(2)", "");
-        }
-        Delegator delegator = (Delegator)request.getAttribute("delegator");
-        if (delegator == null) {
-                //if (Debug.infoOn()) Debug.logInfo("in appendOfbizUrl, delegator is null(5)", "");
         }
         RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_");
         // make and append the link
         String s = rh.makeLink(this.request, this.response, location);
-        if (s.indexOf("null") >= 0) {
-            //if (Debug.infoOn()) Debug.logInfo("in appendOfbizUrl(3), url: " + s, "");
-        }
         writer.append(s);
     }
 
     public void appendContentUrl(Appendable writer, String location) throws IOException {
         ServletContext ctx = (ServletContext) this.request.getAttribute("servletContext");
         if (ctx == null) {
-            //if (Debug.infoOn()) Debug.logInfo("in appendContentUrl, ctx is null(0): buffer=" + buffer.toString() + " location:" + location, "");
             HttpSession session = request.getSession();
             if (session != null) {
                 ctx = session.getServletContext();
-            } else {
-                //if (Debug.infoOn()) Debug.logInfo("in appendContentUrl, session is null(1)", "");
             }
             if (ctx == null) {
                 throw new RuntimeException("ctx is null. location:" + location);
             }
-            //if (Debug.infoOn()) Debug.logInfo("in appendContentUrl, ctx is NOT null(2)", "");
             this.request.setAttribute("servletContext", ctx);
         }
-        Delegator delegator = (Delegator) request.getAttribute("delegator");
-        if (delegator == null) {
-                //if (Debug.infoOn()) Debug.logInfo("in appendContentUrl, delegator is null(6)", "");
-        }
         StringBuilder buffer = new StringBuilder();
         ContentUrlTag.appendContentPrefix(this.request, buffer);
         writer.append(buffer.toString());
@@ -142,10 +123,8 @@ public class HtmlMenuRenderer extends Ht
     }
 
     public void renderMenuItem(Appendable writer, Map<String, Object> context, ModelMenuItem menuItem) throws IOException {
-
-        //Debug.logInfo("in renderMenuItem, menuItem:" + menuItem.getName() + " context:" + context ,"");
         boolean hideThisItem = isHideIfSelected(menuItem, context);
-        //if (Debug.infoOn()) Debug.logInfo("in HtmlMenuRendererImage, hideThisItem:" + hideThisItem,"");
+
         if (hideThisItem)
             return;
 
@@ -181,7 +160,6 @@ public class HtmlMenuRenderer extends Ht
         writer.append(">");
 
         MenuLink link = menuItem.getLink();
-        //if (Debug.infoOn()) Debug.logInfo("in HtmlMenuRendererImage, link(0):" + link,"");
         if (link != null) {
             renderLink(writer, context, link);
         } else {
@@ -225,16 +203,8 @@ public class HtmlMenuRenderer extends Ht
         return disabled;
     }
 
-/*
-    public String buildDivStr(ModelMenuItem menuItem, Map<String, Object> context) {
-        String divStr = "";
-        divStr =  menuItem.getTitle(context);
-        return divStr;
-    }
-*/
     public void renderMenuOpen(Appendable writer, Map<String, Object> context, ModelMenu modelMenu) throws IOException {
 
-            //Debug.logInfo("in HtmlMenuRenderer, userLoginIdHasChanged:" + userLoginIdHasChanged,"");
         this.widgetCommentsEnabled = ModelWidget.widgetBoundaryCommentsEnabled(context);
         renderBeginningBoundaryComment(writer, "Menu Widget", modelMenu);
         writer.append("<div");
@@ -279,7 +249,6 @@ public class HtmlMenuRenderer extends Ht
         if (UtilValidate.isNotEmpty(fillStyle)) {
             writer.append("<div class=\"").append(fillStyle).append("\">&nbsp;</div>");
         }
-        //String menuContainerStyle = modelMenu.getMenuContainerStyle(context);
         if (modelMenu.renderedMenuItemCount(context) > 0) {      
             writer.append(" </ul>");
             appendWhitespace(writer);
@@ -297,9 +266,7 @@ public class HtmlMenuRenderer extends Ht
         GenericValue userLogin = (GenericValue)request.getSession().getAttribute("userLogin");
         if (userLogin != null) {
             String userLoginId = userLogin.getString("userLoginId");
-            //request.getSession().setAttribute("userLoginIdAtPermGrant", userLoginId);
             setUserLoginIdAtPermGrant(userLoginId);
-            //Debug.logInfo("in HtmlMenuRenderer, userLoginId(Close):" + userLoginId + " userLoginIdAtPermGrant:" + request.getSession().getAttribute("userLoginIdAtPermGrant"),"");
         } else {
             request.getSession().setAttribute("userLoginIdAtPermGrant", null);
         }
@@ -326,7 +293,6 @@ public class HtmlMenuRenderer extends Ht
      * @param string
      */
     public void setUserLoginIdAtPermGrant(String string) {
-            //Debug.logInfo("in HtmlMenuRenderer,  userLoginIdAtPermGrant(setUserLoginIdAtPermGrant):" + string,"");
         this.userLoginIdAtPermGrant = string;
     }
 
@@ -339,7 +305,6 @@ public class HtmlMenuRenderer extends Ht
         String currentMenuItemName = menu.getSelectedMenuItemContextFieldName(context);
         String currentItemName = menuItem.getName();
         Boolean hideIfSelected = menuItem.getHideIfSelected();
-            //Debug.logInfo("in HtmlMenuRenderer, currentMenuItemName:" + currentMenuItemName + " currentItemName:" + currentItemName + " hideIfSelected:" + hideIfSelected,"");
         return (hideIfSelected != null && hideIfSelected.booleanValue() && currentMenuItemName != null && currentMenuItemName.equals(currentItemName));
     }
 
@@ -348,11 +313,9 @@ public class HtmlMenuRenderer extends Ht
         boolean hasChanged = false;
         GenericValue userLogin = (GenericValue)request.getSession().getAttribute("userLogin");
         userLoginIdAtPermGrant = getUserLoginIdAtPermGrant();
-        //userLoginIdAtPermGrant = (String)request.getSession().getAttribute("userLoginIdAtPermGrant");
         String userLoginId = null;
         if (userLogin != null)
             userLoginId = userLogin.getString("userLoginId");
-            //Debug.logInfo("in HtmlMenuRenderer, userLoginId:" + userLoginId + " userLoginIdAtPermGrant:" + userLoginIdAtPermGrant ,"");
         if ((userLoginId == null && userLoginIdAtPermGrant != null)
            || (userLoginId != null && userLoginIdAtPermGrant == null)
            || ((userLoginId != null && userLoginIdAtPermGrant != null)
@@ -453,31 +416,13 @@ public class HtmlMenuRenderer extends Ht
             }
 
             writer.append(" href=\"");
-            String confirmationMsg = null;
             if ("hidden-form".equals(linkType)) {
-                if (UtilValidate.isNotEmpty(confirmationMsg)) {
-                    writer.append("javascript:confirmActionFormLink('");
-                    writer.append(confirmationMsg);
-                    writer.append("', '");
-                    writer.append(uniqueItemName);
-                    writer.append("')");
-                } else {
                     writer.append("javascript:document.");
                     writer.append(uniqueItemName);
                     writer.append(".submit()");
-                }
             } else {
-                if (UtilValidate.isNotEmpty(confirmationMsg)) {
-                    writer.append("javascript:confirmActionLink('");
-                    writer.append(confirmationMsg);
-                    writer.append("', '");
-                    WidgetWorker.buildHyperlinkUrl(writer, target, link.getUrlMode(), link.getParameterMap(context), link.getPrefix(context),
-                            link.getFullPath(), link.getSecure(), link.getEncode(), request, response, context);
-                    writer.append("')");
-                } else {
                 WidgetWorker.buildHyperlinkUrl(writer, target, link.getUrlMode(), link.getParameterMap(context), link.getPrefix(context),
                         link.getFullPath(), link.getSecure(), link.getEncode(), request, response, context);
-                }
             }
             writer.append("\">");
         }
@@ -496,31 +441,6 @@ public class HtmlMenuRenderer extends Ht
             writer.append("</a>");
         }
 
-        /* NOTE DEJ20090316: This was here as a comment and not sure what it is for or if it is useful... can probably be safely removed in the future if still not used/needed
-        boolean isSelected = menuItem.isSelected(context);
-
-        String style = null;
-
-        if (isSelected) {
-        style = menuItem.getSelectedStyle();
-        } else {
-        style = link.getStyle(context);
-        if (UtilValidate.isEmpty(style))
-        style = menuItem.getTitleStyle();
-        if (UtilValidate.isEmpty(style))
-        style = menuItem.getWidgetStyle();
-        }
-
-        if (menuItem.getDisabled()) {
-        style = menuItem.getDisabledTitleStyle();
-        }
-
-        if (UtilValidate.isNotEmpty(style)) {
-        writer.append(" class=\"");
-        writer.append(style);
-        writer.append("\"");
-        }
-        */
     }
 
     public void renderImage(Appendable writer, Map<String, Object> context, Image image) throws IOException {