⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 displaymenutag.java

📁 Struts Menu这是为基于JSP和Struts的应用程序提供的Web菜单框架。菜单可以在一个XML文件中定义
💻 JAVA
字号:
package net.sf.navigator.taglib.el;import java.net.MalformedURLException;import javax.servlet.http.HttpServletRequest;import javax.servlet.jsp.JspException;import net.sf.navigator.menu.MenuComponent;import org.apache.struts.util.RequestUtils;/** * This tag acts the same as net.sf.navigator.taglib.DisplayMenuTag, except * that it allows JSTL Expressions in it's name and target attributes. * * @author Matt Raible * @version $Revision: 1.2 $ $Date: 2004/03/31 19:30:38 $ */public class DisplayMenuTag extends net.sf.navigator.taglib.DisplayMenuTag {    /** Holds value of property name. */    private String _name;    /** Holds value of property target. */    private String _target;    /** Setter for property name.     * @param name New value of property name.     */    public void setName(String name) {        this._name = name;    }    /** Setter for property target.     * @param target New value of property target.     */    public void setTarget(String target) {        this._target = target;    }    public DisplayMenuTag() {        super();        init();    }    private void init() {        _name = null;        _target = null;    }    public void release() {        super.release();        init();    }    public int doStartTag() throws JspException {        evaluateExpressions();        return super.doStartTag();    }    /**     * Overrides the setPageLocation in parentTag to use JSTL to evaluate     * the URL.  It's definitely ugly, so if you have a cleaner way, please     * let me know!     *     * @param menu     */    protected void setPageLocation(MenuComponent menu)    throws MalformedURLException, JspException {        HttpServletRequest request =            (HttpServletRequest) pageContext.getRequest();        // if the location attribute is null,        // then set it with a context relative page        // attribute if it exists        if (menu.getLocation() == null) {            if (menu.getPage() != null) {                // are we sure we'll get an HttpServletRequest?                menu.setLocation(request.getContextPath() +                                 getPage(menu.getPage()));            } else if (menu.getForward() != null) {                String fwd =                    RequestUtils.computeURL(pageContext, menu.getForward(),                                            null, null, null, null, null, false);                menu.setLocation(fwd);            } else if (menu.getAction() != null) {                // generate Struts Action URL,                // this will append Context Path (if any),                // Servlet Mapping (path mapping or extension mapping)                // Module Prefix (if any) & Session ID (if any)                String action =                    RequestUtils.computeURL(pageContext, null, null, null,                                            menu.getAction(), null, null, false);                menu.setLocation(action);            }        }        String url = menu.getLocation();        // Use JSTL to replace dynamic values in the URL        ExpressionEvaluator eval = new ExpressionEvaluator(this, pageContext);        String s;        if ((s = eval.evalString("url", url)) != null) {            menu.setUrl(s);        }        // do all contained menus        MenuComponent[] subMenus = menu.getMenuComponents();        if (subMenus.length > 0) {            for (int i = 0; i < subMenus.length; i++) {                setPageLocation(subMenus[i]);            }        }    }    private void evaluateExpressions() throws JspException {        ExpressionEvaluator eval = new ExpressionEvaluator(this, pageContext);        String s;        if ((s = eval.evalString("name", _name)) != null) {            super.setName(s);        }        if ((s = eval.evalString("target", _target)) != null) {            super.setTarget(s);        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -