File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\model\RSS.java.html

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2010, Sun Microsystems, Inc., Kohsuke Kawaguchi
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 package hudson.model;
25
26 import hudson.FeedAdapter;
27 import jenkins.model.Jenkins;
28 import org.kohsuke.stapler.StaplerRequest;
29 import org.kohsuke.stapler.StaplerResponse;
30
31 import javax.servlet.ServletException;
32 import javax.servlet.http.HttpServletResponse;
33 import java.io.IOException;
34 import java.io.PrintWriter;
35 import java.util.Collection;
36
37 /**
38 * RSS related code.
39 *
40 * @author Kohsuke Kawaguchi
41 */
42 public final class RSS {
43
44 /**
45 * Parses trackback ping.
46 */
47 public static void doTrackback( Object it, StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
48
49 String url = req.getParameter("url");
50
51 rsp.setStatus(HttpServletResponse.SC_OK);
52 rsp.setContentType("application/xml; charset=UTF-8");
53 PrintWriter pw = rsp.getWriter();
54 pw.println("<response>");
55 pw.println("<error>"+(url!=null?0:1)+"</error>");
56 if(url==null) {
57 pw.println("<message>url must be specified</message>");
58 }
59 pw.println("</response>");
60 pw.close();
61 }
62
63 /**
64 * Sends the RSS feed to the client.
65 *
66 * @param title
67 * Title of the feed.
68 * @param url
69 * URL of the model object that owns this feed. Relative to the context root.
70 * @param entries
71 * Entries to be listed in the RSS feed.
72 * @param adapter
73 * Controls how to render entries to RSS.
74 */
75 public static <E> void forwardToRss(String title, String url, Collection<? extends E> entries, FeedAdapter<E> adapter, StaplerRequest req, HttpServletResponse rsp) throws IOException, ServletException {
76 req.setAttribute("adapter",adapter);
77 req.setAttribute("title",title);
78 req.setAttribute("url",url);
79 req.setAttribute("entries",entries);
80 req.setAttribute("rootURL", Jenkins.getInstance().getRootUrl());
81
82 String flavor = req.getParameter("flavor");
83 if(flavor==null) flavor="atom";
84 flavor = flavor.replace('/', '_'); // Don't allow path to any jelly
85
86 req.getView(Jenkins.getInstance(),"/hudson/"+flavor+".jelly").forward(req,rsp);
87 }
88 }
89