01: package org.claros.intouch.webmail.services;
02:
03: import java.io.File;
04: import java.io.IOException;
05: import java.io.PrintWriter;
06: import java.util.List;
07:
08: import javax.servlet.ServletException;
09: import javax.servlet.http.HttpServletRequest;
10: import javax.servlet.http.HttpServletResponse;
11:
12: import org.claros.commons.mail.models.EmailPart;
13: import org.claros.intouch.common.services.BaseService;
14:
15: public class DeleteAllAttachmentsService extends BaseService {
16:
17: /**
18: *
19: */
20: private static final long serialVersionUID = 1610552503511607594L;
21:
22: /**
23: * The doGet method of the servlet. <br>
24: *
25: * This method is called when a form has its tag value method equals to get.
26: *
27: * @param request the request send by the client to the server
28: * @param response the response send by the server to the client
29: * @throws ServletException if an error occurred
30: * @throws IOException if an error occurred
31: */
32: public void doGet(HttpServletRequest request,
33: HttpServletResponse response) throws ServletException,
34: IOException {
35:
36: response.setHeader("Expires", "-1");
37: response.setHeader("Pragma", "no-cache");
38: response.setHeader("Cache-control", "no-cache");
39: response.setHeader("Content-Type", "text/html; charset=utf-8");
40:
41: PrintWriter out = response.getWriter();
42:
43: List parts = (List) request.getSession().getAttribute(
44: "attachments");
45: if (parts != null) {
46: deleteAll(parts);
47: }
48: request.getSession().setAttribute("attachments", null);
49: out.print("ok");
50: }
51:
52: /**
53: * The doPost method of the servlet. <br>
54: *
55: * This method is called when a form has its tag value method equals to post.
56: *
57: * @param request the request send by the client to the server
58: * @param response the response send by the server to the client
59: * @throws ServletException if an error occurred
60: * @throws IOException if an error occurred
61: */
62: public void doPost(HttpServletRequest request,
63: HttpServletResponse response) throws ServletException,
64: IOException {
65: doGet(request, response);
66: }
67:
68: /**
69: *
70: * @param parts
71: */
72: public static void deleteAll(List parts) {
73: EmailPart tmp = null;
74: for (int i = 0; i < parts.size(); i++) {
75: tmp = (EmailPart) parts.get(i);
76: File f = new File(tmp.getDisposition());
77: f.delete();
78: }
79: }
80: }
|