Search in sources :

Example 11 with SyndFeed

use of com.rometools.rome.feed.synd.SyndFeed in project rssriver by dadoonet.

the class RssRiver method getFeed.

private SyndFeed getFeed(String url) {
    try {
        URL feedUrl = new URL(url);
        URLConnection openConnection = feedUrl.openConnection();
        openConnection.addRequestProperty("User-Agent", "RSS River for Elasticsearch (https://github.com/dadoonet/rssriver)");
        SyndFeedInput input = new SyndFeedInput();
        input.setPreserveWireFeed(true);
        SyndFeed feed = input.build(new XmlReader(openConnection));
        return feed;
    } catch (MalformedURLException e) {
        logger.error("RSS Url is incorrect : [{}].", url);
    } catch (IllegalArgumentException e) {
        logger.error("Feed from [{}] is incorrect.", url);
    } catch (FeedException e) {
        logger.error("Can not parse feed from [{}].", url);
    } catch (IOException e) {
        logger.error("Can not read feed from [{}].", url);
    }
    return null;
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) MalformedURLException(java.net.MalformedURLException) SyndFeedInput(com.rometools.rome.io.SyndFeedInput) FeedException(com.rometools.rome.io.FeedException) XmlReader(com.rometools.rome.io.XmlReader) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection)

Example 12 with SyndFeed

use of com.rometools.rome.feed.synd.SyndFeed in project rssriver by dadoonet.

the class RomeTest method testLeMonde.

@Test
public void testLeMonde() throws Exception {
    SyndFeedInput input = new SyndFeedInput();
    input.setPreserveWireFeed(true);
    SyndFeed feed = input.build(new XmlReader(getClass().getResource("/lemonde/rss.xml")));
    assertThat(feed, notNullValue());
    assertThat(feed.getEntries().isEmpty(), equalTo(false));
    assertThat(feed.originalWireFeed(), notNullValue());
    assertThat(feed.originalWireFeed(), instanceOf(Channel.class));
    Channel channel = (Channel) feed.originalWireFeed();
    assertThat(channel.getTtl(), equalTo(15));
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SyndFeedInput(com.rometools.rome.io.SyndFeedInput) Channel(com.rometools.rome.feed.rss.Channel) XmlReader(com.rometools.rome.io.XmlReader) Test(org.junit.Test)

Example 13 with SyndFeed

use of com.rometools.rome.feed.synd.SyndFeed in project rssriver by dadoonet.

the class RomeTest method testGeoLoc.

@Test
public void testGeoLoc() throws Exception {
    SyndFeedInput input = new SyndFeedInput();
    input.setPreserveWireFeed(true);
    SyndFeed feed = input.build(new XmlReader(getClass().getResource("/reuters/rss.xml")));
    assertThat(feed, notNullValue());
    assertThat(feed.getEntries().isEmpty(), equalTo(false));
    for (Object o : feed.getEntries()) {
        assertThat(o, instanceOf(SyndEntryImpl.class));
        SyndEntryImpl entry = (SyndEntryImpl) o;
        GeoRSSModule geoRSSModule = GeoRSSUtils.getGeoRSS(entry);
        assertThat(geoRSSModule, notNullValue());
        Position position = geoRSSModule.getPosition();
        assertThat(position, notNullValue());
        assertThat(position.getLatitude(), equalTo(41.8947384616695));
        assertThat(position.getLongitude(), equalTo(12.4839019775391));
    }
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) Position(com.rometools.modules.georss.geometries.Position) SyndFeedInput(com.rometools.rome.io.SyndFeedInput) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) GeoRSSModule(com.rometools.modules.georss.GeoRSSModule) XmlReader(com.rometools.rome.io.XmlReader) Test(org.junit.Test)

Example 14 with SyndFeed

use of com.rometools.rome.feed.synd.SyndFeed in project rssriver by dadoonet.

the class RssToJsonTest method shouldParseRss.

@Test
public /* this test should be moved somewhere else */
void shouldParseRss() throws Exception {
    SyndFeedInput input = new SyndFeedInput();
    SyndFeed feed = input.build(new XmlReader(getClass().getResource("/reuters/rss.xml")));
    assertThat(feed.getEntries().size(), greaterThan(0));
    for (Object o : feed.getEntries()) {
        SyndEntryImpl message = (SyndEntryImpl) o;
        XContentBuilder xcb = toJson(message, null, null, true);
        assertThat(xcb, notNullValue());
    }
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SyndFeedInput(com.rometools.rome.io.SyndFeedInput) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) XmlReader(com.rometools.rome.io.XmlReader) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) Test(org.junit.Test)

Example 15 with SyndFeed

use of com.rometools.rome.feed.synd.SyndFeed in project rssriver by dadoonet.

the class RssToJsonTest method buildEntry.

private SyndEntryImpl buildEntry() throws FeedException, IOException {
    SyndFeedInput input = new SyndFeedInput();
    SyndFeed feed = input.build(new XmlReader(getClass().getResource("/reuters/rss.xml")));
    return (SyndEntryImpl) feed.getEntries().get(0);
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SyndFeedInput(com.rometools.rome.io.SyndFeedInput) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) XmlReader(com.rometools.rome.io.XmlReader)

Aggregations

SyndFeed (com.rometools.rome.feed.synd.SyndFeed)19 SyndEntryImpl (com.rometools.rome.feed.synd.SyndEntryImpl)11 SyndFeedInput (com.rometools.rome.io.SyndFeedInput)10 SyndEntry (com.rometools.rome.feed.synd.SyndEntry)8 XmlReader (com.rometools.rome.io.XmlReader)7 ArrayList (java.util.ArrayList)7 SyndFeedImpl (com.rometools.rome.feed.synd.SyndFeedImpl)6 SyndContent (com.rometools.rome.feed.synd.SyndContent)5 FeedException (com.rometools.rome.io.FeedException)5 Test (org.junit.Test)5 SyndContentImpl (com.rometools.rome.feed.synd.SyndContentImpl)4 SyndFeedOutput (com.rometools.rome.io.SyndFeedOutput)3 SQLException (java.sql.SQLException)3 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)3 OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)2 Filter (org.opennms.web.filter.Filter)2 GeoRSSModule (com.rometools.modules.georss.GeoRSSModule)1 Position (com.rometools.modules.georss.geometries.Position)1 Channel (com.rometools.rome.feed.rss.Channel)1 Pager (com.willshex.blogwt.shared.api.Pager)1