KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hudson > model > RSS


1 package hudson.model;
2
3 import hudson.FeedAdapter;
4 import org.kohsuke.stapler.StaplerRequest;
5 import org.kohsuke.stapler.StaplerResponse;
6
7 import javax.servlet.ServletException JavaDoc;
8 import javax.servlet.http.HttpServletResponse JavaDoc;
9 import java.io.IOException JavaDoc;
10 import java.io.PrintWriter JavaDoc;
11 import java.util.Collection JavaDoc;
12
13 /**
14  * RSS related code.
15  *
16  * @author Kohsuke Kawaguchi
17  */

18 final class RSS {
19
20     /**
21      * Parses trackback ping.
22      */

23     public static void doTrackback( Object JavaDoc it, StaplerRequest req, StaplerResponse rsp ) throws IOException JavaDoc, ServletException JavaDoc {
24         req.setCharacterEncoding("UTF-8");
25
26         String JavaDoc title = req.getParameter("title");
27         String JavaDoc url = req.getParameter("url");
28         String JavaDoc excerpt = req.getParameter("excerpt");
29         String JavaDoc blog_name = req.getParameter("blog_name");
30
31         rsp.setStatus(HttpServletResponse.SC_OK);
32         rsp.setContentType("application/xml; charset=UTF-8");
33         PrintWriter JavaDoc pw = rsp.getWriter();
34         pw.println("<response>");
35         pw.println("<error>"+(url!=null?0:1)+"</error>");
36         if(url==null) {
37             pw.println("<message>url must be specified</message>");
38         }
39         pw.println("</response>");
40         pw.close();
41     }
42
43     /**
44      * Sends the RSS feed to the client.
45      *
46      * @param title
47      * Title of the feed.
48      * @param url
49      * URL of the model object that owns this feed. Relative to the context root.
50      * @param entries
51      * Entries to be listed in the RSS feed.
52      * @param adapter
53      * Controls how to render entries to RSS.
54      */

55     public static <E> void forwardToRss(String JavaDoc title, String JavaDoc url, Collection JavaDoc<? extends E> entries, FeedAdapter<E> adapter, StaplerRequest req, HttpServletResponse JavaDoc rsp) throws IOException JavaDoc, ServletException JavaDoc {
56         req.setAttribute("adapter",adapter);
57         req.setAttribute("title",title);
58         req.setAttribute("url",url);
59         req.setAttribute("entries",entries);
60
61         String JavaDoc flavor = req.getParameter("flavor");
62         if(flavor==null) flavor="atom";
63
64         req.getView(Hudson.getInstance(),"/hudson/"+flavor+".jelly").forward(req,rsp);
65     }
66 }
67
Popular Tags