001: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
002: // Released under the terms of the GNU General Public License version 2 or later.
003: package fitnesse.responders.refactoring;
004:
005: import fitnesse.*;
006: import fitnesse.responders.SecureResponder;
007: import fitnesse.wiki.WikiPage;
008: import fitnesse.authentication.*;
009: import fitnesse.html.*;
010: import fitnesse.http.*;
011:
012: public class RefactorPageResponder implements SecureResponder {
013: private String resource;
014:
015: public Response makeResponse(FitNesseContext context,
016: Request request) throws Exception {
017: resource = request.getResource();
018: SimpleResponse response = new SimpleResponse();
019: response.setContent(html(context));
020: return response;
021: }
022:
023: public String html(FitNesseContext context) throws Exception {
024: HtmlPage html = context.htmlPageFactory.newPage();
025: html.title.use("Refactor: " + resource);
026: html.header.use(HtmlUtil.makeBreadCrumbsWithPageType(resource,
027: WikiPage.ACTION_REFACTOR));
028: html.main.use(mainContent());
029: return html.html();
030: }
031:
032: private HtmlTag mainContent() throws Exception {
033: TagGroup group = new TagGroup();
034: group.add(deletePageForm());
035: group.add(renamePageForm());
036: group.add(movePageForm());
037: return group;
038: }
039:
040: private HtmlTag deletePageForm() throws Exception {
041: TagGroup group = new TagGroup();
042: group.add(makeHeaderTag("Delete:"));
043: group.add("Delete this entire sub-wiki.");
044: group.add(makeDeletePageForm());
045: return group;
046: }
047:
048: private HtmlTag makeHeaderTag(String content) throws Exception {
049: return new HtmlTag("h3", content);
050: }
051:
052: private HtmlTag makeDeletePageForm() throws Exception {
053: HtmlTag form = HtmlUtil.makeFormTag("get", resource);
054: form.add(HtmlUtil.makeInputTag("submit", "delete",
055: "Delete Page"));
056: form.add(HtmlUtil.makeInputTag("hidden", "responder",
057: "deletePage"));
058: return form;
059: }
060:
061: private HtmlTag movePageForm() throws Exception {
062: TagGroup group = new TagGroup();
063: group.add(HtmlUtil.BR);
064: group.add(makeHeaderTag("Move:"));
065: group
066: .add("Moving this page will find all references and change them accordingly.");
067: group.add(makeMovePageForm());
068: return group;
069: }
070:
071: private HtmlTag makeMovePageForm() throws Exception {
072: HtmlTag form = HtmlUtil.makeFormTag("get", resource);
073: form.add(HtmlUtil.makeInputTag("hidden", "responder",
074: "movePage"));
075: form.add("New Location: ");
076: form.add(HtmlUtil.makeInputTag("text", "newLocation", ""));
077: form.add(HtmlUtil.BR);
078: form.add(HtmlUtil.makeInputTag("submit", "move", "Move Page"));
079: return form;
080: }
081:
082: private HtmlTag renamePageForm() throws Exception {
083: TagGroup group = new TagGroup();
084: group.add(HtmlUtil.BR);
085: group.add(makeHeaderTag("Rename:"));
086: group
087: .add("Renaming this page will find all references and change them accordingly.");
088: group.add(makeRenamePageForm());
089: return group;
090: }
091:
092: private HtmlTag makeRenamePageForm() throws Exception {
093: HtmlTag form = HtmlUtil.makeFormTag("get", resource);
094: form.add(HtmlUtil.makeInputTag("hidden", "responder",
095: "renamePage"));
096: form.add(" New Name: ");
097: form.add(HtmlUtil.makeInputTag("text", "newName", ""));
098: form.add(HtmlUtil.BR);
099: form.add(HtmlUtil.makeInputTag("submit", "rename",
100: "Rename Page"));
101: return form;
102: }
103:
104: public SecureOperation getSecureOperation() {
105: return new AlwaysSecureOperation();
106: }
107: }
|