Search in sources :

Example 11 with SyndFeedImpl

use of com.rometools.rome.feed.synd.SyndFeedImpl 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)

Example 12 with SyndFeedImpl

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

the class AlarmFeed 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("Alarms");
    feed.setDescription("OpenNMS Alarms");
    feed.setLink(getUrlBase() + "alarm/list.htm");
    List<SyndEntry> entries = new ArrayList<>();
    List<Filter> filters = new ArrayList<>();
    if (this.getRequest().getParameter("node") != null) {
        Integer nodeId = WebSecurityUtils.safeParseInt(this.getRequest().getParameter("node"));
        filters.add(new NodeFilter(nodeId, getServletContext()));
    }
    if (this.getRequest().getParameter("severity") != null) {
        String sev = this.getRequest().getParameter("severity");
        for (OnmsSeverity severity : OnmsSeverity.values()) {
            if (severity.getLabel().equalsIgnoreCase(sev)) {
                filters.add(new SeverityFilter(severity));
            }
        }
    }
    OnmsCriteria queryCriteria = AlarmUtil.getOnmsCriteria(new AlarmCriteria(filters.toArray(new Filter[] {}), SortStyle.FIRSTEVENTTIME, AcknowledgeType.BOTH, this.getMaxEntries(), AlarmCriteria.NO_OFFSET));
    OnmsAlarm[] alarms = m_webAlarmRepository.getMatchingAlarms(queryCriteria);
    SyndEntry entry;
    for (OnmsAlarm alarm : alarms) {
        entry = new SyndEntryImpl();
        entry.setPublishedDate(alarm.getFirstEventTime());
        if (alarm.getAckTime() != null) {
            entry.setTitle(sanitizeTitle(alarm.getLogMsg()) + " (acknowledged by " + alarm.getAckUser() + ")");
            entry.setUpdatedDate(alarm.getAckTime());
        } else {
            entry.setTitle(sanitizeTitle(alarm.getLogMsg()));
            entry.setUpdatedDate(alarm.getFirstEventTime());
        }
        entry.setLink(getUrlBase() + "alarm/detail.htm?id=" + alarm.getId());
        entry.setAuthor("OpenNMS");
        SyndContent content = new SyndContentImpl();
        content.setType("text/html");
        content.setValue(alarm.getDescription());
        entry.setDescription(content);
        entries.add(entry);
    }
    feed.setEntries(entries);
    return feed;
}
Also used : SyndEntry(com.rometools.rome.feed.synd.SyndEntry) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) ArrayList(java.util.ArrayList) OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SeverityFilter(org.opennms.web.alarm.filter.SeverityFilter) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) SyndContent(com.rometools.rome.feed.synd.SyndContent) SeverityFilter(org.opennms.web.alarm.filter.SeverityFilter) Filter(org.opennms.web.filter.Filter) NodeFilter(org.opennms.web.alarm.filter.NodeFilter) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl) AlarmCriteria(org.opennms.web.alarm.filter.AlarmCriteria) NodeFilter(org.opennms.web.alarm.filter.NodeFilter)

Example 13 with SyndFeedImpl

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

the class EventFeed 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("Events");
    feed.setDescription("OpenNMS Events");
    feed.setLink(getUrlBase() + "event/list.htm");
    List<SyndEntry> entries = new ArrayList<>();
    try {
        Event[] events;
        ArrayList<Filter> filters = new ArrayList<>();
        if (this.getRequest().getParameter("node") != null) {
            Integer nodeId = WebSecurityUtils.safeParseInt(this.getRequest().getParameter("node"));
            filters.add(new NodeFilter(nodeId, getServletContext()));
        }
        if (this.getRequest().getParameter("severity") != null) {
            String parameter = this.getRequest().getParameter("severity");
            try {
                Integer severityId = WebSecurityUtils.safeParseInt(parameter);
                filters.add(new SeverityFilter(severityId));
            } catch (NumberFormatException e) {
                for (OnmsSeverity sev : OnmsSeverity.values()) {
                    if (sev.getLabel().equalsIgnoreCase(parameter)) {
                        filters.add(new SeverityFilter(sev));
                        break;
                    }
                }
            }
        }
        events = EventFactory.getEvents(SortStyle.TIME, AcknowledgeType.BOTH, filters.toArray(new Filter[] {}), this.getMaxEntries(), 0);
        SyndEntry entry;
        for (Event event : events) {
            entry = new SyndEntryImpl();
            entry.setPublishedDate(event.getTime());
            if (event.getAcknowledgeTime() != null) {
                entry.setTitle(sanitizeTitle(event.getLogMessage()) + " (Acknowledged by " + event.getAcknowledgeUser() + ")");
                entry.setUpdatedDate(event.getAcknowledgeTime());
            } else {
                entry.setTitle(sanitizeTitle(event.getLogMessage()));
                entry.setUpdatedDate(event.getTime());
            }
            entry.setLink(getUrlBase() + "event/detail.jsp?id=" + event.getId());
            entry.setAuthor("OpenNMS");
            SyndContent content = new SyndContentImpl();
            content.setType("text/html");
            content.setValue(event.getDescription());
            entry.setDescription(content);
            entries.add(entry);
        }
    } catch (SQLException e) {
        LOG.warn("unable to get event(s)", e);
    }
    feed.setEntries(entries);
    return feed;
}
Also used : SQLException(java.sql.SQLException) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) ArrayList(java.util.ArrayList) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SeverityFilter(org.opennms.web.event.filter.SeverityFilter) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) SyndContent(com.rometools.rome.feed.synd.SyndContent) SeverityFilter(org.opennms.web.event.filter.SeverityFilter) Filter(org.opennms.web.filter.Filter) NodeFilter(org.opennms.web.event.filter.NodeFilter) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) Event(org.opennms.web.event.Event) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl) NodeFilter(org.opennms.web.event.filter.NodeFilter)

Example 14 with SyndFeedImpl

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

the class NotificationFeed 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("Notifications");
    feed.setDescription("Notifications");
    feed.setLink(getUrlBase() + "notification/browse");
    List<SyndEntry> entries = new ArrayList<>();
    try {
        NotificationModel model = new NotificationModel();
        Notification[] notifications = model.allNotifications("desc");
        SyndEntry entry;
        int count = 0;
        for (Notification notification : notifications) {
            if (count++ == this.getMaxEntries()) {
                break;
            }
            entry = new SyndEntryImpl();
            entry.setPublishedDate(notification.getTimeSent());
            if (notification.getTimeReplied() == null) {
                entry.setTitle(sanitizeTitle(notification.getTextMessage()));
                entry.setUpdatedDate(notification.getTimeSent());
            } else {
                entry.setTitle(sanitizeTitle(notification.getTextMessage()) + " (acknowledged)");
                entry.setUpdatedDate(notification.getTimeReplied());
            }
            entry.setLink(getUrlBase() + "notification/detail.jsp?notice=" + notification.getId());
            entry.setAuthor("OpenNMS");
            entries.add(entry);
        }
    } catch (SQLException e) {
        LOG.warn("unable to get outstanding notifications", 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) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) ArrayList(java.util.ArrayList) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl) NotificationModel(org.opennms.web.notification.NotificationModel) Notification(org.opennms.web.notification.Notification)

Example 15 with SyndFeedImpl

use of com.rometools.rome.feed.synd.SyndFeedImpl in project rubia-forums by flashboss.

the class FeedsServlet method doGet.

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try {
        String[] uri = request.getRequestURI().split("/");
        if (uri.length < 5 || (uri[4].equals(GLOBAL) && uri.length != 5) || (!uri[4].equals(GLOBAL) && uri.length != 6)) {
            response.sendError(SC_BAD_REQUEST, WRONG_FEED_REQ);
            return;
        }
        String type = uri[3];
        String what = uri[4];
        Integer id = null;
        if (!what.equals(GLOBAL))
            id = valueOf(uri[5]);
        SyndFeed feed = new SyndFeedImpl();
        if (!setFeedType(feed, type)) {
            response.sendError(SC_BAD_REQUEST, WRONG_FEED_TYPE + type);
            return;
        }
        String url = null;
        String urlType = null;
        String urlRequestParam = request.getParameter("url");
        String urlTypeRequestParam = request.getParameter("urlType");
        if (urlRequestParam != null && urlRequestParam.trim().length() != 0 && urlTypeRequestParam != null && urlTypeRequestParam.trim().length() != 0 && (urlTypeRequestParam.compareTo("p") == 0 || urlTypeRequestParam.compareTo("s") == 0)) {
            url = request.getParameter("url");
            urlType = urlTypeRequestParam;
        }
        String urlInitParam = getServletContext().getInitParameter(URL_INIT_PARAM_NAME);
        String urlTypeInitParam = getServletContext().getInitParameter(URL_TYPE_INIT_PARAM_NAME);
        if (urlInitParam != null && urlInitParam.trim().length() != 0 && urlTypeInitParam != null && urlTypeInitParam.trim().length() != 0) {
            url = urlInitParam;
            urlType = urlTypeInitParam;
        }
        if (url == null || urlType == null) {
            response.sendError(SC_BAD_REQUEST, WRONG_FEED_REQ);
            return;
        }
        try {
            if (what.equals(CATEGORY)) {
                createCategoryFeed(feed, id, url, urlType);
            } else if (what.equals(FORUM)) {
                createForumFeed(feed, id, url, urlType);
            } else if (what.equals(TOPIC)) {
                createTopicFeed(feed, id, url, urlType);
            } else if (what.equals(GLOBAL)) {
                createGlobalFeed(feed, id, url, urlType);
            } else {
                response.sendError(SC_BAD_REQUEST, WRONG_FEED_SHOW_TYPE + what);
                return;
            }
        } catch (ModuleException e) {
            response.sendError(SC_INTERNAL_SERVER_ERROR, e.getMessage());
            return;
        }
        response.setContentType("text/xml");
        Writer writer = response.getWriter();
        SyndFeedOutput output = new SyndFeedOutput();
        output.output(feed, writer);
        writer.flush();
    } catch (Exception e) {
        throw new ServletException(e);
    }
}
Also used : ServletException(javax.servlet.ServletException) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl) SyndFeedOutput(com.rometools.rome.io.SyndFeedOutput) ModuleException(it.vige.rubia.ModuleException) Writer(java.io.Writer) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) ModuleException(it.vige.rubia.ModuleException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

SyndFeedImpl (com.rometools.rome.feed.synd.SyndFeedImpl)17 ArrayList (java.util.ArrayList)15 SyndEntry (com.rometools.rome.feed.synd.SyndEntry)14 SyndEntryImpl (com.rometools.rome.feed.synd.SyndEntryImpl)13 SyndFeed (com.rometools.rome.feed.synd.SyndFeed)12 SyndContentImpl (com.rometools.rome.feed.synd.SyndContentImpl)10 SyndContent (com.rometools.rome.feed.synd.SyndContent)9 SyndFeedOutput (com.rometools.rome.io.SyndFeedOutput)4 SQLException (java.sql.SQLException)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 SProject (org.bimserver.interfaces.objects.SProject)3 StatusGroup (org.onebusaway.enterprise.webapp.actions.status.model.StatusGroup)3 StatusItem (org.onebusaway.enterprise.webapp.actions.status.model.StatusItem)3 Date (java.util.Date)2 SRevision (org.bimserver.interfaces.objects.SRevision)2 SUser (org.bimserver.interfaces.objects.SUser)2 ServiceException (org.bimserver.shared.exceptions.ServiceException)2 OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)2 Filter (org.opennms.web.filter.Filter)2 Pager (com.willshex.blogwt.shared.api.Pager)1