Search in sources :

Example 16 with SyndContent

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);
    }
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) InputSource(org.xml.sax.InputSource) TikaException(org.apache.tika.exception.TikaException) SyndContent(com.rometools.rome.feed.synd.SyndContent) SyndFeedInput(com.rometools.rome.io.SyndFeedInput) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) FeedException(com.rometools.rome.io.FeedException) XHTMLContentHandler(org.apache.tika.sax.XHTMLContentHandler) CloseShieldInputStream(org.apache.commons.io.input.CloseShieldInputStream)

Example 17 with SyndContent

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;
}
Also used : SyndEntry(com.rometools.rome.feed.synd.SyndEntry) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) ArrayList(java.util.ArrayList) OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SeverityFilter(org.opennms.web.alarm.filter.SeverityFilter) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) SyndContent(com.rometools.rome.feed.synd.SyndContent) SeverityFilter(org.opennms.web.alarm.filter.SeverityFilter) Filter(org.opennms.web.filter.Filter) NodeFilter(org.opennms.web.alarm.filter.NodeFilter) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl) AlarmCriteria(org.opennms.web.alarm.filter.AlarmCriteria) NodeFilter(org.opennms.web.alarm.filter.NodeFilter)

Example 18 with SyndContent

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;
}
Also used : SQLException(java.sql.SQLException) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) ArrayList(java.util.ArrayList) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SeverityFilter(org.opennms.web.event.filter.SeverityFilter) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) SyndContent(com.rometools.rome.feed.synd.SyndContent) SeverityFilter(org.opennms.web.event.filter.SeverityFilter) Filter(org.opennms.web.filter.Filter) NodeFilter(org.opennms.web.event.filter.NodeFilter) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) Event(org.opennms.web.event.Event) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl) NodeFilter(org.opennms.web.event.filter.NodeFilter)

Example 19 with SyndContent

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;
}
Also used : SyndContent(com.rometools.rome.feed.synd.SyndContent) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl)

Example 20 with SyndContent

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);
}
Also used : Item(org.olat.modules.webFeed.Item) SyndContent(com.rometools.rome.feed.synd.SyndContent) SyndEnclosure(com.rometools.rome.feed.synd.SyndEnclosure) Date(java.util.Date) Test(org.junit.Test)

Aggregations

SyndContent (com.rometools.rome.feed.synd.SyndContent)23 SyndEntry (com.rometools.rome.feed.synd.SyndEntry)15 SyndContentImpl (com.rometools.rome.feed.synd.SyndContentImpl)13 SyndEntryImpl (com.rometools.rome.feed.synd.SyndEntryImpl)13 ArrayList (java.util.ArrayList)12 SyndFeed (com.rometools.rome.feed.synd.SyndFeed)9 SyndFeedImpl (com.rometools.rome.feed.synd.SyndFeedImpl)9 SyndEnclosure (com.rometools.rome.feed.synd.SyndEnclosure)5 Date (java.util.Date)5 Item (org.olat.modules.webFeed.Item)4 StatusGroup (org.onebusaway.enterprise.webapp.actions.status.model.StatusGroup)4 StatusItem (org.onebusaway.enterprise.webapp.actions.status.model.StatusItem)4 SyndFeedOutput (com.rometools.rome.io.SyndFeedOutput)3 SProject (org.bimserver.interfaces.objects.SProject)3 SyndCategory (com.rometools.rome.feed.synd.SyndCategory)2 SyndPerson (com.rometools.rome.feed.synd.SyndPerson)2 FeedException (com.rometools.rome.io.FeedException)2 SyndFeedInput (com.rometools.rome.io.SyndFeedInput)2 Metacard (ddf.catalog.data.Metacard)2 Result (ddf.catalog.data.Result)2