KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > presentation > velocity > PlanetFeedServlet


1 package org.roller.presentation.velocity;
2 import java.io.IOException JavaDoc;
3 import java.util.Date JavaDoc;
4
5 import javax.servlet.ServletException JavaDoc;
6 import javax.servlet.http.HttpServletRequest JavaDoc;
7 import javax.servlet.http.HttpServletResponse JavaDoc;
8
9 import org.apache.commons.logging.Log;
10 import org.apache.commons.logging.LogFactory;
11 import org.apache.velocity.Template;
12 import org.apache.velocity.context.Context;
13 import org.apache.velocity.servlet.VelocityServlet;
14 import org.roller.RollerException;
15 import org.roller.model.PlanetManager;
16 import org.roller.presentation.RollerRequest;
17 import org.roller.util.Utilities;
18
19 /////////////////////////////////////////////////////////////////////////////
20
/**
21  * Planet Roller (i.e. NOT for Planet Tool) RSS feed.
22  * @author David M Johnson
23  * @web.servlet name="PlanetFeedServlet"
24  * @web.servlet-mapping url-pattern="/planetrss/*"
25  */

26 public class PlanetFeedServlet extends VelocityServlet
27 {
28     private static Log mLogger =
29         LogFactory.getFactory().getInstance(RollerRequest.class);
30     
31     public Template handleRequest(HttpServletRequest JavaDoc request,
32                                   HttpServletResponse JavaDoc response, Context context)
33     {
34         RollerRequest rreq = null;
35         try
36         {
37             rreq = RollerRequest.getRollerRequest(request, getServletContext());
38         }
39         catch (RollerException e)
40         {
41             // An error initializing the request is considered to be a 404
42
if (mLogger.isDebugEnabled())
43             {
44                 mLogger.debug("RollerRequest threw Exception", e);
45             }
46             try
47             {
48                 response.sendError(HttpServletResponse.SC_NOT_FOUND);
49             }
50             catch (IOException JavaDoc e1)
51             {
52                 if (mLogger.isDebugEnabled())
53                 {
54                     mLogger.debug("IOException sending error", e);
55                 }
56             }
57             return null;
58         }
59         try
60         {
61             response.setContentType("application/rss+xml;charset=utf-8");
62             PlanetManager planet =
63                 rreq.getRoller().getPlanetManager();
64             if (request.getParameter("group") != null)
65             {
66                 context.put("group",
67                         planet.getGroup(request.getParameter("group")));
68             }
69             context.put("planet", planet);
70             context.put("date", new Date JavaDoc());
71             context.put("utilities", new Utilities());
72             return getTemplate("planetrss.vm");
73         }
74         catch (Exception JavaDoc e)
75         {
76             mLogger.error("ERROR in PlanetFeedServlet", e);
77         }
78         return null;
79     }
80
81     //------------------------------------------------------------------------
82
/**
83      * Handle error in Velocity processing.
84      */

85     protected void error( HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res,
86         Exception JavaDoc e) throws ServletException JavaDoc, IOException JavaDoc
87     {
88         mLogger.warn("ERROR in PlanetFeedServlet",e);
89     }
90 }
91
92
Popular Tags