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.claros.commons.utility.Utility;
12: import org.claros.intouch.common.services.BaseService;
13: import org.claros.intouch.webdisk.controllers.WebdiskController;
14:
15: public class RenameItemService extends BaseService {
16: private static final long serialVersionUID = 7863734723651766816L;
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 newName = request.getParameter("name");
35: String path = WebdiskController.correctPath(request
36: .getParameter("path"));
37: String username = getAuthProfile(request).getUsername();
38:
39: File f = WebdiskController.getUserFile(username, path);
40:
41: if (newName.indexOf("..") >= 0) {
42: out.print("fail");
43: }
44: newName = Utility.convertTRCharsToENChars(newName);
45:
46: String home = WebdiskController
47: .correctPath(WebdiskController
48: .getUserHome(username).getAbsolutePath());
49:
50: File fNew = new File(home + "/"
51: + path.substring(0, path.lastIndexOf("/")) + "/"
52: + newName);
53:
54: f.renameTo(fNew);
55: out.print("ok");
56: } catch (Exception e) {
57: out.print("fail");
58: }
59: }
60:
61: }
|