KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snipsnap > net > RssServlet


1 /*
2  * This file is part of "SnipSnap Wiki/Weblog".
3  *
4  * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel
5  * All Rights Reserved.
6  *
7  * Please visit http://snipsnap.org/ for updates and contact.
8  *
9  * --LICENSE NOTICE--
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  * --LICENSE NOTICE--
24  */

25 package org.snipsnap.net;
26
27 import org.snipsnap.app.Application;
28 import org.snipsnap.config.Configuration;
29 import org.snipsnap.container.Components;
30 import org.snipsnap.feeder.Feeder;
31 import org.snipsnap.feeder.FeederRepository;
32 import org.snipsnap.render.PlainTextRenderEngine;
33 import org.snipsnap.semanticweb.rss.BlogFeeder;
34 import org.snipsnap.snip.Snip;
35 import org.snipsnap.snip.SnipSpace;
36 import org.snipsnap.snip.SnipSpaceFactory;
37
38 import javax.servlet.RequestDispatcher JavaDoc;
39 import javax.servlet.ServletException JavaDoc;
40 import javax.servlet.http.HttpServlet JavaDoc;
41 import javax.servlet.http.HttpServletRequest JavaDoc;
42 import javax.servlet.http.HttpServletResponse JavaDoc;
43 import java.io.IOException JavaDoc;
44
45
46 /**
47  * Load a snip for output as RSS
48  *
49  * @author Stephan J. Schmidt
50  * @version $Id: RssServlet.java 1679 2004-06-24 14:16:19Z leo $
51  */

52 public class RssServlet extends HttpServlet JavaDoc {
53   public void doGet(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
54           throws IOException JavaDoc, ServletException JavaDoc {
55
56     SnipSpace space = SnipSpaceFactory.getInstance();
57     Configuration config = Application.get().getConfiguration();
58
59     String JavaDoc eTag = request.getHeader("If-None-Match");
60     if (null != eTag && eTag.equals(space.getETag())) {
61       response.setHeader("ETag", space.getETag());
62       response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
63       return;
64     } else {
65       String JavaDoc version = request.getParameter("version");
66       String JavaDoc type = request.getParameter("type");
67       String JavaDoc sourceSnipName = request.getParameter("snip");
68
69       if (null == sourceSnipName) {
70         sourceSnipName = config.getStartSnip();
71       }
72
73       Snip sourceSnip = space.load(sourceSnipName);
74
75       Object JavaDoc object = Components.getComponent(PlainTextRenderEngine.class);
76       System.err.println("object = " + object.getClass());
77
78       FeederRepository repository = (FeederRepository) Components.getComponent(FeederRepository.class);
79
80       Feeder feeder = (Feeder) repository.get(type);
81
82 // System.out.println("Feeder repository: "+repository.getPlugins());
83
if (null == feeder || "blog".equals(feeder.getName())) {
84         if (sourceSnip.isWeblog()) {
85           feeder = new BlogFeeder(sourceSnipName);
86         } else {
87           feeder = new BlogFeeder();
88         }
89       }
90
91       Snip snip = feeder.getContextSnip();
92
93       request.setAttribute("snip", snip);
94       request.setAttribute("rsssnips", feeder.getFeed());
95       request.setAttribute("space", space);
96       request.setAttribute("config", config);
97
98       request.setAttribute("url", config.getUrl("/space"));
99
100       RequestDispatcher JavaDoc dispatcher;
101       if ("1.0".equals(version)) {
102         dispatcher = request.getRequestDispatcher("/rdf.jsp");
103       } else if ("0.92".equals(version)) {
104         dispatcher = request.getRequestDispatcher("/rss.jsp");
105       } else if ("plain".equals(version)) {
106         dispatcher = request.getRequestDispatcher("/plain.jsp");
107       } else {
108         dispatcher = request.getRequestDispatcher("/rss2.jsp");
109       }
110
111       dispatcher.forward(request, response);
112     }
113   }
114 }
115
Popular Tags