KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > administration > CmsAdminMenu


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/administration/CmsAdminMenu.java,v $
3  * Date : $Date: 2006/07/20 10:14:23 $
4  * Version: $Revision: 1.14 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.workplace.administration;
33
34 import org.opencms.jsp.CmsJspActionElement;
35 import org.opencms.main.OpenCms;
36 import org.opencms.util.CmsIdentifiableObjectContainer;
37 import org.opencms.util.CmsStringUtil;
38 import org.opencms.util.I_CmsIdentifiableObjectContainer;
39 import org.opencms.workplace.CmsWorkplace;
40 import org.opencms.workplace.CmsWorkplaceSettings;
41 import org.opencms.workplace.tools.CmsTool;
42 import org.opencms.workplace.tools.CmsToolDialog;
43 import org.opencms.workplace.tools.CmsToolMacroResolver;
44 import org.opencms.workplace.tools.CmsToolManager;
45
46 import java.util.Iterator JavaDoc;
47
48 import javax.servlet.http.HttpServletRequest JavaDoc;
49
50 /**
51  * Implementation of the administration view leftside's menu.<p>
52  *
53  * @author Michael Moossen
54  *
55  * @version $Revision: 1.14 $
56  *
57  * @since 6.0.0
58  */

59 public class CmsAdminMenu extends CmsToolDialog {
60
61     /** Default link target constant. */
62     public static final String JavaDoc DEFAULT_TARGET = "admin_content";
63
64     /** Group container. */
65     private I_CmsIdentifiableObjectContainer m_groupContainer = new CmsIdentifiableObjectContainer(true, true);
66
67     /**
68      * Default Constructor.<p>
69      *
70      * @param jsp the jsp context
71      */

72     public CmsAdminMenu(CmsJspActionElement jsp) {
73
74         super(jsp);
75         try {
76             initAdminTool();
77         } catch (Exception JavaDoc e) {
78             // ignore, only a role violation, not important for left side menu
79
}
80         installMenu();
81     }
82
83     /**
84      * Adds a group.<p>
85      *
86      * @param group the group
87      *
88      * @see I_CmsIdentifiableObjectContainer#addIdentifiableObject(String, Object)
89      */

90     public void addGroup(CmsAdminMenuGroup group) {
91
92         m_groupContainer.addIdentifiableObject(group.getName(), group);
93     }
94
95     /**
96      * Adds a menu item at the given position.<p>
97      *
98      * @param group the group
99      * @param position the position
100      *
101      * @see I_CmsIdentifiableObjectContainer#addIdentifiableObject(String, Object, float)
102      */

103     public void addGroup(CmsAdminMenuGroup group, float position) {
104
105         m_groupContainer.addIdentifiableObject(group.getName(), group, position);
106     }
107
108     /**
109      * Adds a new item to the specified menu.<p>
110      *
111      * If the menu does not exist, it will be created.<p>
112      *
113      * @param groupName the name of the group
114      * @param name the name of the item
115      * @param icon the icon to display
116      * @param link the link to open when selected
117      * @param helpText the help text to display
118      * @param enabled if enabled or not
119      * @param position the relative position to install the item
120      * @param target the target frame to open the link into
121      *
122      * @return the new item
123      */

124     public CmsAdminMenuItem addItem(
125         String JavaDoc groupName,
126         String JavaDoc name,
127         String JavaDoc icon,
128         String JavaDoc link,
129         String JavaDoc helpText,
130         boolean enabled,
131         float position,
132         String JavaDoc target) {
133
134         groupName = CmsToolMacroResolver.resolveMacros(groupName, this);
135         CmsAdminMenuGroup group = getGroup(groupName);
136         if (group == null) {
137             String JavaDoc gid = "group" + m_groupContainer.elementList().size();
138             group = new CmsAdminMenuGroup(gid, groupName);
139             addGroup(group, position);
140         }
141         String JavaDoc id = "item" + group.getId() + group.getMenuItems().size();
142         CmsAdminMenuItem item = new CmsAdminMenuItem(id, name, icon, link, helpText, enabled, target);
143         group.addMenuItem(item, position);
144         return item;
145     }
146
147     /**
148      * Returns the requested group.<p>
149      *
150      * @param name the name of the group
151      *
152      * @return the group
153      *
154      * @see I_CmsIdentifiableObjectContainer#getObject(String)
155      */

156     public CmsAdminMenuGroup getGroup(String JavaDoc name) {
157
158         return (CmsAdminMenuGroup)m_groupContainer.getObject(name);
159     }
160
161     /**
162      * Returns the admin manager.<p>
163      *
164      * @return the admin manager
165      */

166     public CmsToolManager getToolManager() {
167
168         return OpenCms.getWorkplaceManager().getToolManager();
169     }
170
171     /**
172      * Generates the necesary html code for the groups.<p>
173      *
174      * @param wp the page for which the code is generated
175      *
176      * @return html code
177      */

178     public String JavaDoc groupHtml(CmsWorkplace wp) {
179
180         StringBuffer JavaDoc html = new StringBuffer JavaDoc(2048);
181         Iterator JavaDoc itHtml = m_groupContainer.elementList().iterator();
182         while (itHtml.hasNext()) {
183             CmsAdminMenuGroup group = (CmsAdminMenuGroup)itHtml.next();
184             html.append(group.groupHtml(wp));
185         }
186         return html.toString();
187     }
188
189     /**
190      * Creates the default menu as the root tool structure.<p>
191      */

192     public void installMenu() {
193
194         // initialize the menu groups
195
m_groupContainer.clear();
196
197         // creates the context help menu
198
CmsAdminMenuGroup helpMenu = new CmsAdminMenuGroup("help", Messages.get().getBundle(getLocale()).key(
199             Messages.GUI_ADMIN_MENU_HELP_GROUP_0));
200         helpMenu.addMenuItem(new CmsAdminContextHelpMenuItem());
201         addGroup(helpMenu);
202
203         Iterator JavaDoc itElems = getToolManager().getToolsForPath(this, getToolManager().getBaseToolPath(this), false).iterator();
204         while (itElems.hasNext()) {
205             CmsTool tool = (CmsTool)itElems.next();
206             // check visibility
207
String JavaDoc link = tool.getHandler().getLink();
208             if (link.indexOf("?") > 0) {
209                 link = link.substring(0, link.indexOf("?"));
210             }
211             if (!getCms().existsResource(link) || !tool.getHandler().isVisible(getCms())) {
212                 continue;
213             }
214
215             // cut out the base
216
String JavaDoc path = tool.getHandler().getPath().substring(getToolManager().getBaseToolPath(this).length());
217             // special case of the base tool
218
if (CmsStringUtil.isEmpty(path)) {
219                 continue;
220             }
221             // skip initial '/'
222
int pos = tool.getHandler().getPath().indexOf(CmsToolManager.TOOLPATH_SEPARATOR);
223             // only install if at first level
224
if (path.indexOf(CmsToolManager.TOOLPATH_SEPARATOR, pos + 1) < 0) {
225
226                 addItem(
227                     tool.getHandler().getGroup(),
228                     tool.getHandler().getShortName(),
229                     tool.getHandler().getSmallIconPath(),
230                     CmsToolManager.linkForToolPath(getJsp(), tool.getHandler().getPath()),
231                     tool.getHandler().isEnabled(getCms()) ? tool.getHandler().getHelpText()
232                     : tool.getHandler().getDisabledHelpText(),
233                     tool.getHandler().isEnabled(getCms()),
234                     tool.getHandler().getPosition(),
235                     CmsAdminMenu.DEFAULT_TARGET);
236             }
237         }
238     }
239
240     /**
241      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
242      */

243     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
244
245         fillParamValues(request);
246     }
247 }
Popular Tags