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.kernel.KernelConstants;
038: import org.libresource.kernel.interfaces.KernelService;
039:
040: import org.libresource.mailing.LibresourceMailingException;
041: import org.libresource.mailing.MailingListConstant;
042: import org.libresource.mailing.ejb.model.MailingListResourceValue;
043: import org.libresource.mailing.interfaces.LibresourceMailingService;
044:
045: import org.libresource.web.Controller;
046:
047: import java.net.URI;
048:
049: import javax.mail.internet.AddressException;
050: import javax.mail.internet.InternetAddress;
051:
052: import javax.servlet.http.HttpServletRequest;
053: import javax.servlet.http.HttpServletResponse;
054:
055: public class EditMailingListController implements Controller {
056: public Object process(URI uri, HttpServletRequest request,
057: HttpServletResponse response) throws Exception {
058: KernelService kernelService = (KernelService) Libresource
059: .getService(KernelConstants.SERVICE);
060:
061: if (request.getParameter("cancel") != null) {
062: return uri;
063: }
064:
065: LibresourceMailingService mailingService = (LibresourceMailingService) Libresource
066: .getService(MailingListConstant.SERVICE);
067: request.setAttribute("suffix", mailingService.getMailSuffix());
068:
069: // view the edition page
070: if (request.getParameter("mail") == null) {
071: MailingListResourceValue mailingListResourceValue = mailingService
072: .getMailingList(uri);
073: request.setAttribute("mail", mailingListResourceValue
074: .getMail());
075: request.setAttribute("description",
076: mailingListResourceValue.getDescription());
077:
078: return "/pages/modules/mailing/editMailingList.jsp";
079: }
080:
081: // if the mail is void
082: if (request.getParameter("mail").trim().length() == 0) {
083: MailingListResourceValue mailingListResourceValue = mailingService
084: .getMailingList(uri);
085: request.setAttribute("description", request
086: .getParameter("description"));
087: request.setAttribute("error_mail", "The mail is required");
088:
089: return "/pages/modules/mailing/editMailingList.jsp";
090: }
091:
092: // if the mail is invalid
093: try {
094: InternetAddress ia = new InternetAddress(request
095: .getParameter("mail")
096: + "@" + mailingService.getMailSuffix());
097: } catch (AddressException e) {
098: MailingListResourceValue mailingListResourceValue = mailingService
099: .getMailingList(uri);
100: request.setAttribute("description", request
101: .getParameter("description"));
102: request.setAttribute("error_mail",
103: "This mail adress is invalid");
104:
105: return "/pages/modules/mailing/editMailingList.jsp";
106: }
107:
108: // edit the mailinglist
109: try {
110: mailingService.editMailingList(uri, request
111: .getParameter("mail"), request
112: .getParameter("description"));
113: } catch (LibresourceMailingException e) {
114: MailingListResourceValue mailingListResourceValue = mailingService
115: .getMailingList(uri);
116: request.setAttribute("description", request
117: .getParameter("description"));
118: request.setAttribute("error_mail",
119: "This mail adress is already use");
120:
121: return "/pages/modules/mailing/editMailingList.jsp";
122: }
123:
124: return uri;
125: }
126: }
|