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.versions;
04:
05: import fitnesse.http.*;
06: import fitnesse.wiki.*;
07: import fitnesse.html.*;
08: import fitnesse.*;
09: import fitnesse.responders.*;
10: import fitnesse.authentication.*;
11:
12: public class VersionResponder implements SecureResponder {
13: private WikiPage page;
14:
15: private String version;
16:
17: private String resource;
18:
19: public Response makeResponse(FitNesseContext context,
20: Request request) throws Exception {
21: resource = request.getResource();
22: version = (String) request.getInput("version");
23:
24: PageCrawler pageCrawler = context.root.getPageCrawler();
25: WikiPagePath path = PathParser.parse(resource);
26: page = pageCrawler.getPage(context.root, path);
27: if (page == null)
28: return new NotFoundResponder().makeResponse(context,
29: request);
30: PageData pageData = page.getDataVersion(version);
31:
32: String fullPathName = PathParser.render(pageCrawler
33: .getFullPath(page));
34: HtmlPage html = makeHtml(fullPathName, pageData, context);
35:
36: SimpleResponse response = new SimpleResponse();
37: response.setContent(html.html());
38:
39: return response;
40: }
41:
42: private HtmlPage makeHtml(String name, PageData pageData,
43: FitNesseContext context) throws Exception {
44: HtmlPage html = context.htmlPageFactory.newPage();
45: html.title.use("Version " + version + ": " + name);
46: html.header.use(HtmlUtil.makeBreadCrumbsWithPageType(resource,
47: "Version " + version));
48: html.actions.use(HtmlUtil.makeActionLink(name, "Rollback",
49: "responder=rollback&version=" + version, "", false));
50: html.main.use(HtmlUtil.makeNormalWikiPageContent(pageData));
51: return html;
52: }
53:
54: public SecureOperation getSecureOperation() {
55: return new SecureReadOperation();
56: }
57: }
|