Search in sources :

Example 11 with SyndEnclosure

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

the class RomeRssFeed method toRomeEnclosures.

/**
 * Converts a list of enclosures to a <code>ROME</code> enclosure list.
 *
 * @param enclosures
 *          original enclosures
 * @return <code>ROME</code> enclosure list
 */
private List<SyndEnclosure> toRomeEnclosures(List<Enclosure> enclosures) {
    if (enclosures == null)
        return Collections.emptyList();
    List<SyndEnclosure> romeEnclosures = new ArrayList<SyndEnclosure>(enclosures.size());
    for (Enclosure enclosure : enclosures) {
        SyndEnclosureImpl romeEnclosure = new SyndEnclosureImpl();
        romeEnclosure.setLength(enclosure.getLength());
        romeEnclosure.setType(enclosure.getType());
        romeEnclosure.setUrl(enclosure.getUrl());
        romeEnclosures.add(romeEnclosure);
    }
    return romeEnclosures;
}
Also used : SyndEnclosure(com.rometools.rome.feed.synd.SyndEnclosure) ArrayList(java.util.ArrayList) Enclosure(org.opencastproject.feed.api.Enclosure) SyndEnclosure(com.rometools.rome.feed.synd.SyndEnclosure) SyndEnclosureImpl(com.rometools.rome.feed.synd.SyndEnclosureImpl)

Example 12 with SyndEnclosure

use of com.rometools.rome.feed.synd.SyndEnclosure in project openolat by klemens.

the class RomeFeedFetcherTest method convertEnclosures_Url_null.

@Test
public void convertEnclosures_Url_null() {
    when(syndEnclosureMock.getUrl()).thenReturn(null);
    List<SyndEnclosure> enclosures = Arrays.asList(syndEnclosureMock);
    Enclosure enclosure = sut.convertEnclosures(enclosures);
    assertThat(enclosure).isNull();
}
Also used : SyndEnclosure(com.rometools.rome.feed.synd.SyndEnclosure) SyndEnclosure(com.rometools.rome.feed.synd.SyndEnclosure) Enclosure(org.olat.modules.webFeed.Enclosure) Test(org.junit.Test)

Example 13 with SyndEnclosure

use of com.rometools.rome.feed.synd.SyndEnclosure in project openolat by klemens.

the class RomeFeedFetcherTest method convertEnclosures_emptyList.

@Test
public void convertEnclosures_emptyList() {
    List<SyndEnclosure> enclosures = new ArrayList<>();
    Enclosure enclosure = sut.convertEnclosures(enclosures);
    assertThat(enclosure).isNull();
}
Also used : SyndEnclosure(com.rometools.rome.feed.synd.SyndEnclosure) ArrayList(java.util.ArrayList) SyndEnclosure(com.rometools.rome.feed.synd.SyndEnclosure) Enclosure(org.olat.modules.webFeed.Enclosure) Test(org.junit.Test)

Example 14 with SyndEnclosure

use of com.rometools.rome.feed.synd.SyndEnclosure in project openolat by klemens.

the class RomeFeedFetcher method convertEnclosures.

/**
 * Converts a List of <code>SyndEnclosures</code> into an <code>Enclosure</code>.
 * Only one media file is supported. If the List has more than one entry, the
 * first entry is taken.
 * SyndEnclosures without an URL are not converted, because it is necessary to
 * fetch the enclosure.
 *
 * @param enclosures
 * @return the enclosure or null
 */
protected Enclosure convertEnclosures(List<SyndEnclosure> enclosures) {
    if (enclosures == null || enclosures.isEmpty())
        return null;
    SyndEnclosure syndEnclosure = enclosures.get(0);
    Enclosure enclosure = null;
    if (StringHelper.containsNonWhitespace(syndEnclosure.getUrl())) {
        enclosure = new EnclosureImpl();
        enclosure.setExternalUrl(syndEnclosure.getUrl());
        enclosure.setLength(syndEnclosure.getLength());
        enclosure.setType(syndEnclosure.getType());
    }
    return enclosure;
}
Also used : SyndEnclosure(com.rometools.rome.feed.synd.SyndEnclosure) Enclosure(org.olat.modules.webFeed.Enclosure) SyndEnclosure(com.rometools.rome.feed.synd.SyndEnclosure) EnclosureImpl(org.olat.modules.webFeed.model.EnclosureImpl)

Example 15 with SyndEnclosure

use of com.rometools.rome.feed.synd.SyndEnclosure in project structr by structr.

the class DataFeed method updateFeed.

static void updateFeed(final DataFeed thisFeed, final boolean cleanUp) {
    final String remoteUrl = thisFeed.getUrl();
    if (StringUtils.isNotBlank(remoteUrl)) {
        final SecurityContext securityContext = thisFeed.getSecurityContext();
        final App app = StructrApp.getInstance(securityContext);
        try {
            final PropertyKey<Date> dateKey = StructrApp.key(FeedItem.class, "pubDate");
            final PropertyKey<String> urlKey = StructrApp.key(FeedItem.class, "url");
            final URL remote = new URL(remoteUrl);
            final SyndFeedInput input = new SyndFeedInput();
            try (final Reader reader = new XmlReader(remote)) {
                final SyndFeed feed = input.build(reader);
                final List<SyndEntry> entries = feed.getEntries();
                thisFeed.setProperty(StructrApp.key(DataFeed.class, "feedType"), feed.getFeedType());
                thisFeed.setProperty(StructrApp.key(DataFeed.class, "description"), feed.getDescription());
                final List<FeedItem> newItems = Iterables.toList(thisFeed.getItems());
                for (final SyndEntry entry : entries) {
                    final PropertyMap props = new PropertyMap();
                    final String link = entry.getLink();
                    // Check if item with this link already exists
                    if (app.nodeQuery(FeedItem.class).and(urlKey, link).getFirst() == null) {
                        props.put(urlKey, entry.getLink());
                        props.put(StructrApp.key(FeedItem.class, "name"), entry.getTitle());
                        props.put(StructrApp.key(FeedItem.class, "author"), entry.getAuthor());
                        props.put(StructrApp.key(FeedItem.class, "comments"), entry.getComments());
                        props.put(StructrApp.key(FeedItem.class, "description"), entry.getDescription().getValue());
                        final FeedItem item = app.create(FeedItem.class, props);
                        item.setProperty(dateKey, entry.getPublishedDate());
                        final List<FeedItemContent> itemContents = new LinkedList<>();
                        final List<FeedItemEnclosure> itemEnclosures = new LinkedList<>();
                        // Get and add all contents
                        final List<SyndContent> contents = entry.getContents();
                        for (final SyndContent content : contents) {
                            final FeedItemContent itemContent = app.create(FeedItemContent.class);
                            itemContent.setValue(content.getValue());
                            itemContents.add(itemContent);
                        }
                        // Get and add all enclosures
                        final List<SyndEnclosure> enclosures = entry.getEnclosures();
                        for (final SyndEnclosure enclosure : enclosures) {
                            final FeedItemEnclosure itemEnclosure = app.create(FeedItemEnclosure.class);
                            itemEnclosure.setProperty(StructrApp.key(FeedItemEnclosure.class, "url"), enclosure.getUrl());
                            itemEnclosure.setProperty(StructrApp.key(FeedItemEnclosure.class, "enclosureLength"), enclosure.getLength());
                            itemEnclosure.setProperty(StructrApp.key(FeedItemEnclosure.class, "enclosureType"), enclosure.getType());
                            itemEnclosures.add(itemEnclosure);
                        }
                        item.setProperty(StructrApp.key(FeedItem.class, "contents"), itemContents);
                        item.setProperty(StructrApp.key(FeedItem.class, "enclosures"), itemEnclosures);
                        newItems.add(item);
                        logger.debug("Created new item: {} ({}) ", item.getProperty(FeedItem.name), item.getProperty(dateKey));
                    }
                }
                thisFeed.setProperty(StructrApp.key(DataFeed.class, "items"), newItems);
                thisFeed.setProperty(StructrApp.key(DataFeed.class, "lastUpdated"), new Date());
            }
        } catch (IllegalArgumentException | IOException | FeedException | FrameworkException ex) {
            logger.error("Error while updating feed", ex);
        }
    }
    if (cleanUp) {
        thisFeed.cleanUp();
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) XmlReader(com.rometools.rome.io.XmlReader) Reader(java.io.Reader) URL(java.net.URL) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SyndFeedInput(com.rometools.rome.io.SyndFeedInput) SyndEnclosure(com.rometools.rome.feed.synd.SyndEnclosure) FrameworkException(org.structr.common.error.FrameworkException) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) FeedException(com.rometools.rome.io.FeedException) XmlReader(com.rometools.rome.io.XmlReader) IOException(java.io.IOException) Date(java.util.Date) LinkedList(java.util.LinkedList) PropertyMap(org.structr.core.property.PropertyMap) SyndContent(com.rometools.rome.feed.synd.SyndContent) SecurityContext(org.structr.common.SecurityContext)

Aggregations

SyndEnclosure (com.rometools.rome.feed.synd.SyndEnclosure)15 Test (org.junit.Test)8 Enclosure (org.olat.modules.webFeed.Enclosure)8 SyndContent (com.rometools.rome.feed.synd.SyndContent)5 Item (org.olat.modules.webFeed.Item)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 EnclosureImpl (org.olat.modules.webFeed.model.EnclosureImpl)2 ItemImpl (org.olat.modules.webFeed.model.ItemImpl)2 GeoRSSModule (com.rometools.modules.georss.GeoRSSModule)1 Position (com.rometools.modules.georss.geometries.Position)1 MediaEntryModule (com.rometools.modules.mediarss.MediaEntryModule)1 MediaContent (com.rometools.modules.mediarss.types.MediaContent)1 PlayerReference (com.rometools.modules.mediarss.types.PlayerReference)1 UrlReference (com.rometools.modules.mediarss.types.UrlReference)1 SyndCategory (com.rometools.rome.feed.synd.SyndCategory)1 SyndContentImpl (com.rometools.rome.feed.synd.SyndContentImpl)1 SyndEnclosureImpl (com.rometools.rome.feed.synd.SyndEnclosureImpl)1 SyndEntry (com.rometools.rome.feed.synd.SyndEntry)1 SyndFeed (com.rometools.rome.feed.synd.SyndFeed)1