001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/workplace/broadcast/CmsSessionsList.java,v $
003: * Date : $Date: 2008-02-27 12:05:53 $
004: * Version: $Revision: 1.17 $
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.workplace.broadcast;
033:
034: import org.opencms.file.CmsUser;
035: import org.opencms.jsp.CmsJspActionElement;
036: import org.opencms.main.CmsException;
037: import org.opencms.main.CmsSessionInfo;
038: import org.opencms.main.OpenCms;
039: import org.opencms.util.CmsUUID;
040: import org.opencms.workplace.CmsDialog;
041: import org.opencms.workplace.list.A_CmsListDialog;
042: import org.opencms.workplace.list.CmsListColumnAlignEnum;
043: import org.opencms.workplace.list.CmsListColumnDefinition;
044: import org.opencms.workplace.list.CmsListDateMacroFormatter;
045: import org.opencms.workplace.list.CmsListDefaultAction;
046: import org.opencms.workplace.list.CmsListDirectAction;
047: import org.opencms.workplace.list.CmsListItem;
048: import org.opencms.workplace.list.CmsListItemActionIconComparator;
049: import org.opencms.workplace.list.CmsListItemDetails;
050: import org.opencms.workplace.list.CmsListItemDetailsFormatter;
051: import org.opencms.workplace.list.CmsListMetadata;
052: import org.opencms.workplace.list.CmsListMultiAction;
053: import org.opencms.workplace.list.CmsListOrderEnum;
054: import org.opencms.workplace.list.CmsListTimeIntervalFormatter;
055:
056: import java.io.IOException;
057: import java.util.ArrayList;
058: import java.util.Date;
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: import javax.servlet.http.HttpServletRequest;
066: import javax.servlet.http.HttpServletResponse;
067: import javax.servlet.jsp.PageContext;
068:
069: /**
070: * Session list for broadcasting messages.<p>
071: *
072: * @author Michael Moossen
073: *
074: * @version $Revision: 1.17 $
075: *
076: * @since 6.0.0
077: */
078: public class CmsSessionsList extends A_CmsListDialog {
079:
080: /** list action id constant. */
081: public static final String LIST_ACTION_MESSAGE = "am";
082:
083: /** list action id constant. */
084: public static final String LIST_ACTION_PENDING_DISABLED = "apd";
085:
086: /** list action id constant. */
087: public static final String LIST_ACTION_PENDING_ENABLED = "ape";
088:
089: /** list column id constant. */
090: public static final String LIST_COLUMN_CREATION = "cc";
091:
092: /** list column id constant. */
093: public static final String LIST_COLUMN_INACTIVE = "ci";
094:
095: /** list column id constant. */
096: public static final String LIST_COLUMN_MESSAGE = "cm";
097:
098: /** list column id constant. */
099: public static final String LIST_COLUMN_ORGUNIT = "cou";
100:
101: /** list column id constant. */
102: public static final String LIST_COLUMN_PENDING = "cp";
103:
104: /** list column id constant. */
105: public static final String LIST_COLUMN_PROJECT = "cj";
106:
107: /** list column id constant. */
108: public static final String LIST_COLUMN_SITE = "cs";
109:
110: /** list column id constant. */
111: public static final String LIST_COLUMN_USER = "cu";
112:
113: /** list action id constant. */
114: public static final String LIST_DEFACTION_MESSAGE = "dm";
115:
116: /** list column id constant. */
117: public static final String LIST_DETAIL_EMAIL = "de";
118:
119: /** list id constant. */
120: public static final String LIST_ID = "ls";
121:
122: /** list action id constant. */
123: public static final String LIST_MACTION_EMAIL = "me";
124:
125: /** list action id constant. */
126: public static final String LIST_MACTION_MESSAGE = "mm";
127:
128: /** Path to the list buttons. */
129: public static final String PATH_BUTTONS = "tools/workplace/buttons/";
130:
131: /**
132: * Public constructor.<p>
133: *
134: * @param jsp an initialized JSP action element
135: */
136: public CmsSessionsList(CmsJspActionElement jsp) {
137:
138: super (jsp, LIST_ID, Messages.get().container(
139: Messages.GUI_SESSIONS_LIST_NAME_0), LIST_COLUMN_USER,
140: CmsListOrderEnum.ORDER_ASCENDING, LIST_COLUMN_USER);
141: }
142:
143: /**
144: * Public constructor with JSP variables.<p>
145: *
146: * @param context the JSP page context
147: * @param req the JSP request
148: * @param res the JSP response
149: */
150: public CmsSessionsList(PageContext context, HttpServletRequest req,
151: HttpServletResponse res) {
152:
153: this (new CmsJspActionElement(context, req, res));
154: }
155:
156: /**
157: * @see org.opencms.workplace.list.A_CmsListDialog#executeListMultiActions()
158: */
159: public void executeListMultiActions() throws IOException,
160: ServletException {
161:
162: Map params = new HashMap();
163: params.put(A_CmsMessageDialog.PARAM_SESSIONIDS,
164: getParamSelItems());
165: // set action parameter to initial dialog call
166: params.put(CmsDialog.PARAM_ACTION, CmsDialog.DIALOG_INITIAL);
167:
168: if (getParamListAction().equals(LIST_MACTION_MESSAGE)) {
169: // execute the send message multiaction
170: // forward to the edit message screen
171: getToolManager().jspForwardTool(this ,
172: "/workplace/broadcast/message", params);
173: } else if (getParamListAction().equals(LIST_MACTION_EMAIL)) {
174: // execute the send email multiaction
175: // forward to the edit email screen
176: getToolManager().jspForwardTool(this ,
177: "/workplace/broadcast/email", params);
178: } else {
179: throwListUnsupportedActionException();
180: }
181: }
182:
183: /**
184: * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
185: */
186: public void executeListSingleActions() throws IOException,
187: ServletException {
188:
189: Map params = new HashMap();
190: params.put(A_CmsMessageDialog.PARAM_SESSIONIDS,
191: getSelectedItem().getId());
192: // set action parameter to initial dialog call
193: params.put(CmsDialog.PARAM_ACTION, CmsDialog.DIALOG_INITIAL);
194:
195: if (getParamListAction().equals(LIST_ACTION_MESSAGE)
196: || getParamListAction().equals(LIST_DEFACTION_MESSAGE)) {
197: getToolManager().jspForwardTool(this ,
198: "/workplace/broadcast/message", params);
199: } else {
200: throwListUnsupportedActionException();
201: }
202: listSave();
203: }
204:
205: /**
206: * @see org.opencms.workplace.list.A_CmsListDialog#fillDetails(java.lang.String)
207: */
208: protected void fillDetails(String detailId) {
209:
210: // get content
211: List sessions = getList().getAllContent();
212: Iterator i = sessions.iterator();
213: while (i.hasNext()) {
214: CmsListItem item = (CmsListItem) i.next();
215: CmsSessionInfo session = OpenCms.getSessionManager()
216: .getSessionInfo(new CmsUUID(item.getId()));
217: StringBuffer html = new StringBuffer(32);
218: if (detailId.equals(LIST_DETAIL_EMAIL)) {
219: // email
220: try {
221: CmsUser user = getCms().readUser(
222: session.getUserId());
223: html.append(user.getEmail());
224: } catch (CmsException e) {
225: // should never happen
226: }
227: } else {
228: continue;
229: }
230: item.set(detailId, html.toString());
231: }
232: }
233:
234: /**
235: * @see org.opencms.workplace.list.A_CmsListDialog#getListItems()
236: */
237: protected List getListItems() throws CmsException {
238:
239: List manageableUsers = OpenCms.getRoleManager()
240: .getManageableUsers(getCms(), "", true);
241: List ret = new ArrayList();
242: // get content
243: List sessionInfos = OpenCms.getSessionManager()
244: .getSessionInfos();
245: Iterator itSessions = sessionInfos.iterator();
246: while (itSessions.hasNext()) {
247: CmsSessionInfo sessionInfo = (CmsSessionInfo) itSessions
248: .next();
249: CmsListItem item = getList().newItem(
250: sessionInfo.getSessionId().toString());
251: CmsUser user = getCms().readUser(sessionInfo.getUserId());
252: if (!manageableUsers.contains(user)) {
253: continue;
254: }
255: item.set(LIST_COLUMN_USER, user.getFullName());
256: item.set(LIST_COLUMN_ORGUNIT, OpenCms.getOrgUnitManager()
257: .readOrganizationalUnit(getCms(), user.getOuFqn())
258: .getDisplayName(getLocale()));
259: item.set(LIST_COLUMN_CREATION, new Date(sessionInfo
260: .getTimeCreated()));
261: item.set(LIST_COLUMN_INACTIVE, new Long(System
262: .currentTimeMillis()
263: - sessionInfo.getTimeUpdated()));
264: try {
265: item.set(LIST_COLUMN_PROJECT, getCms().readProject(
266: sessionInfo.getProject()).getName());
267: } catch (Exception e) {
268: // ignore
269: }
270: item.set(LIST_COLUMN_SITE, sessionInfo.getSiteRoot());
271: ret.add(item);
272: }
273:
274: // hide ou column if only one ou exists
275: try {
276: if (OpenCms.getOrgUnitManager().getOrganizationalUnits(
277: getCms(), "", true).isEmpty()) {
278: getList().getMetadata().getColumnDefinition(
279: LIST_COLUMN_ORGUNIT).setVisible(false);
280: getList().getMetadata().getColumnDefinition(
281: LIST_COLUMN_USER).setWidth("40%");
282: } else {
283: getList().getMetadata().getColumnDefinition(
284: LIST_COLUMN_ORGUNIT).setVisible(true);
285: getList().getMetadata().getColumnDefinition(
286: LIST_COLUMN_USER).setWidth("20%");
287: }
288: } catch (CmsException e) {
289: // noop
290: }
291:
292: return ret;
293: }
294:
295: /**
296: * @see org.opencms.workplace.CmsWorkplace#initMessages()
297: */
298: protected void initMessages() {
299:
300: // add specific dialog resource bundle
301: addMessages(Messages.get().getBundleName());
302: addMessages(org.opencms.workplace.tools.workplace.Messages
303: .get().getBundleName());
304: // add default resource bundles
305: super .initMessages();
306: }
307:
308: /**
309: * @see org.opencms.workplace.list.A_CmsListDialog#setColumns(org.opencms.workplace.list.CmsListMetadata)
310: */
311: protected void setColumns(CmsListMetadata metadata) {
312:
313: // create column for send message
314: CmsListColumnDefinition messageCol = new CmsListColumnDefinition(
315: LIST_COLUMN_MESSAGE);
316: messageCol.setName(Messages.get().container(
317: Messages.GUI_SESSIONS_LIST_COLS_MESSAGE_0));
318: messageCol.setHelpText(Messages.get().container(
319: Messages.GUI_SESSIONS_LIST_COLS_MESSAGE_HELP_0));
320: messageCol.setWidth("20");
321: messageCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
322: messageCol.setSorteable(false);
323: // add send message action
324: CmsListDirectAction messageAction = new CmsListDirectAction(
325: LIST_ACTION_MESSAGE);
326: messageAction.setName(Messages.get().container(
327: Messages.GUI_SESSIONS_LIST_ACTION_MESSAGE_NAME_0));
328: messageAction.setHelpText(Messages.get().container(
329: Messages.GUI_SESSIONS_LIST_ACTION_MESSAGE_HELP_0));
330: messageAction.setIconPath(PATH_BUTTONS + "send_message.png");
331: messageCol.addDirectAction(messageAction);
332: // add it to the list definition
333: metadata.addColumn(messageCol);
334:
335: // create column for pending
336: CmsListColumnDefinition pendingCol = new CmsListColumnDefinition(
337: LIST_COLUMN_PENDING);
338: pendingCol.setName(Messages.get().container(
339: Messages.GUI_SESSIONS_LIST_COLS_PENDING_0));
340: pendingCol.setWidth("20");
341: pendingCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
342: pendingCol
343: .setListItemComparator(new CmsListItemActionIconComparator());
344: // add pending action
345: CmsListDirectAction pendingAction = new CmsListDirectAction(
346: LIST_ACTION_PENDING_ENABLED) {
347:
348: /**
349: * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#isVisible()
350: */
351: public boolean isVisible() {
352:
353: if (getItem() != null) {
354: return !OpenCms.getSessionManager()
355: .getBroadcastQueue(getItem().getId())
356: .isEmpty();
357: }
358: return super .isVisible();
359: }
360: };
361: pendingAction.setName(Messages.get().container(
362: Messages.GUI_SESSIONS_LIST_ACTION_PENDING_NAME_0));
363: pendingAction.setHelpText(Messages.get().container(
364: Messages.GUI_SESSIONS_LIST_ACTION_PENDING_HELP_0));
365: pendingAction.setIconPath(PATH_BUTTONS + "message_pending.png");
366: pendingAction.setEnabled(false);
367: pendingCol.addDirectAction(pendingAction);
368:
369: // not pending action
370: CmsListDirectAction notPendingAction = new CmsListDirectAction(
371: LIST_ACTION_PENDING_DISABLED) {
372:
373: /**
374: * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#isVisible()
375: */
376: public boolean isVisible() {
377:
378: if (getItem() != null) {
379: return OpenCms.getSessionManager()
380: .getBroadcastQueue(getItem().getId())
381: .isEmpty();
382: }
383: return super .isVisible();
384: }
385: };
386: notPendingAction.setName(Messages.get().container(
387: Messages.GUI_SESSIONS_LIST_ACTION_NOTPENDING_NAME_0));
388: notPendingAction.setHelpText(Messages.get().container(
389: Messages.GUI_SESSIONS_LIST_ACTION_NOTPENDING_HELP_0));
390: notPendingAction.setIconPath(PATH_BUTTONS
391: + "message_notpending.png");
392: notPendingAction.setEnabled(false);
393: pendingCol.addDirectAction(notPendingAction);
394:
395: // add it to the list definition
396: metadata.addColumn(pendingCol);
397:
398: // create column for user name
399: CmsListColumnDefinition userCol = new CmsListColumnDefinition(
400: LIST_COLUMN_USER);
401: userCol.setName(Messages.get().container(
402: Messages.GUI_SESSIONS_LIST_COLS_USER_0));
403: //userCol.setWidth("20%");
404:
405: // create default edit message action
406: CmsListDefaultAction messageEditAction = new CmsListDefaultAction(
407: LIST_DEFACTION_MESSAGE);
408: messageEditAction.setName(Messages.get().container(
409: Messages.GUI_SESSIONS_LIST_ACTION_MESSAGE_NAME_0));
410: messageEditAction.setHelpText(Messages.get().container(
411: Messages.GUI_SESSIONS_LIST_ACTION_MESSAGE_HELP_0));
412: userCol.addDefaultAction(messageEditAction);
413: // add it to the list definition
414: metadata.addColumn(userCol);
415:
416: // add column for organizational units
417: CmsListColumnDefinition ouCol = new CmsListColumnDefinition(
418: LIST_COLUMN_ORGUNIT);
419: ouCol.setName(Messages.get().container(
420: Messages.GUI_SESSIONS_LIST_COLS_ORGUNIT_0));
421: ouCol.setWidth("30%");
422: metadata.addColumn(ouCol);
423:
424: // add column for creation date
425: CmsListColumnDefinition creationCol = new CmsListColumnDefinition(
426: LIST_COLUMN_CREATION);
427: creationCol.setName(Messages.get().container(
428: Messages.GUI_SESSIONS_LIST_COLS_CREATION_0));
429: creationCol.setWidth("16%");
430: creationCol.setFormatter(CmsListDateMacroFormatter
431: .getDefaultDateFormatter());
432: metadata.addColumn(creationCol);
433:
434: // add column for inactive time
435: CmsListColumnDefinition inactiveCol = new CmsListColumnDefinition(
436: LIST_COLUMN_INACTIVE);
437: inactiveCol.setName(Messages.get().container(
438: Messages.GUI_SESSIONS_LIST_COLS_INACTIVE_0));
439: inactiveCol.setWidth("10%");
440: inactiveCol.setFormatter(new CmsListTimeIntervalFormatter());
441: metadata.addColumn(inactiveCol);
442:
443: // add column for project
444: CmsListColumnDefinition projectCol = new CmsListColumnDefinition(
445: LIST_COLUMN_PROJECT);
446: projectCol.setName(Messages.get().container(
447: Messages.GUI_SESSIONS_LIST_COLS_PROJECT_0));
448: projectCol.setWidth("12%");
449: metadata.addColumn(projectCol);
450:
451: // add column for site
452: CmsListColumnDefinition siteCol = new CmsListColumnDefinition(
453: LIST_COLUMN_SITE);
454: siteCol.setName(Messages.get().container(
455: Messages.GUI_SESSIONS_LIST_COLS_SITE_0));
456: siteCol.setWidth("12%");
457: metadata.addColumn(siteCol);
458: }
459:
460: /**
461: * @see org.opencms.workplace.list.A_CmsListDialog#setIndependentActions(org.opencms.workplace.list.CmsListMetadata)
462: */
463: protected void setIndependentActions(CmsListMetadata metadata) {
464:
465: // create list item detail
466: CmsListItemDetails emailDetail = new CmsListItemDetails(
467: LIST_DETAIL_EMAIL);
468: emailDetail.setAtColumn(LIST_COLUMN_USER);
469: emailDetail.setVisible(false);
470: emailDetail.setFormatter(new CmsListItemDetailsFormatter(
471: Messages.get().container(
472: Messages.GUI_SESSIONS_LABEL_EMAIL_0)));
473: emailDetail.setShowActionName(Messages.get().container(
474: Messages.GUI_SESSIONS_DETAIL_SHOW_EMAIL_NAME_0));
475: emailDetail.setShowActionHelpText(Messages.get().container(
476: Messages.GUI_SESSIONS_DETAIL_SHOW_EMAIL_HELP_0));
477: emailDetail.setHideActionName(Messages.get().container(
478: Messages.GUI_SESSIONS_DETAIL_HIDE_EMAIL_NAME_0));
479: emailDetail.setHideActionHelpText(Messages.get().container(
480: Messages.GUI_SESSIONS_DETAIL_HIDE_EMAIL_HELP_0));
481: metadata.addItemDetails(emailDetail);
482: }
483:
484: /**
485: * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata)
486: */
487: protected void setMultiActions(CmsListMetadata metadata) {
488:
489: // add message multi action
490: CmsListMultiAction messageMultiAction = new CmsListMultiAction(
491: LIST_MACTION_MESSAGE);
492: messageMultiAction.setName(Messages.get().container(
493: Messages.GUI_SESSIONS_LIST_MACTION_MESSAGE_NAME_0));
494: messageMultiAction.setHelpText(Messages.get().container(
495: Messages.GUI_SESSIONS_LIST_MACTION_MESSAGE_HELP_0));
496: messageMultiAction
497: .setConfirmationMessage(Messages
498: .get()
499: .container(
500: Messages.GUI_SESSIONS_LIST_MACTION_MESSAGE_CONF_0));
501: messageMultiAction.setIconPath(PATH_BUTTONS
502: + "multi_send_message.png");
503: metadata.addMultiAction(messageMultiAction);
504:
505: // add email multi action
506: CmsListMultiAction emailMultiAction = new CmsListMultiAction(
507: LIST_MACTION_EMAIL);
508: emailMultiAction.setName(Messages.get().container(
509: Messages.GUI_SESSIONS_LIST_MACTION_EMAIL_NAME_0));
510: emailMultiAction.setHelpText(Messages.get().container(
511: Messages.GUI_SESSIONS_LIST_MACTION_EMAIL_HELP_0));
512: emailMultiAction
513: .setConfirmationMessage(Messages
514: .get()
515: .container(
516: Messages.GUI_SESSIONS_LIST_MACTION_EMAIL_CONF_0));
517: emailMultiAction.setIconPath(PATH_BUTTONS
518: + "multi_send_email.png");
519: metadata.addMultiAction(emailMultiAction);
520: }
521:
522: }
|