Search in sources :

Example 11 with SyndEntryImpl

use of com.sun.syndication.feed.synd.SyndEntryImpl in project camel by apache.

the class AggregateRssFeedStrategy method aggregate.

public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
    if (oldExchange == null) {
        return newExchange;
    }
    SyndFeed oldFeed = oldExchange.getIn().getBody(SyndFeed.class);
    SyndFeed newFeed = newExchange.getIn().getBody(SyndFeed.class);
    if (oldFeed != null && newFeed != null) {
        List<SyndEntryImpl> oldEntries = CastUtils.cast(oldFeed.getEntries());
        List<SyndEntryImpl> newEntries = CastUtils.cast(newFeed.getEntries());
        List<SyndEntryImpl> mergedList = new ArrayList<SyndEntryImpl>(oldEntries.size() + newEntries.size());
        mergedList.addAll(oldEntries);
        mergedList.addAll(newEntries);
        oldFeed.setEntries(mergedList);
    } else {
        log.debug("Could not merge exchanges. One body was null.");
    }
    return oldExchange;
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl) ArrayList(java.util.ArrayList)

Example 12 with SyndEntryImpl

use of com.sun.syndication.feed.synd.SyndEntryImpl in project modules.playframework.org by playframework.

the class FeedCreationActor method createFeed.

private void createFeed(List<HistoricalEvent> historicalEvents, String feedType, File outputDirectory, String classifier) {
    SyndFeed feed = new SyndFeedImpl();
    feed.setFeedType(feedType);
    feed.setTitle("Play! Modules");
    feed.setLink("http://modules.playframework.org");
    feed.setUri("http://modules.playframework.org");
    feed.setPublishedDate(new Date());
    feed.setDescription("The Play! Framework's module repository feed");
    List<SyndEntry> entries = new ArrayList<SyndEntry>(historicalEvents.size());
    for (HistoricalEvent historicalEvent : historicalEvents) {
        SyndEntry entry = new SyndEntryImpl();
        entry.setTitle(historicalEvent.category);
        entry.setAuthor("Play framework modules");
        entry.setPublishedDate(historicalEvent.creationDate);
        // todo this will be the url of the module
        entry.setLink("http://modules.playframework.org");
        entry.setUri("mpo-he-" + historicalEvent.id);
        SyndContent description = new SyndContentImpl();
        description.setType("text/plain");
        description.setValue(historicalEvent.message);
        entry.setDescription(description);
        entries.add(entry);
    }
    feed.setEntries(entries);
    Writer writer = null;
    try {
        File outputFile = new File(outputDirectory, String.format("mpo.%s.xml", classifier));
        writer = new FileWriter(outputFile);
        SyndFeedOutput output = new SyndFeedOutput();
        output.output(feed, writer);
        writer.close();
    } catch (IOException e) {
        Logger.error(String.format("A problem occurred when generating the %s feed", classifier), e);
    } catch (FeedException e) {
        Logger.error(String.format("A problem occurred when generating the %s feed", classifier), e);
    } finally {
        IOUtils.close(writer);
    }
}
Also used : SyndEntry(com.sun.syndication.feed.synd.SyndEntry) SyndContentImpl(com.sun.syndication.feed.synd.SyndContentImpl) HistoricalEvent(models.HistoricalEvent) FileWriter(java.io.FileWriter) FeedException(com.sun.syndication.io.FeedException) ArrayList(java.util.ArrayList) SyndFeedOutput(com.sun.syndication.io.SyndFeedOutput) IOException(java.io.IOException) Date(java.util.Date) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndContent(com.sun.syndication.feed.synd.SyndContent) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl) SyndFeedImpl(com.sun.syndication.feed.synd.SyndFeedImpl) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 13 with SyndEntryImpl

use of com.sun.syndication.feed.synd.SyndEntryImpl in project play-cookbook by spinscale.

the class FeedResult method createEntry.

private SyndEntry createEntry(String title, String link, String description, Date createDate) {
    SyndEntry entry = new SyndEntryImpl();
    entry.setTitle(title);
    entry.setLink(link);
    entry.setPublishedDate(createDate);
    SyndContent entryDescription = new SyndContentImpl();
    entryDescription.setType("text/html");
    entryDescription.setValue(description);
    entry.setDescription(entryDescription);
    return entry;
}
Also used : SyndContent(com.sun.syndication.feed.synd.SyndContent) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) SyndContentImpl(com.sun.syndication.feed.synd.SyndContentImpl) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl)

Example 14 with SyndEntryImpl

use of com.sun.syndication.feed.synd.SyndEntryImpl 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 15 with SyndEntryImpl

use of com.sun.syndication.feed.synd.SyndEntryImpl 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)

Aggregations

SyndEntryImpl (com.sun.syndication.feed.synd.SyndEntryImpl)17 SyndEntry (com.sun.syndication.feed.synd.SyndEntry)12 SyndFeed (com.sun.syndication.feed.synd.SyndFeed)10 ArrayList (java.util.ArrayList)10 SyndFeedImpl (com.sun.syndication.feed.synd.SyndFeedImpl)9 SyndContentImpl (com.sun.syndication.feed.synd.SyndContentImpl)8 SyndContent (com.sun.syndication.feed.synd.SyndContent)7 FeedException (com.sun.syndication.io.FeedException)4 Date (java.util.Date)4 SyndFeedOutput (com.sun.syndication.io.SyndFeedOutput)3 IOException (java.io.IOException)3 SQLException (java.sql.SQLException)3 FeedEntryModel (com.gitblit.models.FeedEntryModel)2 SyndCategory (com.sun.syndication.feed.synd.SyndCategory)2 OutputStreamWriter (java.io.OutputStreamWriter)2 OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)2 Filter (org.opennms.web.filter.Filter)2 Post (com.erudika.scoold.core.Post)1 Question (com.erudika.scoold.core.Question)1 GitBlitException (com.gitblit.GitBlitException)1