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.intouch.common.services.BaseService;
13: import org.claros.intouch.webdisk.controllers.WebdiskController;
14:
15: public class RenameDirService extends BaseService {
16: private static final long serialVersionUID = 7116921849130450239L;
17:
18: /**
19: * @param request the request send by the client to the server
20: * @param response the response send by the server to the client
21: * @throws ServletException if an error occurred
22: * @throws IOException if an error occurred
23: */
24: public void doPost(HttpServletRequest request,
25: HttpServletResponse response) throws ServletException,
26: IOException {
27: response.setHeader("Expires", "-1");
28: response.setHeader("Pragma", "no-cache");
29: response.setHeader("Cache-control", "no-cache");
30: response.setContentType("text/html");
31: PrintWriter out = response.getWriter();
32:
33: try {
34: String from = request.getParameter("from");
35: String dir = request.getParameter("dir");
36: String username = getAuthProfile(request).getUsername();
37:
38: String home = WebdiskController
39: .correctPath(WebdiskController
40: .getUserHome(username).getAbsolutePath());
41:
42: if (from == null || from.equals("undefined")) {
43: out.print("ok");
44: } else {
45: if (dir.startsWith("/")) {
46: dir = dir.substring(1);
47: }
48: dir = WebdiskController.correctPath(dir);
49: from = WebdiskController.correctPath(from);
50:
51: String parentDir = from.substring(0, from
52: .lastIndexOf("/"));
53:
54: String myDir = home + parentDir + "/" + dir;
55: myDir = WebdiskController.correctPath(myDir);
56: File to = new File(myDir);
57:
58: File fromDir = new File(home + from);
59:
60: FileUtils.copyDirectory(fromDir, to);
61: FileUtils.deleteDirectory(fromDir);
62: out.print("ok");
63: }
64: } catch (Exception e) {
65: out.print("fail");
66: }
67: }
68:
69: }
|