📄 htmlmenurenderer.java
字号:
/* * $Id: HtmlMenuRenderer.java 5864 2005-09-30 14:27:12Z jonesde $ * * Copyright (c) 2003 The Open For Business Project - www.ofbiz.org * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * THE USE OR OTHER DEALINGS IN THE SOFTWARE. */package org.ofbiz.widget.html;import java.util.Iterator;import java.util.List;import java.util.Map;import javax.servlet.ServletContext;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import org.ofbiz.base.util.StringUtil;import org.ofbiz.base.util.UtilValidate;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.GenericValue;import org.ofbiz.webapp.control.RequestHandler;import org.ofbiz.webapp.taglib.ContentUrlTag;import org.ofbiz.widget.menu.MenuStringRenderer;import org.ofbiz.widget.menu.ModelMenu;import org.ofbiz.widget.menu.ModelMenuItem;import org.ofbiz.widget.menu.ModelMenuItem.Image;import org.ofbiz.widget.menu.ModelMenuItem.Link;/** * Widget Library - HTML Menu Renderer implementation * * @author <a href="mailto:jonesde@ofbiz.org">David E. Jones</a> * @author <a href="mailto:byersa@automationgroups.com">Al Byers</a> * @version $Rev: 5864 $ * @since 2.2 */public class HtmlMenuRenderer implements MenuStringRenderer { HttpServletRequest request; HttpServletResponse response; protected String userLoginIdAtPermGrant; protected boolean userLoginIdHasChanged = true; protected String permissionErrorMessage = ""; public static final String module = HtmlMenuRenderer.class.getName(); protected HtmlMenuRenderer() {} public HtmlMenuRenderer(HttpServletRequest request, HttpServletResponse response) { this.request = request; this.response = response; } public void appendWhitespace(StringBuffer buffer) { // appending line ends for now, but this could be replaced with a simple space or something buffer.append("\r\n"); //buffer.append(' '); } public void appendOfbizUrl(StringBuffer buffer, String location) { 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. buffer=" + buffer.toString() + " location:" + location); } //if (Debug.infoOn()) Debug.logInfo("in appendOfbizUrl, ctx is NOT null(2)", ""); } GenericDelegator delegator = (GenericDelegator)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, ""); } buffer.append(s); } public void appendContentUrl(StringBuffer buffer, String location) { 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. buffer=" + buffer.toString() + " location:" + location); } //if (Debug.infoOn()) Debug.logInfo("in appendContentUrl, ctx is NOT null(2)", ""); this.request.setAttribute("servletContext", ctx); } GenericDelegator delegator = (GenericDelegator)request.getAttribute("delegator"); if (delegator == null) { //if (Debug.infoOn()) Debug.logInfo("in appendContentUrl, delegator is null(6)", ""); } ContentUrlTag.appendContentPrefix(this.request, buffer); buffer.append(location); } public void appendTooltip(StringBuffer buffer, Map context, ModelMenuItem modelMenuItem) { // render the tooltip, in other methods too String tooltip = modelMenuItem.getTooltip(context); if (UtilValidate.isNotEmpty(tooltip)) { buffer.append("<span"); String tooltipStyle = modelMenuItem.getTooltipStyle(); if (UtilValidate.isNotEmpty(tooltipStyle)) { buffer.append(" class=\""); buffer.append(tooltipStyle); buffer.append("\""); } buffer.append("> -["); buffer.append(tooltip); buffer.append("]- </span>"); } } public void renderFormatSimpleWrapperRows(StringBuffer buffer, Map context, Object menuObj) { List menuItemList = ((ModelMenu)menuObj).getMenuItemList(); Iterator menuItemIter = menuItemList.iterator(); ModelMenuItem currentMenuItem = null; while (menuItemIter.hasNext()) { currentMenuItem = (ModelMenuItem)menuItemIter.next(); renderMenuItem(buffer, context, currentMenuItem); } return; } public void renderMenuItem(StringBuffer buffer, Map context, ModelMenuItem menuItem) { //Debug.logInfo("in renderMenuItem, menuItem:" + menuItem.getName() + " context:" + context ,""); boolean hideThisItem = isHideIfSelected(menuItem); //if (Debug.infoOn()) Debug.logInfo("in HtmlMenuRendererImage, hideThisItem:" + hideThisItem,""); if (hideThisItem) return; String style = menuItem.getAlignStyle(); if (UtilValidate.isNotEmpty(style)) { String orientation = menuItem.getModelMenu().getOrientation(); if (orientation.equalsIgnoreCase("vertical")) style += "-vert"; String align = menuItem.getAlign(); if (align.equalsIgnoreCase("right")) style += "-right"; buffer.append("<div class=\"" + style + "\">"); } Link link = menuItem.getLink(); //if (Debug.infoOn()) Debug.logInfo("in HtmlMenuRendererImage, link(0):" + link,""); if (link != null) { renderLink(buffer, context, link); } if (UtilValidate.isNotEmpty(style)) { // only render the close tag if we rendered the open buffer.append("</div>"); } this.appendWhitespace(buffer); return; } public boolean isDisableIfEmpty(ModelMenuItem menuItem, Map context) { boolean disabled = false; String disableIfEmpty = menuItem.getDisableIfEmpty(); if (UtilValidate.isNotEmpty(disableIfEmpty)) { List keys = StringUtil.split(disableIfEmpty, "|"); Iterator iter = keys.iterator(); while (iter.hasNext()) { Object obj = context.get(disableIfEmpty); if (obj == null) { disabled = true; break; } } } return disabled; } public String buildDivStr(ModelMenuItem menuItem, Map context) { String divStr = ""; divStr = menuItem.getTitle(context); return divStr; } public void renderMenuOpen(StringBuffer buffer, Map context, ModelMenu modelMenu) { if (!userLoginIdHasChanged) { userLoginIdHasChanged = userLoginIdHasChanged(); } //Debug.logInfo("in HtmlMenuRenderer, userLoginIdHasChanged:" + userLoginIdHasChanged,""); String menuWidth = modelMenu.getMenuWidth(); String menuContainerStyle = modelMenu.getMenuContainerStyle(context); String widthStr = ""; if (UtilValidate.isNotEmpty(menuWidth)) { widthStr = " style=\"width:" + menuWidth + ";\""; } buffer.append("<div class=\"" + menuContainerStyle + "\"" + widthStr + ">"); this.appendWhitespace(buffer); } /* (non-Javadoc) * @see org.ofbiz.widget.menu.MenuStringRenderer#renderMenuClose(java.lang.StringBuffer, java.util.Map, org.ofbiz.widget.menu.ModelMenu) */ public void renderMenuClose(StringBuffer buffer, Map context, ModelMenu modelMenu) { String fillStyle = modelMenu.getFillStyle(); if (UtilValidate.isNotEmpty(fillStyle)) { buffer.append("<div class=\"" + fillStyle + "\"> </div>"); } //String menuContainerStyle = modelMenu.getMenuContainerStyle(context); buffer.append("</div>"); this.appendWhitespace(buffer); userLoginIdHasChanged = userLoginIdHasChanged(); GenericValue userLogin = (GenericValue)request.getSession().getAttribute("userLogin"); if (userLogin != null) { String userLoginId = userLogin.getString("userLoginId"); //request.getSession().setAttribute("userLoginIdAtPermGrant", userLoginId);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -