use of com.sun.syndication.feed.synd.SyndEntry in project camel by apache.
the class UpdatedDateFilter method isValidEntry.
public boolean isValidEntry(FeedEndpoint endpoint, Object feed, Object entry) {
Date updated = ((SyndEntry) entry).getUpdatedDate();
if (updated == null) {
// never been updated so get published date
updated = ((SyndEntry) entry).getPublishedDate();
}
if (updated == null) {
LOG.debug("No updated time for entry so assuming its valid: entry=[{}]", entry);
return true;
}
if (lastUpdate != null) {
if (lastUpdate.after(updated)) {
LOG.debug("Entry is older than lastupdate=[{}], no valid entry=[{}]", lastUpdate, entry);
return false;
} else {
Integer hash = entry.hashCode();
if (lastUpdate.equals(updated)) {
if (entriesForLastUpdate.containsKey(hash)) {
LOG.debug("Already processed entry=[{}]", entry);
return false;
}
} else {
entriesForLastUpdate.clear();
}
entriesForLastUpdate.put(hash, hash);
}
}
lastUpdate = updated;
return true;
}
use of com.sun.syndication.feed.synd.SyndEntry 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.SyndEntry 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.SyndEntry in project play-cookbook by spinscale.
the class FeedResult method createEntry.
private SyndEntry createEntry(String title, String link, String description, Date createDate) {
SyndEntry entry = new SyndEntryImpl();
entry.setTitle(title);
entry.setLink(link);
entry.setPublishedDate(createDate);
SyndContent entryDescription = new SyndContentImpl();
entryDescription.setType("text/html");
entryDescription.setValue(description);
entry.setDescription(entryDescription);
return entry;
}
use of com.sun.syndication.feed.synd.SyndEntry in project cubrid-manager by CUBRID.
the class NoticeDashboardEntity method getHtmlContent.
/**
* Get HTML content by category.
*
* @param categories
* @return
*/
public String getHtmlContent(String... categories) {
Set<String> categorySet = new HashSet<String>();
if (categories == null) {
return "";
}
for (String category : categories) {
if (category != null) {
categorySet.add(category);
}
}
Set<SyndEntry> syndEntries = new HashSet<SyndEntry>();
if (contents == null || contents.entrySet() == null) {
return "";
}
for (Entry<Set<String>, Set<SyndEntry>> entity : contents.entrySet()) {
if (entity.getKey().containsAll(categorySet)) {
syndEntries.addAll(entity.getValue());
}
}
List<SyndEntry> syndEntryList = new ArrayList<SyndEntry>(syndEntries);
Collections.sort(syndEntryList, new Comparator<SyndEntry>() {
public int compare(SyndEntry o1, SyndEntry o2) {
if (o1 == null || o2 == null || o1.getPublishedDate() == null || o2.getPublishedDate() == null) {
return 0;
}
return o2.getPublishedDate().compareTo(o1.getPublishedDate());
}
});
StringBuilder sb = new StringBuilder();
sb.append("<p>");
if (syndEntryList != null && !syndEntryList.isEmpty()) {
for (SyndEntry entry : syndEntryList) {
SyndContent description = entry.getDescription();
sb.append("<li>");
sb.append("<img href=\"icons/action/host_connect.png\"/>");
sb.append("<a href=\"").append(entry.getLink()).append("\">");
sb.append(entry.getTitle());
sb.append("</a>");
sb.append("</li>");
if (!StringUtil.isEmpty(description.getValue())) {
sb.append("<p>");
sb.append(description.getValue().trim());
sb.append("</p>");
}
}
} else {
sb.append("<p>No data.</p>");
}
sb.append("</p>");
return sb.toString();
}
Aggregations