01: package org.claros.intouch.webdisk.services;
02:
03: import java.io.File;
04: import java.io.IOException;
05: import java.io.PrintWriter;
06: import java.util.ArrayList;
07: import java.util.List;
08:
09: import javax.servlet.ServletException;
10: import javax.servlet.http.HttpServletRequest;
11: import javax.servlet.http.HttpServletResponse;
12:
13: import org.claros.commons.exception.NoPermissionException;
14: import org.claros.commons.mail.models.EmailPart;
15: import org.claros.commons.mail.utility.Utility;
16: import org.claros.intouch.common.services.BaseService;
17: import org.claros.intouch.webdisk.controllers.WebdiskController;
18: import org.claros.intouch.webmail.controllers.IconController;
19:
20: public class ForwardFileService extends BaseService {
21: private static final long serialVersionUID = 7698586538538606204L;
22:
23: /**
24: * @param request the request send by the client to the server
25: * @param response the response send by the server to the client
26: * @throws ServletException if an error occurred
27: * @throws IOException if an error occurred
28: */
29: public void doPost(HttpServletRequest request,
30: HttpServletResponse response) throws ServletException,
31: IOException {
32: response.setHeader("Expires", "-1");
33: response.setHeader("Pragma", "no-cache");
34: response.setHeader("Cache-control", "no-cache");
35: response.setHeader("Content-Type", "text/html; charset=utf-8");
36:
37: PrintWriter out = response.getWriter();
38:
39: try {
40: String path = request.getParameter("path");
41:
42: EmailPart part = new EmailPart();
43:
44: if (path.indexOf("../") >= 0) {
45: throw new NoPermissionException();
46: }
47:
48: String home = WebdiskController.getUserHome(
49: getAuthProfile(request).getUsername())
50: .getAbsolutePath();
51: path = home + path;
52:
53: if (path.endsWith("/"))
54: path = path.substring(0, path.length() - 1);
55: String fn = path.substring(path.lastIndexOf("/") + 1);
56: File fnF = new File(path);
57: part.setFilename(fn);
58: part.setSize(fnF.length());
59: part.setSizeReadable(Utility.sizeToHumanReadable(part
60: .getSize()));
61: part.setContentType(IconController.findMimeByName(fn));
62: part.setDisposition(path);
63:
64: String res = "<li size=\"" + part.getSize()
65: + "\"><img src=\"images/attachment.gif\"/><span>"
66: + part.getFilename() + " ("
67: + part.getSizeReadable()
68: + ")</span> <a href=\"javascript:removeAttach('"
69: + fn + "')\" attid=\"" + 0
70: + "\" style='color:#5A799E;'>"
71: + getText(request, "remove") + "</a></li>";
72:
73: List newParts = new ArrayList();
74: newParts.add(part);
75: request.getSession().setAttribute("attachments", newParts);
76: out.print(res);
77: } catch (Exception e) {
78: // TODO Auto-generated catch block
79: e.printStackTrace();
80: }
81: }
82:
83: }
|