Search in sources :

Example 11 with SyndEntry

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;
}
Also used : SyndEntry(com.sun.syndication.feed.synd.SyndEntry) Date(java.util.Date)

Example 12 with SyndEntry

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);
    }
}
Also used : SyndEntry(com.sun.syndication.feed.synd.SyndEntry) SyndContentImpl(com.sun.syndication.feed.synd.SyndContentImpl) HistoricalEvent(models.HistoricalEvent) FileWriter(java.io.FileWriter) FeedException(com.sun.syndication.io.FeedException) ArrayList(java.util.ArrayList) SyndFeedOutput(com.sun.syndication.io.SyndFeedOutput) IOException(java.io.IOException) Date(java.util.Date) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndContent(com.sun.syndication.feed.synd.SyndContent) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl) SyndFeedImpl(com.sun.syndication.feed.synd.SyndFeedImpl) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 13 with SyndEntry

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);
    }
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) UnexpectedException(play.exceptions.UnexpectedException) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) Post(models.Post) ArrayList(java.util.ArrayList) SyndFeedImpl(com.sun.syndication.feed.synd.SyndFeedImpl) SyndFeedOutput(com.sun.syndication.io.SyndFeedOutput) UnexpectedException(play.exceptions.UnexpectedException)

Example 14 with SyndEntry

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;
}
Also used : SyndContent(com.sun.syndication.feed.synd.SyndContent) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) SyndContentImpl(com.sun.syndication.feed.synd.SyndContentImpl) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl)

Example 15 with SyndEntry

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();
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) SyndContent(com.sun.syndication.feed.synd.SyndContent) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Aggregations

SyndEntry (com.sun.syndication.feed.synd.SyndEntry)20 SyndEntryImpl (com.sun.syndication.feed.synd.SyndEntryImpl)12 SyndFeed (com.sun.syndication.feed.synd.SyndFeed)11 SyndFeedImpl (com.sun.syndication.feed.synd.SyndFeedImpl)10 ArrayList (java.util.ArrayList)10 SyndContent (com.sun.syndication.feed.synd.SyndContent)8 SyndContentImpl (com.sun.syndication.feed.synd.SyndContentImpl)8 Date (java.util.Date)5 SyndFeedOutput (com.sun.syndication.io.SyndFeedOutput)4 IOException (java.io.IOException)3 SQLException (java.sql.SQLException)3 SyndCategory (com.sun.syndication.feed.synd.SyndCategory)2 FeedException (com.sun.syndication.io.FeedException)2 SyndFeedInput (com.sun.syndication.io.SyndFeedInput)2 OutputStreamWriter (java.io.OutputStreamWriter)2 HashSet (java.util.HashSet)2 Test (org.junit.Test)2 OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)2 Filter (org.opennms.web.filter.Filter)2 Post (com.erudika.scoold.core.Post)1