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 fitnesse.*;
06: import fitnesse.authentication.*;
07: import fitnesse.responders.SecureResponder;
08: import fitnesse.html.*;
09: import fitnesse.http.*;
10: import java.io.File;
11:
12: public class DeleteConfirmationResponder implements SecureResponder {
13: private String resource;
14:
15: public Response makeResponse(FitNesseContext context,
16: Request request) throws Exception {
17: SimpleResponse response = new SimpleResponse();
18: resource = request.getResource();
19: String filename = (String) request.getInput("filename");
20: response
21: .setContent(makeDirectoryListingPage(filename, context));
22: response.setLastModifiedHeader("Delete");
23: return response;
24: }
25:
26: private String makeDirectoryListingPage(String filename,
27: FitNesseContext context) throws Exception {
28: HtmlPage page = context.htmlPageFactory.newPage();
29: page.title.use("Delete File(s): ");
30: page.header.use(HtmlUtil.makeBreadCrumbsWithPageType(resource
31: + filename, "/", "Delete File"));
32: page.main.use(makeConfirmationHTML(filename, context));
33:
34: return page.html();
35: }
36:
37: private HtmlTag makeConfirmationHTML(String filename,
38: FitNesseContext context) throws Exception {
39: String pathname = context.rootPagePath + "/" + resource
40: + filename;
41: File file = new File(pathname);
42: boolean isDir = file.isDirectory();
43:
44: TagGroup group = new TagGroup();
45: group.add(messageText(filename, isDir, file));
46:
47: group.add(HtmlUtil.BR);
48: group.add(HtmlUtil.BR);
49: group.add(HtmlUtil.BR);
50: group.add(makeYesForm(filename));
51: group.add(makeNoForm());
52: group.add(HtmlUtil.NBSP);
53: group.add(HtmlUtil.NBSP);
54: return group;
55: }
56:
57: private String messageText(String filename, boolean dir, File file) {
58: String message = "Are you sure you would like to delete <b>"
59: + filename + "</b> ";
60: if (dir)
61: message += " and all " + file.listFiles().length
62: + " files inside";
63:
64: return message + "?";
65: }
66:
67: private HtmlTag makeNoForm() {
68: HtmlTag noForm = HtmlUtil.makeFormTag("get", "/" + resource);
69: noForm.add(HtmlUtil.makeInputTag("submit", "", "No"));
70: return noForm;
71: }
72:
73: private HtmlTag makeYesForm(String filename) {
74: HtmlTag yesForm = HtmlUtil.makeFormTag("get", "/" + resource);
75: yesForm.add(HtmlUtil.makeInputTag("submit", "", "Yes"));
76: yesForm.add(HtmlUtil.makeInputTag("hidden", "responder",
77: "deleteFile"));
78: yesForm.add(HtmlUtil.makeInputTag("hidden", "filename",
79: filename));
80: return yesForm;
81: }
82:
83: public SecureOperation getSecureOperation() {
84: return new AlwaysSecureOperation();
85: }
86: }
|