KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/workplace/broadcast/CmsBroadcastMessageDialog.java,v $
3  * Date : $Date: 2005/06/27 23:22:23 $
4  * Version: $Revision: 1.9 $
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.OpenCms;
36 import org.opencms.util.CmsStringUtil;
37 import org.opencms.widgets.CmsDisplayWidget;
38 import org.opencms.widgets.CmsTextareaWidget;
39 import org.opencms.workplace.CmsWidgetDialogParameter;
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 import javax.servlet.http.HttpServletResponse JavaDoc;
48 import javax.servlet.jsp.PageContext JavaDoc;
49
50 /**
51  * Dialog to edit a message to broadcast in the administration view.<p>
52  *
53  * @author Michael Moossen
54  *
55  * @version $Revision: 1.9 $
56  *
57  * @since 6.0.0
58  */

59 public class CmsBroadcastMessageDialog extends A_CmsMessageDialog {
60
61     /** localized messages Keys prefix. */
62     public static final String JavaDoc KEY_PREFIX = "message";
63
64     /**
65      * Public constructor with JSP action element.<p>
66      *
67      * @param jsp an initialized JSP action element
68      */

69     public CmsBroadcastMessageDialog(CmsJspActionElement jsp) {
70
71         super(jsp);
72     }
73
74     /**
75      * Public constructor with JSP variables.<p>
76      *
77      * @param context the JSP page context
78      * @param req the JSP request
79      * @param res the JSP response
80      */

81     public CmsBroadcastMessageDialog(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
82
83         this(new CmsJspActionElement(context, req, res));
84     }
85
86     /**
87      * Commits the edited project to the db.<p>
88      */

89     public void actionCommit() {
90
91         List errors = new ArrayList JavaDoc();
92
93         try {
94             if (isForAll()) {
95                 OpenCms.getSessionManager().sendBroadcast(getCms(), m_msgInfo.getMsg());
96             } else {
97                 List ids = CmsStringUtil.splitAsList(getParamSessionids(), CmsHtmlList.ITEM_SEPARATOR);
98                 Iterator JavaDoc itIds = ids.iterator();
99                 while (itIds.hasNext()) {
100                     String JavaDoc id = itIds.next().toString();
101                     OpenCms.getSessionManager().sendBroadcast(getCms(), m_msgInfo.getMsg(), id);
102                 }
103             }
104         } catch (Throwable JavaDoc t) {
105             errors.add(t);
106         }
107         // set the list of errors to display when saving failed
108
setCommitErrors(errors);
109     }
110
111     /**
112      * @see org.opencms.workplace.CmsWidgetDialog#createDialogHtml(java.lang.String)
113      */

114     protected String JavaDoc createDialogHtml(String JavaDoc dialog) {
115
116         StringBuffer JavaDoc result = new StringBuffer JavaDoc(1024);
117
118         result.append(createWidgetTableStart());
119         // show error header once if there were validation errors
120
result.append(createWidgetErrorHeader());
121
122         if (dialog.equals(PAGES[0])) {
123             // create the widgets for the first dialog page
124
result.append(dialogBlockStart(key(Messages.GUI_MESSAGE_EDITOR_LABEL_HEADER_BLOCK_0)));
125             result.append(createWidgetTableStart());
126             result.append(createDialogRowsHtml(0, 1));
127             result.append(createWidgetTableEnd());
128             result.append(dialogBlockEnd());
129             result.append(dialogBlockStart(key(Messages.GUI_MESSAGE_EDITOR_LABEL_CONTENT_BLOCK_0)));
130             result.append(createWidgetTableStart());
131             result.append(createDialogRowsHtml(2, 2));
132             result.append(createWidgetTableEnd());
133             result.append(dialogBlockEnd());
134         }
135
136         result.append(createWidgetTableEnd());
137         return result.toString();
138     }
139
140     /**
141      * Creates the list of widgets for this dialog.<p>
142      */

143     protected void defineWidgets() {
144
145         // initialize the project object to use for the dialog
146
initMessageObject();
147
148         setKeyPrefix(KEY_PREFIX);
149
150         addWidget(new CmsWidgetDialogParameter(m_msgInfo, "from", PAGES[0], new CmsDisplayWidget()));
151         addWidget(new CmsWidgetDialogParameter(m_msgInfo, "to", PAGES[0], new CmsDisplayWidget()));
152         addWidget(new CmsWidgetDialogParameter(m_msgInfo, "msg", PAGES[0], new CmsTextareaWidget(12)));
153     }
154 }
Popular Tags