use of com.rometools.rome.feed.synd.SyndEntry 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;
}
use of com.rometools.rome.feed.synd.SyndEntry 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;
}
use of com.rometools.rome.feed.synd.SyndEntry 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;
}
use of com.rometools.rome.feed.synd.SyndEntry in project rubia-forums by flashboss.
the class FeedsServlet method getEntry.
private SyndEntry getEntry(Post post, String url, String urlType) {
SyndEntry entry;
SyndContent description;
entry = new SyndEntryImpl();
entry.setTitle(post.getMessage().getSubject() + BY + post.getPoster().getUserId());
entry.setLink(postLink(post.getId().toString(), url, urlType));
entry.setPublishedDate(post.getCreateDate());
description = new SyndContentImpl();
description.setType("text/html");
String text = post.getMessage().getText();
description.setValue(post.getMessage().getHTMLEnabled() ? escapeHtml(text) : text);
entry.setDescription(description);
return entry;
}
use of com.rometools.rome.feed.synd.SyndEntry in project OpenOLAT by OpenOLAT.
the class RomeFeedFetcher method validateFeedUrl.
@Override
public ValidatedURL validateFeedUrl(String url, boolean enclosuresExpected) {
SyndFeedInput input = new SyndFeedInput();
boolean modifiedProtocol = false;
try {
if (url != null) {
url = url.trim();
}
if (url.startsWith("feed") || url.startsWith("itpc")) {
// accept feed(s) urls like generated in safari browser
url = "http" + url.substring(4);
modifiedProtocol = true;
}
URL realUrl = new URL(url);
SyndFeed feed = input.build(new XmlReader(realUrl));
if (!feed.getEntries().isEmpty()) {
if (enclosuresExpected) {
SyndEntry entry = feed.getEntries().get(0);
if (entry.getEnclosures().isEmpty()) {
return new ValidatedURL(url, ValidatedURL.State.NO_ENCLOSURE);
}
}
return new ValidatedURL(url, ValidatedURL.State.VALID);
}
// The feed was read successfully
return new ValidatedURL(url, ValidatedURL.State.VALID);
} catch (ParsingFeedException e) {
if (modifiedProtocol) {
// fallback for SWITCHcast itpc -> http -> https
url = "https" + url.substring(4);
return validateFeedUrl(url, enclosuresExpected);
}
String message = String.format("Validation of the feed url %s failed. %s: %s ", url, e.getClass(), e.getMessage());
log.debug(message);
return new ValidatedURL(url, ValidatedURL.State.NOT_FOUND);
} catch (FileNotFoundException e) {
String message = String.format("Validation of the feed url %s failed. %s: %s ", url, e.getClass(), e.getMessage());
log.debug(message);
return new ValidatedURL(url, ValidatedURL.State.NOT_FOUND);
} catch (Exception e) {
String message = String.format("Validation of the feed url %s failed. %s: %s ", url, e.getClass(), e.getMessage());
log.debug(message);
}
return new ValidatedURL(url, ValidatedURL.State.MALFORMED);
}
Aggregations