Search in sources :

Example 16 with SyndEntry

use of com.sun.syndication.feed.synd.SyndEntry in project opennms by OpenNMS.

the class AlarmFeed method getFeed.

/**
     * <p>getFeed</p>
     *
     * @return a {@link com.sun.syndication.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<SyndEntry>();
    List<Filter> filters = new ArrayList<Filter>();
    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.sun.syndication.feed.synd.SyndEntry) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) SyndContentImpl(com.sun.syndication.feed.synd.SyndContentImpl) ArrayList(java.util.ArrayList) OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SeverityFilter(org.opennms.web.alarm.filter.SeverityFilter) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) SyndContent(com.sun.syndication.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.sun.syndication.feed.synd.SyndEntryImpl) SyndFeedImpl(com.sun.syndication.feed.synd.SyndFeedImpl) AlarmCriteria(org.opennms.web.alarm.filter.AlarmCriteria) NodeFilter(org.opennms.web.alarm.filter.NodeFilter)

Example 17 with SyndEntry

use of com.sun.syndication.feed.synd.SyndEntry in project opennms by OpenNMS.

the class EventFeed method getFeed.

/**
     * <p>getFeed</p>
     *
     * @return a {@link com.sun.syndication.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<SyndEntry>();
    try {
        Event[] events;
        ArrayList<Filter> filters = new ArrayList<Filter>();
        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.sun.syndication.feed.synd.SyndEntry) SyndContentImpl(com.sun.syndication.feed.synd.SyndContentImpl) ArrayList(java.util.ArrayList) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SeverityFilter(org.opennms.web.event.filter.SeverityFilter) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) SyndContent(com.sun.syndication.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.sun.syndication.feed.synd.SyndEntryImpl) Event(org.opennms.web.event.Event) SyndFeedImpl(com.sun.syndication.feed.synd.SyndFeedImpl) NodeFilter(org.opennms.web.event.filter.NodeFilter)

Example 18 with SyndEntry

use of com.sun.syndication.feed.synd.SyndEntry in project opennms by OpenNMS.

the class NotificationFeed method getFeed.

/**
     * <p>getFeed</p>
     *
     * @return a {@link com.sun.syndication.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<SyndEntry>();
    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.sun.syndication.feed.synd.SyndFeed) SQLException(java.sql.SQLException) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl) ArrayList(java.util.ArrayList) SyndFeedImpl(com.sun.syndication.feed.synd.SyndFeedImpl) NotificationModel(org.opennms.web.notification.NotificationModel) Notification(org.opennms.web.notification.Notification)

Example 19 with SyndEntry

use of com.sun.syndication.feed.synd.SyndEntry in project jaggery by wso2.

the class FeedHostObject method jsFunction_getFeed.

public static synchronized void jsFunction_getFeed(Context cx, Scriptable thisObj, Object[] arguments, Function funObj) throws ScriptException {
    if (arguments.length != 1) {
        throw new ScriptException("Invalid parameter");
    }
    if (arguments[0] instanceof String) {
        feed = null;
        URL url = null;
        try {
            url = new URL((String) arguments[0]);
            feed = (Feed) Abdera.getNewParser().parse(url.openStream()).getRoot();
            isRssFeed = false;
        } catch (ClassCastException e) {
            XmlReader reader = null;
            try {
                reader = new XmlReader(url);
                rssFeed = new SyndFeedInput().build(reader);
                isRssFeed = true;
                for (Iterator i = rssFeed.getEntries().iterator(); i.hasNext(); ) {
                    SyndEntry entry = (SyndEntry) i.next();
                }
            } catch (IOException e1) {
                throw new ScriptException(e1);
            } catch (Exception e1) {
                throw new ScriptException(e1);
            } finally {
                if (reader != null)
                    try {
                        reader.close();
                    } catch (IOException e1) {
                        throw new ScriptException(e1);
                    }
            }
        } catch (IRISyntaxException e) {
            throw new ScriptException(e);
        } catch (MalformedURLException e) {
            throw new ScriptException(e);
        } catch (IOException e) {
            throw new ScriptException(e);
        }
    } else {
        throw new ScriptException("Invalid parameter, It is must to be a String");
    }
}
Also used : ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) MalformedURLException(java.net.MalformedURLException) SyndFeedInput(com.sun.syndication.io.SyndFeedInput) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) Iterator(java.util.Iterator) IRISyntaxException(org.apache.abdera.i18n.iri.IRISyntaxException) XmlReader(com.sun.syndication.io.XmlReader) IOException(java.io.IOException) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) IRISyntaxException(org.apache.abdera.i18n.iri.IRISyntaxException) ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException)

Example 20 with SyndEntry

use of com.sun.syndication.feed.synd.SyndEntry in project maven-plugins by apache.

the class FeedGenerator method getEntries.

private List<SyndEntry> getEntries(final List<Release> releases) {
    final List<SyndEntry> entries = new ArrayList<SyndEntry>(1);
    if (releases.size() > 0) {
        // TODO: is this guaranteed to be the latest?
        final Release release = releases.get(0);
        final SyndEntry entry = new SyndEntryImpl();
        entry.setTitle(release.getVersion());
        entry.setLink(link + "#" + HtmlTools.encodeId(release.getVersion()));
        entry.setDescription(getSyndContent(release));
        entry.setPublishedDate(getDate(release.getDateRelease(), dateFormat));
        entries.add(entry);
    }
    return entries;
}
Also used : SyndEntry(com.sun.syndication.feed.synd.SyndEntry) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl) ArrayList(java.util.ArrayList) Release(org.apache.maven.plugins.changes.model.Release)

Aggregations

SyndEntry (com.sun.syndication.feed.synd.SyndEntry)20 SyndEntryImpl (com.sun.syndication.feed.synd.SyndEntryImpl)12 SyndFeed (com.sun.syndication.feed.synd.SyndFeed)11 SyndFeedImpl (com.sun.syndication.feed.synd.SyndFeedImpl)10 ArrayList (java.util.ArrayList)10 SyndContent (com.sun.syndication.feed.synd.SyndContent)8 SyndContentImpl (com.sun.syndication.feed.synd.SyndContentImpl)8 Date (java.util.Date)5 SyndFeedOutput (com.sun.syndication.io.SyndFeedOutput)4 IOException (java.io.IOException)3 SQLException (java.sql.SQLException)3 SyndCategory (com.sun.syndication.feed.synd.SyndCategory)2 FeedException (com.sun.syndication.io.FeedException)2 SyndFeedInput (com.sun.syndication.io.SyndFeedInput)2 OutputStreamWriter (java.io.OutputStreamWriter)2 HashSet (java.util.HashSet)2 Test (org.junit.Test)2 OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)2 Filter (org.opennms.web.filter.Filter)2 Post (com.erudika.scoold.core.Post)1