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.io.PrintWriter;
19:
20: import javax.servlet.http.HttpServletRequest;
21: import javax.servlet.http.HttpServletResponse;
22:
23: import org.jamwiki.WikiBase;
24: import org.jamwiki.utils.WikiLogger;
25: import org.jamwiki.utils.WikiUtil;
26: import org.springframework.web.servlet.ModelAndView;
27:
28: /**
29: * Used to generate the jamwiki.css stylesheet.
30: */
31: public class StylesheetServlet extends JAMWikiServlet {
32:
33: private static final WikiLogger logger = WikiLogger
34: .getLogger(StylesheetServlet.class.getName());
35:
36: /**
37: *
38: */
39: protected ModelAndView handleJAMWikiRequest(
40: HttpServletRequest request, HttpServletResponse response,
41: ModelAndView next, WikiPageInfo pageInfo) throws Exception {
42: String virtualWiki = null;
43: try {
44: virtualWiki = WikiUtil.getVirtualWikiFromURI(request);
45: String stylesheet = ServletUtil.cachedContent(request
46: .getContextPath(), request.getLocale(),
47: virtualWiki, WikiBase.SPECIAL_PAGE_STYLESHEET,
48: false);
49: response.setContentType("text/css");
50: response.setCharacterEncoding("UTF-8");
51: // cache for 30 minutes (60 * 30 = 1800)
52: // FIXME - make configurable
53: response.setHeader("Cache-Control", "max-age=1800");
54: PrintWriter out = response.getWriter();
55: out.print(stylesheet);
56: out.close();
57: } catch (Exception e) {
58: logger.severe(
59: "Failure while loading stylesheet for virtualWiki "
60: + virtualWiki, e);
61: }
62: // do not load defaults or redirect - return as raw CSS
63: return null;
64: }
65:
66: /**
67: *
68: */
69: protected void initParams() {
70: this .layout = false;
71: }
72: }
|