001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.web.controllers.mailing;
034:
035: import org.libresource.Libresource;
036:
037: import org.libresource.mailing.MailingListConstant;
038: import org.libresource.mailing.ejb.model.MailingListResourceValue;
039: import org.libresource.mailing.interfaces.LibresourceMailingService;
040:
041: import org.libresource.web.Controller;
042:
043: import java.net.URI;
044:
045: import java.util.Iterator;
046: import java.util.Vector;
047:
048: import javax.servlet.http.HttpServletRequest;
049: import javax.servlet.http.HttpServletResponse;
050: import javax.servlet.http.HttpSession;
051:
052: public class SendMailController implements Controller {
053: public Object process(URI uri, HttpServletRequest request,
054: HttpServletResponse response) throws Exception {
055: if (request.getParameter("cancel") != null) {
056: HttpSession session = request.getSession();
057: session.removeAttribute("subject");
058: session.removeAttribute("content");
059: session.removeAttribute("attachments");
060:
061: return uri;
062: }
063:
064: LibresourceMailingService mailingService = (LibresourceMailingService) Libresource
065: .getService(MailingListConstant.SERVICE);
066: MailingListResourceValue mailingList = (MailingListResourceValue) mailingService
067: .getMailingList(uri);
068: request.setAttribute("mail", mailingList.getMail() + "@"
069: + mailingService.getMailSuffix());
070: request.setAttribute("description", mailingList
071: .getDescription());
072: request.setAttribute("reply", request.getParameter("reply"));
073:
074: if (mailingService.isSubscriber(uri)) {
075: request.setAttribute("isSubscriber", "true");
076: } else {
077: return uri;
078: }
079:
080: if (request.getParameter("send") == null) {
081: String subject = (String) request.getSession()
082: .getAttribute("subject");
083:
084: if (subject == null) {
085: subject = request.getParameter("subject");
086: }
087:
088: if (request.getParameter("reply") != null) {
089: if (subject == null) {
090: subject = "RE: ";
091: } else {
092: if (!subject.startsWith("RE: ")) {
093: subject = "RE: " + subject;
094: }
095: }
096: }
097:
098: request.setAttribute("subject", subject);
099: request.setAttribute("content", request.getSession()
100: .getAttribute("content"));
101: request.setAttribute("attachments", request.getSession()
102: .getAttribute("attachments"));
103:
104: return "/pages/modules/mailing/viewMailingList.jsp";
105: }
106:
107: HttpSession session = request.getSession();
108: session.removeAttribute("subject");
109: session.removeAttribute("content");
110:
111: String attachments = makeAttachmentsList((Vector) request
112: .getSession().getAttribute("attachments"));
113: session.removeAttribute("attachments");
114: mailingService.sendMessage(uri,
115: request.getParameter("subject"), request
116: .getParameter("content"), attachments, request
117: .getParameter("reply"));
118:
119: return uri;
120: }
121:
122: private String makeAttachmentsList(Vector list) {
123: if (list == null) {
124: return "";
125: }
126:
127: String res = new String();
128:
129: for (Iterator i = list.iterator(); i.hasNext();) {
130: String[] tab = (String[]) i.next();
131:
132: if (res.trim().length() == 0) {
133: res = tab[0] + "," + tab[1].replace(',', '-');
134: } else {
135: res = res + "," + tab[0] + ","
136: + tab[1].replace(',', '-');
137: }
138: }
139:
140: return res;
141: }
142: }
|