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 java.util.Collection;
19:
20: import javax.servlet.http.HttpServletRequest;
21: import javax.servlet.http.HttpServletResponse;
22: import org.apache.commons.lang.StringUtils;
23: import org.jamwiki.WikiBase;
24: import org.jamwiki.WikiException;
25: import org.jamwiki.WikiMessage;
26: import org.jamwiki.utils.WikiLogger;
27: import org.jamwiki.utils.WikiUtil;
28: import org.springframework.web.servlet.ModelAndView;
29:
30: /**
31: * Used to display all topics that contain links to the current topic.
32: */
33: public class LinkToServlet extends JAMWikiServlet {
34:
35: private static final WikiLogger logger = WikiLogger
36: .getLogger(LinkToServlet.class.getName());
37: protected static final String JSP_LINKTO = "linkto.jsp";
38:
39: /**
40: *
41: */
42: protected ModelAndView handleJAMWikiRequest(
43: HttpServletRequest request, HttpServletResponse response,
44: ModelAndView next, WikiPageInfo pageInfo) throws Exception {
45: this .linksTo(request, next, pageInfo);
46: return next;
47: }
48:
49: /**
50: *
51: */
52: private void linksTo(HttpServletRequest request, ModelAndView next,
53: WikiPageInfo pageInfo) throws Exception {
54: String virtualWiki = WikiUtil.getVirtualWikiFromURI(request);
55: String topicName = WikiUtil.getTopicFromRequest(request);
56: if (StringUtils.isBlank(topicName)) {
57: throw new WikiException(new WikiMessage(
58: "common.exception.notopic"));
59: }
60: WikiMessage pageTitle = new WikiMessage("linkto.title",
61: topicName);
62: pageInfo.setPageTitle(pageTitle);
63: // grab search engine instance and find
64: Collection results = WikiBase.getSearchEngine().findLinkedTo(
65: virtualWiki, topicName);
66: next.addObject("results", results);
67: next.addObject("link", topicName);
68: pageInfo.setContentJsp(JSP_LINKTO);
69: pageInfo.setTopicName(topicName);
70: }
71: }
|