001: /*
002: * File : $Source: /usr/local/cvs/alkacon/com.alkacon.opencms.newsletter/src/com/alkacon/opencms/newsletter/admin/CmsNewsletterListSend.java,v $
003: * Date : $Date: 2007-11-30 11:57:27 $
004: * Version: $Revision: 1.7 $
005: *
006: * This file is part of the Alkacon OpenCms Add-On Module Package
007: *
008: * Copyright (c) 2007 Alkacon Software GmbH (http://www.alkacon.com)
009: *
010: * The Alkacon OpenCms Add-On Module Package is free software:
011: * you can redistribute it and/or modify
012: * it under the terms of the GNU General Public License as published by
013: * the Free Software Foundation, either version 3 of the License, or
014: * (at your option) any later version.
015: *
016: * The Alkacon OpenCms Add-On Module Package is distributed
017: * in the hope that it will be useful,
018: * but WITHOUT ANY WARRANTY; without even the implied warranty of
019: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
020: * GNU General Public License for more details.
021: *
022: * You should have received a copy of the GNU General Public License
023: * along with the Alkacon OpenCms Add-On Module Package.
024: * If not, see http://www.gnu.org/licenses/.
025: *
026: * For further information about Alkacon Software GmbH, please see the
027: * company website: http://www.alkacon.com.
028: *
029: * For further information about OpenCms, please see the
030: * project website: http://www.opencms.org.
031: */
032:
033: package com.alkacon.opencms.newsletter.admin;
034:
035: import com.alkacon.opencms.newsletter.CmsNewsletterMail;
036: import com.alkacon.opencms.newsletter.CmsNewsletterManager;
037: import com.alkacon.opencms.newsletter.I_CmsNewsletterMailData;
038:
039: import org.opencms.db.CmsUserSettings;
040: import org.opencms.file.CmsGroup;
041: import org.opencms.jsp.CmsJspActionElement;
042: import org.opencms.main.CmsLog;
043: import org.opencms.util.CmsStringUtil;
044: import org.opencms.util.CmsUUID;
045: import org.opencms.workplace.explorer.CmsExplorer;
046: import org.opencms.workplace.explorer.CmsResourceUtil;
047: import org.opencms.workplace.list.A_CmsListExplorerDialog;
048: import org.opencms.workplace.list.CmsListColumnAlignEnum;
049: import org.opencms.workplace.list.CmsListColumnDefinition;
050: import org.opencms.workplace.list.CmsListDirectAction;
051: import org.opencms.workplace.list.CmsListExplorerColumn;
052: import org.opencms.workplace.list.CmsListMetadata;
053: import org.opencms.workplace.list.CmsListOrderEnum;
054: import org.opencms.workplace.list.I_CmsListResourceCollector;
055:
056: import javax.servlet.http.HttpServletRequest;
057: import javax.servlet.http.HttpServletResponse;
058: import javax.servlet.jsp.PageContext;
059:
060: import org.apache.commons.logging.Log;
061:
062: /**
063: * Newsletter list to select which newsletter is sent.<p>
064: *
065: * @author Andreas Zahner
066: *
067: * @version $Revision $
068: *
069: * @since 7.0.3
070: */
071: public class CmsNewsletterListSend extends A_CmsListExplorerDialog {
072:
073: /** List column id constant. */
074: public static final String LIST_ACTION_SEND = "ease";
075:
076: /** List column id constant. */
077: public static final String LIST_COLUMN_DATA = "ecda";
078:
079: /** List column id constant. */
080: public static final String LIST_COLUMN_SCORE = "cs";
081:
082: /** List column id constant. */
083: public static final String LIST_COLUMN_SEND = "ecse";
084:
085: /** list id constant. */
086: public static final String LIST_ID = "anls";
087:
088: /** Path to the list buttons. */
089: public static final String PATH_BUTTONS = "tools/newsletter/buttons/";
090:
091: /** The internal collector instance. */
092: private I_CmsListResourceCollector m_collector;
093:
094: /** Stores the value of the request parameter for the group id. */
095: private String m_paramGroupId;
096:
097: /** Stores the value of the request parameter for the organizational unit fqn. */
098: private String m_paramOufqn;
099:
100: /**
101: * Public constructor with JSP action element.<p>
102: *
103: * @param jsp an initialized JSP action element
104: */
105: public CmsNewsletterListSend(CmsJspActionElement jsp) {
106:
107: super (jsp, LIST_ID, Messages.get().container(
108: Messages.GUI_NEWSLETTER_LIST_NAME_0),
109: A_CmsListExplorerDialog.LIST_COLUMN_NAME,
110: CmsListOrderEnum.ORDER_ASCENDING, null);
111: }
112:
113: /**
114: * Public constructor with JSP variables.<p>
115: *
116: * @param context the JSP page context
117: * @param req the JSP request
118: * @param res the JSP response
119: */
120: public CmsNewsletterListSend(PageContext context,
121: HttpServletRequest req, HttpServletResponse res) {
122:
123: this (new CmsJspActionElement(context, req, res));
124: }
125:
126: /**
127: * @see org.opencms.workplace.list.A_CmsListDialog#executeListMultiActions()
128: */
129: public void executeListMultiActions() {
130:
131: throwListUnsupportedActionException();
132: }
133:
134: /** The log object for this class. */
135: private static final Log LOG = CmsLog
136: .getLog(CmsNewsletterListSend.class);
137:
138: /**
139: * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
140: */
141: public void executeListSingleActions() {
142:
143: if (getParamListAction().equals(LIST_ACTION_SEND)) {
144: // send the newsletter to the selected list
145: String resourceName = (String) getSelectedItem().get(
146: LIST_COLUMN_NAME);
147: CmsUUID groupId = new CmsUUID(getParamGroupId());
148: try {
149: CmsGroup group = getCms().readGroup(groupId);
150: // generate the newsletter mail and list of recipients
151: I_CmsNewsletterMailData mailData = CmsNewsletterManager
152: .getMailData(getJsp(), group, resourceName);
153: String rootPath = resourceName;
154: if (mailData.getContent() != null) {
155: rootPath = mailData.getContent().getFile()
156: .getRootPath();
157: }
158: if (mailData.isSendable()) {
159: //send the emails to the mailing list group
160: CmsNewsletterMail nlMail = new CmsNewsletterMail(
161: mailData.getEmail(), mailData
162: .getRecipients(), rootPath);
163: nlMail.start();
164: getList().clear();
165: }
166: } catch (Exception e) {
167: // should never happen
168: if (LOG.isErrorEnabled()) {
169: LOG.error(Messages.get().container(
170: Messages.LOG_NEWSLETTER_SEND_FAILED_0), e);
171: }
172: throwListUnsupportedActionException();
173: }
174: } else {
175: throwListUnsupportedActionException();
176: }
177: }
178:
179: /**
180: * @see org.opencms.workplace.list.A_CmsListExplorerDialog#getCollector()
181: */
182: public I_CmsListResourceCollector getCollector() {
183:
184: if (m_collector == null) {
185: m_collector = new CmsNewsletterResourcesCollector(this );
186: // set the right resource util parameters
187: CmsResourceUtil resUtil = getResourceUtil();
188: resUtil.setAbbrevLength(50);
189: resUtil.setSiteMode(CmsResourceUtil.SITE_MODE_MATCHING);
190: }
191: return m_collector;
192: }
193:
194: /**
195: * Returns the value of the request parameter for the group id.<p>
196: *
197: * @return the value of the request parameter for the group id
198: */
199: public String getParamGroupId() {
200:
201: return m_paramGroupId;
202: }
203:
204: /**
205: * Returns the organizational unit fqn parameter value.<p>
206: *
207: * @return the organizational unit fqn parameter value
208: */
209: public String getParamOufqn() {
210:
211: return m_paramOufqn;
212: }
213:
214: /**
215: * Sets the value of the request parameter for the group id.<p>
216: *
217: * @param paramGroupId the value of the request parameter for the group id
218: */
219: public void setParamGroupId(String paramGroupId) {
220:
221: m_paramGroupId = paramGroupId;
222: }
223:
224: /**
225: * Sets the organizational unit fqn parameter value.<p>
226: *
227: * @param ouFqn the organizational unit fqn parameter value
228: */
229: public void setParamOufqn(String ouFqn) {
230:
231: if (ouFqn == null) {
232: ouFqn = "";
233: }
234: m_paramOufqn = ouFqn;
235: }
236:
237: /**
238: * Generates the dialog starting html code.<p>
239: *
240: * @return html code
241: */
242: protected String defaultActionHtmlStart() {
243:
244: StringBuffer result = new StringBuffer(2048);
245: result.append(htmlStart(null));
246: result.append(getList().listJs());
247: result.append(CmsListExplorerColumn.getExplorerStyleDef());
248: result.append("<script language='JavaScript'>\n");
249: result.append(new CmsExplorer(getJsp())
250: .getInitializationHeader());
251: result.append("\ntop.updateWindowStore();\n");
252: result.append("top.displayHead(top.win.head, 0, 1);\n}\n");
253: result.append("</script>");
254: result.append(bodyStart("dialog", "onload='initialize();'"));
255: result.append(dialogStart());
256: result.append(dialogContentStart(getParamTitle()));
257: return result.toString();
258: }
259:
260: /**
261: * @see org.opencms.workplace.list.A_CmsListDialog#fillDetails(java.lang.String)
262: */
263: protected void fillDetails(String detailId) {
264:
265: // no details
266: }
267:
268: /**
269: * @see org.opencms.workplace.CmsWorkplace#initMessages()
270: */
271: protected void initMessages() {
272:
273: // add specific dialog resource bundle
274: addMessages(Messages.get().getBundleName());
275: // add default resource bundles
276: super .initMessages();
277: }
278:
279: /**
280: * @see org.opencms.workplace.list.A_CmsListDialog#setColumns(org.opencms.workplace.list.CmsListMetadata)
281: */
282: protected void setColumns(CmsListMetadata metadata) {
283:
284: super .setColumns(metadata);
285:
286: // add column with send icon
287: CmsListColumnDefinition sendIconCol = new CmsListColumnDefinition(
288: LIST_COLUMN_SEND);
289: sendIconCol.setName(Messages.get().container(
290: Messages.GUI_NEWSLETTER_LIST_COLS_SEND_0));
291: sendIconCol.setHelpText(Messages.get().container(
292: Messages.GUI_NEWSLETTER_LIST_COLS_SEND_HELP_0));
293: sendIconCol.setWidth("20");
294: sendIconCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
295:
296: // add enabled send action
297: CmsListDirectAction sendAction = new CmsListSendNewsletterAction(
298: LIST_ACTION_SEND, LIST_COLUMN_NAME);
299: //sendAction.setName(Messages.get().container(Messages.GUI_NEWSLETTER_LIST_ACTION_SEND_0));
300: //sendAction.setHelpText(Messages.get().container(Messages.GUI_NEWSLETTER_LIST_ACTION_SEND_HELP_0));
301: sendAction.setEnabled(true);
302: //sendAction.setIconPath("tools/newsletter/buttons/newsletter_send.png");
303: sendAction.setConfirmationMessage(Messages.get().container(
304: Messages.GUI_NEWSLETTER_LIST_ACTION_SEND_CONF_0));
305: sendIconCol.addDirectAction(sendAction);
306:
307: CmsListDirectAction nosendAction = new CmsListSendNewsletterAction(
308: LIST_ACTION_SEND + "d", LIST_COLUMN_NAME);
309: nosendAction.setEnabled(false);
310: sendIconCol.addDirectAction(nosendAction);
311:
312: metadata.addColumn(sendIconCol, 0);
313:
314: // add column with information about the send process
315: CmsListColumnDefinition newsletterCol = new CmsListExplorerColumn(
316: LIST_COLUMN_DATA);
317: newsletterCol.setName(Messages.get().container(
318: Messages.GUI_NEWSLETTER_LIST_COLS_DATA_0));
319: newsletterCol.setHelpText(Messages.get().container(
320: Messages.GUI_NEWSLETTER_LIST_COLS_DATA_HELP_0));
321: newsletterCol.setVisible(true);
322: newsletterCol.setSorteable(false);
323: metadata.addColumn(newsletterCol);
324: }
325:
326: /**
327: * @see org.opencms.workplace.list.A_CmsListExplorerDialog#setColumnVisibilities()
328: */
329: protected void setColumnVisibilities() {
330:
331: super .setColumnVisibilities();
332: setColumnVisibility(LIST_COLUMN_EDIT.hashCode(),
333: LIST_COLUMN_EDIT.hashCode());
334:
335: // set visibility of some columns to false, they are not required for the newsletter send list
336: setColumnVisibility(CmsUserSettings.FILELIST_TYPE, 0);
337: setColumnVisibility(CmsUserSettings.FILELIST_TYPE, 0);
338: setColumnVisibility(CmsUserSettings.FILELIST_SIZE, 0);
339: setColumnVisibility(CmsUserSettings.FILELIST_PERMISSIONS, 0);
340: setColumnVisibility(CmsUserSettings.FILELIST_DATE_CREATED, 0);
341: setColumnVisibility(CmsUserSettings.FILELIST_USER_CREATED, 0);
342: setColumnVisibility(CmsUserSettings.FILELIST_STATE, 0);
343: setColumnVisibility(CmsUserSettings.FILELIST_LOCKEDBY, 0);
344: setColumnVisibility(CmsUserSettings.FILELIST_DATE_LASTMODIFIED,
345: 0);
346: setColumnVisibility(CmsUserSettings.FILELIST_DATE_RELEASED, 0);
347: setColumnVisibility(CmsUserSettings.FILELIST_DATE_EXPIRED, 0);
348:
349: // set the visibility of standard columns to false
350: setColumnVisibility(LIST_COLUMN_EDIT.hashCode(), 0);
351: setColumnVisibility(LIST_COLUMN_TYPEICON.hashCode(), 0);
352: setColumnVisibility(LIST_COLUMN_LOCKICON.hashCode(), 0);
353: setColumnVisibility(LIST_COLUMN_PROJSTATEICON.hashCode(), 0);
354: }
355:
356: /**
357: * @see org.opencms.workplace.list.A_CmsListExplorerDialog#setIndependentActions(org.opencms.workplace.list.CmsListMetadata)
358: */
359: protected void setIndependentActions(CmsListMetadata metadata) {
360:
361: // no LIAs
362: }
363:
364: /**
365: * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata)
366: */
367: protected void setMultiActions(CmsListMetadata metadata) {
368:
369: // no LMAs
370: }
371:
372: /**
373: * @see org.opencms.workplace.list.A_CmsListDialog#validateParamaters()
374: */
375: protected void validateParamaters() throws Exception {
376:
377: if (CmsStringUtil.isEmptyOrWhitespaceOnly(getParamOufqn())) {
378: throw new Exception();
379: }
380: }
381: }
|