001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/workplace/broadcast/CmsBroadcastMessageDialog.java,v $
003: * Date : $Date: 2008-02-27 12:05:54 $
004: * Version: $Revision: 1.11 $
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.jsp.CmsJspActionElement;
035: import org.opencms.main.OpenCms;
036: import org.opencms.util.CmsStringUtil;
037: import org.opencms.widgets.CmsDisplayWidget;
038: import org.opencms.widgets.CmsTextareaWidget;
039: import org.opencms.workplace.CmsWidgetDialogParameter;
040: import org.opencms.workplace.list.CmsHtmlList;
041:
042: import java.util.ArrayList;
043: import java.util.Iterator;
044: import java.util.List;
045:
046: import javax.servlet.http.HttpServletRequest;
047: import javax.servlet.http.HttpServletResponse;
048: import javax.servlet.jsp.PageContext;
049:
050: /**
051: * Dialog to edit a message to broadcast in the administration view.<p>
052: *
053: * @author Michael Moossen
054: *
055: * @version $Revision: 1.11 $
056: *
057: * @since 6.0.0
058: */
059: public class CmsBroadcastMessageDialog extends A_CmsMessageDialog {
060:
061: /** localized messages Keys prefix. */
062: public static final String KEY_PREFIX = "message";
063:
064: /**
065: * Public constructor with JSP action element.<p>
066: *
067: * @param jsp an initialized JSP action element
068: */
069: public CmsBroadcastMessageDialog(CmsJspActionElement jsp) {
070:
071: super (jsp);
072: }
073:
074: /**
075: * Public constructor with JSP variables.<p>
076: *
077: * @param context the JSP page context
078: * @param req the JSP request
079: * @param res the JSP response
080: */
081: public CmsBroadcastMessageDialog(PageContext context,
082: HttpServletRequest req, HttpServletResponse res) {
083:
084: this (new CmsJspActionElement(context, req, res));
085: }
086:
087: /**
088: * Commits the edited project to the db.<p>
089: */
090: public void actionCommit() {
091:
092: List errors = new ArrayList();
093:
094: try {
095: if (isForAll()) {
096: OpenCms.getSessionManager().sendBroadcast(getCms(),
097: m_msgInfo.getMsg());
098: } else {
099: List ids = CmsStringUtil.splitAsList(
100: getParamSessionids(),
101: CmsHtmlList.ITEM_SEPARATOR);
102: Iterator itIds = ids.iterator();
103: while (itIds.hasNext()) {
104: String id = itIds.next().toString();
105: OpenCms.getSessionManager().sendBroadcast(getCms(),
106: m_msgInfo.getMsg(), id);
107: }
108: }
109: } catch (Throwable t) {
110: errors.add(t);
111: }
112: // set the list of errors to display when saving failed
113: setCommitErrors(errors);
114: }
115:
116: /**
117: * @see org.opencms.workplace.CmsWidgetDialog#createDialogHtml(java.lang.String)
118: */
119: protected String createDialogHtml(String dialog) {
120:
121: StringBuffer result = new StringBuffer(1024);
122:
123: result.append(createWidgetTableStart());
124: // show error header once if there were validation errors
125: result.append(createWidgetErrorHeader());
126:
127: if (dialog.equals(PAGES[0])) {
128: // create the widgets for the first dialog page
129: result
130: .append(dialogBlockStart(key(Messages.GUI_MESSAGE_EDITOR_LABEL_HEADER_BLOCK_0)));
131: result.append(createWidgetTableStart());
132: result.append(createDialogRowsHtml(0, 1));
133: result.append(createWidgetTableEnd());
134: result.append(dialogBlockEnd());
135: result
136: .append(dialogBlockStart(key(Messages.GUI_MESSAGE_EDITOR_LABEL_CONTENT_BLOCK_0)));
137: result.append(createWidgetTableStart());
138: result.append(createDialogRowsHtml(2, 2));
139: result.append(createWidgetTableEnd());
140: result.append(dialogBlockEnd());
141: }
142:
143: result.append(createWidgetTableEnd());
144: return result.toString();
145: }
146:
147: /**
148: * Creates the list of widgets for this dialog.<p>
149: */
150: protected void defineWidgets() {
151:
152: // initialize the project object to use for the dialog
153: initMessageObject();
154:
155: setKeyPrefix(KEY_PREFIX);
156:
157: addWidget(new CmsWidgetDialogParameter(m_msgInfo, "from",
158: PAGES[0], new CmsDisplayWidget()));
159: addWidget(new CmsWidgetDialogParameter(m_msgInfo, "to",
160: PAGES[0], new CmsDisplayWidget()));
161: addWidget(new CmsWidgetDialogParameter(m_msgInfo, "msg",
162: PAGES[0], new CmsTextareaWidget(12)));
163: }
164: }
|