01: /**
02: * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, version 2.1, dated February 1999.
03: *
04: * This program is free software; you can redistribute it and/or modify
05: * it under the terms of the latest version of the GNU Lesser General
06: * Public License as published by the Free Software Foundation;
07: *
08: * This program is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11: * GNU Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public License
14: * along with this program (LICENSE.txt); if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16: */package org.jamwiki.servlets;
17:
18: import javax.servlet.http.HttpServletRequest;
19: import javax.servlet.http.HttpServletResponse;
20: import org.apache.commons.lang.StringUtils;
21: import org.jamwiki.WikiBase;
22: import org.jamwiki.WikiException;
23: import org.jamwiki.WikiMessage;
24: import org.jamwiki.model.Topic;
25: import org.jamwiki.utils.WikiLogger;
26: import org.jamwiki.utils.WikiUtil;
27: import org.springframework.web.servlet.ModelAndView;
28:
29: /**
30: * Used to display a print-friendly version of a topic.
31: */
32: public class PrintableServlet extends JAMWikiServlet {
33:
34: private static final WikiLogger logger = WikiLogger
35: .getLogger(PrintableServlet.class.getName());
36:
37: /**
38: *
39: */
40: protected ModelAndView handleJAMWikiRequest(
41: HttpServletRequest request, HttpServletResponse response,
42: ModelAndView next, WikiPageInfo pageInfo) throws Exception {
43: this .print(request, next, pageInfo);
44: return next;
45: }
46:
47: /**
48: *
49: */
50: protected void initParams() {
51: this .displayJSP = "printable";
52: }
53:
54: /**
55: *
56: */
57: private void print(HttpServletRequest request, ModelAndView next,
58: WikiPageInfo pageInfo) throws Exception {
59: String virtualWiki = WikiUtil.getVirtualWikiFromURI(request);
60: String topicName = WikiUtil.getTopicFromRequest(request);
61: if (StringUtils.isBlank(topicName)) {
62: throw new WikiException(new WikiMessage(
63: "common.exception.notopic"));
64: }
65: Topic topic = WikiBase.getDataHandler().lookupTopic(
66: virtualWiki, topicName, false, null);
67: if (topic == null) {
68: throw new WikiException(new WikiMessage(
69: "common.exception.notopic"));
70: }
71: WikiMessage pageTitle = new WikiMessage("topic.title",
72: topicName);
73: ServletUtil.viewTopic(request, next, pageInfo, pageTitle,
74: topic, false);
75: }
76: }
|