001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/accounts/CmsRolesList.java,v $
003: * Date : $Date: 2008-02-27 12:05:26 $
004: * Version: $Revision: 1.4 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.workplace.tools.accounts;
033:
034: import org.opencms.file.CmsUser;
035: import org.opencms.i18n.CmsMessageContainer;
036: import org.opencms.jsp.CmsJspActionElement;
037: import org.opencms.main.CmsException;
038: import org.opencms.main.CmsRuntimeException;
039: import org.opencms.main.OpenCms;
040: import org.opencms.security.CmsRole;
041: import org.opencms.workplace.CmsDialog;
042: import org.opencms.workplace.list.CmsListDefaultAction;
043: import org.opencms.workplace.list.CmsListItem;
044: import org.opencms.workplace.list.CmsListItemDetails;
045: import org.opencms.workplace.list.CmsListItemDetailsFormatter;
046: import org.opencms.workplace.list.CmsListMetadata;
047:
048: import java.io.IOException;
049: import java.util.HashMap;
050: import java.util.Iterator;
051: import java.util.List;
052: import java.util.Map;
053:
054: import javax.servlet.ServletException;
055: import javax.servlet.http.HttpServletRequest;
056: import javax.servlet.http.HttpServletResponse;
057: import javax.servlet.jsp.PageContext;
058:
059: /**
060: * Roles overview view.<p>
061: *
062: * @author Raphael Schnuck
063: *
064: * @version $Revision: 1.4 $
065: *
066: * @since 6.5.6
067: */
068: public class CmsRolesList extends A_CmsRolesList {
069:
070: /** list action id constant. */
071: public static final String LIST_DEFACTION_OVERVIEW = "do";
072:
073: /** list item detail id constant. */
074: public static final String LIST_DETAIL_USERS = "du";
075:
076: /** list id constant. */
077: public static final String LIST_ID = "lsrs";
078:
079: /** Request parameter name for the role name. */
080: public static final String PARAM_ROLE = "role";
081:
082: /**
083: * Public constructor.<p>
084: *
085: * @param jsp an initialized JSP action element
086: */
087: public CmsRolesList(CmsJspActionElement jsp) {
088:
089: this (jsp, LIST_ID);
090: }
091:
092: /**
093: * Public constructor.<p>
094: *
095: * @param jsp an initialized JSP action element
096: * @param listId the id of the list
097: */
098: public CmsRolesList(CmsJspActionElement jsp, String listId) {
099:
100: this (jsp, listId, Messages.get().container(
101: Messages.GUI_ROLEEDIT_LIST_NAME_0));
102: }
103:
104: /**
105: * Public constructor with JSP variables.<p>
106: *
107: * @param context the JSP page context
108: * @param req the JSP request
109: * @param res the JSP response
110: */
111: public CmsRolesList(PageContext context, HttpServletRequest req,
112: HttpServletResponse res) {
113:
114: this (new CmsJspActionElement(context, req, res));
115: }
116:
117: /**
118: * Public constructor.<p>
119: *
120: * @param jsp an initialized JSP action element
121: * @param listId the id of the list
122: * @param listName the name of the list
123: */
124: protected CmsRolesList(CmsJspActionElement jsp, String listId,
125: CmsMessageContainer listName) {
126:
127: super (jsp, listId, listName);
128: }
129:
130: /**
131: * @see org.opencms.workplace.list.A_CmsListDialog#executeListMultiActions()
132: */
133: public void executeListMultiActions() throws CmsRuntimeException {
134:
135: throw new UnsupportedOperationException();
136: }
137:
138: /**
139: * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
140: */
141: public void executeListSingleActions() throws IOException,
142: ServletException, CmsRuntimeException {
143:
144: String roleName = getSelectedItem().get(LIST_COLUMN_GROUP_NAME)
145: .toString();
146: Map params = new HashMap();
147: params.put(A_CmsOrgUnitDialog.PARAM_OUFQN, getParamOufqn());
148: params.put(PARAM_ROLE, roleName);
149: params.put(CmsDialog.PARAM_ACTION, CmsDialog.DIALOG_INITIAL);
150: if (getParamListAction().equals(LIST_ACTION_ICON)) {
151: try {
152: if (OpenCms.getRoleManager().hasRole(getCms(),
153: CmsRole.valueOf(getCms().readGroup(roleName)))) {
154: // forward to the edit user screen
155: getToolManager().jspForwardTool(this ,
156: getCurrentToolPath() + "/overview/edit",
157: params);
158: } else {
159: getToolManager().jspForwardTool(this ,
160: getCurrentToolPath() + "/overview", params);
161: }
162: } catch (CmsException e) {
163: // noop
164: }
165: } else if (getParamListAction().equals(LIST_DEFACTION_OVERVIEW)) {
166: // forward to the overview screen
167: getToolManager().jspForwardTool(this ,
168: getCurrentToolPath() + "/overview", params);
169: } else {
170: throwListUnsupportedActionException();
171: }
172: listSave();
173: }
174:
175: /**
176: * Returns the path of the edit icon.<p>
177: *
178: * @return the path of the edit icon
179: */
180: public String getEditIcon() {
181:
182: return PATH_BUTTONS + "user.png";
183: }
184:
185: /**
186: * @see org.opencms.workplace.tools.accounts.A_CmsRolesList#getIconPath(org.opencms.workplace.list.CmsListItem)
187: */
188: public String getIconPath(CmsListItem item) {
189:
190: return PATH_BUTTONS + "role.png";
191: }
192:
193: /**
194: * @see org.opencms.workplace.list.A_CmsListDialog#fillDetails(java.lang.String)
195: */
196: protected void fillDetails(String detailId) {
197:
198: if (!detailId.equals(LIST_DETAIL_USERS)) {
199: super .fillDetails(detailId);
200: return;
201: }
202: // get content
203: List roles = getList().getAllContent();
204: Iterator itRoles = roles.iterator();
205: while (itRoles.hasNext()) {
206: CmsListItem item = (CmsListItem) itRoles.next();
207: String roleName = item.get(LIST_COLUMN_GROUP_NAME)
208: .toString();
209: StringBuffer html = new StringBuffer(512);
210: try {
211: if (detailId.equals(LIST_DETAIL_USERS)) {
212: CmsRole role = CmsRole.valueOf(getCms().readGroup(
213: roleName));
214: List users = OpenCms.getRoleManager()
215: .getUsersOfRole(getCms(), role, true, true);
216: Iterator itUsers = users.iterator();
217: while (itUsers.hasNext()) {
218: CmsUser user = (CmsUser) itUsers.next();
219: if (user.getOuFqn().equals(getParamOufqn())) {
220: html.append(user.getSimpleName());
221: } else {
222: html.append(user.getDisplayName(getCms(),
223: getLocale()));
224: }
225: if (itUsers.hasNext()) {
226: html.append("<br>");
227: }
228: html.append("\n");
229: }
230: } else {
231: continue;
232: }
233: } catch (Exception e) {
234: // noop
235: }
236: item.set(detailId, html.toString());
237: }
238: }
239:
240: /**
241: * @see org.opencms.workplace.tools.accounts.A_CmsRolesList#getRoles()
242: */
243: protected List getRoles() throws CmsException {
244:
245: return OpenCms.getRoleManager().getRoles(getCms(),
246: getParamOufqn(), false);
247: }
248:
249: /**
250: * @see org.opencms.workplace.list.A_CmsListDialog#setColumns(org.opencms.workplace.list.CmsListMetadata)
251: */
252: protected void setColumns(CmsListMetadata metadata) {
253:
254: super .setColumns(metadata);
255:
256: // create default overview action
257: CmsListDefaultAction defOverviewAction = new CmsListDefaultAction(
258: LIST_DEFACTION_OVERVIEW);
259: defOverviewAction.setName(Messages.get().container(
260: Messages.GUI_ROLEEDIT_LIST_DEFACTION_OVERVIEW_NAME_0));
261: defOverviewAction.setHelpText(Messages.get().container(
262: Messages.GUI_ROLEEDIT_LIST_DEFACTION_OVERVIEW_HELP_0));
263: metadata.getColumnDefinition(LIST_COLUMN_NAME)
264: .addDefaultAction(defOverviewAction);
265:
266: // activate icon action and set a more descriptive help text
267: metadata.getColumnDefinition(LIST_COLUMN_ICON).getDirectAction(
268: LIST_ACTION_ICON).setEnabled(true);
269: metadata.getColumnDefinition(LIST_COLUMN_ICON).setHelpText(
270: Messages.get().container(
271: Messages.GUI_ROLEEDIT_LIST_COLS_EDIT_HELP_0));
272: }
273:
274: /**
275: * @see org.opencms.workplace.tools.accounts.A_CmsRolesList#includeOuDetails()
276: */
277: protected boolean includeOuDetails() {
278:
279: return false;
280: }
281:
282: /**
283: * @see org.opencms.workplace.list.A_CmsListDialog#setIndependentActions(org.opencms.workplace.list.CmsListMetadata)
284: */
285: protected void setIndependentActions(CmsListMetadata metadata) {
286:
287: super .setIndependentActions(metadata);
288:
289: // add users details
290: CmsListItemDetails usersDetails = new CmsListItemDetails(
291: LIST_DETAIL_USERS);
292: usersDetails.setAtColumn(LIST_COLUMN_NAME);
293: usersDetails.setVisible(false);
294: usersDetails.setShowActionName(Messages.get().container(
295: Messages.GUI_ROLES_DETAIL_SHOW_USERS_NAME_0));
296: usersDetails.setShowActionHelpText(Messages.get().container(
297: Messages.GUI_ROLES_DETAIL_SHOW_USERS_HELP_0));
298: usersDetails.setHideActionName(Messages.get().container(
299: Messages.GUI_ROLES_DETAIL_HIDE_USERS_NAME_0));
300: usersDetails.setHideActionHelpText(Messages.get().container(
301: Messages.GUI_ROLES_DETAIL_HIDE_USERS_HELP_0));
302: usersDetails.setName(Messages.get().container(
303: Messages.GUI_ROLES_DETAIL_USERS_NAME_0));
304: usersDetails.setFormatter(new CmsListItemDetailsFormatter(
305: Messages.get().container(
306: Messages.GUI_ROLES_DETAIL_USERS_NAME_0)));
307: metadata.addItemDetails(usersDetails);
308: }
309:
310: /**
311: * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata)
312: */
313: protected void setMultiActions(CmsListMetadata metadata) {
314:
315: // noop
316: }
317: }
|