Search in sources :

Example 11 with SyndEntry

use of com.rometools.rome.feed.synd.SyndEntry in project opencast by opencast.

the class RomeRssFeed method init.

/**
 * Converts the replay feed to a rome feed, that can then be written to the reponse.
 *
 * @param originalFeed
 *          the original feed
 * @param feedInfo
 *          the feed info
 */
private void init(Feed originalFeed, FeedInfo feedInfo) {
    if (originalFeed == null)
        throw new IllegalArgumentException("Feed is null");
    // Create SyndFeed
    setEncoding(originalFeed.getEncoding());
    setFeedType(feedInfo.toROMEVersion());
    // Convert fields
    setModules(toRomeModules(originalFeed.getModules()));
    setAuthors(toRomePersons(originalFeed.getAuthors()));
    setCategories(toRomeCategories(originalFeed.getCategories()));
    setContributors(toRomePersons(originalFeed.getContributors()));
    setDescriptionEx(toRomeContent(originalFeed.getDescription()));
    setImage(toRomeImage(originalFeed.getImage()));
    setLanguage(originalFeed.getLanguage());
    setLinks(toRomeLinks(originalFeed.getLinks()));
    setPublishedDate(originalFeed.getPublishedDate());
    setTitleEx(toRomeContent(originalFeed.getTitle()));
    setCopyright(originalFeed.getCopyright());
    setUri(originalFeed.getUri());
    setLink(originalFeed.getLink());
    // Add SyndFeedEntries
    if (originalFeed.getEntries() != null) {
        List<SyndEntry> romeEntries = new ArrayList<SyndEntry>();
        for (FeedEntry entry : originalFeed.getEntries()) {
            SyndEntryImpl e = new SyndEntryImpl();
            e.setModules(toRomeModules(entry.getModules()));
            e.setAuthors(toRomePersons(entry.getAuthors()));
            e.setCategories(toRomeCategories(entry.getCategories()));
            e.setContents(toRomeContents(entry.getContents()));
            e.setContributors(toRomePersons(entry.getContributors()));
            e.setDescription(toRomeContent(entry.getDescription()));
            e.setEnclosures(toRomeEnclosures(entry.getEnclosures()));
            e.setPublishedDate(entry.getPublishedDate());
            e.setTitleEx(toRomeContent(entry.getTitle()));
            e.setUpdatedDate(entry.getUpdatedDate());
            e.setUri(entry.getUri());
            List<SyndLink> links = toRomeLinks(entry.getLinks());
            e.setLinks(links);
            // todo this strategy seems to work but is unproven
            if (links.size() > 0)
                e.setLink(links.get(0).getHref());
            romeEntries.add(e);
        }
        setEntries(romeEntries);
    }
}
Also used : FeedEntry(org.opencastproject.feed.api.FeedEntry) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) ArrayList(java.util.ArrayList) SyndLink(com.rometools.rome.feed.synd.SyndLink)

Example 12 with SyndEntry

use of com.rometools.rome.feed.synd.SyndEntry in project spring-integration by spring-projects.

the class FeedEntryMessageSource method populateEntryList.

private void populateEntryList() {
    SyndFeed syndFeed = this.getFeed();
    if (syndFeed != null) {
        List<SyndEntry> retrievedEntries = syndFeed.getEntries();
        if (!CollectionUtils.isEmpty(retrievedEntries)) {
            boolean withinNewEntries = false;
            Collections.sort(retrievedEntries, this.syndEntryComparator);
            for (SyndEntry entry : retrievedEntries) {
                Date entryDate = getLastModifiedDate(entry);
                if ((entryDate != null && entryDate.getTime() > this.lastTime) || (entryDate == null && withinNewEntries)) {
                    this.entries.add(entry);
                    withinNewEntries = true;
                }
            }
        }
    }
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) Date(java.util.Date)

Example 13 with SyndEntry

use of com.rometools.rome.feed.synd.SyndEntry in project spring-integration by spring-projects.

the class FeedEntryMessageSource method receive.

@Override
public Message<SyndEntry> receive() {
    Assert.isTrue(this.initialized, "'FeedEntryReaderMessageSource' must be initialized before it can produce Messages.");
    SyndEntry entry = doReceive();
    if (entry == null) {
        return null;
    }
    return this.getMessageBuilderFactory().withPayload(entry).build();
}
Also used : SyndEntry(com.rometools.rome.feed.synd.SyndEntry)

Example 14 with SyndEntry

use of com.rometools.rome.feed.synd.SyndEntry in project spring-integration by spring-projects.

the class FeedEntryMessageSource method doReceive.

private SyndEntry doReceive() {
    SyndEntry nextEntry = null;
    synchronized (this.monitor) {
        nextEntry = getNextEntry();
        if (nextEntry == null) {
            // read feed and try again
            this.populateEntryList();
            nextEntry = getNextEntry();
        }
    }
    return nextEntry;
}
Also used : SyndEntry(com.rometools.rome.feed.synd.SyndEntry)

Example 15 with SyndEntry

use of com.rometools.rome.feed.synd.SyndEntry in project spring-integration by spring-projects.

the class FeedEntryMessageSource method getNextEntry.

private SyndEntry getNextEntry() {
    SyndEntry next = this.entries.poll();
    if (next == null) {
        return null;
    }
    Date lastModifiedDate = FeedEntryMessageSource.getLastModifiedDate(next);
    if (lastModifiedDate != null) {
        this.lastTime = lastModifiedDate.getTime();
    } else {
        // NOSONAR - single poller thread
        this.lastTime += 1;
    }
    this.metadataStore.put(this.metadataKey, this.lastTime + "");
    return next;
}
Also used : SyndEntry(com.rometools.rome.feed.synd.SyndEntry) Date(java.util.Date)

Aggregations

SyndEntry (com.rometools.rome.feed.synd.SyndEntry)45 ArrayList (java.util.ArrayList)23 SyndFeed (com.rometools.rome.feed.synd.SyndFeed)22 SyndEntryImpl (com.rometools.rome.feed.synd.SyndEntryImpl)18 SyndContent (com.rometools.rome.feed.synd.SyndContent)15 SyndFeedImpl (com.rometools.rome.feed.synd.SyndFeedImpl)14 SyndContentImpl (com.rometools.rome.feed.synd.SyndContentImpl)13 SyndFeedInput (com.rometools.rome.io.SyndFeedInput)9 FeedException (com.rometools.rome.io.FeedException)7 Test (org.junit.Test)7 XmlReader (com.rometools.rome.io.XmlReader)6 URL (java.net.URL)6 Date (java.util.Date)5 StatusGroup (org.onebusaway.enterprise.webapp.actions.status.model.StatusGroup)5 StatusItem (org.onebusaway.enterprise.webapp.actions.status.model.StatusItem)5 IOException (java.io.IOException)4 BeanFactory (org.springframework.beans.factory.BeanFactory)4 ClassPathResource (org.springframework.core.io.ClassPathResource)4 SyndFeedOutput (com.rometools.rome.io.SyndFeedOutput)3 Post (it.vige.rubia.model.Post)3