KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > tools > workplace > broadcast > A_CmsMessageDialog


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/workplace/broadcast/A_CmsMessageDialog.java,v $
3  * Date : $Date: 2005/06/27 23:22:23 $
4  * Version: $Revision: 1.6 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.workplace.tools.workplace.broadcast;
33
34 import org.opencms.jsp.CmsJspActionElement;
35 import org.opencms.main.CmsSessionInfo;
36 import org.opencms.main.OpenCms;
37 import org.opencms.util.CmsStringUtil;
38 import org.opencms.workplace.CmsWidgetDialog;
39 import org.opencms.workplace.CmsWorkplaceSettings;
40 import org.opencms.workplace.list.CmsHtmlList;
41
42 import java.util.ArrayList JavaDoc;
43 import java.util.Iterator JavaDoc;
44 import java.util.List JavaDoc;
45
46 import javax.servlet.http.HttpServletRequest JavaDoc;
47
48 /**
49  * Base dialog to edit a message info object.<p>
50  *
51  * @author Michael Moossen
52  *
53  * @version $Revision: 1.6 $
54  *
55  * @since 6.0.0
56  */

57 public abstract class A_CmsMessageDialog extends CmsWidgetDialog {
58
59     /** Defines which pages are valid for this dialog. */
60     public static final String JavaDoc[] PAGES = {"page1"};
61
62     /** Request parameter name for the list of session ids. */
63     public static final String JavaDoc PARAM_SESSIONIDS = "sessionids";
64
65     /** Message info object. */
66     protected CmsMessageInfo m_msgInfo;
67
68     /** Stores the value of the request parameter for the list of session ids. */
69     private String JavaDoc m_paramSessionids;
70
71     /**
72      * Public constructor with JSP action element.<p>
73      *
74      * @param jsp an initialized JSP action element
75      */

76     public A_CmsMessageDialog(CmsJspActionElement jsp) {
77
78         super(jsp);
79     }
80
81     /**
82      * Returns the list of session ids parameter value.<p>
83      *
84      * @return the list of session ids parameter value
85      */

86     public String JavaDoc getParamSessionids() {
87
88         return m_paramSessionids;
89     }
90
91     /**
92      * Sets the list of session ids parameter value.<p>
93      *
94      * @param sessionIds the list of session ids parameter value
95      */

96     public void setParamSessionids(String JavaDoc sessionIds) {
97
98         m_paramSessionids = sessionIds;
99     }
100
101     /**
102      * @see org.opencms.workplace.CmsWidgetDialog#getPageArray()
103      */

104     protected String JavaDoc[] getPageArray() {
105
106         return PAGES;
107     }
108
109     /**
110      * Returns a semicolon separated list of user names.<p>
111      *
112      * @return a semicolon separated list of user names
113      */

114     protected String JavaDoc getToNames() {
115
116         List users = new ArrayList JavaDoc();
117         Iterator JavaDoc itIds = idsList().iterator();
118         while (itIds.hasNext()) {
119             String JavaDoc id = itIds.next().toString();
120             CmsSessionInfo session = OpenCms.getSessionManager().getSessionInfo(id);
121             if (session != null) {
122                 String JavaDoc userName = session.getUser().getFullName();
123                 if (!users.contains(userName)) {
124                     users.add(userName);
125                 }
126             }
127         }
128         StringBuffer JavaDoc result = new StringBuffer JavaDoc(256);
129         Iterator JavaDoc itUsers = users.iterator();
130         while (itUsers.hasNext()) {
131             result.append(itUsers.next().toString());
132             if (itUsers.hasNext()) {
133                 result.append("; ");
134             }
135         }
136         return result.toString();
137     }
138
139     /**
140      * Returns the list of session ids.<p>
141      *
142      * @return the list of session ids
143      */

144     protected List idsList() {
145
146         if (!isForAll()) {
147             return CmsStringUtil.splitAsList(getParamSessionids(), CmsHtmlList.ITEM_SEPARATOR);
148         }
149         List ids = new ArrayList JavaDoc();
150         Iterator JavaDoc itSessions = OpenCms.getSessionManager().getSessionInfos().iterator();
151         while (itSessions.hasNext()) {
152             ids.add(((CmsSessionInfo)itSessions.next()).getSessionId());
153         }
154         return ids;
155     }
156
157     /**
158      * Initializes the message info object to work with depending on the dialog state and request parameters.<p>
159      */

160     protected void initMessageObject() {
161
162         Object JavaDoc o = null;
163
164         try {
165             // this is not the initial call, get the message info object from session
166
o = getDialogObject();
167             m_msgInfo = (CmsMessageInfo)o;
168             // test
169
m_msgInfo.getTo();
170         } catch (Exception JavaDoc e) {
171             // create a new message info object
172
m_msgInfo = new CmsMessageInfo();
173         }
174         m_msgInfo.setFrom(getCms().getRequestContext().currentUser().getFullName());
175         m_msgInfo.setTo(getToNames());
176     }
177
178     /**
179      * @see org.opencms.workplace.CmsWorkplace#initMessages()
180      */

181     protected void initMessages() {
182
183         // add specific dialog resource bundle
184
addMessages(Messages.get().getBundleName());
185         addMessages(org.opencms.workplace.tools.workplace.Messages.get().getBundleName());
186         // add default resource bundles
187
super.initMessages();
188     }
189
190     /**
191      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
192      */

193     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
194
195         // initialize parameters and dialog actions in super implementation
196
super.initWorkplaceRequestValues(settings, request);
197
198         // save the current state of the message (may be changed because of the widget values)
199
setDialogObject(m_msgInfo);
200     }
201
202     /**
203      * Checks if the edited message has to be sent to all sessions.<p>
204      *
205      * @return <code>true</code> if the edited message has to be sent to all sessions
206      */

207     protected boolean isForAll() {
208
209         return CmsStringUtil.isEmptyOrWhitespaceOnly(getParamSessionids());
210     }
211 }
Popular Tags