Search in sources :

Example 1 with SyndFeed

use of com.rometools.rome.feed.synd.SyndFeed in project asterixdb by apache.

the class RSSFeedServlet method get.

@Override
protected void get(IServletRequest req, IServletResponse res) throws IOException {
    try {
        SyndFeed feed = getFeed(req);
        String feedType = req.getParameter(FEED_TYPE);
        feedType = (feedType != null) ? feedType : defaultFeedType;
        feed.setFeedType(feedType);
        HttpUtil.setContentType(res, MIME_TYPE);
        SyndFeedOutput output = new SyndFeedOutput();
        output.output(feed, res.writer());
    } catch (FeedException | ParseException ex) {
        GlobalConfig.ASTERIX_LOGGER.log(Level.WARNING, ex.getMessage(), ex);
        String msg = COULD_NOT_GENERATE_FEED_ERROR;
        res.writer().print(msg);
        res.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
    }
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) FeedException(com.rometools.rome.io.FeedException) SyndFeedOutput(com.rometools.rome.io.SyndFeedOutput) ParseException(java.text.ParseException)

Example 2 with SyndFeed

use of com.rometools.rome.feed.synd.SyndFeed in project BIMserver by opensourceBIM.

the class SyndicationServlet method writeCheckoutsFeed.

private void writeCheckoutsFeed(HttpServletRequest request, HttpServletResponse response, ServiceMap serviceMap) throws ServiceException, IOException, FeedException, 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 checkouts feed for project '" + sProject.getName() + "'");
    feed.setLink(request.getContextPath());
    feed.setDescription("This feed represents all the checkouts of project '" + sProject.getName() + "'");
    List<SyndEntry> entries = new ArrayList<SyndEntry>();
    try {
        List<SCheckout> allCheckoutsOfProject = serviceMap.getServiceInterface().getAllCheckoutsOfProjectAndSubProjects(poid);
        for (SCheckout sCheckout : allCheckoutsOfProject) {
            SRevision revision = serviceMap.getServiceInterface().getRevision(sCheckout.getRevision().getOid());
            SProject project = serviceMap.getServiceInterface().getProjectByPoid(sCheckout.getProjectId());
            SUser user = serviceMap.getServiceInterface().getUserByUoid(sCheckout.getUserId());
            SyndEntry entry = new SyndEntryImpl();
            entry.setTitle("Checkout on " + project.getName() + ", revision " + revision.getId());
            entry.setLink(request.getContextPath() + "/project.jsp?poid=" + sProject.getOid());
            entry.setPublishedDate(sCheckout.getDate());
            SyndContent description = new SyndContentImpl();
            description.setType("text/plain");
            description.setValue("<table><tr><td>User</td><td>" + user.getUsername() + "</td></tr><tr><td>Revision</td><td>" + sCheckout.getRevision().getOid() + "</td></tr></table>");
            entry.setDescription(description);
            entries.add(entry);
        }
    } catch (UserException 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) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl) UserException(org.bimserver.shared.exceptions.UserException) SCheckout(org.bimserver.interfaces.objects.SCheckout)

Example 3 with SyndFeed

use of com.rometools.rome.feed.synd.SyndFeed in project BIMserver by opensourceBIM.

the class SyndicationServlet method writeProjectsFeed.

private void writeProjectsFeed(HttpServletRequest request, HttpServletResponse response, ServiceMap serviceMap) throws UserException, IOException, FeedException, PublicInterfaceNotFoundException {
    SyndFeed feed = new SyndFeedImpl();
    feed.setFeedType(FEED_TYPE);
    feed.setTitle("BIMserver.org projects feed");
    feed.setLink(request.getContextPath());
    feed.setDescription("This feed represents all your available projects within this BIMserver");
    List<SyndEntry> entries = new ArrayList<SyndEntry>();
    try {
        List<SProject> allProjects = serviceMap.getServiceInterface().getAllProjects(false, true);
        for (SProject sProject : allProjects) {
            SyndEntry entry = new SyndEntryImpl();
            entry.setAuthor(serviceMap.getServiceInterface().getUserByUoid(sProject.getCreatedById()).getName());
            entry.setTitle(sProject.getName());
            entry.setLink(request.getContextPath() + "/project.jsp?poid=" + sProject.getOid());
            entry.setPublishedDate(sProject.getCreatedDate());
            SyndContent description = new SyndContentImpl();
            description.setType("text/plain");
            description.setValue(sProject.getDescription());
            entry.setDescription(description);
            entries.add(entry);
        }
        if (allProjects.size() == 0) {
            SyndEntry entry = new SyndEntryImpl();
            entry.setTitle("No projects found");
            entry.setLink(request.getContextPath() + "/main.jsp");
            entry.setPublishedDate(new Date());
            SyndContent description = new SyndContentImpl();
            description.setType("text/plain");
            description.setValue("No projects found");
            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) ArrayList(java.util.ArrayList) SyndFeedOutput(com.rometools.rome.io.SyndFeedOutput) SProject(org.bimserver.interfaces.objects.SProject) Date(java.util.Date) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) 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)

Example 4 with SyndFeed

use of com.rometools.rome.feed.synd.SyndFeed in project opennms by OpenNMS.

the class OutageFeed method getFeed.

/**
 * <p>getFeed</p>
 *
 * @return a {@link com.rometools.rome.feed.synd.SyndFeed} object.
 */
@Override
public SyndFeed getFeed() {
    SyndFeed feed = new SyndFeedImpl();
    feed.setTitle("Nodes with Outages");
    feed.setDescription("OpenNMS Nodes with Outages");
    feed.setLink(getUrlBase() + "outage/list.htm");
    List<SyndEntry> entries = new ArrayList<>();
    try {
        Date date = new Date();
        date.setTime(date.getTime() - (1000 * 60 * 60 * 24));
        OutageSummary[] summaries = OutageModel.getAllOutageSummaries(date);
        SyndEntry entry;
        int count = 0;
        for (OutageSummary summary : summaries) {
            if (count++ == this.getMaxEntries()) {
                break;
            }
            String link = getUrlBase() + "element/node.jsp?node=" + summary.getNodeId();
            entry = new SyndEntryImpl();
            entry.setPublishedDate(summary.getTimeDown());
            if (summary.getTimeUp() == null) {
                entry.setTitle(sanitizeTitle(summary.getNodeLabel()));
                entry.setUpdatedDate(summary.getTimeDown());
            } else {
                entry.setTitle(sanitizeTitle(summary.getNodeLabel()) + " (Resolved)");
                entry.setUpdatedDate(summary.getTimeUp());
            }
            entry.setLink(link);
            entry.setAuthor("OpenNMS");
            entries.add(entry);
        }
    } catch (SQLException e) {
        LOG.warn("unable to get current outages", e);
    }
    feed.setEntries(entries);
    return feed;
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SQLException(java.sql.SQLException) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) OutageSummary(org.opennms.netmgt.model.outage.OutageSummary) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) ArrayList(java.util.ArrayList) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl) Date(java.util.Date)

Example 5 with SyndFeed

use of com.rometools.rome.feed.synd.SyndFeed 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;
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) Matcher(java.util.regex.Matcher) SyndFeedInput(com.rometools.rome.io.SyndFeedInput) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) FeedException(com.rometools.rome.io.FeedException) XmlReader(com.rometools.rome.io.XmlReader) IOException(java.io.IOException) URL(java.net.URL) IOException(java.io.IOException) FeedException(com.rometools.rome.io.FeedException)

Aggregations

SyndFeed (com.rometools.rome.feed.synd.SyndFeed)44 SyndEntry (com.rometools.rome.feed.synd.SyndEntry)21 SyndFeedInput (com.rometools.rome.io.SyndFeedInput)16 SyndEntryImpl (com.rometools.rome.feed.synd.SyndEntryImpl)15 XmlReader (com.rometools.rome.io.XmlReader)15 ArrayList (java.util.ArrayList)14 FeedException (com.rometools.rome.io.FeedException)13 SyndFeedImpl (com.rometools.rome.feed.synd.SyndFeedImpl)12 SyndFeedOutput (com.rometools.rome.io.SyndFeedOutput)10 URL (java.net.URL)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