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;
04:
05: import fitnesse.http.*;
06: import fitnesse.wiki.*;
07: import fitnesse.*;
08: import fitnesse.authentication.*;
09: import fitnesse.html.*;
10:
11: public class WikiPageResponder implements SecureResponder {
12: protected WikiPage page;
13:
14: protected PageData pageData;
15:
16: protected String pageTitle;
17:
18: protected Request request;
19:
20: public WikiPageResponder() {
21: }
22:
23: public WikiPageResponder(WikiPage page) throws Exception {
24: this .page = page;
25: this .pageData = page.getData();
26: }
27:
28: public Response makeResponse(FitNesseContext context,
29: Request request) throws Exception {
30: String resource = request.getResource();
31:
32: if ("".equals(resource)) {
33: resource = "FrontPage";
34: }
35:
36: WikiPagePath path = PathParser.parse(resource);
37: PageCrawler crawler = context.root.getPageCrawler();
38: crawler.setDeadEndStrategy(new VirtualEnabledPageCrawler());
39: this .page = crawler.getPage(context.root, path);
40: if (this .page == null) {
41: return new NotFoundResponder().makeResponse(context,
42: request);
43: }
44: this .pageData = this .page.getData();
45:
46: this .pageTitle = PathParser.render(crawler
47: .getFullPath(this .page));
48: String html = makeHtml(context);
49:
50: SimpleResponse response = new SimpleResponse();
51: response.setMaxAge(0);
52: response.setContent(html);
53:
54: return response;
55: }
56:
57: public String makeHtml(FitNesseContext context) throws Exception {
58: WikiPage page = this .pageData.getWikiPage();
59: HtmlPage html = context.htmlPageFactory.newPage();
60: WikiPagePath fullPath = page.getPageCrawler().getFullPath(page);
61: String fullPathName = PathParser.render(fullPath);
62: html.title.use(fullPathName);
63: html.header.use(HtmlUtil
64: .makeBreadCrumbsWithCurrentPageNotLinked(fullPathName));
65: html.actions.use(HtmlUtil.makeActions(this .pageData));
66: html.main.use(HtmlUtil.addHeaderAndFooter(page, HtmlUtil
67: .testableHtml(this .pageData)));
68:
69: if (this .pageData.hasAttribute("WikiImportSource")) {
70: html.body.addAttribute("class", "imported");
71: } else if (page instanceof ProxyPage) {
72: html.body.addAttribute("class", "virtual");
73: }
74:
75: return html.html();
76: }
77:
78: public SecureOperation getSecureOperation() {
79: return new SecureReadOperation();
80: }
81: }
|