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;
}
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;
}
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());
}
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;
}
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;
}
Aggregations