Search in sources :

Example 1 with SyndEntry

use of com.rometools.rome.feed.synd.SyndEntry 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 2 with SyndEntry

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

Example 3 with SyndEntry

use of com.rometools.rome.feed.synd.SyndEntry in project xwiki-platform by xwiki.

the class DefaultNotificationRSSRendererTest method testCompositeEventRendering.

@Test
public void testCompositeEventRendering() throws Exception {
    CompositeEvent testCompositeEvent = mock(CompositeEvent.class);
    this.mockEvent(testCompositeEvent);
    when(this.scriptContextManager.getCurrentScriptContext()).thenReturn(Mockito.mock(ScriptContext.class));
    SyndEntry resultEntry = this.mocker.getComponentUnderTest().renderNotification(testCompositeEvent);
    assertEquals("TranslatedEventTitle", resultEntry.getTitle());
    assertEquals(1, resultEntry.getAuthors().size());
    assertEquals("id1", resultEntry.getUri());
}
Also used : SyndEntry(com.rometools.rome.feed.synd.SyndEntry) ScriptContext(javax.script.ScriptContext) CompositeEvent(org.xwiki.notifications.CompositeEvent) Test(org.junit.Test)

Example 4 with SyndEntry

use of com.rometools.rome.feed.synd.SyndEntry in project xwiki-platform by xwiki.

the class DefaultNotificationRSSManager method renderFeed.

@Override
public SyndFeed renderFeed(List<CompositeEvent> events) {
    SyndFeed feed = new SyndFeedImpl();
    // Define the general properties of the rss
    feed.setFeedType("rss_2.0");
    feed.setTitle(this.contextualLocalizationManager.getTranslationPlain("notifications.rss.feedTitle"));
    // Set the RSS feed link to the service generating the feed
    feed.setLink(this.modelBridge.getDocumentURL(new DocumentReference(wikiDescriptorManager.getCurrentWikiId(), Arrays.asList("XWiki", "Notifications", "Code"), "NotificationRSSService"), "get", "outputSyntax=plain"));
    // Set the feed description
    feed.setDescription(this.contextualLocalizationManager.getTranslationPlain("notifications.rss.feedDescription"));
    // Add every given CompositeEvent entry to the rss
    List<SyndEntry> entries = new ArrayList<>();
    for (CompositeEvent event : events) {
        try {
            NotificationRSSRenderer renderer = this.getRenderer(event);
            if (renderer != null) {
                entries.add(renderer.renderNotification(event));
            } else {
                entries.add(defaultNotificationRSSRenderer.renderNotification(event));
            }
        } catch (NotificationException e) {
            this.logger.warn("Unable to render RSS entry for CompositeEvent [{}] : [{}]", event, ExceptionUtils.getRootCauseMessage(e));
        }
    }
    feed.setEntries(entries);
    return feed;
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) NotificationRSSRenderer(org.xwiki.notifications.notifiers.rss.NotificationRSSRenderer) ArrayList(java.util.ArrayList) NotificationException(org.xwiki.notifications.NotificationException) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl) CompositeEvent(org.xwiki.notifications.CompositeEvent) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 5 with SyndEntry

use of com.rometools.rome.feed.synd.SyndEntry in project xwiki-platform by xwiki.

the class DefaultNotificationRSSRenderer method renderNotification.

@Override
public SyndEntry renderNotification(CompositeEvent eventNotification) throws NotificationException {
    SyndEntry entry = new SyndEntryImpl();
    SyndContent entryDescription = new SyndContentImpl();
    // The users contained in the CompositeEvent are already stored in a Set, they are therefore necessarily unique
    List<SyndPerson> eventAuthors = new ArrayList<SyndPerson>();
    // Convert every author of the CompositeEvent to a SyndPerson and add it to the new entry
    for (DocumentReference author : eventNotification.getUsers()) {
        SyndPerson person = new SyndPersonImpl();
        person.setName(author.getName());
        eventAuthors.add(person);
    }
    entry.setAuthors(eventAuthors);
    // Define the GUID of the event
    entry.setUri(String.join("-", eventNotification.getEventIds()));
    // Set the entry title
    entry.setTitle(this.contextualLocalizationManager.getTranslationPlain(eventNotification.getEvents().get(0).getTitle(), eventNotification.getEvents().get(0).getDocumentTitle()));
    // Render the description (the main part) of the feed entry
    try {
        this.scriptContextManager.getCurrentScriptContext().setAttribute(COMPOSITE_EVENT_BUILDING_NAME, eventNotification, ScriptContext.ENGINE_SCOPE);
        // Try to get a template associated with the composite event
        Template template = this.templateManager.getTemplate(String.format("notification/rss/%s.vm", eventNotification.getType().replaceAll("\\/", ".")));
        // If no template is found, fallback on the default one
        if (template == null) {
            template = this.templateManager.getTemplate("notification/rss/default.vm");
        }
        XDOM descriptionXDOM = this.templateManager.execute(template);
        WikiPrinter printer = new DefaultWikiPrinter();
        blockRenderer.render(descriptionXDOM, printer);
        // Add the description to the entry
        entryDescription.setType("text/html");
        entryDescription.setValue(printer.toString());
        entry.setDescription(entryDescription);
    } catch (Exception e) {
        throw new NotificationException(String.format("Unable to render the description of the event [%s].", eventNotification), e);
    } finally {
        this.scriptContextManager.getCurrentScriptContext().removeAttribute(COMPOSITE_EVENT_BUILDING_NAME, ScriptContext.ENGINE_SCOPE);
    }
    // Dates are sorted in descending order in a CompositeEvent, the first date is then the most recent one
    entry.setUpdatedDate(eventNotification.getDates().get(0));
    return entry;
}
Also used : XDOM(org.xwiki.rendering.block.XDOM) DefaultWikiPrinter(org.xwiki.rendering.renderer.printer.DefaultWikiPrinter) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) ArrayList(java.util.ArrayList) NotificationException(org.xwiki.notifications.NotificationException) WikiPrinter(org.xwiki.rendering.renderer.printer.WikiPrinter) DefaultWikiPrinter(org.xwiki.rendering.renderer.printer.DefaultWikiPrinter) NotificationException(org.xwiki.notifications.NotificationException) Template(org.xwiki.template.Template) SyndPerson(com.rometools.rome.feed.synd.SyndPerson) SyndPersonImpl(com.rometools.rome.feed.synd.SyndPersonImpl) SyndContent(com.rometools.rome.feed.synd.SyndContent) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) DocumentReference(org.xwiki.model.reference.DocumentReference)

Aggregations

SyndEntry (com.rometools.rome.feed.synd.SyndEntry)45 ArrayList (java.util.ArrayList)23 SyndFeed (com.rometools.rome.feed.synd.SyndFeed)22 SyndEntryImpl (com.rometools.rome.feed.synd.SyndEntryImpl)18 SyndContent (com.rometools.rome.feed.synd.SyndContent)15 SyndFeedImpl (com.rometools.rome.feed.synd.SyndFeedImpl)14 SyndContentImpl (com.rometools.rome.feed.synd.SyndContentImpl)13 SyndFeedInput (com.rometools.rome.io.SyndFeedInput)9 FeedException (com.rometools.rome.io.FeedException)7 Test (org.junit.Test)7 XmlReader (com.rometools.rome.io.XmlReader)6 URL (java.net.URL)6 Date (java.util.Date)5 StatusGroup (org.onebusaway.enterprise.webapp.actions.status.model.StatusGroup)5 StatusItem (org.onebusaway.enterprise.webapp.actions.status.model.StatusItem)5 IOException (java.io.IOException)4 BeanFactory (org.springframework.beans.factory.BeanFactory)4 ClassPathResource (org.springframework.core.io.ClassPathResource)4 SyndFeedOutput (com.rometools.rome.io.SyndFeedOutput)3 Post (it.vige.rubia.model.Post)3