001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/accounts/CmsShowUserRolesList.java,v $
003: * Date : $Date: 2008-02-27 12:05:26 $
004: * Version: $Revision: 1.5 $
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.i18n.CmsMessageContainer;
035: import org.opencms.jsp.CmsJspActionElement;
036: import org.opencms.main.CmsException;
037: import org.opencms.main.CmsRuntimeException;
038: import org.opencms.main.OpenCms;
039: import org.opencms.security.CmsRole;
040: import org.opencms.util.CmsUUID;
041: import org.opencms.workplace.list.A_CmsListDialog;
042: import org.opencms.workplace.list.CmsListIndependentAction;
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.ArrayList;
050: import java.util.Iterator;
051: import java.util.List;
052:
053: import javax.servlet.http.HttpServletRequest;
054: import javax.servlet.http.HttpServletResponse;
055: import javax.servlet.jsp.PageContext;
056:
057: /**
058: * User roles overview view.<p>
059: *
060: * @author Raphael Schnuck
061: *
062: * @version $Revision: 1.5 $
063: *
064: * @since 6.5.6
065: */
066: public class CmsShowUserRolesList extends A_CmsRolesList {
067:
068: /** list id constant. */
069: public static final String LIST_ID = "lsur";
070:
071: /** Cached value. */
072: private Boolean m_hasRolesInOtherOus;
073:
074: /** Stores the value of the request parameter for the user id. */
075: private String m_paramUserid;
076:
077: /**
078: * Public constructor.<p>
079: *
080: * @param jsp an initialized JSP action element
081: */
082: public CmsShowUserRolesList(CmsJspActionElement jsp) {
083:
084: this (jsp, LIST_ID);
085: }
086:
087: /**
088: * Public constructor.<p>
089: *
090: * @param jsp an initialized JSP action element
091: * @param listId the id of the list
092: */
093: public CmsShowUserRolesList(CmsJspActionElement jsp, String listId) {
094:
095: this (jsp, listId, Messages.get().container(
096: Messages.GUI_USERROLES_LIST_NAME_0));
097: }
098:
099: /**
100: * Public constructor with JSP variables.<p>
101: *
102: * @param context the JSP page context
103: * @param req the JSP request
104: * @param res the JSP response
105: */
106: public CmsShowUserRolesList(PageContext context,
107: HttpServletRequest req, HttpServletResponse res) {
108:
109: this (new CmsJspActionElement(context, req, res));
110: }
111:
112: /**
113: * Public constructor.<p>
114: *
115: * @param jsp an initialized JSP action element
116: * @param listId the id of the list
117: * @param listName the name of the list
118: */
119: protected CmsShowUserRolesList(CmsJspActionElement jsp,
120: String listId, CmsMessageContainer listName) {
121:
122: super (jsp, listId, listName);
123: }
124:
125: /**
126: * @see org.opencms.workplace.list.A_CmsListDialog#executeListMultiActions()
127: */
128: public void executeListMultiActions() throws CmsRuntimeException {
129:
130: throwListUnsupportedActionException();
131: }
132:
133: /**
134: * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
135: */
136: public void executeListSingleActions() throws CmsRuntimeException {
137:
138: throwListUnsupportedActionException();
139: }
140:
141: /**
142: * @see org.opencms.workplace.tools.accounts.A_CmsRolesList#getIconPath(CmsListItem)
143: */
144: public String getIconPath(CmsListItem item) {
145:
146: List roles = getList().getAllContent();
147: Iterator itRoles = roles.iterator();
148: List roleObjects = new ArrayList();
149: try {
150: while (itRoles.hasNext()) {
151: CmsListItem listItem = (CmsListItem) itRoles.next();
152: roleObjects
153: .add(CmsRole.valueOf(getCms().readGroup(
154: (String) listItem
155: .get(LIST_COLUMN_GROUP_NAME))));
156: }
157:
158: CmsRole role = CmsRole.valueOf(getCms().readGroup(
159: (String) item.get(LIST_COLUMN_GROUP_NAME)));
160: if ((role.getParentRole() != null)
161: && roleObjects.contains(role.getParentRole())) {
162: if (role.getOuFqn().equals(getParamOufqn())) {
163: return PATH_BUTTONS + "role_child.png";
164: } else {
165: return PATH_BUTTONS + "role_other_ou_inherit.png";
166: }
167: }
168: if (role.getOuFqn().equals(getParamOufqn())) {
169: return PATH_BUTTONS + "role.png";
170: } else {
171: return PATH_BUTTONS + "role_other_ou.png";
172: }
173: } catch (CmsException e) {
174: return PATH_BUTTONS + "role.png";
175: }
176: }
177:
178: /**
179: * Returns the User id parameter value.<p>
180: *
181: * @return the User id parameter value
182: */
183: public String getParamUserid() {
184:
185: return m_paramUserid;
186: }
187:
188: /**
189: * Sets the User id parameter value.<p>
190: *
191: * @param userid the userid to set
192: */
193: public void setParamUserid(String userid) {
194:
195: m_paramUserid = userid;
196: }
197:
198: /**
199: * @see org.opencms.workplace.list.A_CmsListDialog#writeDialog()
200: */
201: public void writeDialog() throws IOException {
202:
203: try {
204: if (!getCms().readUser(new CmsUUID(getParamUserid()))
205: .isWebuser()) {
206: super .writeDialog();
207: }
208: } catch (CmsException e) {
209: // ignore
210: }
211: }
212:
213: /**
214: * @see org.opencms.workplace.list.A_CmsListDialog#defaultActionHtmlStart()
215: */
216: protected String defaultActionHtmlStart() {
217:
218: return dialogContentStart(getParamTitle());
219: }
220:
221: /**
222: * @see org.opencms.workplace.tools.accounts.A_CmsRolesList#getRoles()
223: */
224: protected List getRoles() throws CmsException {
225:
226: List allRoles = OpenCms.getRoleManager().getRolesOfUser(
227: getCms(),
228: getCms().readUser(new CmsUUID(getParamUserid()))
229: .getName(), "", true, true, false);
230:
231: List childRoles = OpenCms.getRoleManager().getRolesOfUser(
232: getCms(),
233: getCms().readUser(new CmsUUID(getParamUserid()))
234: .getName(), getParamOufqn(), false, false,
235: false);
236:
237: Iterator itChildRoles = childRoles.iterator();
238: while (itChildRoles.hasNext()) {
239: CmsRole role = (CmsRole) itChildRoles.next();
240: if (!allRoles.contains(role)) {
241: allRoles.add(role);
242: }
243: }
244: return allRoles;
245: }
246:
247: /**
248: * Returns true if the list of users has users of other organizational units.<p>
249: *
250: * @return <code>true</code> if the list of users has users of other organizational units
251: */
252: protected boolean hasRolesInOtherOus() {
253:
254: if (m_hasRolesInOtherOus == null) {
255: m_hasRolesInOtherOus = Boolean.FALSE;
256: try {
257: Iterator itRoles = getRoles().iterator();
258: while (itRoles.hasNext()) {
259: CmsRole role = (CmsRole) itRoles.next();
260: if (!role.getOuFqn().equals(getParamOufqn())) {
261: m_hasRolesInOtherOus = Boolean.TRUE;
262: break;
263: }
264: }
265: } catch (Exception e) {
266: // ignore
267: }
268: }
269: return m_hasRolesInOtherOus.booleanValue();
270: }
271:
272: /**
273: * @see org.opencms.workplace.tools.accounts.A_CmsRolesList#includeOuDetails()
274: */
275: protected boolean includeOuDetails() {
276:
277: return false;
278: }
279:
280: /**
281: * @see org.opencms.workplace.tools.accounts.A_CmsRolesList#setIndependentActions(org.opencms.workplace.list.CmsListMetadata)
282: */
283: protected void setIndependentActions(CmsListMetadata metadata) {
284:
285: super .setIndependentActions(metadata);
286:
287: // add other ou button
288: CmsListItemDetails pathDetails = new CmsListItemDetails(
289: LIST_DETAIL_PATH);
290: pathDetails.setAtColumn(LIST_COLUMN_NAME);
291: pathDetails.setVisible(false);
292: pathDetails.setHideAction(new CmsListIndependentAction(
293: LIST_DETAIL_PATH) {
294:
295: /**
296: * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#getIconPath()
297: */
298: public String getIconPath() {
299:
300: return A_CmsListDialog.ICON_DETAILS_HIDE;
301: }
302:
303: /**
304: * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#isVisible()
305: */
306: public boolean isVisible() {
307:
308: return ((CmsShowUserRolesList) getWp())
309: .hasRolesInOtherOus();
310: }
311: });
312: pathDetails.setShowAction(new CmsListIndependentAction(
313: LIST_DETAIL_PATH) {
314:
315: /**
316: * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#getIconPath()
317: */
318: public String getIconPath() {
319:
320: return A_CmsListDialog.ICON_DETAILS_SHOW;
321: }
322:
323: /**
324: * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#isVisible()
325: */
326: public boolean isVisible() {
327:
328: return ((CmsShowUserRolesList) getWp())
329: .hasRolesInOtherOus();
330: }
331: });
332: pathDetails.setShowActionName(Messages.get().container(
333: Messages.GUI_ROLES_DETAIL_SHOW_PATH_NAME_0));
334: pathDetails.setShowActionHelpText(Messages.get().container(
335: Messages.GUI_ROLES_DETAIL_SHOW_PATH_HELP_0));
336: pathDetails.setHideActionName(Messages.get().container(
337: Messages.GUI_ROLES_DETAIL_HIDE_PATH_NAME_0));
338: pathDetails.setHideActionHelpText(Messages.get().container(
339: Messages.GUI_ROLES_DETAIL_HIDE_PATH_HELP_0));
340: pathDetails.setName(Messages.get().container(
341: Messages.GUI_ROLES_DETAIL_PATH_NAME_0));
342: pathDetails.setFormatter(new CmsListItemDetailsFormatter(
343: Messages.get().container(
344: Messages.GUI_ROLES_DETAIL_PATH_NAME_0)));
345: metadata.addItemDetails(pathDetails);
346: }
347:
348: /**
349: * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata)
350: */
351: protected void setMultiActions(CmsListMetadata metadata) {
352:
353: // noop
354: }
355: }
|