View Javadoc

1   package net.sf.navigator.taglib.el;
2   
3   import net.sf.navigator.displayer.MenuDisplayer;
4   import org.apache.taglibs.standard.tag.common.fmt.BundleSupport;
5   
6   import javax.servlet.jsp.JspException;
7   import javax.servlet.jsp.jstl.fmt.LocalizationContext;
8   import javax.servlet.jsp.tagext.Tag;
9   
10  
11  /**
12   * This tag acts the same as net.sf.navigator.taglib.UseMenuDisplayerTag, except
13   * that it allows JSTL Expressions in all it's attributes.
14   *
15   * @author Matt Raible
16   * @version $Revision: 1.5 $ $Date: 2006/03/02 08:04:33 $
17   */
18  public class UseMenuDisplayerTag  extends net.sf.navigator.taglib.UseMenuDisplayerTag {
19      private String name;
20      private String bundle;
21      private String config = MenuDisplayer.DEFAULT_CONFIG;
22      private String locale;
23      private String permissions;
24      private String repository;
25  
26      public void setName(String name) {
27          this.name = name;
28      }
29  
30      public void setBundle(String bundle) {
31          this.bundle = bundle;
32      }
33  
34      public void setConfig(String config) {
35          this.config = config;
36      }
37  
38      public void setLocale(String locale) {
39          this.locale = locale;
40      }
41  
42      public void setPermissions(String permissions) {
43          this.permissions = permissions;
44      }
45  
46      public void setRepository(String key) {
47          this.repository = key;
48      }
49  
50      public UseMenuDisplayerTag() {
51          super();
52          init();
53      }
54  
55      private void init() {
56          name = null;
57          bundle = null;
58          config = null;
59          locale = null;
60          permissions = null;
61          repository = null;
62      }
63  
64      public void release() {
65          super.release();
66          init();
67      }
68  
69      public int doStartTag() throws JspException {
70          evaluateExpressions();
71  
72          // Default to JSTL Bundle to use (for EL Tag)
73          Tag tag = findAncestorWithClass(this, BundleSupport.class);
74  
75          if (tag != null) {
76              BundleSupport parent = (BundleSupport) tag;
77              rb = parent.getLocalizationContext().getResourceBundle();
78          } else {
79              // check for the localizationContext in applicationScope, set in web.xml
80              LocalizationContext localization =
81                  BundleSupport.getLocalizationContext(pageContext);
82  
83              if (localization != null) {
84                  rb = localization.getResourceBundle();
85              }
86          }
87  
88          return super.doStartTag();
89      }
90  
91      private void evaluateExpressions() throws JspException {
92          ExpressionEvaluator eval = new ExpressionEvaluator(this, pageContext);
93  
94          if (name != null) {
95              super.setName(eval.evalString("name", name));
96          }
97  
98          if (bundle != null) {
99              super.setBundle(eval.evalString("bundle", bundle));
100         }
101 
102         if (config != null) {
103             super.setConfig(eval.evalString("config", config));
104         }
105 
106         if (locale != null) {
107             super.setLocale(eval.evalString("locale", locale));
108         }
109 
110         if (permissions != null) {
111             super.setPermissions(eval.evalString("permissions", permissions));
112         }
113 
114         if (repository != null) {
115             super.setRepository(eval.evalString("repository", repository));
116         }
117     }
118 }