001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/accounts/A_CmsOrgUnitsList.java,v $
003: * Date : $Date: 2008-02-27 12:05:27 $
004: * Version: $Revision: 1.8 $
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.main.OpenCms;
042: import org.opencms.security.CmsOrganizationalUnit;
043: import org.opencms.security.CmsRole;
044: import org.opencms.workplace.CmsDialog;
045: import org.opencms.workplace.list.A_CmsListDialog;
046: import org.opencms.workplace.list.CmsListColumnAlignEnum;
047: import org.opencms.workplace.list.CmsListColumnDefinition;
048: import org.opencms.workplace.list.CmsListDefaultAction;
049: import org.opencms.workplace.list.CmsListDirectAction;
050: import org.opencms.workplace.list.CmsListItem;
051: import org.opencms.workplace.list.CmsListItemDetails;
052: import org.opencms.workplace.list.CmsListItemDetailsFormatter;
053: import org.opencms.workplace.list.CmsListMetadata;
054: import org.opencms.workplace.list.CmsListOrderEnum;
055: import org.opencms.workplace.list.CmsListSearchAction;
056:
057: import java.io.IOException;
058: import java.util.ArrayList;
059: import java.util.HashMap;
060: import java.util.Iterator;
061: import java.util.List;
062: import java.util.Map;
063:
064: import javax.servlet.ServletException;
065:
066: /**
067: * Main organization unit management view.<p>
068: *
069: * @author Raphael Schnuck
070: *
071: * @version $Revision: 1.8 $
072: *
073: * @since 6.5.6
074: */
075: public abstract class A_CmsOrgUnitsList extends A_CmsListDialog {
076:
077: /** list action id constant. */
078: public static final String LIST_ACTION_DEACTIVE = "add";
079:
080: /** list action id constant. */
081: public static final String LIST_ACTION_DELETE = "ad";
082:
083: /** list action id constant. */
084: public static final String LIST_ACTION_EDIT = "ae";
085:
086: /** list action id constant. */
087: public static final String LIST_ACTION_GROUP = "ag";
088:
089: /** list action id constant. */
090: public static final String LIST_ACTION_USER = "au";
091:
092: /** list column id constant. */
093: public static final String LIST_COLUMN_ADMIN = "ca";
094:
095: /** list column id constant. */
096: public static final String LIST_COLUMN_DELETE = "cd";
097:
098: /** list column id constant. */
099: public static final String LIST_COLUMN_DESCRIPTION = "cb";
100:
101: /** list column id constant. */
102: public static final String LIST_COLUMN_EDIT = "ce";
103:
104: /** list column id constant. */
105: public static final String LIST_COLUMN_GROUP = "cg";
106:
107: /** list column id constant. */
108: public static final String LIST_COLUMN_NAME = "cn";
109:
110: /** list column id constant. */
111: public static final String LIST_COLUMN_USER = "cu";
112:
113: /** list column id constant. */
114: public static final String LIST_COLUMN_WEBUSER = "cw";
115:
116: /** list action id constant. */
117: public static final String LIST_DEFACTION_OVERVIEW = "do";
118:
119: /** list item detail id constant. */
120: public static final String LIST_DETAIL_GROUPS = "dg";
121:
122: /** list item detail id constant. */
123: public static final String LIST_DETAIL_RESOURCES = "dr";
124:
125: /** list item detail id constant. */
126: public static final String LIST_DETAIL_USERS = "du";
127:
128: /** list action id constant. */
129: public static final String LIST_MACTION_DELETE = "md";
130:
131: /** Path to the list buttons. */
132: public static final String PATH_BUTTONS = "tools/accounts/buttons/";
133:
134: /**
135: * Public constructor.<p>
136: *
137: * @param jsp an initialized JSP action element
138: * @param listId the id of the list
139: * @param listName the list name
140: */
141: public A_CmsOrgUnitsList(CmsJspActionElement jsp, String listId,
142: CmsMessageContainer listName) {
143:
144: super (jsp, listId, listName, LIST_COLUMN_NAME,
145: CmsListOrderEnum.ORDER_ASCENDING, null);
146: }
147:
148: /**
149: * @see org.opencms.workplace.list.A_CmsListDialog#executeListMultiActions()
150: */
151: public void executeListMultiActions() {
152:
153: Iterator itItems = getSelectedItems().iterator();
154:
155: if (getParamListAction().equals(LIST_MACTION_DELETE)) {
156: while (itItems.hasNext()) {
157: CmsListItem item = (CmsListItem) itItems.next();
158: String ouFqn = item.get(LIST_COLUMN_NAME).toString();
159: try {
160: OpenCms.getOrgUnitManager()
161: .deleteOrganizationalUnit(getCms(),
162: ouFqn.substring(1));
163: } catch (CmsException e) {
164: throw new CmsRuntimeException(Messages.get()
165: .container(Messages.ERR_DELETE_ORGUNIT_1,
166: ouFqn), e);
167: }
168: }
169: } else {
170: throwListUnsupportedActionException();
171: }
172: listSave();
173: }
174:
175: /**
176: * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
177: */
178: public void executeListSingleActions() throws IOException,
179: ServletException {
180:
181: String ouFqn = getSelectedItem().get(LIST_COLUMN_NAME)
182: .toString();
183: Map params = new HashMap();
184: params.put(A_CmsOrgUnitDialog.PARAM_OUFQN, ouFqn.substring(1));
185: params.put(CmsDialog.PARAM_ACTION, CmsDialog.DIALOG_INITIAL);
186: if (getParamListAction().equals(LIST_ACTION_EDIT)) {
187: // forward to the edit user screen
188: getToolManager().jspForwardTool(this ,
189: "/accounts/orgunit/mgmt/edit", params);
190: } else if (getParamListAction().equals(LIST_ACTION_USER)) {
191: // forward to the edit user screen
192: getToolManager().jspForwardTool(this ,
193: "/accounts/orgunit/users", params);
194: } else if (getParamListAction().equals(LIST_ACTION_GROUP)) {
195: // forward to the edit user screen
196: getToolManager().jspForwardTool(this ,
197: "/accounts/orgunit/groups", params);
198: } else if (getParamListAction().equals(LIST_ACTION_DELETE)) {
199: // forward to the edit user screen
200: getToolManager().jspForwardTool(this ,
201: "/accounts/orgunit/mgmt/delete", params);
202: } else if (getParamListAction().equals(LIST_DEFACTION_OVERVIEW)) {
203: // forward to the edit user screen
204: getToolManager().jspForwardTool(this , "/accounts/orgunit",
205: params);
206: } else {
207: throwListUnsupportedActionException();
208: }
209: listSave();
210: }
211:
212: /**
213: * Returns the path of the edit icon.<p>
214: *
215: * @return the path of the edit icon
216: */
217: public String getEditIcon() {
218:
219: return PATH_BUTTONS + "orgunit.png";
220: }
221:
222: /**
223: * Returns the path of the group icon.<p>
224: *
225: * @return the path of the group icon
226: */
227: public String getGroupIcon() {
228:
229: return PATH_BUTTONS + "group.png";
230: }
231:
232: /**
233: * Returns the path of the user icon.<p>
234: *
235: * @return the path of the user icon
236: */
237: public String getUserIcon() {
238:
239: return PATH_BUTTONS + "user.png";
240: }
241:
242: /**
243: * @see org.opencms.workplace.list.A_CmsListDialog#fillDetails(java.lang.String)
244: */
245: protected void fillDetails(String detailId) {
246:
247: // get content
248: List orgUnits = getList().getAllContent();
249: Iterator itOrgUnits = orgUnits.iterator();
250: while (itOrgUnits.hasNext()) {
251: CmsListItem item = (CmsListItem) itOrgUnits.next();
252: String ouFqn = item.get(LIST_COLUMN_NAME).toString();
253: StringBuffer html = new StringBuffer(512);
254: try {
255: if (detailId.equals(LIST_DETAIL_USERS)) {
256: List usersOrgUnit = OpenCms.getOrgUnitManager()
257: .getUsers(getCms(), ouFqn, false);
258: Iterator itUsersOrgUnit = usersOrgUnit.iterator();
259: while (itUsersOrgUnit.hasNext()) {
260: CmsUser user = (CmsUser) itUsersOrgUnit.next();
261: html.append(user.getFullName());
262: if (itUsersOrgUnit.hasNext()) {
263: html.append("<br>");
264: }
265: html.append("\n");
266: }
267: } else if (detailId.equals(LIST_DETAIL_GROUPS)) {
268: List groupsOrgUnit = OpenCms.getOrgUnitManager()
269: .getGroups(getCms(), ouFqn, false);
270: Iterator itGroupsOrgUnit = groupsOrgUnit.iterator();
271: while (itGroupsOrgUnit.hasNext()) {
272: CmsGroup group = (CmsGroup) itGroupsOrgUnit
273: .next();
274: html.append(group.getSimpleName());
275: if (itGroupsOrgUnit.hasNext()) {
276: html.append("<br>");
277: }
278: html.append("\n");
279: }
280: } else if (detailId.equals(LIST_DETAIL_RESOURCES)) {
281: List resourcesOrgUnit = OpenCms.getOrgUnitManager()
282: .getResourcesForOrganizationalUnit(
283: getCms(), ouFqn);
284: Iterator itResourcesOrgUnit = resourcesOrgUnit
285: .iterator();
286: while (itResourcesOrgUnit.hasNext()) {
287: CmsResource resource = (CmsResource) itResourcesOrgUnit
288: .next();
289: html.append(resource.getRootPath());
290: if (itResourcesOrgUnit.hasNext()) {
291: html.append("<br>");
292: }
293: html.append("\n");
294: }
295: } else {
296: continue;
297: }
298: } catch (Exception e) {
299: // noop
300: }
301: item.set(detailId, html.toString());
302: }
303: }
304:
305: /**
306: * @see org.opencms.workplace.list.A_CmsListDialog#getListItems()
307: */
308: protected List getListItems() throws CmsException {
309:
310: List ret = new ArrayList();
311: List orgUnits = getOrgUnits();
312: Iterator itOrgUnits = orgUnits.iterator();
313: while (itOrgUnits.hasNext()) {
314: CmsOrganizationalUnit childOrgUnit = (CmsOrganizationalUnit) itOrgUnits
315: .next();
316: CmsListItem item = getList()
317: .newItem(childOrgUnit.getName());
318: item.set(LIST_COLUMN_NAME, CmsOrganizationalUnit.SEPARATOR
319: + childOrgUnit.getName());
320: item.set(LIST_COLUMN_DESCRIPTION, childOrgUnit
321: .getDescription(getLocale()));
322: item.set(LIST_COLUMN_ADMIN, Boolean
323: .valueOf(OpenCms.getRoleManager()
324: .hasRole(
325: getCms(),
326: CmsRole.ADMINISTRATOR
327: .forOrgUnit(childOrgUnit
328: .getName()))));
329: item.set(LIST_COLUMN_WEBUSER, Boolean.valueOf(childOrgUnit
330: .hasFlagWebuser()));
331: ret.add(item);
332: }
333: return ret;
334: }
335:
336: /**
337: * Returns the organizational units to display.<p>
338: *
339: * @return the organizational units
340: *
341: * @throws CmsException if something goes wrong
342: */
343: protected List getOrgUnits() throws CmsException {
344:
345: return OpenCms.getRoleManager().getOrgUnitsForRole(getCms(),
346: CmsRole.ACCOUNT_MANAGER.forOrgUnit(""), true);
347: }
348:
349: /**
350: * @see org.opencms.workplace.list.A_CmsListDialog#setColumns(org.opencms.workplace.list.CmsListMetadata)
351: */
352: protected void setColumns(CmsListMetadata metadata) {
353:
354: // create column for edit
355: CmsListColumnDefinition editCol = new CmsListColumnDefinition(
356: LIST_COLUMN_EDIT);
357: editCol.setName(Messages.get().container(
358: Messages.GUI_ORGUNITS_LIST_COLS_EDIT_0));
359: editCol.setHelpText(Messages.get().container(
360: Messages.GUI_ORGUNITS_LIST_COLS_EDIT_HELP_0));
361: editCol.setWidth("20");
362: editCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
363: editCol.setSorteable(false);
364: // add edit action
365: CmsListDirectAction editAction = new CmsListDirectAction(
366: LIST_ACTION_EDIT) {
367:
368: /**
369: * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#getHelpText()
370: */
371: public CmsMessageContainer getHelpText() {
372:
373: if (!isEnabled()) {
374: return Messages
375: .get()
376: .container(
377: Messages.GUI_ORGUNIT_ADMIN_TOOL_DISABLED_EDIT_HELP_0);
378: }
379: return super .getHelpText();
380: }
381:
382: /**
383: * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#getIconPath()
384: */
385: public String getIconPath() {
386:
387: if (getItem() != null) {
388: if (((Boolean) getItem().get(LIST_COLUMN_WEBUSER))
389: .booleanValue()) {
390: return PATH_BUTTONS + "webuser_ou.png";
391: }
392: }
393: return super .getIconPath();
394: }
395:
396: /**
397: * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#isEnabled()
398: */
399: public boolean isEnabled() {
400:
401: if (getItem() != null) {
402: return ((Boolean) getItem().get(LIST_COLUMN_ADMIN))
403: .booleanValue();
404: }
405: return super .isVisible();
406: }
407: };
408: editAction.setName(Messages.get().container(
409: Messages.GUI_ORGUNITS_LIST_ACTION_EDIT_NAME_0));
410: editAction.setHelpText(Messages.get().container(
411: Messages.GUI_ORGUNITS_LIST_COLS_EDIT_HELP_0));
412: editAction.setIconPath(getEditIcon());
413: editCol.addDirectAction(editAction);
414: // add it to the list definition
415: metadata.addColumn(editCol);
416:
417: // create column for user
418: CmsListColumnDefinition userCol = new CmsListColumnDefinition(
419: LIST_COLUMN_USER);
420: userCol.setName(Messages.get().container(
421: Messages.GUI_ORGUNITS_LIST_COLS_USER_0));
422: userCol.setHelpText(Messages.get().container(
423: Messages.GUI_ORGUNITS_LIST_COLS_USER_HELP_0));
424: userCol.setWidth("20");
425: userCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
426: userCol.setSorteable(false);
427: // add user action
428: CmsListDirectAction userAction = new CmsListDirectAction(
429: LIST_ACTION_USER);
430: userAction.setName(Messages.get().container(
431: Messages.GUI_ORGUNITS_LIST_ACTION_USER_NAME_0));
432: userAction.setHelpText(Messages.get().container(
433: Messages.GUI_ORGUNITS_LIST_COLS_USER_HELP_0));
434: userAction.setIconPath(getUserIcon());
435: userCol.addDirectAction(userAction);
436: // add it to the list definition
437: metadata.addColumn(userCol);
438:
439: // create column for group
440: CmsListColumnDefinition groupCol = new CmsListColumnDefinition(
441: LIST_COLUMN_GROUP);
442: groupCol.setName(Messages.get().container(
443: Messages.GUI_ORGUNITS_LIST_COLS_GROUP_0));
444: groupCol.setHelpText(Messages.get().container(
445: Messages.GUI_ORGUNITS_LIST_COLS_GROUP_HELP_0));
446: groupCol.setWidth("20");
447: groupCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
448: groupCol.setSorteable(false);
449: // add group action
450: CmsListDirectAction groupAction = new CmsListDirectAction(
451: LIST_ACTION_GROUP);
452: groupAction.setName(Messages.get().container(
453: Messages.GUI_ORGUNITS_LIST_ACTION_GROUP_NAME_0));
454: groupAction.setHelpText(Messages.get().container(
455: Messages.GUI_ORGUNITS_LIST_COLS_GROUP_HELP_0));
456: groupAction.setIconPath(getGroupIcon());
457: groupCol.addDirectAction(groupAction);
458: // add it to the list definition
459: metadata.addColumn(groupCol);
460:
461: // create column for description
462: CmsListColumnDefinition descCol = new CmsListColumnDefinition(
463: LIST_COLUMN_DESCRIPTION);
464: descCol.setName(Messages.get().container(
465: Messages.GUI_ORGUNITS_LIST_COLS_DESCRIPTION_0));
466: descCol.setWidth("60%");
467: descCol.setSorteable(true);
468: // create default overview action
469: CmsListDefaultAction defOverviewAction = new CmsListDefaultAction(
470: LIST_DEFACTION_OVERVIEW);
471: defOverviewAction.setName(Messages.get().container(
472: Messages.GUI_ORGUNITS_LIST_DEFACTION_OVERVIEW_NAME_0));
473: defOverviewAction.setHelpText(Messages.get().container(
474: Messages.GUI_ORGUNITS_LIST_DEFACTION_OVERVIEW_HELP_0));
475: descCol.addDefaultAction(defOverviewAction);
476: // add it to the list definition
477: metadata.addColumn(descCol);
478:
479: // create column for name / path
480: CmsListColumnDefinition nameCol = new CmsListColumnDefinition(
481: LIST_COLUMN_NAME);
482: nameCol.setName(Messages.get().container(
483: Messages.GUI_ORGUNITS_LIST_COLS_NAME_0));
484: nameCol.setWidth("40%");
485: // add it to the list definition
486: metadata.addColumn(nameCol);
487:
488: // create column for manageable flag
489: CmsListColumnDefinition adminCol = new CmsListColumnDefinition(
490: LIST_COLUMN_ADMIN);
491: adminCol.setVisible(false);
492: metadata.addColumn(adminCol);
493:
494: // create column for webuser flag
495: CmsListColumnDefinition webuserCol = new CmsListColumnDefinition(
496: LIST_COLUMN_WEBUSER);
497: webuserCol.setVisible(false);
498: metadata.addColumn(webuserCol);
499: }
500:
501: /**
502: * @see org.opencms.workplace.list.A_CmsListDialog#setIndependentActions(org.opencms.workplace.list.CmsListMetadata)
503: */
504: protected void setIndependentActions(CmsListMetadata metadata) {
505:
506: // add users details
507: CmsListItemDetails usersDetails = new CmsListItemDetails(
508: LIST_DETAIL_USERS);
509: usersDetails.setAtColumn(LIST_COLUMN_DESCRIPTION);
510: usersDetails.setVisible(false);
511: usersDetails.setShowActionName(Messages.get().container(
512: Messages.GUI_ORGUNITS_DETAIL_SHOW_USERS_NAME_0));
513: usersDetails.setShowActionHelpText(Messages.get().container(
514: Messages.GUI_ORGUNITS_DETAIL_SHOW_USERS_HELP_0));
515: usersDetails.setHideActionName(Messages.get().container(
516: Messages.GUI_ORGUNITS_DETAIL_HIDE_USERS_NAME_0));
517: usersDetails.setHideActionHelpText(Messages.get().container(
518: Messages.GUI_ORGUNITS_DETAIL_HIDE_USERS_HELP_0));
519: usersDetails.setName(Messages.get().container(
520: Messages.GUI_ORGUNITS_DETAIL_USERS_NAME_0));
521: usersDetails.setFormatter(new CmsListItemDetailsFormatter(
522: Messages.get().container(
523: Messages.GUI_ORGUNITS_DETAIL_USERS_NAME_0)));
524: metadata.addItemDetails(usersDetails);
525:
526: // add groups details
527: CmsListItemDetails groupsDetails = new CmsListItemDetails(
528: LIST_DETAIL_GROUPS);
529: groupsDetails.setAtColumn(LIST_COLUMN_DESCRIPTION);
530: groupsDetails.setVisible(false);
531: groupsDetails.setShowActionName(Messages.get().container(
532: Messages.GUI_ORGUNITS_DETAIL_SHOW_GROUPS_NAME_0));
533: groupsDetails.setShowActionHelpText(Messages.get().container(
534: Messages.GUI_ORGUNITS_DETAIL_SHOW_GROUPS_HELP_0));
535: groupsDetails.setHideActionName(Messages.get().container(
536: Messages.GUI_ORGUNITS_DETAIL_HIDE_GROUPS_NAME_0));
537: groupsDetails.setHideActionHelpText(Messages.get().container(
538: Messages.GUI_ORGUNITS_DETAIL_HIDE_GROUPS_HELP_0));
539: groupsDetails.setName(Messages.get().container(
540: Messages.GUI_ORGUNITS_DETAIL_GROUPS_NAME_0));
541: groupsDetails.setFormatter(new CmsListItemDetailsFormatter(
542: Messages.get().container(
543: Messages.GUI_ORGUNITS_DETAIL_GROUPS_NAME_0)));
544: metadata.addItemDetails(groupsDetails);
545:
546: // add resources details
547: CmsListItemDetails resourcesDetails = new CmsListItemDetails(
548: LIST_DETAIL_RESOURCES);
549: resourcesDetails.setAtColumn(LIST_COLUMN_DESCRIPTION);
550: resourcesDetails.setVisible(false);
551: resourcesDetails.setShowActionName(Messages.get().container(
552: Messages.GUI_ORGUNITS_DETAIL_SHOW_RESOURCES_NAME_0));
553: resourcesDetails
554: .setShowActionHelpText(Messages
555: .get()
556: .container(
557: Messages.GUI_ORGUNITS_DETAIL_SHOW_RESOURCES_HELP_0));
558: resourcesDetails.setHideActionName(Messages.get().container(
559: Messages.GUI_ORGUNITS_DETAIL_HIDE_RESOURCES_NAME_0));
560: resourcesDetails
561: .setHideActionHelpText(Messages
562: .get()
563: .container(
564: Messages.GUI_ORGUNITS_DETAIL_HIDE_RESOURCES_HELP_0));
565: resourcesDetails.setName(Messages.get().container(
566: Messages.GUI_ORGUNITS_DETAIL_RESOURCES_NAME_0));
567: resourcesDetails
568: .setFormatter(new CmsListItemDetailsFormatter(
569: Messages
570: .get()
571: .container(
572: Messages.GUI_ORGUNITS_DETAIL_RESOURCES_NAME_0)));
573: metadata.addItemDetails(resourcesDetails);
574:
575: // makes the list searchable
576: CmsListSearchAction searchAction = new CmsListSearchAction(
577: metadata.getColumnDefinition(LIST_COLUMN_NAME));
578: searchAction.addColumn(metadata
579: .getColumnDefinition(LIST_COLUMN_DESCRIPTION));
580: metadata.setSearchAction(searchAction);
581: }
582:
583: /**
584: * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata)
585: */
586: protected void setMultiActions(CmsListMetadata metadata) {
587:
588: // noop
589: }
590:
591: }
|