Update of /cvsroot/struts-menu/navigator/src/java/net/sf/navigator/taglib
In directory sc8-pr-cvs1:/tmp/cvs-serv5193/src/java/net/sf/navigator/taglib

Modified Files:
        DisplayMenuTag.java UseMenuDisplayerTag.java 
Log Message:
fixed bug where an invalid forward or mapping killed all menus.  Also added ability to 
define the config in menu-config.xml (convenient for Velocity templates)


Index: DisplayMenuTag.java
===================================================================
RCS file: 
/cvsroot/struts-menu/navigator/src/java/net/sf/navigator/taglib/DisplayMenuTag.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** DisplayMenuTag.java 29 Oct 2003 00:16:12 -0000      1.9
--- DisplayMenuTag.java 18 Dec 2003 23:21:18 -0000      1.10
***************
*** 64,68 ****
  
      /** Creates new DisplayMenuTag */
!     public DisplayMenuTag() {}
  
      //~ Methods ================================================================
--- 64,69 ----
  
      /** Creates new DisplayMenuTag */
!     public DisplayMenuTag() {
!     }
  
      //~ Methods ================================================================
***************
*** 102,106 ****
      public int doStartTag() throws JspException {
          MenuDisplayer displayer =
!             (MenuDisplayer) 
pageContext.getAttribute(UseMenuDisplayerTag.DISPLAYER_KEY);
  
          if (displayer == null) {
--- 103,107 ----
      public int doStartTag() throws JspException {
          MenuDisplayer displayer =
!                 (MenuDisplayer) 
pageContext.getAttribute(UseMenuDisplayerTag.DISPLAYER_KEY);
  
          if (displayer == null) {
***************
*** 109,113 ****
  
          MenuRepository repository =
!             (MenuRepository) 
pageContext.getServletContext().getAttribute(MenuRepository.MENU_REPOSITORY_KEY);
  
          if (repository == null) {
--- 110,114 ----
  
          MenuRepository repository =
!                 (MenuRepository) 
pageContext.getServletContext().getAttribute(MenuRepository.MENU_REPOSITORY_KEY);
  
          if (repository == null) {
***************
*** 127,131 ****
                  // the context relative page attribute
                  // if specified in the menu
!                 setPageLocation(menu);
  
                  displayer.display(menu);
--- 128,138 ----
                  // the context relative page attribute
                  // if specified in the menu
!                 try {
!                     setPageLocation(menu);
!                 } catch (MalformedURLException m) {
!                     log.error("Incorrect action or forward: " + m.getMessage());
!                     log.debug("setting location to #");
!                     menu.setLocation("#");
!                 }
  
                  displayer.display(menu);
***************
*** 137,141 ****
          } else {
              throw new 
JspException(UseMenuDisplayerTag.messages.getString("menu.not.found") +
!                                    " " + this.name);
          }
  
--- 144,148 ----
          } else {
              throw new 
JspException(UseMenuDisplayerTag.messages.getString("menu.not.found") +
!                     " " + this.name);
          }
  
***************
*** 162,168 ****
       */
      protected void setPageLocation(MenuComponent menu)
!     throws MalformedURLException {
          HttpServletRequest request =
!             (HttpServletRequest) pageContext.getRequest();
  
          // if the location attribute is null,
--- 169,175 ----
       */
      protected void setPageLocation(MenuComponent menu)
!             throws MalformedURLException {
          HttpServletRequest request =
!                 (HttpServletRequest) pageContext.getRequest();
  
          // if the location attribute is null,
***************
*** 173,181 ****
                  // 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) {
--- 180,188 ----
                  // 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) {
***************
*** 185,190 ****
                  // Module Prefix (if any) & Session ID (if any)
                  String action =
!                     RequestUtils.computeURL(pageContext, null, null, null,
!                                             menu.getAction(), null, null, false);
                  menu.setLocation(action);
              }
--- 192,197 ----
                  // Module Prefix (if any) & Session ID (if any)
                  String action =
!                         RequestUtils.computeURL(pageContext, null, null, null,
!                                 menu.getAction(), null, null, false);
                  menu.setLocation(action);
              }
***************
*** 250,254 ****
  
              String variable =
!                 str.substring(str.indexOf("${") + 2, str.indexOf("}"));
              String value = (String) pageContext.findAttribute(variable);
  
--- 257,261 ----
  
              String variable =
!                     str.substring(str.indexOf("${") + 2, str.indexOf("}"));
              String value = (String) pageContext.findAttribute(variable);
  
***************
*** 261,265 ****
              if (value == null) {
                  log.warn("Value for '" + variable +
!                          "' not found in pageContext or as a request parameter");
              }
  
--- 268,272 ----
              if (value == null) {
                  log.warn("Value for '" + variable +
!                         "' not found in pageContext or as a request parameter");
              }
  

Index: UseMenuDisplayerTag.java
===================================================================
RCS file: 
/cvsroot/struts-menu/navigator/src/java/net/sf/navigator/taglib/UseMenuDisplayerTag.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** UseMenuDisplayerTag.java    20 Nov 2003 17:16:02 -0000      1.4
--- UseMenuDisplayerTag.java    18 Dec 2003 23:21:18 -0000      1.5
***************
*** 33,227 ****
   */
  public class UseMenuDisplayerTag extends TagSupport {
!       //~ Static fields/initializers =============================================
! 
!       public static final String DISPLAYER_KEY =
!               "net.sf.navigator.taglib.DISPLAYER";
  
!       //used by the menu displayer tag to get the menu repository
!       //it is possible that the user may have multiple repositories
!       // although it's unlikely
!       public static final String MENU_REPOSITORY_KEY =
!               "net.sf.navigator.MENU_REPOSITORY";
!       protected static ResourceBundle messages =
!               ResourceBundle.getBundle("net.sf.navigator.taglib.LocalStrings");
!       public static final String ROLES_ADAPTER = "rolesAdapter";
  
!       //~ Instance fields ========================================================
  
!       private Log log = LogFactory.getLog(UseMenuDisplayerTag.class);
!       protected MenuDisplayer menuDisplayer = null;
!       private String bundleKey;
!       private String config = MenuDisplayer.DEFAULT_CONFIG;
!       protected String localeKey;
!       protected String name;
  
!       /** Holds value of property permissions. */
!       private String permissions;
  
!       //~ Methods ================================================================
  
!       public String getBundle() {
!               return bundleKey;
!       }
  
!       public void setBundle(String bundle) {
!               this.bundleKey = bundle;
!       }
  
!       public String getConfig() {
!               return config;
!       }
  
!       public void setConfig(String config) {
!               if (log.isDebugEnabled()) {
!                       log.debug("setting config to: " + config);
!               }
  
!               this.config = config;
!       }
  
!       public String getLocale() {
!               return localeKey;
!       }
  
!       public void setLocale(String locale) {
!               this.localeKey = locale;
!       }
  
!       public String getName() {
!               return name;
!       }
  
!       public void setName(String name) {
!               this.name = name;
!       }
  
!       /** Getter for property permissions.
!        * @return Value of property permissions.
!        */
!       public String getPermissions() {
!               return this.permissions;
!       }
  
!       /** Setter for property permissions.
!        * @param permissions New value of property permissions.
!        */
!       public void setPermissions(String permissions) {
!               this.permissions = permissions;
!       }
  
!       public int doStartTag() throws JspException {
!               //get the menu repository
!               MenuRepository menuRep =
!                       (MenuRepository) 
pageContext.findAttribute(MenuRepository.MENU_REPOSITORY_KEY);
  
!               if (menuRep == null) {
!                       throw new 
JspException(messages.getString("menurepository.not.found"));
!               }
  
!               //get the displayer mapping
!               MenuDisplayerMapping displayerMapping =
!                       menuRep.getMenuDisplayerMapping(this.name);
  
!               if (displayerMapping == null) {
!                       throw new 
JspException(messages.getString("displayer.mapping.not.found"));
!               }
  
!               PermissionsAdapter permissions = getPermissionsAdapter();
  
!               //get an instance of the menu displayer
!               MenuDisplayer displayerInstance = null;
  
!               try {
!                       displayerInstance =
!                               (MenuDisplayer) 
Class.forName(displayerMapping.getType())
!                               .newInstance();
!                       menuDisplayer = displayerInstance;
!               } catch (Exception e) {
!                       throw new JspException(e.getMessage());
!               }
  
!               // setup the displayerInstance
!               // if the displayer is a MessageResourceMenuDisplayer
!               // and a bundle is specified, then pass it the bundle (message 
resources) and
!               // the locale
!               if ((bundleKey != null) &&
!                       (displayerInstance instanceof MessageResourcesMenuDisplayer)) {
!                       MessageResourcesMenuDisplayer mrDisplayerInstance =
!                               (MessageResourcesMenuDisplayer) displayerInstance;
!                       MessageResources resources =
!                               (MessageResources) 
pageContext.findAttribute(bundleKey);
!                       Locale locale = null;
  
!                       if (localeKey == null) {
!                               locale = pageContext.getRequest().getLocale();
!                       } else {
!                               locale = (Locale) pageContext.findAttribute(localeKey);
!                       }
  
!                       mrDisplayerInstance.setMessageResources(resources);
!                       mrDisplayerInstance.setLocale(locale);
!               }
  
!               displayerInstance.setConfig(config);
  
!               displayerInstance.init(pageContext, displayerMapping);
  
!               displayerInstance.setPermissionsAdapter(permissions);
  
!               pageContext.setAttribute(DISPLAYER_KEY, displayerInstance);
  
!               //make the menu repository available to the menu displayers
!               //pageContext.setAttribute(MENU_REPOSITORY_KEY, menuRep);
!               return (EVAL_BODY_INCLUDE);
!       }
  
!       protected PermissionsAdapter getPermissionsAdapter()
!               throws JspException {
!               PermissionsAdapter adapter = null;
  
!               if (permissions != null) {
!                       // If set to "rolesAdapter", then create automatically
!                       if (permissions.equalsIgnoreCase(ROLES_ADAPTER)) {
!                               adapter =
!                                       new 
RolesPermissionsAdapter((HttpServletRequest) pageContext.getRequest());
!                       } else {
!                               adapter =
!                                       (PermissionsAdapter) 
pageContext.findAttribute(permissions);
  
!                               if (adapter == null) {
!                                       throw new 
JspException(messages.getString("permissions.not.found"));
!                               }
!                       }
!               }
  
!               return adapter;
!       }
  
!       public int doEndTag() throws JspException {
!               menuDisplayer.end(pageContext);
!               pageContext.removeAttribute(DISPLAYER_KEY);
!               pageContext.removeAttribute(MENU_REPOSITORY_KEY);
!               // Might have to apply fix for
!               // http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16001
!               // release(); // don't seem to need it at this point...
!               return (EVAL_PAGE);
!       }
  
!       public void release() {
!               if (log.isDebugEnabled()) {
!                       log.debug("release() called");
!               }
  
!               super.release();
!               this.menuDisplayer = null;
!               this.bundleKey = null;
!               this.config = MenuDisplayer.DEFAULT_CONFIG;
!               this.localeKey = null;
!               this.name = null;
!               this.menuDisplayer = null;
  
!               //this.repository = MenuRepository.MENU_REPOSITORY_KEY;
!               this.permissions = null;
!       }
  }
--- 33,231 ----
   */
  public class UseMenuDisplayerTag extends TagSupport {
!     //~ Static fields/initializers =============================================
  
!     public static final String DISPLAYER_KEY =
!             "net.sf.navigator.taglib.DISPLAYER";
  
!     //used by the menu displayer tag to get the menu repository
!     //it is possible that the user may have multiple repositories
!     // although it's unlikely
!     public static final String MENU_REPOSITORY_KEY =
!             "net.sf.navigator.MENU_REPOSITORY";
!     protected static ResourceBundle messages =
!             ResourceBundle.getBundle("net.sf.navigator.taglib.LocalStrings");
!     public static final String ROLES_ADAPTER = "rolesAdapter";
  
!     //~ Instance fields ========================================================
  
!     private Log log = LogFactory.getLog(UseMenuDisplayerTag.class);
!     protected MenuDisplayer menuDisplayer = null;
!     private String bundleKey;
!     private String config = MenuDisplayer.DEFAULT_CONFIG;
!     protected String localeKey;
!     protected String name;
  
!     /** Holds value of property permissions. */
!     private String permissions;
  
!     //~ Methods ================================================================
  
!     public String getBundle() {
!         return bundleKey;
!     }
  
!     public void setBundle(String bundle) {
!         this.bundleKey = bundle;
!     }
  
!     public String getConfig() {
!         return config;
!     }
  
!     public void setConfig(String config) {
!         if (log.isDebugEnabled()) {
!             log.debug("setting config to: " + config);
!         }
  
!         this.config = config;
!     }
  
!     public String getLocale() {
!         return localeKey;
!     }
  
!     public void setLocale(String locale) {
!         this.localeKey = locale;
!     }
  
!     public String getName() {
!         return name;
!     }
  
!     public void setName(String name) {
!         this.name = name;
!     }
  
!     /** Getter for property permissions.
!      * @return Value of property permissions.
!      */
!     public String getPermissions() {
!         return this.permissions;
!     }
  
!     /** Setter for property permissions.
!      * @param permissions New value of property permissions.
!      */
!     public void setPermissions(String permissions) {
!         this.permissions = permissions;
!     }
  
!     public int doStartTag() throws JspException {
!         //get the menu repository
!         MenuRepository menuRep =
!                 (MenuRepository) 
pageContext.findAttribute(MenuRepository.MENU_REPOSITORY_KEY);
  
!         if (menuRep == null) {
!             throw new JspException(messages.getString("menurepository.not.found"));
!         }
  
!         //get the displayer mapping
!         MenuDisplayerMapping displayerMapping =
!                 menuRep.getMenuDisplayerMapping(this.name);
  
!         if (displayerMapping == null) {
!             throw new 
JspException(messages.getString("displayer.mapping.not.found"));
!         }
  
!         PermissionsAdapter permissions = getPermissionsAdapter();
  
!         //get an instance of the menu displayer
!         MenuDisplayer displayerInstance = null;
  
!         try {
!             displayerInstance =
!                     (MenuDisplayer) Class.forName(displayerMapping.getType())
!                     .newInstance();
!             menuDisplayer = displayerInstance;
!             // default to use the config on the mapping
!             if (displayerMapping.getConfig() != null) {
!                 // this value (config) is set on the displayer below
!                 setConfig(displayerMapping.getConfig());
!             }
!         } catch (Exception e) {
!             throw new JspException(e.getMessage());
!         }
  
!         // setup the displayerInstance
!         // if the displayer is a MessageResourceMenuDisplayer
!         // and a bundle is specified, then pass it the bundle (message resources) and
!         // the locale
!         if ((bundleKey != null) &&
!                 (displayerInstance instanceof MessageResourcesMenuDisplayer)) {
!             MessageResourcesMenuDisplayer mrDisplayerInstance =
!                     (MessageResourcesMenuDisplayer) displayerInstance;
!             MessageResources resources =
!                     (MessageResources) pageContext.findAttribute(bundleKey);
!             Locale locale = null;
  
!             if (localeKey == null) {
!                 locale = pageContext.getRequest().getLocale();
!             } else {
!                 locale = (Locale) pageContext.findAttribute(localeKey);
!             }
  
!             mrDisplayerInstance.setMessageResources(resources);
!             mrDisplayerInstance.setLocale(locale);
!         }
  
!         displayerInstance.setConfig(config);
  
!         displayerInstance.init(pageContext, displayerMapping);
!         displayerInstance.setPermissionsAdapter(permissions);
  
!         pageContext.setAttribute(DISPLAYER_KEY, displayerInstance);
  
!         //make the menu repository available to the menu displayers
!         //pageContext.setAttribute(MENU_REPOSITORY_KEY, menuRep);
!         return (EVAL_BODY_INCLUDE);
!     }
  
!     protected PermissionsAdapter getPermissionsAdapter()
!             throws JspException {
!         PermissionsAdapter adapter = null;
  
!         if (permissions != null) {
!             // If set to "rolesAdapter", then create automatically
!             if (permissions.equalsIgnoreCase(ROLES_ADAPTER)) {
!                 adapter =
!                         new RolesPermissionsAdapter((HttpServletRequest) 
pageContext.getRequest());
!             } else {
!                 adapter =
!                         (PermissionsAdapter) pageContext.findAttribute(permissions);
  
!                 if (adapter == null) {
!                     throw new 
JspException(messages.getString("permissions.not.found"));
!                 }
!             }
!         }
  
!         return adapter;
!     }
  
!     public int doEndTag() throws JspException {
!         menuDisplayer.end(pageContext);
!         pageContext.removeAttribute(DISPLAYER_KEY);
!         pageContext.removeAttribute(MENU_REPOSITORY_KEY);
!         // Might have to apply fix for
!         // http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16001
!         // release(); // don't seem to need it at this point...
!         return (EVAL_PAGE);
!     }
  
!     public void release() {
!         if (log.isDebugEnabled()) {
!             log.debug("release() called");
!         }
  
!         super.release();
!         this.menuDisplayer = null;
!         this.bundleKey = null;
!         this.config = MenuDisplayer.DEFAULT_CONFIG;
!         this.localeKey = null;
!         this.name = null;
!         this.menuDisplayer = null;
  
!         //this.repository = MenuRepository.MENU_REPOSITORY_KEY;
!         this.permissions = null;
!     }
  }




-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills.  Sign up for IBM's
Free Linux Tutorials.  Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
_______________________________________________
struts-menu-devel mailing list
[EMAIL PROTECTED]
https://lists.sf.net/lists/listinfo/struts-menu-devel

Reply via email to