use of com.rometools.rome.io.ParsingFeedException 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);
}
use of com.rometools.rome.io.ParsingFeedException in project openolat by klemens.
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