Search in sources :

Example 16 with SyndFeed

use of com.rometools.rome.feed.synd.SyndFeed in project rssriver by dadoonet.

the class RssToJsonTest method shouldHaveRawContent.

@Test
public void shouldHaveRawContent() throws Exception {
    SyndFeedInput input = new SyndFeedInput();
    SyndFeed feed = input.build(new XmlReader(getClass().getResource("/dcrainmaker/rss.xml")));
    assertThat(feed.getEntries().size(), greaterThan(0));
    for (Object o : feed.getEntries()) {
        SyndEntryImpl message = (SyndEntryImpl) o;
        XContentBuilder xcb = toJson(message, null, null, true);
        assertThat(xcb, notNullValue());
        assertThat(xcb.string(), containsString("<p>"));
        logger.info(xcb.string());
    }
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SyndFeedInput(com.rometools.rome.io.SyndFeedInput) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) XmlReader(com.rometools.rome.io.XmlReader) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) Test(org.junit.Test)

Example 17 with SyndFeed

use of com.rometools.rome.feed.synd.SyndFeed in project asterixdb by apache.

the class RSSFeedServlet method getFeed.

protected SyndFeed getFeed(IServletRequest req) throws IOException, FeedException, ParseException {
    SyndFeed feed = new SyndFeedImpl();
    feed.setTitle("Sample Feed (created with ROME)");
    feed.setLink("http://rome.dev.java.net");
    feed.setDescription("This feed has been created using ROME (Java syndication utilities");
    List<SyndEntry> entries = new ArrayList<>();
    SyndEntry entry;
    SyndContent description;
    entry = new SyndEntryImpl();
    entry.setTitle("AsterixDB 0.8.7");
    entry.setLink("http://http://asterixdb.apache.org/docs/0.8.7-incubating/index.html");
    entry.setPublishedDate(DATE_PARSER.parse("2012-06-08"));
    description = new SyndContentImpl();
    description.setType("text/plain");
    description.setValue("AsterixDB 0.8.7 Release");
    entry.setDescription(description);
    entries.add(entry);
    entry = new SyndEntryImpl();
    entry.setTitle("Couchbase 4.1");
    entry.setLink("http://blog.couchbase.com/2015/december/introducing-couchbase-server-4.1");
    entry.setPublishedDate(DATE_PARSER.parse("2015-12-09"));
    description = new SyndContentImpl();
    description.setType("text/plain");
    description.setValue("Couchbase Server 4.1 Release. Bug fixes, minor API changes and some new features");
    entry.setDescription(description);
    entries.add(entry);
    entry = new SyndEntryImpl();
    entry.setTitle("ROME v0.3");
    entry.setLink("http://wiki.java.net/bin/view/Javawsxml/rome03");
    entry.setPublishedDate(DATE_PARSER.parse("2004-07-27"));
    description = new SyndContentImpl();
    description.setType("text/html");
    description.setValue("<p>Bug fixes, API changes, some new features and some Unit testing</p>" + "<p>For details check the <a href=\"https://rometools.jira.com/wiki/display/ROME/Change+Log#" + "ChangeLog-Changesmadefromv0.3tov0.4\">Changes Log for 0.3</a></p>");
    entry.setDescription(description);
    entries.add(entry);
    entry = new SyndEntryImpl();
    entry.setTitle("ROME v0.4");
    entry.setLink("http://wiki.java.net/bin/view/Javawsxml/rome04");
    entry.setPublishedDate(DATE_PARSER.parse("2004-09-24"));
    description = new SyndContentImpl();
    description.setType("text/html");
    description.setValue("<p>Bug fixes, API changes, some new features, Unit testing completed</p>" + "<p>For details check the <a href=\"https://rometools.jira.com/wiki/display/ROME/Change+Log#" + "ChangeLog-Changesmadefromv0.4tov0.5\">Changes Log for 0.4</a></p>");
    entry.setDescription(description);
    entries.add(entry);
    feed.setEntries(entries);
    return feed;
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) 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) ArrayList(java.util.ArrayList) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl)

Example 18 with SyndFeed

use of com.rometools.rome.feed.synd.SyndFeed in project ddf by codice.

the class OpenSearchSource method processResponse.

/**
     * @param is
     * @param queryRequest
     * @return
     * @throws ddf.catalog.source.UnsupportedQueryException
     */
private SourceResponseImpl processResponse(InputStream is, QueryRequest queryRequest) throws UnsupportedQueryException {
    List<Result> resultQueue = new ArrayList<>();
    SyndFeedInput syndFeedInput = new SyndFeedInput();
    SyndFeed syndFeed = null;
    try {
        syndFeed = syndFeedInput.build(new InputStreamReader(is, StandardCharsets.UTF_8));
    } catch (FeedException e) {
        LOGGER.debug("Unable to read RSS/Atom feed.", e);
    }
    List<SyndEntry> entries = null;
    long totalResults = 0;
    if (syndFeed != null) {
        entries = syndFeed.getEntries();
        for (SyndEntry entry : entries) {
            resultQueue.addAll(createResponseFromEntry(entry));
        }
        totalResults = entries.size();
        List<Element> foreignMarkup = syndFeed.getForeignMarkup();
        for (Element element : foreignMarkup) {
            if (element.getName().equals("totalResults")) {
                try {
                    totalResults = Long.parseLong(element.getContent(0).getValue());
                } catch (NumberFormatException | IndexOutOfBoundsException e) {
                    // totalResults is already initialized to the correct value, so don't change it here.
                    LOGGER.debug("Received invalid number of results.", e);
                }
            }
        }
    }
    SourceResponseImpl response = new SourceResponseImpl(queryRequest, resultQueue);
    response.setHits(totalResults);
    return response;
}
Also used : InputStreamReader(java.io.InputStreamReader) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) FeedException(com.rometools.rome.io.FeedException) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) Result(ddf.catalog.data.Result) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SyndFeedInput(com.rometools.rome.io.SyndFeedInput)

Example 19 with SyndFeed

use of com.rometools.rome.feed.synd.SyndFeed 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)

Aggregations

SyndFeed (com.rometools.rome.feed.synd.SyndFeed)19 SyndEntryImpl (com.rometools.rome.feed.synd.SyndEntryImpl)11 SyndFeedInput (com.rometools.rome.io.SyndFeedInput)10 SyndEntry (com.rometools.rome.feed.synd.SyndEntry)8 XmlReader (com.rometools.rome.io.XmlReader)7 ArrayList (java.util.ArrayList)7 SyndFeedImpl (com.rometools.rome.feed.synd.SyndFeedImpl)6 SyndContent (com.rometools.rome.feed.synd.SyndContent)5 FeedException (com.rometools.rome.io.FeedException)5 Test (org.junit.Test)5 SyndContentImpl (com.rometools.rome.feed.synd.SyndContentImpl)4 SyndFeedOutput (com.rometools.rome.io.SyndFeedOutput)3 SQLException (java.sql.SQLException)3 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)3 OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)2 Filter (org.opennms.web.filter.Filter)2 GeoRSSModule (com.rometools.modules.georss.GeoRSSModule)1 Position (com.rometools.modules.georss.geometries.Position)1 Channel (com.rometools.rome.feed.rss.Channel)1 Pager (com.willshex.blogwt.shared.api.Pager)1