Search in sources :

Example 41 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 42 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)

Example 43 with SyndFeed

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

the class RssToJsonTest method shouldHaveRawContent.

@Test
public void shouldHaveRawContent() throws Exception {
    SyndFeedInput input = new SyndFeedInput();
    SyndFeed feed = input.build(new XmlReader(getClass().getResource("/dcrainmaker/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());
        assertThat(xcb.string(), containsString("<p>"));
        logger.info(xcb.string());
    }
}
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 44 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 45 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)

Aggregations

SyndFeed (com.rometools.rome.feed.synd.SyndFeed)45 SyndEntry (com.rometools.rome.feed.synd.SyndEntry)22 SyndFeedInput (com.rometools.rome.io.SyndFeedInput)17 XmlReader (com.rometools.rome.io.XmlReader)16 SyndEntryImpl (com.rometools.rome.feed.synd.SyndEntryImpl)15 ArrayList (java.util.ArrayList)14 FeedException (com.rometools.rome.io.FeedException)13 SyndFeedImpl (com.rometools.rome.feed.synd.SyndFeedImpl)12 URL (java.net.URL)11 SyndFeedOutput (com.rometools.rome.io.SyndFeedOutput)10 SyndContent (com.rometools.rome.feed.synd.SyndContent)9 SyndContentImpl (com.rometools.rome.feed.synd.SyndContentImpl)8 IOException (java.io.IOException)7 Test (org.junit.Test)7 Date (java.util.Date)6 ParsingFeedException (com.rometools.rome.io.ParsingFeedException)4 FileNotFoundException (java.io.FileNotFoundException)4 Reader (java.io.Reader)4 Writer (java.io.Writer)4 SQLException (java.sql.SQLException)3