use of com.sun.syndication.feed.synd.SyndFeed in project play-cookbook by spinscale.
the class FeedResult method apply.
public void apply(Request request, Response response) {
try {
SyndFeed feed = new SyndFeedImpl();
feed.setAuthor(Play.configuration.getProperty("rss.author"));
feed.setTitle(Play.configuration.getProperty("rss.title"));
feed.setDescription(Play.configuration.getProperty("rss.description"));
feed.setLink(getFeedLink());
List<SyndEntry> entries = new ArrayList<SyndEntry>();
for (Post post : posts) {
String url = createUrl("Application.showPost", "id", post.id.toString());
SyndEntry entry = createEntry(post.title, url, post.content, post.createdAt);
entries.add(entry);
}
feed.setEntries(entries);
feed.setFeedType(getFeedType());
setContentType(response);
SyndFeedOutput output = new SyndFeedOutput();
String rss = output.outputString(feed);
response.out.write(rss.getBytes("utf-8"));
} catch (Exception e) {
throw new UnexpectedException(e);
}
}
use of com.sun.syndication.feed.synd.SyndFeed in project play-cookbook by spinscale.
the class FeedTest method testThatRss10Works.
@Test
public void testThatRss10Works() throws Exception {
Response response = GET("/feed/posts.rss");
assertIsOk(response);
assertContentType("application/rss+xml", response);
assertCharset("utf-8", response);
SyndFeed feed = getFeed(response);
assertEquals("rss_1.0", feed.getFeedType());
}
use of com.sun.syndication.feed.synd.SyndFeed in project OpenClinica by OpenClinica.
the class RssReaderServlet method getFeed.
void getFeed(PrintWriter pw) {
SyndFeed feed = null;
String htmlFeed = null;
try {
feed = feedFetcher.retrieveFeed(new URL(rssUrl));
htmlFeed = feedHtml(feed);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
htmlFeed = errorFeedHtml(e.getMessage());
e.printStackTrace();
} catch (FeedException e) {
// TODO Auto-generated catch block
htmlFeed = errorFeedHtml(e.getMessage());
e.printStackTrace();
} catch (FetcherException e) {
htmlFeed = errorFeedHtml(e.getMessage());
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
htmlFeed = errorFeedHtml(e.getMessage());
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
pw.println(htmlFeed);
pw.close();
}
}
use of com.sun.syndication.feed.synd.SyndFeed in project modules.playframework.org by playframework.
the class FeedCreationActor method createFeed.
private void createFeed(List<HistoricalEvent> historicalEvents, String feedType, File outputDirectory, String classifier) {
SyndFeed feed = new SyndFeedImpl();
feed.setFeedType(feedType);
feed.setTitle("Play! Modules");
feed.setLink("http://modules.playframework.org");
feed.setUri("http://modules.playframework.org");
feed.setPublishedDate(new Date());
feed.setDescription("The Play! Framework's module repository feed");
List<SyndEntry> entries = new ArrayList<SyndEntry>(historicalEvents.size());
for (HistoricalEvent historicalEvent : historicalEvents) {
SyndEntry entry = new SyndEntryImpl();
entry.setTitle(historicalEvent.category);
entry.setAuthor("Play framework modules");
entry.setPublishedDate(historicalEvent.creationDate);
// todo this will be the url of the module
entry.setLink("http://modules.playframework.org");
entry.setUri("mpo-he-" + historicalEvent.id);
SyndContent description = new SyndContentImpl();
description.setType("text/plain");
description.setValue(historicalEvent.message);
entry.setDescription(description);
entries.add(entry);
}
feed.setEntries(entries);
Writer writer = null;
try {
File outputFile = new File(outputDirectory, String.format("mpo.%s.xml", classifier));
writer = new FileWriter(outputFile);
SyndFeedOutput output = new SyndFeedOutput();
output.output(feed, writer);
writer.close();
} catch (IOException e) {
Logger.error(String.format("A problem occurred when generating the %s feed", classifier), e);
} catch (FeedException e) {
Logger.error(String.format("A problem occurred when generating the %s feed", classifier), e);
} finally {
IOUtils.close(writer);
}
}
Aggregations