use of com.rometools.rome.feed.synd.SyndFeed 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.feed.synd.SyndFeed 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.feed.synd.SyndFeed in project OpenOLAT by OpenOLAT.
the class PersonalRSSServlet method doGet.
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
try (Writer writer = response.getWriter()) {
String pathInfo = request.getPathInfo();
if ((pathInfo == null) || (pathInfo.equals(""))) {
// error
return;
}
SyndFeed feed = null;
// pathInfo is like /personal/username/tokenid.rss
if (pathInfo.indexOf(PersonalRSSUtil.RSS_PREFIX_PERSONAL) == 0) {
feed = getPersonalFeed(pathInfo);
if (feed == null) {
DispatcherModule.sendNotFound(pathInfo, response);
return;
}
} else {
DispatcherModule.sendNotFound(pathInfo, response);
return;
}
// OLAT-5400 and OLAT-5243 related: sending back the reply can take arbitrary long,
// considering slow end-user connections for example - or a sudden death of the connection
// on the client-side which remains unnoticed (network partitioning)
DBFactory.getInstance().intermediateCommit();
response.setBufferSize(response.getBufferSize());
String encoding = feed.getEncoding();
if (encoding == null) {
encoding = DEFAULT_ENCODING;
if (log.isDebug()) {
log.debug("Feed encoding::" + encoding);
}
log.warn("No encoding provided by feed::" + feed.getClass().getCanonicalName() + " Using utf-8 as default.");
}
response.setCharacterEncoding(encoding);
response.setContentType("application/rss+xml");
Date pubDate = feed.getPublishedDate();
if (pubDate != null) {
response.setDateHeader("Last-Modified", pubDate.getTime());
}
SyndFeedOutput output = new SyndFeedOutput();
output.output(feed, writer);
} catch (FeedException e) {
// throw olat exception for nice logging
log.warn("Error when generating RSS stream for path::" + request.getPathInfo(), e);
DispatcherModule.sendNotFound("none", response);
} catch (Exception e) {
log.warn("Unknown Exception in rssservlet", e);
DispatcherModule.sendNotFound("none", response);
} catch (Error e) {
log.warn("Unknown Error in rssservlet", e);
DispatcherModule.sendNotFound("none", response);
} finally {
DBFactory.getInstance().commitAndCloseSession();
}
}
use of com.rometools.rome.feed.synd.SyndFeed in project spring-integration by spring-projects.
the class FeedEntryMessageSource method getFeed.
private SyndFeed getFeed() {
try {
synchronized (this.feedMonitor) {
Reader reader = this.feedUrl != null ? new XmlReader(this.feedUrl) : new XmlReader(this.feedResource.getInputStream());
SyndFeed feed = this.syndFeedInput.build(reader);
if (logger.isDebugEnabled()) {
logger.debug("Retrieved feed for [" + this + "]");
}
if (feed == null) {
if (logger.isDebugEnabled()) {
logger.debug("No feeds updated for [" + this + "], returning null");
}
}
return feed;
}
} catch (Exception e) {
throw new MessagingException("Failed to retrieve feed for '" + this + "'", e);
}
}
use of com.rometools.rome.feed.synd.SyndFeed in project BIMserver by opensourceBIM.
the class SyndicationServlet method writeRevisionsFeed.
private void writeRevisionsFeed(HttpServletRequest request, HttpServletResponse response, ServiceMap serviceMap) throws IOException, FeedException, ServiceException, PublicInterfaceNotFoundException {
long poid = Long.parseLong(request.getParameter("poid"));
SProject sProject = serviceMap.getServiceInterface().getProjectByPoid(poid);
SyndFeed feed = new SyndFeedImpl();
feed.setFeedType(FEED_TYPE);
feed.setTitle("BIMserver.org revisions feed for project '" + sProject.getName() + "'");
feed.setLink(request.getContextPath());
feed.setDescription("This feed represents all the revisions of project '" + sProject.getName() + "'");
List<SyndEntry> entries = new ArrayList<SyndEntry>();
try {
List<SRevision> allRevisionsOfProject = serviceMap.getServiceInterface().getAllRevisionsOfProject(poid);
Collections.sort(allRevisionsOfProject, new SRevisionIdComparator(false));
for (SRevision sVirtualRevision : allRevisionsOfProject) {
SUser user = serviceMap.getServiceInterface().getUserByUoid(sVirtualRevision.getUserId());
SyndEntry entry = new SyndEntryImpl();
entry.setTitle("Revision " + sVirtualRevision.getOid());
entry.setLink(request.getContextPath() + "/revision.jsp?poid=" + sVirtualRevision.getOid() + "&roid=" + sVirtualRevision.getOid());
entry.setPublishedDate(sVirtualRevision.getDate());
SyndContent description = new SyndContentImpl();
description.setType("text/html");
description.setValue("<table><tr><td>User</td><td>" + user.getUsername() + "</td></tr><tr><td>Comment</td><td>" + sVirtualRevision.getComment() + "</td></tr></table>");
entry.setDescription(description);
entries.add(entry);
}
} catch (ServiceException e) {
LOGGER.error("", e);
}
feed.setEntries(entries);
SyndFeedOutput output = new SyndFeedOutput();
output.output(feed, response.getWriter());
}
Aggregations