View Javadoc

1   package net.sf.navigator.taglib.el;
2   
3   import net.sf.navigator.menu.MenuComponent;
4   
5   import javax.servlet.jsp.JspException;
6   import java.net.MalformedURLException;
7   
8   
9   /**
10   * This tag acts the same as net.sf.navigator.taglib.DisplayMenuTag, except
11   * that it allows JSTL Expressions in it's name and target attributes.
12   *
13   * @author Matt Raible
14   * @version $Revision: 1.6 $ $Date: 2006/07/09 08:08:10 $
15   */
16  public class DisplayMenuTag extends net.sf.navigator.taglib.DisplayMenuTag {
17      private String name;
18      private String target;
19  
20      public void setName(String name) {
21          this.name = name;
22      }
23  
24      public void setTarget(String target) {
25          this.target = target;
26      }
27  
28      public DisplayMenuTag() {
29          super();
30          init();
31      }
32  
33      private void init() {
34          name = null;
35          target = null;
36      }
37  
38      public void release() {
39          super.release();
40          init();
41      }
42  
43      public int doStartTag() throws JspException {
44          evaluateExpressions();
45          return super.doStartTag();
46      }
47  
48      /**
49       * Overrides the setPageLocation in parentTag to use JSTL to evaluate
50       * the URL.  It's definitely ugly, so if you have a cleaner way, please
51       * let me know!
52       *
53       * @param menu
54       */
55      protected void setPageLocation(MenuComponent menu)
56      throws MalformedURLException, JspException {
57          setLocation(menu);
58          String url = menu.getLocation();
59  
60          if (url != null) {
61              ExpressionEvaluator eval = new ExpressionEvaluator(this, pageContext);
62              menu.setUrl(eval.evalString("url", url));
63          }
64  
65          // do all contained menus
66          MenuComponent[] subMenus = menu.getMenuComponents();
67  
68          if (subMenus.length > 0) {
69              for (int i = 0; i < subMenus.length; i++) {
70                  this.setPageLocation(subMenus[i]);
71              }
72          }
73      }
74  
75      private void evaluateExpressions() throws JspException {
76          ExpressionEvaluator eval = new ExpressionEvaluator(this, pageContext);
77  
78          if (name != null) {
79              super.setName(eval.evalString("name", name));
80          }
81  
82          if (target != null) {
83              super.setTarget(eval.evalString("target", target));
84          }
85      }
86  }