001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/accounts/CmsGroupDependenciesList.java,v $
003: * Date : $Date: 2008-02-27 12:05:25 $
004: * Version: $Revision: 1.7 $
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.CmsGroup;
035: import org.opencms.file.CmsResource;
036: import org.opencms.file.CmsUser;
037: import org.opencms.i18n.CmsMessageContainer;
038: import org.opencms.jsp.CmsJspActionElement;
039: import org.opencms.main.CmsException;
040: import org.opencms.main.CmsRuntimeException;
041: import org.opencms.security.CmsAccessControlEntry;
042: import org.opencms.util.CmsStringUtil;
043: import org.opencms.util.CmsUUID;
044: import org.opencms.workplace.CmsDialog;
045: import org.opencms.workplace.CmsWorkplaceSettings;
046: import org.opencms.workplace.list.A_CmsListDialog;
047: import org.opencms.workplace.list.CmsHtmlList;
048: import org.opencms.workplace.list.CmsListColumnAlignEnum;
049: import org.opencms.workplace.list.CmsListColumnDefinition;
050: import org.opencms.workplace.list.CmsListDirectAction;
051: import org.opencms.workplace.list.CmsListItem;
052: import org.opencms.workplace.list.CmsListItemActionIconComparator;
053: import org.opencms.workplace.list.CmsListMetadata;
054: import org.opencms.workplace.list.CmsListOrderEnum;
055: import org.opencms.workplace.tools.CmsIdentifiableObjectContainer;
056:
057: import java.io.IOException;
058: import java.util.HashMap;
059: import java.util.Iterator;
060: import java.util.List;
061: import java.util.Map;
062:
063: import javax.servlet.ServletException;
064: import javax.servlet.http.HttpServletRequest;
065: import javax.servlet.http.HttpServletResponse;
066: import javax.servlet.jsp.JspException;
067: import javax.servlet.jsp.PageContext;
068:
069: /**
070: * Group dependencies list view.<p>
071: *
072: * @author Michael Moossen
073: *
074: * @version $Revision: 1.7 $
075: *
076: * @since 6.0.0
077: */
078: public class CmsGroupDependenciesList extends A_CmsListDialog {
079:
080: /** Value for the delete action. */
081: public static final int ACTION_DELETE = 131;
082:
083: /** Value for the transfer action. */
084: public static final int ACTION_TRANSFER = 132;
085:
086: /** Request parameter value for the delete action. */
087: public static final String DELETE_ACTION = "delete";
088:
089: /** list action id constant. */
090: public static final String LIST_ACTION_ICON = "ai";
091:
092: /** list column id constant. */
093: public static final String LIST_COLUMN_ICON = "ci";
094:
095: /** list column id constant. */
096: public static final String LIST_COLUMN_NAME = "cn";
097:
098: /** list column id constant. */
099: public static final String LIST_COLUMN_TYPE = "ct";
100:
101: /** list column id constant. */
102: public static final String LIST_COLUMN_PERMISSIONS = "cp";
103:
104: /** List id constant. */
105: public static final String LIST_ID = "lgd";
106:
107: /** Request parameter name for the group id, could be a list of ids. */
108: public static final String PARAM_GROUPID = "groupid";
109:
110: /** Path to the list buttons. */
111: public static final String PATH_BUTTONS = "tools/accounts/buttons/";
112:
113: /** Request parameter value for the transfer action. */
114: public static final String TRANSFER_ACTION = "transfer";
115:
116: /** Stores the value of the group name, could be a list of names. */
117: private String m_groupName;
118:
119: /** Stores the value of the request parameter for the group id, could be a list of ids. */
120: private String m_paramGroupid;
121:
122: /**
123: * Public constructor.<p>
124: *
125: * @param jsp an initialized JSP action element
126: */
127: public CmsGroupDependenciesList(CmsJspActionElement jsp) {
128:
129: this (LIST_ID, jsp);
130: }
131:
132: /**
133: * Public constructor with JSP variables.<p>
134: *
135: * @param context the JSP page context
136: * @param req the JSP request
137: * @param res the JSP response
138: */
139: public CmsGroupDependenciesList(PageContext context,
140: HttpServletRequest req, HttpServletResponse res) {
141:
142: this (new CmsJspActionElement(context, req, res));
143: }
144:
145: /**
146: * Protected constructor.<p>
147: *
148: * @param listId the id of the specialized list
149: * @param jsp an initialized JSP action element
150: */
151: protected CmsGroupDependenciesList(String listId,
152: CmsJspActionElement jsp) {
153:
154: super (jsp, listId, Messages.get().container(
155: Messages.GUI_GROUP_DEPENDENCIES_LIST_NAME_0),
156: LIST_COLUMN_NAME, CmsListOrderEnum.ORDER_ASCENDING,
157: LIST_COLUMN_NAME);
158: }
159:
160: /**
161: * @see org.opencms.workplace.list.A_CmsListDialog#actionDialog()
162: */
163: public void actionDialog() throws JspException, ServletException,
164: IOException {
165:
166: switch (getAction()) {
167: case ACTION_DELETE:
168: Iterator it = CmsStringUtil.splitAsList(getGroupName(),
169: CmsHtmlList.ITEM_SEPARATOR, true).iterator();
170: while (it.hasNext()) {
171: String name = (String) it.next();
172: try {
173: getCms().deleteGroup(name);
174: } catch (CmsException e) {
175: throw new CmsRuntimeException(e
176: .getMessageContainer(), e);
177: }
178: }
179: setAction(ACTION_CANCEL);
180: actionCloseDialog();
181: break;
182: case ACTION_TRANSFER:
183: Map params = new HashMap();
184: // set action parameter to initial dialog call
185: params
186: .put(CmsDialog.PARAM_ACTION,
187: CmsDialog.DIALOG_INITIAL);
188: // forward to the select replacement screen
189: params.put(PARAM_GROUPID, getParamGroupid());
190: getToolManager().jspForwardPage(
191: this ,
192: getJsp().getRequestContext().getFolderUri()
193: + "group_transfer.jsp", params);
194: break;
195:
196: default:
197: super .actionDialog();
198: }
199: }
200:
201: /**
202: * @see org.opencms.workplace.list.A_CmsListDialog#defaultActionHtmlContent()
203: */
204: public String defaultActionHtmlContent() {
205:
206: if (getList().getTotalSize() > 0) {
207: return super .defaultActionHtmlContent();
208: }
209: return "";
210: }
211:
212: /**
213: * @see org.opencms.workplace.list.A_CmsListDialog#executeListMultiActions()
214: */
215: public void executeListMultiActions() {
216:
217: throwListUnsupportedActionException();
218: }
219:
220: /**
221: * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
222: */
223: public void executeListSingleActions() {
224:
225: throwListUnsupportedActionException();
226: }
227:
228: /**
229: * Returns the group Name.<p>
230: *
231: * @return the group Name
232: */
233: public String getGroupName() {
234:
235: return m_groupName;
236: }
237:
238: /**
239: * Returns the group id parameter value.<p>
240: *
241: * @return the group id parameter value
242: */
243: public String getParamGroupid() {
244:
245: return m_paramGroupid;
246: }
247:
248: /**
249: * Sets the group id parameter value.<p>
250: *
251: * @param groupId the group id parameter value
252: */
253: public void setParamGroupid(String groupId) {
254:
255: m_paramGroupid = groupId;
256: }
257:
258: /**
259: * @see org.opencms.workplace.list.A_CmsListDialog#customHtmlEnd()
260: */
261: protected String customHtmlEnd() {
262:
263: StringBuffer result = new StringBuffer(512);
264: result.append(super .customHtmlEnd());
265: result.append("<form name='actions' method='post' action='");
266: result.append(getDialogRealUri());
267: result
268: .append("' class='nomargin' onsubmit=\"return submitAction('ok', null, 'actions');\">\n");
269: result.append(allParamsAsHidden());
270: result.append(dialogButtonRow(HTML_START));
271: result.append("<input name='");
272: result.append(DELETE_ACTION);
273: result.append("' type='button' value='");
274: result.append(Messages.get().container(
275: Messages.GUI_DEPENDENCIES_BUTTON_DELETE_0).key(
276: getLocale()));
277: result.append("' onclick=\"submitAction('");
278: result.append(DELETE_ACTION);
279: result.append("', form);\" class='dialogbutton'>\n");
280: if (getList().getTotalSize() > 0) {
281: result.append("<input name='");
282: result.append(TRANSFER_ACTION);
283: result.append("' type='button' value='");
284: result.append(Messages.get().container(
285: Messages.GUI_DEPENDENCIES_BUTTON_TRANSFER_0).key(
286: getLocale()));
287: result.append("' onclick=\"submitAction('");
288: result.append(TRANSFER_ACTION);
289: result.append("', form);\" class='dialogbutton'>\n");
290: }
291: dialogButtonsHtml(result, BUTTON_CANCEL, "");
292: result.append(dialogButtonRow(HTML_END));
293: result.append("</form>\n");
294: return result.toString();
295: }
296:
297: /**
298: * @see org.opencms.workplace.list.A_CmsListDialog#customHtmlStart()
299: */
300: protected String customHtmlStart() {
301:
302: StringBuffer result = new StringBuffer(512);
303: result.append(dialogBlockStart(Messages.get().container(
304: Messages.GUI_GROUP_DEPENDENCIES_NOTICE_0).key(
305: getLocale())));
306: if (getCurrentToolPath().indexOf("/edit/") < 0) {
307: result
308: .append(key(Messages.GUI_GROUP_DEPENDENCIES_SELECTED_GROUPS_0));
309: result.append(":<br>\n");
310: List users = CmsStringUtil.splitAsList(getGroupName(),
311: CmsHtmlList.ITEM_SEPARATOR, true);
312: result.append("<ul>\n");
313: Iterator it = users.iterator();
314: while (it.hasNext()) {
315: String name = (String) it.next();
316: result.append("<li>");
317: result.append(name);
318: result.append("</li>\n");
319: }
320: result.append("</ul>\n");
321: }
322: if (getList().getTotalSize() > 0) {
323: result
324: .append(key(Messages.GUI_GROUP_DEPENDENCIES_NOTICE_TEXT_0));
325: } else {
326: result
327: .append(key(Messages.GUI_GROUP_DEPENDENCIES_DELETE_0));
328: }
329: result.append(dialogBlockEnd());
330: return result.toString();
331: }
332:
333: /**
334: * @see org.opencms.workplace.list.A_CmsListDialog#fillDetails(java.lang.String)
335: */
336: protected void fillDetails(String detailId) {
337:
338: // no-op
339: }
340:
341: /**
342: * @see org.opencms.workplace.list.A_CmsListDialog#getListItems()
343: */
344: protected List getListItems() throws CmsException {
345:
346: CmsIdentifiableObjectContainer ret = new CmsIdentifiableObjectContainer(
347: true, false);
348: Iterator itGroups = CmsStringUtil.splitAsList(
349: getParamGroupid(), CmsHtmlList.ITEM_SEPARATOR, true)
350: .iterator();
351: String storedSiteRoot = getCms().getRequestContext()
352: .getSiteRoot();
353: try {
354: getCms().getRequestContext().setSiteRoot("/");
355: while (itGroups.hasNext()) {
356: CmsGroup group = getCms().readGroup(
357: new CmsUUID(itGroups.next().toString()));
358: // get content
359: List resources = getCms().getResourcesForPrincipal(
360: group.getId(), null, true);
361: Iterator itRes = resources.iterator();
362: while (itRes.hasNext()) {
363: CmsResource resource = (CmsResource) itRes.next();
364: CmsListItem item = (CmsListItem) ret
365: .getObject(resource.getResourceId()
366: .toString());
367: if (item == null) {
368: item = getList().newItem(
369: resource.getResourceId().toString());
370: item.set(LIST_COLUMN_NAME, resource
371: .getRootPath());
372: item.set(LIST_COLUMN_TYPE, new Integer(resource
373: .getTypeId()));
374: Iterator itAces = getCms()
375: .getAccessControlEntries(
376: resource.getRootPath(), false)
377: .iterator();
378: while (itAces.hasNext()) {
379: CmsAccessControlEntry ace = (CmsAccessControlEntry) itAces
380: .next();
381: if (ace.getPrincipal()
382: .equals(group.getId())) {
383: if (CmsStringUtil
384: .isNotEmptyOrWhitespaceOnly(ace
385: .getPermissions()
386: .getPermissionString())) {
387: item
388: .set(
389: LIST_COLUMN_PERMISSIONS,
390: group.getName()
391: + ": "
392: + ace
393: .getPermissions()
394: .getPermissionString());
395: }
396: break;
397: }
398: }
399: ret.addIdentifiableObject(item.getId(), item);
400: } else {
401: String oldData = (String) item
402: .get(LIST_COLUMN_PERMISSIONS);
403: Iterator itAces = getCms()
404: .getAccessControlEntries(
405: resource.getRootPath(), false)
406: .iterator();
407: while (itAces.hasNext()) {
408: CmsAccessControlEntry ace = (CmsAccessControlEntry) itAces
409: .next();
410: if (ace.getPrincipal()
411: .equals(group.getId())) {
412: if (CmsStringUtil
413: .isNotEmptyOrWhitespaceOnly(ace
414: .getPermissions()
415: .getPermissionString())) {
416: String data = group.getName()
417: + ": "
418: + ace
419: .getPermissions()
420: .getPermissionString();
421: if (oldData != null) {
422: data = oldData + ", " + data;
423: }
424: item.set(LIST_COLUMN_PERMISSIONS,
425: data);
426: }
427: break;
428: }
429: }
430: }
431: }
432: // add users
433: Iterator itUsers = getCms().getUsersOfGroup(
434: group.getName()).iterator();
435: while (itUsers.hasNext()) {
436: CmsUser user = (CmsUser) itUsers.next();
437: CmsListItem item = (CmsListItem) ret.getObject(user
438: .getId().toString());
439: if (item == null) {
440: item = getList().newItem(
441: user.getId().toString());
442: item.set(LIST_COLUMN_NAME, user.getName());
443: item.set(LIST_COLUMN_PERMISSIONS, "--");
444: ret.addIdentifiableObject(item.getId(), item);
445: }
446: }
447: // add child groups
448: Iterator itChildren = getCms().getChildren(
449: group.getName(), false).iterator();
450: while (itChildren.hasNext()) {
451: CmsGroup child = (CmsGroup) itChildren.next();
452: CmsListItem item = (CmsListItem) ret
453: .getObject(child.getId().toString());
454: if (item == null) {
455: item = getList().newItem(
456: child.getId().toString());
457: item.set(LIST_COLUMN_NAME, child.getName());
458: item.set(LIST_COLUMN_PERMISSIONS, "--");
459: ret.addIdentifiableObject(item.getId(), item);
460: }
461: }
462: }
463: } finally {
464: getCms().getRequestContext().setSiteRoot(storedSiteRoot);
465: }
466: return ret.elementList();
467: }
468:
469: /**
470: * @see org.opencms.workplace.CmsWorkplace#initMessages()
471: */
472: protected void initMessages() {
473:
474: // add specific dialog resource bundle
475: addMessages(Messages.get().getBundleName());
476: // add cms dialog resource bundle
477: addMessages(org.opencms.workplace.Messages.get()
478: .getBundleName());
479: // add default resource bundles
480: super .initMessages();
481: }
482:
483: /**
484: * @see org.opencms.workplace.list.A_CmsListDialog#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
485: */
486: protected void initWorkplaceRequestValues(
487: CmsWorkplaceSettings settings, HttpServletRequest request) {
488:
489: super .initWorkplaceRequestValues(settings, request);
490: if (DELETE_ACTION.equals(getParamAction())) {
491: setAction(ACTION_DELETE);
492: } else if (TRANSFER_ACTION.equals(getParamAction())) {
493: setAction(ACTION_TRANSFER);
494: }
495: }
496:
497: /**
498: * @see org.opencms.workplace.list.A_CmsListDialog#setColumns(org.opencms.workplace.list.CmsListMetadata)
499: */
500: protected void setColumns(CmsListMetadata metadata) {
501:
502: // create column for edit
503: CmsListColumnDefinition iconCol = new CmsListColumnDefinition(
504: LIST_COLUMN_ICON);
505: iconCol.setName(Messages.get().container(
506: Messages.GUI_GROUP_DEPENDENCIES_LIST_COLS_ICON_0));
507: iconCol.setHelpText(Messages.get().container(
508: Messages.GUI_GROUP_DEPENDENCIES_LIST_COLS_ICON_HELP_0));
509: iconCol.setWidth("20");
510: iconCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
511: iconCol
512: .setListItemComparator(new CmsListItemActionIconComparator());
513:
514: // add icon actions
515: setIconActions(iconCol);
516:
517: // add it to the list definition
518: metadata.addColumn(iconCol);
519:
520: // add column for name
521: CmsListColumnDefinition nameCol = new CmsListColumnDefinition(
522: LIST_COLUMN_NAME);
523: nameCol.setName(Messages.get().container(
524: Messages.GUI_GROUP_DEPENDENCIES_LIST_COLS_NAME_0));
525: nameCol.setWidth("80%");
526: metadata.addColumn(nameCol);
527:
528: // add column for permissions
529: CmsListColumnDefinition permissionsCol = new CmsListColumnDefinition(
530: LIST_COLUMN_PERMISSIONS);
531: permissionsCol
532: .setName(Messages
533: .get()
534: .container(
535: Messages.GUI_GROUP_DEPENDENCIES_LIST_COLS_PERMISSIONS_0));
536: permissionsCol.setWidth("20%");
537: metadata.addColumn(permissionsCol);
538:
539: // add column for type
540: CmsListColumnDefinition typeCol = new CmsListColumnDefinition(
541: LIST_COLUMN_TYPE);
542: typeCol.setName(new CmsMessageContainer(null, "type"));
543: typeCol.setVisible(false);
544: metadata.addColumn(typeCol);
545: }
546:
547: /**
548: * Sets the right icon actions for the dialog.<p>
549: *
550: * @param iconCol the column to set the actions
551: */
552: protected void setIconActions(CmsListColumnDefinition iconCol) {
553:
554: // add resource icon action
555: CmsListDirectAction resourceIconAction = new CmsDependencyIconAction(
556: LIST_ACTION_ICON, CmsDependencyIconActionType.RESOURCE,
557: getCms());
558: resourceIconAction
559: .setName(Messages
560: .get()
561: .container(
562: Messages.GUI_GROUP_DEPENDENCIES_LIST_ACTION_RES_NAME_0));
563: resourceIconAction
564: .setHelpText(Messages
565: .get()
566: .container(
567: Messages.GUI_GROUP_DEPENDENCIES_LIST_ACTION_RES_HELP_0));
568: resourceIconAction.setEnabled(false);
569: iconCol.addDirectAction(resourceIconAction);
570:
571: // add group icon action
572: CmsListDirectAction groupIconAction = new CmsDependencyIconAction(
573: LIST_ACTION_ICON, CmsDependencyIconActionType.GROUP,
574: getCms());
575: groupIconAction
576: .setName(Messages
577: .get()
578: .container(
579: Messages.GUI_GROUP_DEPENDENCIES_LIST_ACTION_GRP_NAME_0));
580: groupIconAction
581: .setHelpText(Messages
582: .get()
583: .container(
584: Messages.GUI_GROUP_DEPENDENCIES_LIST_ACTION_GRP_HELP_0));
585: groupIconAction.setEnabled(false);
586: iconCol.addDirectAction(groupIconAction);
587:
588: // add group icon action
589: CmsListDirectAction userIconAction = new CmsDependencyIconAction(
590: LIST_ACTION_ICON, CmsDependencyIconActionType.USER,
591: getCms());
592: userIconAction
593: .setName(Messages
594: .get()
595: .container(
596: Messages.GUI_GROUP_DEPENDENCIES_LIST_ACTION_USR_NAME_0));
597: userIconAction
598: .setHelpText(Messages
599: .get()
600: .container(
601: Messages.GUI_GROUP_DEPENDENCIES_LIST_ACTION_USR_HELP_0));
602: userIconAction.setEnabled(false);
603: iconCol.addDirectAction(userIconAction);
604: }
605:
606: /**
607: * @see org.opencms.workplace.list.A_CmsListDialog#setIndependentActions(org.opencms.workplace.list.CmsListMetadata)
608: */
609: protected void setIndependentActions(CmsListMetadata metadata) {
610:
611: // no-op
612: }
613:
614: /**
615: * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata)
616: */
617: protected void setMultiActions(CmsListMetadata metadata) {
618:
619: // no-op
620: }
621:
622: /**
623: * @see org.opencms.workplace.list.A_CmsListDialog#validateParamaters()
624: */
625: protected void validateParamaters() throws Exception {
626:
627: // test the needed parameters
628: m_groupName = "";
629: Iterator itGroups = CmsStringUtil.splitAsList(
630: getParamGroupid(), CmsHtmlList.ITEM_SEPARATOR, true)
631: .iterator();
632: while (itGroups.hasNext()) {
633: CmsUUID id = new CmsUUID(itGroups.next().toString());
634: m_groupName += getCms().readGroup(id).getName();
635: if (itGroups.hasNext()) {
636: m_groupName += CmsHtmlList.ITEM_SEPARATOR;
637: }
638: }
639: }
640: }
|