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.wikitext.widgets.WikiWordWidget;
07: import fitnesse.*;
08: import fitnesse.html.*;
09:
10: import java.util.regex.Pattern;
11:
12: public class NotFoundResponder implements Responder {
13: private String resource;
14:
15: public NotFoundResponder() {
16: }
17:
18: public Response makeResponse(FitNesseContext context,
19: Request request) throws Exception {
20: SimpleResponse response = new SimpleResponse(404);
21: resource = request.getResource();
22:
23: response.setContent(makeHtml(context));
24: return response;
25: }
26:
27: private String makeHtml(FitNesseContext context) throws Exception {
28: HtmlPage page = context.htmlPageFactory.newPage();
29: HtmlUtil.addTitles(page, "Not Found:" + resource);
30: page.main.use(makeRightColumn(resource));
31: return page.html();
32: }
33:
34: private String makeRightColumn(String name) throws Exception {
35: StringBuffer buffer = new StringBuffer();
36: buffer.append("The requested resource: <i>" + name
37: + "</i> was not found.");
38: if (Pattern.matches(WikiWordWidget.REGEXP, name)) {
39: HtmlTag unorderedListTag = new HtmlTag("ul");
40: HtmlTag item = new HtmlTag("li");
41: item.add(HtmlUtil.makeLink(name + "?edit",
42: "create this page"));
43: unorderedListTag.add(item);
44: buffer.append(unorderedListTag.html());
45: }
46: return buffer.toString();
47: }
48:
49: }
|