001: /**
002: * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, version 2.1, dated February 1999.
003: *
004: * This program is free software; you can redistribute it and/or modify
005: * it under the terms of the latest version of the GNU Lesser General
006: * Public License as published by the Free Software Foundation;
007: *
008: * This program is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
011: * GNU Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public License
014: * along with this program (LICENSE.txt); if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
016: */package org.jamwiki.servlets;
017:
018: import java.util.Collection;
019: import java.util.Iterator;
020: import java.util.Vector;
021:
022: import javax.servlet.http.HttpServletRequest;
023: import javax.servlet.http.HttpServletResponse;
024:
025: import org.jamwiki.WikiBase;
026: import org.jamwiki.WikiMessage;
027: import org.jamwiki.model.Topic;
028: import org.jamwiki.utils.NamespaceHandler;
029: import org.jamwiki.utils.Pagination;
030: import org.jamwiki.utils.WikiLogger;
031: import org.jamwiki.utils.WikiUtil;
032: import org.springframework.web.servlet.ModelAndView;
033:
034: /**
035: * Used to build Special: pages that display lists of topics on the Wiki, such
036: * as when displaying lists of all existing images or topics.
037: */
038: public class ItemsServlet extends JAMWikiServlet {
039:
040: /** Logger for this class and subclasses. */
041: private static final WikiLogger logger = WikiLogger
042: .getLogger(ItemsServlet.class.getName());
043: protected static final String JSP_ITEMS = "items.jsp";
044:
045: /**
046: * This method handles the request after its parent class receives control. It gets the topic's name and the
047: * virtual wiki name from the uri, loads the topic and returns a view to the end user.
048: *
049: * @param request - Standard HttpServletRequest object.
050: * @param response - Standard HttpServletResponse object.
051: * @return A <code>ModelAndView</code> object to be handled by the rest of the Spring framework.
052: */
053: protected ModelAndView handleJAMWikiRequest(
054: HttpServletRequest request, HttpServletResponse response,
055: ModelAndView next, WikiPageInfo pageInfo) throws Exception {
056: if (ServletUtil.isTopic(request, "Special:Imagelist")) {
057: viewImages(request, next, pageInfo);
058: } else if (ServletUtil.isTopic(request, "Special:Filelist")) {
059: viewFiles(request, next, pageInfo);
060: } else if (ServletUtil.isTopic(request, "Special:Listusers")) {
061: viewUsers(request, next, pageInfo);
062: } else if (ServletUtil.isTopic(request, "Special:TopicsAdmin")) {
063: viewTopicsAdmin(request, next, pageInfo);
064: } else {
065: viewTopics(request, next, pageInfo);
066: }
067: return next;
068: }
069:
070: /**
071: *
072: */
073: private void viewFiles(HttpServletRequest request,
074: ModelAndView next, WikiPageInfo pageInfo) throws Exception {
075: String virtualWiki = WikiUtil.getVirtualWikiFromURI(request);
076: Pagination pagination = ServletUtil.loadPagination(request,
077: next);
078: Collection items = WikiBase.getDataHandler().lookupTopicByType(
079: virtualWiki, Topic.TYPE_FILE, pagination);
080: next.addObject("itemCount", new Integer(items.size()));
081: next.addObject("items", items);
082: next.addObject("rootUrl", "Special:Filelist");
083: pageInfo.setPageTitle(new WikiMessage("allfiles.title"));
084: pageInfo.setContentJsp(JSP_ITEMS);
085: pageInfo.setSpecial(true);
086: }
087:
088: /**
089: *
090: */
091: private void viewUsers(HttpServletRequest request,
092: ModelAndView next, WikiPageInfo pageInfo) throws Exception {
093: Pagination pagination = ServletUtil.loadPagination(request,
094: next);
095: Collection items = WikiBase.getDataHandler().lookupWikiUsers(
096: pagination);
097: Vector links = new Vector();
098: for (Iterator iter = items.iterator(); iter.hasNext();) {
099: String link = (String) iter.next();
100: links.add(NamespaceHandler.NAMESPACE_USER
101: + NamespaceHandler.NAMESPACE_SEPARATOR + link);
102: }
103: next.addObject("itemCount", new Integer(items.size()));
104: next.addObject("items", links);
105: next.addObject("rootUrl", "Special:Listusers");
106: pageInfo.setPageTitle(new WikiMessage("allusers.title"));
107: pageInfo.setContentJsp(JSP_ITEMS);
108: pageInfo.setSpecial(true);
109: }
110:
111: /**
112: *
113: */
114: private void viewImages(HttpServletRequest request,
115: ModelAndView next, WikiPageInfo pageInfo) throws Exception {
116: String virtualWiki = WikiUtil.getVirtualWikiFromURI(request);
117: Pagination pagination = ServletUtil.loadPagination(request,
118: next);
119: Collection items = WikiBase.getDataHandler().lookupTopicByType(
120: virtualWiki, Topic.TYPE_IMAGE, pagination);
121: next.addObject("itemCount", new Integer(items.size()));
122: next.addObject("items", items);
123: next.addObject("rootUrl", "Special:Imagelist");
124: pageInfo.setPageTitle(new WikiMessage("allimages.title"));
125: pageInfo.setContentJsp(JSP_ITEMS);
126: pageInfo.setSpecial(true);
127: }
128:
129: /**
130: *
131: */
132: private void viewTopics(HttpServletRequest request,
133: ModelAndView next, WikiPageInfo pageInfo) throws Exception {
134: String virtualWiki = WikiUtil.getVirtualWikiFromURI(request);
135: Pagination pagination = ServletUtil.loadPagination(request,
136: next);
137: Collection items = WikiBase.getDataHandler().lookupTopicByType(
138: virtualWiki, Topic.TYPE_ARTICLE, pagination);
139: next.addObject("itemCount", new Integer(items.size()));
140: next.addObject("items", items);
141: next.addObject("rootUrl", "Special:Allpages");
142: pageInfo.setPageTitle(new WikiMessage("alltopics.title"));
143: pageInfo.setContentJsp(JSP_ITEMS);
144: pageInfo.setSpecial(true);
145: }
146:
147: /**
148: *
149: */
150: private void viewTopicsAdmin(HttpServletRequest request,
151: ModelAndView next, WikiPageInfo pageInfo) throws Exception {
152: String virtualWiki = WikiUtil.getVirtualWikiFromURI(request);
153: Pagination pagination = ServletUtil.loadPagination(request,
154: next);
155: Collection items = WikiBase.getDataHandler().getTopicsAdmin(
156: virtualWiki, pagination);
157: next.addObject("itemCount", new Integer(items.size()));
158: next.addObject("items", items);
159: next.addObject("rootUrl", "Special:TopicsAdmin");
160: pageInfo.setPageTitle(new WikiMessage("topicsadmin.title"));
161: pageInfo.setContentJsp(JSP_ITEMS);
162: pageInfo.setSpecial(true);
163: }
164: }
|