01: package org.claros.intouch.webdisk.services;
02:
03: import java.io.File;
04: import java.io.IOException;
05: import java.io.OutputStream;
06:
07: import javax.servlet.ServletException;
08: import javax.servlet.http.HttpServletRequest;
09: import javax.servlet.http.HttpServletResponse;
10:
11: import org.claros.commons.configuration.Paths;
12: import org.claros.commons.exception.NoPermissionException;
13: import org.claros.intouch.common.services.BaseService;
14: import org.claros.intouch.webdisk.controllers.ImageController;
15: import org.claros.intouch.webdisk.controllers.WebdiskController;
16: import org.claros.intouch.webmail.controllers.IconController;
17:
18: public class ShowImgPreviewService extends BaseService {
19:
20: private static final long serialVersionUID = -6154464522984604466L;
21:
22: /**
23: * @param request the request send by the client to the server
24: * @param response the response send by the server to the client
25: * @throws ServletException if an error occurred
26: * @throws IOException if an error occurred
27: */
28: public void doGet(HttpServletRequest request,
29: HttpServletResponse response) throws ServletException,
30: IOException {
31: OutputStream out = response.getOutputStream();
32:
33: try {
34: response.setHeader("Expires", "-1");
35: response.setHeader("Pragma", "no-cache");
36: response.setHeader("Cache-control", "no-cache");
37:
38: String size = request.getParameter("size");
39: String path = request.getParameter("path");
40:
41: String username = getAuthProfile(request).getUsername();
42:
43: File f = WebdiskController.getUserFile(username, path);
44: String mime = IconController.findMimeByName(f.getName());
45: if (mime == null || !mime.startsWith("image/")) {
46: throw new NoPermissionException();
47: }
48:
49: byte b[] = null;
50: if (f.length() > 102400) {
51: response.setContentType(mime);
52: b = ImageController.getImgBytes(Paths.getResFolder()
53: + "/download-big.gif");
54: } else {
55: if (size != null && size.equals("normal")) {
56: response.setContentType(mime);
57: b = ImageController
58: .getImgBytes(f.getAbsolutePath());
59: } else {
60: response.setContentType("image/jpeg");
61: int width = Integer.parseInt(request
62: .getParameter("width"));
63: int height = Integer.parseInt(request
64: .getParameter("height"));
65: b = ImageController.getCustomImgBytes(f
66: .getAbsolutePath(), width, height);
67: }
68: }
69: out.write(b);
70: } catch (Exception e) {
71: e.printStackTrace();
72: }
73: }
74:
75: }
|