Search in sources :

Example 6 with SyndFeed

use of com.sun.syndication.feed.synd.SyndFeed in project play-cookbook by spinscale.

the class FeedTest method testThatRss20Works.

@Test
public void testThatRss20Works() throws Exception {
    Response response = GET("/feed/posts.rss2");
    assertIsOk(response);
    assertContentType("application/rss+xml", response);
    assertCharset("utf-8", response);
    SyndFeed feed = getFeed(response);
    assertEquals("rss_2.0", feed.getFeedType());
}
Also used : Response(play.mvc.Http.Response) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) FunctionalTest(play.test.FunctionalTest) Test(org.junit.Test)

Example 7 with SyndFeed

use of com.sun.syndication.feed.synd.SyndFeed in project camel by apache.

the class RssPollingConsumerTest method testGrabbingListOfEntries.

@Test
public void testGrabbingListOfEntries() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMinimumMessageCount(1);
    mock.assertIsSatisfied();
    Exchange exchange = mock.getExchanges().get(0);
    Message in = exchange.getIn();
    assertNotNull(in);
    assertTrue(in.getBody() instanceof SyndFeed);
    assertTrue(in.getHeader(RssConstants.RSS_FEED) instanceof SyndFeed);
    SyndFeed feed = in.getHeader(RssConstants.RSS_FEED, SyndFeed.class);
    assertTrue(feed.getAuthor().contains("Jonathan Anstey"));
    SyndFeed body = in.getBody(SyndFeed.class);
    assertEquals(10, body.getEntries().size());
}
Also used : Exchange(org.apache.camel.Exchange) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) Message(org.apache.camel.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 8 with SyndFeed

use of com.sun.syndication.feed.synd.SyndFeed in project camel by apache.

the class RssDataFormat method marshal.

public void marshal(Exchange exchange, Object body, OutputStream out) throws Exception {
    SyndFeed feed = ExchangeHelper.convertToMandatoryType(exchange, SyndFeed.class, body);
    String xml = RssConverter.feedToXml(feed);
    out.write(xml.getBytes());
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed)

Example 9 with SyndFeed

use of com.sun.syndication.feed.synd.SyndFeed in project gitblit by gitblit.

the class SyndicationUtils method toRSS.

/**
	 * Outputs an RSS feed of the list of entries to the outputstream.
	 *
	 * @param hostUrl
	 * @param feedLink
	 * @param title
	 * @param description
	 * @param entryModels
	 * @param os
	 * @throws IOException
	 * @throws FeedException
	 */
public static void toRSS(String hostUrl, String feedLink, String title, String description, List<FeedEntryModel> entryModels, OutputStream os) throws IOException, FeedException {
    SyndFeed feed = new SyndFeedImpl();
    feed.setFeedType("rss_2.0");
    feed.setEncoding("UTF-8");
    feed.setTitle(title);
    feed.setLink(feedLink);
    if (StringUtils.isEmpty(description)) {
        feed.setDescription(title);
    } else {
        feed.setDescription(description);
    }
    SyndImageImpl image = new SyndImageImpl();
    image.setTitle(Constants.NAME);
    image.setUrl(hostUrl + "/gitblt_25.png");
    image.setLink(hostUrl);
    feed.setImage(image);
    List<SyndEntry> entries = new ArrayList<SyndEntry>();
    for (FeedEntryModel entryModel : entryModels) {
        SyndEntry entry = new SyndEntryImpl();
        entry.setTitle(entryModel.title);
        entry.setAuthor(entryModel.author);
        entry.setLink(entryModel.link);
        entry.setPublishedDate(entryModel.published);
        if (entryModel.tags != null && entryModel.tags.size() > 0) {
            List<SyndCategory> tags = new ArrayList<SyndCategory>();
            for (String tag : entryModel.tags) {
                SyndCategoryImpl cat = new SyndCategoryImpl();
                cat.setName(tag);
                tags.add(cat);
            }
            entry.setCategories(tags);
        }
        SyndContent content = new SyndContentImpl();
        if (StringUtils.isEmpty(entryModel.contentType) || entryModel.contentType.equalsIgnoreCase("text/plain")) {
            content.setType("text/html");
            content.setValue(StringUtils.breakLinesForHtml(entryModel.content));
        } else {
            content.setType(entryModel.contentType);
            content.setValue(entryModel.content);
        }
        entry.setDescription(content);
        entries.add(entry);
    }
    feed.setEntries(entries);
    OutputStreamWriter writer = new OutputStreamWriter(os, "UTF-8");
    SyndFeedOutput output = new SyndFeedOutput();
    output.output(feed, writer);
    writer.close();
}
Also used : SyndCategory(com.sun.syndication.feed.synd.SyndCategory) SyndImageImpl(com.sun.syndication.feed.synd.SyndImageImpl) FeedEntryModel(com.gitblit.models.FeedEntryModel) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) SyndContentImpl(com.sun.syndication.feed.synd.SyndContentImpl) ArrayList(java.util.ArrayList) SyndFeedOutput(com.sun.syndication.io.SyndFeedOutput) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndCategoryImpl(com.sun.syndication.feed.synd.SyndCategoryImpl) SyndContent(com.sun.syndication.feed.synd.SyndContent) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl) SyndFeedImpl(com.sun.syndication.feed.synd.SyndFeedImpl) OutputStreamWriter(java.io.OutputStreamWriter)

Example 10 with SyndFeed

use of com.sun.syndication.feed.synd.SyndFeed in project scoold by Erudika.

the class SearchController method getFeed.

private SyndFeed getFeed() throws IOException, FeedException {
    List<Post> questions = pc.findQuery(Utils.type(Question.class), "*");
    List<SyndEntry> entries = new ArrayList<SyndEntry>();
    String baseurl = Config.getConfigParam("base_url", "https://scoold.com");
    baseurl = baseurl.endsWith("/") ? baseurl : baseurl + "/";
    SyndFeed feed = new SyndFeedImpl();
    feed.setFeedType("atom_1.0");
    feed.setTitle("Scoold - Recent questions");
    feed.setLink(baseurl);
    feed.setDescription("A summary of the most recent questions asked on Scoold.");
    for (Post post : questions) {
        SyndEntry entry;
        SyndContent description;
        String baselink = baseurl.concat("question/").concat(post.getId());
        entry = new SyndEntryImpl();
        entry.setTitle(post.getTitle());
        entry.setLink(baselink);
        entry.setPublishedDate(new Date(post.getTimestamp()));
        entry.setAuthor(baseurl.concat("profile/").concat(post.getCreatorid()));
        entry.setUri(baselink.concat("/").concat(Utils.stripAndTrim(post.getTitle()).replaceAll("\\p{Z}+", "-").toLowerCase()));
        description = new SyndContentImpl();
        description.setType("text/html");
        description.setValue(Utils.markdownToHtml(post.getBody()));
        entry.setDescription(description);
        entries.add(entry);
    }
    feed.setEntries(entries);
    return feed;
}
Also used : Post(com.erudika.scoold.core.Post) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) SyndContentImpl(com.sun.syndication.feed.synd.SyndContentImpl) ArrayList(java.util.ArrayList) Date(java.util.Date) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndContent(com.sun.syndication.feed.synd.SyndContent) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl) Question(com.erudika.scoold.core.Question) SyndFeedImpl(com.sun.syndication.feed.synd.SyndFeedImpl)

Aggregations

SyndFeed (com.sun.syndication.feed.synd.SyndFeed)26 SyndEntry (com.sun.syndication.feed.synd.SyndEntry)11 SyndEntryImpl (com.sun.syndication.feed.synd.SyndEntryImpl)10 ArrayList (java.util.ArrayList)10 SyndFeedImpl (com.sun.syndication.feed.synd.SyndFeedImpl)9 SyndContent (com.sun.syndication.feed.synd.SyndContent)6 SyndContentImpl (com.sun.syndication.feed.synd.SyndContentImpl)6 Test (org.junit.Test)6 SyndFeedOutput (com.sun.syndication.io.SyndFeedOutput)5 FeedException (com.sun.syndication.io.FeedException)4 Date (java.util.Date)4 SyndFeedInput (com.sun.syndication.io.SyndFeedInput)3 IOException (java.io.IOException)3 URL (java.net.URL)3 SQLException (java.sql.SQLException)3 FeedEntryModel (com.gitblit.models.FeedEntryModel)2 SyndCategory (com.sun.syndication.feed.synd.SyndCategory)2 FeedFetcherCache (com.sun.syndication.fetcher.impl.FeedFetcherCache)2 SyndFeedInfo (com.sun.syndication.fetcher.impl.SyndFeedInfo)2 XmlReader (com.sun.syndication.io.XmlReader)2