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: protected PageData pageData;
14: protected String pageTitle;
15: protected Request request;
16: protected PageCrawler crawler;
17:
18: public WikiPageResponder() {
19: }
20:
21: public WikiPageResponder(WikiPage page) throws Exception {
22: this .page = page;
23: pageData = page.getData();
24: }
25:
26: public Response makeResponse(FitNesseContext context,
27: Request request) throws Exception {
28: String resource = request.getResource();
29:
30: if ("".equals(resource))
31: resource = "FrontPage";
32:
33: loadPage(resource, context);
34: if (page == null)
35: return new NotFoundResponder().makeResponse(context,
36: request);
37: loadPageData();
38:
39: pageTitle = PathParser.render(crawler.getFullPath(page));
40: String html = makeHtml(context);
41:
42: SimpleResponse response = new SimpleResponse();
43: response.setMaxAge(0);
44: response.setContent(html);
45:
46: return response;
47: }
48:
49: protected void loadPageData() throws Exception {
50: pageData = page.getData();
51: }
52:
53: protected void loadPage(String resource, FitNesseContext context)
54: throws Exception {
55: WikiPagePath path = PathParser.parse(resource);
56: crawler = context.root.getPageCrawler();
57: crawler.setDeadEndStrategy(new VirtualEnabledPageCrawler());
58: page = crawler.getPage(context.root, path);
59: }
60:
61: public String makeHtml(FitNesseContext context) throws Exception {
62: WikiPage page = pageData.getWikiPage();
63: HtmlPage html = context.htmlPageFactory.newPage();
64: WikiPagePath fullPath = page.getPageCrawler().getFullPath(page);
65: String fullPathName = PathParser.render(fullPath);
66: html.title.use(fullPathName);
67: html.header.use(HtmlUtil
68: .makeBreadCrumbsWithCurrentPageNotLinked(fullPathName));
69: html.actions.use(HtmlUtil.makeActions(pageData));
70: html.main.use(HtmlUtil.addHeaderAndFooter(page, HtmlUtil
71: .testableHtml(pageData)));
72:
73: handleSpecialProperties(html, page);
74:
75: return html.html();
76: }
77:
78: private void handleSpecialProperties(HtmlPage html, WikiPage page)
79: throws Exception {
80: WikiImportProperty.handleImportProperties(html, page, pageData);
81: }
82:
83: public SecureOperation getSecureOperation() {
84: return new SecureReadOperation();
85: }
86: }
|