use of com.sun.syndication.feed.synd.SyndFeed in project jersey by jersey.
the class FeedEntriesAtomBodyWriter method writeTo.
@Override
public void writeTo(List<FeedEntry> entries, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
List<SyndEntry> syndEntries = entries.parallelStream().map(entry -> {
SyndContent description = new SyndContentImpl();
description.setType(MediaType.TEXT_PLAIN);
description.setValue(entry.getDescription());
SyndEntry syndEntry = new SyndEntryImpl();
syndEntry.setTitle(entry.getTitle());
syndEntry.setLink(entry.getLink());
syndEntry.setPublishedDate(entry.getPublishDate());
syndEntry.setDescription(description);
return syndEntry;
}).collect(Collectors.toList());
SyndFeed feed = new SyndFeedImpl();
feed.setFeedType("atom_1.0");
feed.setTitle("Combined Feed");
feed.setDescription("Combined Feed created by a feed-combiner application");
feed.setPublishedDate(new Date());
feed.setEntries(syndEntries);
writeSyndFeed(entityStream, feed);
}
use of com.sun.syndication.feed.synd.SyndFeed in project camel by apache.
the class AggregateRssFeedStrategy method aggregate.
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
if (oldExchange == null) {
return newExchange;
}
SyndFeed oldFeed = oldExchange.getIn().getBody(SyndFeed.class);
SyndFeed newFeed = newExchange.getIn().getBody(SyndFeed.class);
if (oldFeed != null && newFeed != null) {
List<SyndEntryImpl> oldEntries = CastUtils.cast(oldFeed.getEntries());
List<SyndEntryImpl> newEntries = CastUtils.cast(newFeed.getEntries());
List<SyndEntryImpl> mergedList = new ArrayList<SyndEntryImpl>(oldEntries.size() + newEntries.size());
mergedList.addAll(oldEntries);
mergedList.addAll(newEntries);
oldFeed.setEntries(mergedList);
} else {
log.debug("Could not merge exchanges. One body was null.");
}
return oldExchange;
}
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);
}
}
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());
}
Aggregations