01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.responders.files;
04:
05: import java.io.File;
06:
07: import fitnesse.FitNesseContext;
08: import fitnesse.authentication.AlwaysSecureOperation;
09: import fitnesse.authentication.SecureOperation;
10: import fitnesse.http.Request;
11: import fitnesse.http.Response;
12: import fitnesse.http.SimpleResponse;
13: import fitnesse.responders.SecureResponder;
14:
15: public class RenameFileResponder implements SecureResponder {
16: private String resource;
17:
18: String newFilename;
19:
20: public Response makeResponse(FitNesseContext context,
21: Request request) throws Exception {
22: Response response = new SimpleResponse();
23: resource = request.getResource();
24: String filename = (String) request.getInput("filename");
25: newFilename = (String) request.getInput("newName");
26: newFilename = newFilename.trim();
27:
28: String pathname = context.rootPagePath + "/" + resource;
29: File file = new File(pathname + filename);
30: file.renameTo(new File(pathname + newFilename));
31: response.redirect("/" + resource);
32: return response;
33: }
34:
35: public SecureOperation getSecureOperation() {
36: return new AlwaysSecureOperation();
37: }
38: }
|