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 DeleteAttachmentController implements Controller {
053: public Object process(URI uri, HttpServletRequest request,
054: HttpServletResponse response) throws Exception {
055: LibresourceMailingService mailingService = (LibresourceMailingService) Libresource
056: .getService(MailingListConstant.SERVICE);
057: MailingListResourceValue mailingList = (MailingListResourceValue) mailingService
058: .getMailingList(uri);
059:
060: if (!mailingService.isSubscriber(uri)) {
061: return uri;
062: }
063:
064: HttpSession session = request.getSession();
065:
066: if ((request.getParameter("fileId") == null)
067: || (request.getParameter("fileId").trim().length() == 0)) {
068: request.setAttribute("attachments", session
069: .getAttribute("attachments"));
070: request.setAttribute("subject", request
071: .getParameter("subject"));
072: session.setAttribute("subject", request
073: .getParameter("subject"));
074: request.setAttribute("content", request
075: .getParameter("content"));
076: session.setAttribute("content", request
077: .getParameter("content"));
078: request.setAttribute("mail", mailingList.getMail() + "@"
079: + mailingService.getMailSuffix());
080: request.setAttribute("description", mailingList
081: .getDescription());
082: request.setAttribute("isSubscriber", "true");
083:
084: return uri + "?action=send";
085: }
086:
087: String fileId = request.getParameter("fileId");
088: mailingService.deleteAttachment(fileId);
089:
090: Vector attachments = deleteInAttachments((Vector) session
091: .getAttribute("attachments"), fileId);
092:
093: request.setAttribute("attachments", attachments);
094: session.setAttribute("attachments", attachments);
095:
096: request
097: .setAttribute("subject", request
098: .getParameter("subject"));
099: session
100: .setAttribute("subject", request
101: .getParameter("subject"));
102: request
103: .setAttribute("content", request
104: .getParameter("content"));
105: session
106: .setAttribute("content", request
107: .getParameter("content"));
108:
109: request.setAttribute("mail", mailingList.getMail() + "@"
110: + mailingService.getMailSuffix());
111: request.setAttribute("description", mailingList
112: .getDescription());
113: request.setAttribute("isSubscriber", "true");
114:
115: return uri + "?action=send";
116: }
117:
118: // additionals methods
119: private Vector deleteInAttachments(Vector list, String id) {
120: if ((list == null) || (list.size() == 0)) {
121: return null;
122: }
123:
124: int x = 0;
125: int index = -1;
126:
127: for (Iterator i = list.iterator(); i.hasNext();) {
128: if (((String[]) i.next())[0].compareTo(id) == 0) {
129: index = x;
130: }
131:
132: x++;
133: }
134:
135: if (index != -1) {
136: list.removeElementAt(index);
137: }
138:
139: return list;
140: }
141: }
|