Search in sources :

Example 26 with SyndFeed

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;
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) Reader(java.io.Reader) XmlReader(com.rometools.rome.io.XmlReader) XmlReader(com.rometools.rome.io.XmlReader) URL(java.net.URL) FileNotFoundException(java.io.FileNotFoundException) ParsingFeedException(com.rometools.rome.io.ParsingFeedException)

Example 27 with 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);
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) ParsingFeedException(com.rometools.rome.io.ParsingFeedException) SyndFeedInput(com.rometools.rome.io.SyndFeedInput) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) FileNotFoundException(java.io.FileNotFoundException) XmlReader(com.rometools.rome.io.XmlReader) URL(java.net.URL) FileNotFoundException(java.io.FileNotFoundException) ParsingFeedException(com.rometools.rome.io.ParsingFeedException)

Example 28 with SyndFeed

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();
    }
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) FeedException(com.rometools.rome.io.FeedException) SyndFeedOutput(com.rometools.rome.io.SyndFeedOutput) Writer(java.io.Writer) Date(java.util.Date) FeedException(com.rometools.rome.io.FeedException)

Example 29 with SyndFeed

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);
    }
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) MessagingException(org.springframework.messaging.MessagingException) Reader(java.io.Reader) XmlReader(com.rometools.rome.io.XmlReader) XmlReader(com.rometools.rome.io.XmlReader) MessagingException(org.springframework.messaging.MessagingException)

Example 30 with SyndFeed

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());
}
Also used : SyndEntry(com.rometools.rome.feed.synd.SyndEntry) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) SUser(org.bimserver.interfaces.objects.SUser) ArrayList(java.util.ArrayList) SyndFeedOutput(com.rometools.rome.io.SyndFeedOutput) SProject(org.bimserver.interfaces.objects.SProject) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SRevision(org.bimserver.interfaces.objects.SRevision) SyndContent(com.rometools.rome.feed.synd.SyndContent) ServiceException(org.bimserver.shared.exceptions.ServiceException) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl) SRevisionIdComparator(org.bimserver.shared.comparators.SRevisionIdComparator)

Aggregations

SyndFeed (com.rometools.rome.feed.synd.SyndFeed)45 SyndEntry (com.rometools.rome.feed.synd.SyndEntry)22 SyndFeedInput (com.rometools.rome.io.SyndFeedInput)17 XmlReader (com.rometools.rome.io.XmlReader)16 SyndEntryImpl (com.rometools.rome.feed.synd.SyndEntryImpl)15 ArrayList (java.util.ArrayList)14 FeedException (com.rometools.rome.io.FeedException)13 SyndFeedImpl (com.rometools.rome.feed.synd.SyndFeedImpl)12 URL (java.net.URL)11 SyndFeedOutput (com.rometools.rome.io.SyndFeedOutput)10 SyndContent (com.rometools.rome.feed.synd.SyndContent)9 SyndContentImpl (com.rometools.rome.feed.synd.SyndContentImpl)8 IOException (java.io.IOException)7 Test (org.junit.Test)7 Date (java.util.Date)6 ParsingFeedException (com.rometools.rome.io.ParsingFeedException)4 FileNotFoundException (java.io.FileNotFoundException)4 Reader (java.io.Reader)4 Writer (java.io.Writer)4 SQLException (java.sql.SQLException)3