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.model.VirtualWiki;
23: import org.jamwiki.utils.WikiLogger;
24: import org.jamwiki.utils.WikiUtil;
25: import org.springframework.web.servlet.ModelAndView;
26:
27: /**
28: * Used to display a JAMWiki topic.
29: */
30: public class TopicServlet extends JAMWikiServlet {
31:
32: /** Logger for this class and subclasses. */
33: private static final WikiLogger logger = WikiLogger
34: .getLogger(TopicServlet.class.getName());
35:
36: /**
37: * This method handles the request after its parent class receives control. It gets the topic's name and the
38: * virtual wiki name from the uri, loads the topic and returns a view to the end user.
39: *
40: * @param request - Standard HttpServletRequest object.
41: * @param response - Standard HttpServletResponse object.
42: * @return A <code>ModelAndView</code> object to be handled by the rest of the Spring framework.
43: */
44: protected ModelAndView handleJAMWikiRequest(
45: HttpServletRequest request, HttpServletResponse response,
46: ModelAndView next, WikiPageInfo pageInfo) throws Exception {
47: view(request, next, pageInfo);
48: return next;
49: }
50:
51: /**
52: *
53: */
54: private void view(HttpServletRequest request, ModelAndView next,
55: WikiPageInfo pageInfo) throws Exception {
56: String topic = WikiUtil.getTopicFromURI(request);
57: if (StringUtils.isBlank(topic)) {
58: String virtualWikiName = WikiUtil
59: .getVirtualWikiFromURI(request);
60: VirtualWiki virtualWiki = WikiBase.getDataHandler()
61: .lookupVirtualWiki(virtualWikiName);
62: topic = virtualWiki.getDefaultTopicName();
63: }
64: ServletUtil.viewTopic(request, next, pageInfo, topic);
65: }
66: }
|