01: package org.claros.intouch.webdisk.services;
02:
03: import java.io.File;
04: import java.io.IOException;
05: import java.io.PrintWriter;
06:
07: import javax.servlet.ServletException;
08: import javax.servlet.http.HttpServletRequest;
09: import javax.servlet.http.HttpServletResponse;
10:
11: import org.apache.commons.io.FileUtils;
12: import org.claros.commons.utility.Utility;
13: import org.claros.intouch.common.services.BaseService;
14: import org.claros.intouch.webdisk.controllers.WebdiskController;
15:
16: public class MoveItemService extends BaseService {
17:
18: /**
19: *
20: */
21: private static final long serialVersionUID = -552540293565310867L;
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.setContentType("text/html");
36: PrintWriter out = response.getWriter();
37:
38: try {
39: String moveTo = WebdiskController.correctPath(request
40: .getParameter("moveto"));
41: String path = WebdiskController.correctPath(request
42: .getParameter("path"));
43: String username = getAuthProfile(request).getUsername();
44:
45: File from = WebdiskController.getUserFile(username, path);
46:
47: String home = WebdiskController
48: .correctPath(WebdiskController
49: .getUserHome(username).getAbsolutePath());
50: File dest = new File(WebdiskController.correctPath(Utility
51: .convertTRCharsToENChars(home + moveTo)));
52:
53: if (from.getAbsolutePath().equals(dest.getAbsolutePath())) {
54: // do nothing
55: } else if (from.getAbsolutePath().equals(
56: WebdiskController.getUploadDir(username)
57: .getAbsolutePath())) {
58: // do nothing
59: } else {
60: if (from.isFile()) {
61: // moving file to another directory
62: FileUtils.copyFileToDirectory(from, dest);
63: from.delete();
64: } else if (from.isDirectory()) {
65: FileUtils.copyDirectoryToDirectory(from, dest);
66: FileUtils.deleteDirectory(from);
67: }
68: }
69: out.print("ok");
70: } catch (Exception e) {
71: out.print("fail");
72: }
73: }
74:
75: }
|