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;
}
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();
}
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();
}
}
}
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());
}
}
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;
}
Aggregations