Search in sources :

Example 1 with SyndFeedInput

use of com.rometools.rome.io.SyndFeedInput in project KaellyBot by Kaysoro.

the class RSS method getRSSFeeds.

public static List<RSS> getRSSFeeds(Language lg) {
    List<RSS> rss = new ArrayList<>();
    try {
        SyndFeedInput input = new SyndFeedInput();
        SyndFeed feed = input.build(new XmlReader(new URL(Translator.getLabel(lg, "game.url") + Translator.getLabel(lg, "feed.url"))));
        for (SyndEntry entry : feed.getEntries()) {
            Matcher m = Pattern.compile("<img.+src=\"(.*\\.jpg)\".+>").matcher(entry.getDescription().getValue());
            rss.add(new RSS(entry.getTitle(), entry.getLink(), (m.find() ? m.group(1) : null), entry.getPublishedDate().getTime()));
        }
    } catch (FeedException e) {
        Reporter.report(e);
        LOG.error("getRSSFeeds", e);
    } catch (IOException e) {
        ExceptionManager.manageSilentlyIOException(e);
    } catch (Exception e) {
        ExceptionManager.manageSilentlyException(e);
    }
    Collections.sort(rss);
    return rss;
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) Matcher(java.util.regex.Matcher) SyndFeedInput(com.rometools.rome.io.SyndFeedInput) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) FeedException(com.rometools.rome.io.FeedException) XmlReader(com.rometools.rome.io.XmlReader) IOException(java.io.IOException) URL(java.net.URL) IOException(java.io.IOException) FeedException(com.rometools.rome.io.FeedException)

Example 2 with SyndFeedInput

use of com.rometools.rome.io.SyndFeedInput in project spring-integration by spring-projects.

the class FeedInboundChannelAdapterParserTests method validateSuccessfulFileConfigurationWithCustomMetadataStore.

@Test
public void validateSuccessfulFileConfigurationWithCustomMetadataStore() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("FeedInboundChannelAdapterParserTests-file-context.xml", this.getClass());
    SourcePollingChannelAdapter adapter = context.getBean("feedAdapter", SourcePollingChannelAdapter.class);
    FeedEntryMessageSource source = (FeedEntryMessageSource) TestUtils.getPropertyValue(adapter, "source");
    assertSame(context.getBean(MetadataStore.class), TestUtils.getPropertyValue(source, "metadataStore"));
    SyndFeedInput syndFeedInput = TestUtils.getPropertyValue(source, "syndFeedInput", SyndFeedInput.class);
    assertSame(context.getBean(SyndFeedInput.class), syndFeedInput);
    assertFalse(syndFeedInput.isPreserveWireFeed());
    context.close();
}
Also used : FeedEntryMessageSource(org.springframework.integration.feed.inbound.FeedEntryMessageSource) MetadataStore(org.springframework.integration.metadata.MetadataStore) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SyndFeedInput(com.rometools.rome.io.SyndFeedInput) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) Test(org.junit.Test)

Example 3 with SyndFeedInput

use of com.rometools.rome.io.SyndFeedInput in project muikku by otavanopisto.

the class FeedSynchronizer method updateFeeds.

@Schedule(second = "0", minute = "0", hour = "*", persistent = false)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void updateFeeds() {
    Client client = ClientBuilder.newClient();
    feedItemDao.deleteAll();
    List<Feed> feeds = feedDao.listAll();
    for (Feed feed : feeds) {
        WebTarget target = client.target(feed.getUrl());
        try (InputStream stream = target.request("*").get(InputStream.class)) {
            SyndFeedInput input = new SyndFeedInput();
            SyndFeed syndFeed = input.build(new XmlReader(stream));
            List<SyndEntry> entries = syndFeed.getEntries();
            for (SyndEntry entry : entries) {
                feedItemDao.create(entry.getTitle(), entry.getLink(), entry.getAuthor(), entry.getDescription() == null ? null : clean(entry.getDescription().getValue()), entry.getPublishedDate(), (String) null, feed);
            }
        } catch (IOException | IllegalArgumentException | FeedException e) {
            logger.warning(String.format("Error while synchronizing feeds: %s", e.getMessage()));
            ejbContext.setRollbackOnly();
        }
    }
}
Also used : InputStream(java.io.InputStream) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) FeedException(com.rometools.rome.io.FeedException) XmlReader(com.rometools.rome.io.XmlReader) IOException(java.io.IOException) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SyndFeedInput(com.rometools.rome.io.SyndFeedInput) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) Feed(fi.otavanopisto.muikku.plugins.feed.model.Feed) TransactionAttribute(javax.ejb.TransactionAttribute) Schedule(javax.ejb.Schedule)

Example 4 with SyndFeedInput

use of com.rometools.rome.io.SyndFeedInput in project rssriver by dadoonet.

the class RssToJsonTest method shouldNotHaveRawContent.

@Test
public void shouldNotHaveRawContent() 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, false);
        assertThat(xcb, notNullValue());
        assertThat(xcb.string(), new SubstringMatcher("<p>") {

            @Override
            protected boolean evalSubstringOf(String s) {
                return s.indexOf(substring) < 0;
            }

            @Override
            protected String relationship() {
                return "not containing";
            }
        });
        logger.info(xcb.string());
    }
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SubstringMatcher(org.hamcrest.core.SubstringMatcher) 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 5 with SyndFeedInput

use of com.rometools.rome.io.SyndFeedInput in project ddf by codice.

the class OpenSearchSource method processResponse.

private SourceResponseImpl processResponse(InputStream is, QueryRequest queryRequest) throws UnsupportedQueryException {
    List<Result> resultQueue = new ArrayList<>();
    SyndFeedInput syndFeedInput = new SyndFeedInput();
    SyndFeed syndFeed = null;
    try {
        syndFeed = syndFeedInput.build(new InputStreamReader(is, StandardCharsets.UTF_8));
    } catch (FeedException e) {
        LOGGER.debug("Unable to read RSS/Atom feed.", e);
    }
    List<SyndEntry> entries;
    long totalResults = 0;
    List<Element> foreignMarkup = null;
    if (syndFeed != null) {
        entries = syndFeed.getEntries();
        for (SyndEntry entry : entries) {
            resultQueue.addAll(createResponseFromEntry(entry));
        }
        totalResults = entries.size();
        foreignMarkup = syndFeed.getForeignMarkup();
        for (Element element : foreignMarkup) {
            if (element.getName().equals("totalResults")) {
                try {
                    totalResults = Long.parseLong(element.getContent(0).getValue());
                } catch (NumberFormatException | IndexOutOfBoundsException e) {
                    // totalResults is already initialized to the correct value, so don't change it here.
                    LOGGER.debug("Received invalid number of results.", e);
                }
            }
        }
    }
    SourceResponseImpl response = new SourceResponseImpl(queryRequest, resultQueue);
    response.setHits(totalResults);
    if (foreignMarkup != null) {
        this.foreignMarkupBiConsumer.accept(Collections.unmodifiableList(foreignMarkup), response);
    }
    return response;
}
Also used : InputStreamReader(java.io.InputStreamReader) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) FeedException(com.rometools.rome.io.FeedException) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) Result(ddf.catalog.data.Result) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SyndFeedInput(com.rometools.rome.io.SyndFeedInput)

Aggregations

SyndFeedInput (com.rometools.rome.io.SyndFeedInput)18 SyndFeed (com.rometools.rome.feed.synd.SyndFeed)16 XmlReader (com.rometools.rome.io.XmlReader)13 SyndEntry (com.rometools.rome.feed.synd.SyndEntry)8 FeedException (com.rometools.rome.io.FeedException)7 URL (java.net.URL)6 Test (org.junit.Test)6 SyndEntryImpl (com.rometools.rome.feed.synd.SyndEntryImpl)5 IOException (java.io.IOException)4 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)3 SyndContent (com.rometools.rome.feed.synd.SyndContent)2 ParsingFeedException (com.rometools.rome.io.ParsingFeedException)2 Result (ddf.catalog.data.Result)2 SourceResponseImpl (ddf.catalog.operation.impl.SourceResponseImpl)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStreamReader (java.io.InputStreamReader)2 ArrayList (java.util.ArrayList)2 Element (org.jdom2.Element)2 InputSource (org.xml.sax.InputSource)2 GeoRSSModule (com.rometools.modules.georss.GeoRSSModule)1