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: import java.util.Iterator;
20: import java.util.LinkedHashMap;
21:
22: import javax.servlet.http.HttpServletRequest;
23: import javax.servlet.http.HttpServletResponse;
24:
25: import org.jamwiki.WikiBase;
26: import org.jamwiki.WikiMessage;
27: import org.jamwiki.model.Category;
28: import org.jamwiki.utils.NamespaceHandler;
29: import org.jamwiki.utils.Pagination;
30: import org.jamwiki.utils.WikiLogger;
31: import org.jamwiki.utils.WikiUtil;
32: import org.springframework.web.servlet.ModelAndView;
33:
34: /**
35: * Used for display a list of all categories that are currently in use for a
36: * virtual wiki.
37: */
38: public class CategoryServlet extends JAMWikiServlet {
39:
40: /** Logger for this class and subclasses. */
41: private static final WikiLogger logger = WikiLogger
42: .getLogger(CategoryServlet.class.getName());
43: protected static final String JSP_CATEGORIES = "categories.jsp";
44:
45: /**
46: *
47: */
48: protected ModelAndView handleJAMWikiRequest(
49: HttpServletRequest request, HttpServletResponse response,
50: ModelAndView next, WikiPageInfo pageInfo) throws Exception {
51: this .viewCategories(request, next, pageInfo);
52: return next;
53: }
54:
55: /**
56: *
57: */
58: private void viewCategories(HttpServletRequest request,
59: ModelAndView next, WikiPageInfo pageInfo) throws Exception {
60: String virtualWiki = WikiUtil.getVirtualWikiFromURI(request);
61: Pagination pagination = ServletUtil.loadPagination(request,
62: next);
63: Collection categoryObjects = WikiBase.getDataHandler()
64: .getAllCategories(virtualWiki, pagination);
65: LinkedHashMap categories = new LinkedHashMap();
66: for (Iterator iterator = categoryObjects.iterator(); iterator
67: .hasNext();) {
68: Category category = (Category) iterator.next();
69: String key = category.getName();
70: String value = key
71: .substring(NamespaceHandler.NAMESPACE_CATEGORY
72: .length()
73: + NamespaceHandler.NAMESPACE_SEPARATOR
74: .length());
75: categories.put(key, value);
76: }
77: next.addObject("categoryCount", new Integer(categories.size()));
78: next.addObject("categories", categories);
79: pageInfo.setPageTitle(new WikiMessage("allcategories.title"));
80: pageInfo.setContentJsp(JSP_CATEGORIES);
81: pageInfo.setSpecial(true);
82: }
83: }
|