use of com.rometools.rome.feed.synd.SyndContent in project tika by apache.
the class FeedParser method parse.
public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException {
// set the encoding?
try {
SyndFeed feed = new SyndFeedInput().build(new InputSource(new CloseShieldInputStream(stream)));
String title = stripTags(feed.getTitleEx());
String description = stripTags(feed.getDescriptionEx());
metadata.set(TikaCoreProperties.TITLE, title);
metadata.set(TikaCoreProperties.DESCRIPTION, description);
// store the other fields in the metadata
XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
xhtml.startDocument();
xhtml.element("h1", title);
xhtml.element("p", description);
xhtml.startElement("ul");
for (Object e : feed.getEntries()) {
SyndEntry entry = (SyndEntry) e;
String link = entry.getLink();
if (link != null) {
xhtml.startElement("li");
xhtml.startElement("a", "href", link);
xhtml.characters(stripTags(entry.getTitleEx()));
xhtml.endElement("a");
SyndContent content = entry.getDescription();
if (content != null) {
xhtml.newline();
xhtml.characters(stripTags(content));
}
xhtml.endElement("li");
}
}
xhtml.endElement("ul");
xhtml.endDocument();
} catch (FeedException e) {
throw new TikaException("RSS parse error", e);
}
}
use of com.rometools.rome.feed.synd.SyndContent 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.SyndContent 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.SyndContent 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.SyndContent in project OpenOLAT by OpenOLAT.
the class RomeFeedFetcherTest method convertEntry.
@Test
public void convertEntry() {
// prepare the mock
String author = "author";
when(syndEntryMock.getAuthor()).thenReturn(author);
String description = "description";
when(syndEntryMock.getDescription().getValue()).thenReturn(description);
String link = "link";
when(syndEntryMock.getLink()).thenReturn(link);
String title = "title";
when(syndEntryMock.getTitle()).thenReturn(title);
String uri = "uri";
when(syndEntryMock.getUri()).thenReturn(uri);
Date publishedDate = new Date();
when(syndEntryMock.getPublishedDate()).thenReturn(publishedDate);
Date updatedDate = new Date();
when(syndEntryMock.getUpdatedDate()).thenReturn(updatedDate);
List<SyndContent> contents = Arrays.asList(syndContentMock);
when(syndEntryMock.getContents()).thenReturn(contents);
when(syndEnclosureMock.getUrl()).thenReturn("URL");
List<SyndEnclosure> enclosures = Arrays.asList(syndEnclosureMock);
when(syndEntryMock.getEnclosures()).thenReturn(enclosures);
// call the method
Item item = sut.convertEntry(feedMock, syndEntryMock);
// test
assertThat(item.getFeed()).isEqualTo(feedMock);
assertThat(item.getAuthor()).isEqualTo(author);
assertThat(item.getContent()).isNotNull();
assertThat(item.getDescription()).isEqualTo(description);
assertThat(item.getEnclosure()).isNotNull();
assertThat(item.getExternalLink()).isEqualTo(link);
assertThat(item.getTitle()).isEqualTo(title);
assertThat(item.getGuid()).isEqualTo(uri);
assertThat(item.getLastModified()).isEqualTo(updatedDate);
assertThat(item.getPublishDate()).isEqualTo(publishedDate);
}
Aggregations