| 1 |
|
package com.atlassian.xwork.results; |
| 2 |
|
|
| 3 |
|
import com.opensymphony.webwork.ServletActionContext; |
| 4 |
|
import com.opensymphony.webwork.dispatcher.WebWorkResultSupport; |
| 5 |
|
import com.opensymphony.xwork.ActionInvocation; |
| 6 |
|
import com.sun.syndication.feed.WireFeed; |
| 7 |
|
import com.sun.syndication.feed.synd.SyndFeed; |
| 8 |
|
import com.sun.syndication.io.WireFeedOutput; |
| 9 |
|
import org.apache.log4j.Logger; |
| 10 |
|
|
| 11 |
|
import javax.servlet.ServletException; |
| 12 |
|
import javax.servlet.http.HttpServletResponse; |
| 13 |
|
import java.io.IOException; |
| 14 |
|
|
|
|
|
| 0% |
Uncovered Elements: 27 (27) |
Complexity: 6 |
Complexity Density: 0.33 |
|
| 15 |
|
public class RssResult extends WebWorkResultSupport { |
| 16 |
|
private static final Logger log = Logger.getLogger(RssResult.class); |
| 17 |
|
private static final String DEFAULT_DEFAULT_ENCODING = "UTF-8"; |
| 18 |
|
|
| 19 |
|
public static final String RSS = "rss"; |
| 20 |
|
public static final String RSS1 = "rss1"; |
| 21 |
|
public static final String RSS2 = "rss2"; |
| 22 |
|
public static final String ATOM = "atom"; |
| 23 |
|
|
|
|
|
| 0% |
Uncovered Elements: 26 (26) |
Complexity: 6 |
Complexity Density: 0.33 |
|
| 24 |
0
|
protected void doExecute(String finalDestination, ActionInvocation actionInvocation) throws Exception {... |
| 25 |
|
|
| 26 |
0
|
ServletActionContext.getRequest().getSession(false); |
| 27 |
0
|
HttpServletResponse response = ServletActionContext.getResponse(); |
| 28 |
|
|
| 29 |
0
|
if (finalDestination.startsWith("rss")) |
| 30 |
0
|
response.setContentType("application/rss+xml; charset=" + DEFAULT_DEFAULT_ENCODING); |
| 31 |
0
|
else if (finalDestination.startsWith("atom")) |
| 32 |
0
|
response.setContentType("application/atom+xml; charset=" + DEFAULT_DEFAULT_ENCODING); |
| 33 |
|
else |
| 34 |
0
|
response.setContentType("text/xml; charset=" + DEFAULT_DEFAULT_ENCODING); |
| 35 |
|
|
| 36 |
0
|
SyndFeed feed = (SyndFeed) actionInvocation.getStack().findValue("syndFeed"); |
| 37 |
0
|
if (feed == null) |
| 38 |
0
|
throw new ServletException("Unable to find feed for this action"); |
| 39 |
|
|
| 40 |
0
|
WireFeed outFeed = feed.createWireFeed(finalDestination); |
| 41 |
0
|
outFeed.setEncoding(DEFAULT_DEFAULT_ENCODING); |
| 42 |
0
|
new WireFeedOutput().output(outFeed, response.getWriter()); |
| 43 |
0
|
try { |
| 44 |
0
|
response.flushBuffer(); |
| 45 |
|
} catch (IOException e) { |
| 46 |
0
|
log.info("Client aborted (closed the connection) before the rss feed could be returned."); |
| 47 |
0
|
if (log.isDebugEnabled()) { |
| 48 |
0
|
log.debug("Error sending rss result to client", e); |
| 49 |
|
} |
| 50 |
|
} |
| 51 |
|
} |
| 52 |
|
} |