use of com.rometools.rome.io.XmlReader 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.XmlReader 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.XmlReader 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.XmlReader in project OpenOLAT by OpenOLAT.
the class RomeFeedFetcher method fetchSyndFeed.
/**
* Fetches the SyndFeed of an URL.
* @param feedURL
* @return
*/
protected SyndFeed fetchSyndFeed(String feedURL) {
SyndFeed syndFeed = null;
try (Reader xmlReader = new XmlReader(new URL(feedURL))) {
syndFeed = syndFeedInput.build(xmlReader);
log.info("Read external feed: " + feedURL);
} catch (Exception e) {
log.warn("Cannot read external feed: : " + feedURL);
}
return syndFeed;
}
use of com.rometools.rome.io.XmlReader in project OpenOLAT by OpenOLAT.
the class RomeFeedFetcher method validateFeedUrl.
@Override
public ValidatedURL validateFeedUrl(String url, boolean enclosuresExpected) {
SyndFeedInput input = new SyndFeedInput();
boolean modifiedProtocol = false;
try {
if (url != null) {
url = url.trim();
}
if (url.startsWith("feed") || url.startsWith("itpc")) {
// accept feed(s) urls like generated in safari browser
url = "http" + url.substring(4);
modifiedProtocol = true;
}
URL realUrl = new URL(url);
SyndFeed feed = input.build(new XmlReader(realUrl));
if (!feed.getEntries().isEmpty()) {
if (enclosuresExpected) {
SyndEntry entry = feed.getEntries().get(0);
if (entry.getEnclosures().isEmpty()) {
return new ValidatedURL(url, ValidatedURL.State.NO_ENCLOSURE);
}
}
return new ValidatedURL(url, ValidatedURL.State.VALID);
}
// The feed was read successfully
return new ValidatedURL(url, ValidatedURL.State.VALID);
} catch (ParsingFeedException e) {
if (modifiedProtocol) {
// fallback for SWITCHcast itpc -> http -> https
url = "https" + url.substring(4);
return validateFeedUrl(url, enclosuresExpected);
}
String message = String.format("Validation of the feed url %s failed. %s: %s ", url, e.getClass(), e.getMessage());
log.debug(message);
return new ValidatedURL(url, ValidatedURL.State.NOT_FOUND);
} catch (FileNotFoundException e) {
String message = String.format("Validation of the feed url %s failed. %s: %s ", url, e.getClass(), e.getMessage());
log.debug(message);
return new ValidatedURL(url, ValidatedURL.State.NOT_FOUND);
} catch (Exception e) {
String message = String.format("Validation of the feed url %s failed. %s: %s ", url, e.getClass(), e.getMessage());
log.debug(message);
}
return new ValidatedURL(url, ValidatedURL.State.MALFORMED);
}
Aggregations