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 CreateDirService extends BaseService {
16:
17: /**
18: *
19: */
20: private static final long serialVersionUID = 7436273005995690425L;
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 doPost(HttpServletRequest request,
29: HttpServletResponse response) throws ServletException,
30: IOException {
31: response.setHeader("Expires", "-1");
32: response.setHeader("Pragma", "no-cache");
33: response.setHeader("Cache-control", "no-cache");
34: response.setContentType("text/html");
35: PrintWriter out = response.getWriter();
36:
37: try {
38: String parent = request.getParameter("parent");
39: String dir = request.getParameter("dir");
40: String username = getAuthProfile(request).getUsername();
41:
42: String home = WebdiskController
43: .correctPath(WebdiskController
44: .getUserHome(username).getAbsolutePath());
45:
46: if (parent == null || parent.equals("undefined")) {
47: parent = "";
48: }
49:
50: if (dir.startsWith("/")) {
51: dir = dir.substring(1);
52: }
53: dir = WebdiskController.correctPath(dir);
54: String myDir = home + parent + "/" + dir;
55: myDir = WebdiskController.correctPath(myDir);
56:
57: File f = new File(myDir);
58: FileUtils.forceMkdir(f);
59: out.print("ok");
60: } catch (Exception e) {
61: out.print("fail");
62: }
63:
64: }
65:
66: }
|