use of com.sun.syndication.feed.synd.SyndFeed in project OpenClinica by OpenClinica.
the class RssReaderServlet method getFeed.
void getFeed(PrintWriter pw) {
SyndFeed feed = null;
String htmlFeed = null;
try {
feed = feedFetcher.retrieveFeed(new URL(rssUrl));
htmlFeed = feedHtml(feed);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
htmlFeed = errorFeedHtml(e.getMessage());
e.printStackTrace();
} catch (FeedException e) {
// TODO Auto-generated catch block
htmlFeed = errorFeedHtml(e.getMessage());
e.printStackTrace();
} catch (FetcherException e) {
htmlFeed = errorFeedHtml(e.getMessage());
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
htmlFeed = errorFeedHtml(e.getMessage());
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
pw.println(htmlFeed);
pw.close();
}
}
use of com.sun.syndication.feed.synd.SyndFeed in project opennms by OpenNMS.
the class AbstractFeed method render.
/**
* <p>render</p>
*
* @return a {@link java.lang.String} object.
*/
@Override
public final String render() {
SyndFeed feed = this.getFeed();
feed.setFeedType(this.getFeedType());
feed.setAuthor("OpenNMS");
SyndFeedOutput output = new SyndFeedOutput();
try {
StringWriter writer = new StringWriter();
output.output(feed, writer);
return writer.toString();
} catch (Throwable e) {
LOG.warn("unable to render feed", e);
return "";
}
}
use of com.sun.syndication.feed.synd.SyndFeed 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;
}
use of com.sun.syndication.feed.synd.SyndFeed 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;
}
use of com.sun.syndication.feed.synd.SyndFeed 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;
}
Aggregations