KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > navigation > tags > MenuTag


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.navigation.tags;
21
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
24
25 import javax.servlet.http.HttpServletRequest JavaDoc;
26 import javax.servlet.http.HttpSession JavaDoc;
27 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
28
29 import com.sslexplorer.core.AvailableMenuItem;
30 import com.sslexplorer.core.CoreMenuTree;
31 import com.sslexplorer.navigation.NavigationBar;
32 import com.sslexplorer.navigation.NavigationManager;
33 import com.sslexplorer.security.Constants;
34
35 public class MenuTag extends TagSupport JavaDoc {
36
37     String JavaDoc name;
38     String JavaDoc submenu;
39     String JavaDoc hide;
40
41     public MenuTag() {
42     }
43
44     public void setName(String JavaDoc name) {
45         this.name = name;
46     }
47
48     public int doStartTag() {
49         return (EVAL_BODY_INCLUDE);
50     }
51
52     public int doEndTag() {
53
54         HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc) pageContext.getRequest();
55         HttpSession JavaDoc session = request.getSession();
56
57         // If the main navigation has not been configured, then configure it
58
if (session.getAttribute(Constants.MENU_TREE) == null) {
59             session.setAttribute(Constants.MENU_TREE, NavigationManager.getMenuTree(CoreMenuTree.MENU_ITEM_MENU_TREE).rebuildMenus(
60                             request));
61         }
62         pageContext.getRequest().removeAttribute(Constants.SELECTED_MENU);
63         List JavaDoc menus = (List JavaDoc) pageContext.getSession().getAttribute(Constants.MENU_TREE);
64         if (menus == null) {
65         } else {
66             AvailableMenuItem it = findAvailableMenuItem(menus);
67             if (it != null) {
68                 pageContext.getRequest().setAttribute(Constants.SELECTED_MENU, it);
69             }
70         }
71
72         session.setAttribute(Constants.NAV_BAR, NavigationManager.getMenuTree(NavigationBar.NAV_BAR_MENU_TREE)
73                         .rebuildMenus(request));
74
75         return (EVAL_PAGE);
76     }
77
78     private AvailableMenuItem findAvailableMenuItem(List JavaDoc l) {
79         for (Iterator JavaDoc i = l.iterator(); i.hasNext();) {
80             AvailableMenuItem item = (AvailableMenuItem) i.next();
81             if (item.getMenuItem().getId().equals(name)) {
82                 return item;
83             }
84             AvailableMenuItem f = findAvailableMenuItem(item);
85             if (f != null) {
86                 return f;
87             }
88         }
89         return null;
90     }
91
92 }
Popular Tags