All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hudson.model.RSS Maven / Gradle / Ivy

The newest version!
/*******************************************************************************
 *
 * Copyright (c) 2004-2010 Oracle Corporation.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *
 *    Kohsuke Kawaguchi
 *
 *
 *******************************************************************************/ 

package hudson.model;

import hudson.FeedAdapter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collection;

/**
 * RSS related code.
 *
 * @author Kohsuke Kawaguchi
 */
public final class RSS {

    /**
     * Parses trackback ping.
     */
    public static void doTrackback(Object it, StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {

        String url = req.getParameter("url");

        rsp.setStatus(HttpServletResponse.SC_OK);
        rsp.setContentType("application/xml; charset=UTF-8");
        PrintWriter pw = rsp.getWriter();
        pw.println("");
        pw.println("" + (url != null ? 0 : 1) + "");
        if (url == null) {
            pw.println("url must be specified");
        }
        pw.println("");
        pw.close();
    }

    /**
     * Sends the RSS feed to the client.
     *
     * @param title Title of the feed.
     * @param url URL of the model object that owns this feed. Relative to the
     * context root.
     * @param entries Entries to be listed in the RSS feed.
     * @param adapter Controls how to render entries to RSS.
     */
    public static  void forwardToRss(String title, String url, Collection entries, FeedAdapter adapter, StaplerRequest req, HttpServletResponse rsp) throws IOException, ServletException {
        req.setAttribute("adapter", adapter);
        req.setAttribute("title", title);
        req.setAttribute("url", url);
        req.setAttribute("entries", entries);
        req.setAttribute("rootURL", Hudson.getInstance().getRootUrl());

        String flavor = req.getParameter("flavor");
        if (flavor == null) {
            flavor = "atom";
        }
        flavor = flavor.replace('/', '_'); // Don't allow path to any jelly

        req.getView(Hudson.getInstance(), "/hudson/" + flavor + ".jelly").forward(req, rsp);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy