Improved: General refactoring and code improvements, package

org.apache.ofbiz.widget.renderer.html.
(OFBIZ-9933)

Thanks Dennis Balkir for reporting and providing the patches.

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1818541 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Brohl
2017-12-18 09:35:36 +00:00
parent 1a85712bb2
commit 4436e8b96f
5 changed files with 26 additions and 41 deletions
@@ -32,7 +32,6 @@ import org.apache.ofbiz.base.util.StringUtil;
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 HtmlWidgetRenderer implements MenuStringRe
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 HtmlWidgetRenderer implements MenuStringRe
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 HtmlWidgetRenderer implements MenuStringRe
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 HtmlWidgetRenderer implements MenuStringRe
}
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 HtmlWidgetRenderer implements MenuStringRe
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;
}
@@ -52,7 +52,6 @@ public class HtmlMenuRendererImage extends HtmlMenuRenderer {
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 extends HtmlMenuRenderer {
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();
@@ -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);
@@ -58,19 +58,13 @@ public class HtmlMenuWrapperImage extends HtmlMenuWrapper {
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) {
@@ -28,7 +28,6 @@ import javax.servlet.http.HttpServletResponse;
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 HtmlWidgetRenderer implements TreeStringRe
// 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 HtmlWidgetRenderer implements TreeStringRe
}
} else {
context.put("processChildren", Boolean.TRUE);
//expandCollapseLink.setText("&nbsp;-&nbsp;");
String lastContentId = currentNodeTrail.remove(currentNodeTrail.size() - 1);
currentNodeTrailPiped = StringUtil.join(currentNodeTrail, "|");
if (currentNodeTrailPiped == null) {