Search in sources :

Example 1 with SyndEntryImpl

use of com.sun.syndication.feed.synd.SyndEntryImpl in project jersey by jersey.

the class FeedDownloadTaskTest method syndEntry.

private SyndEntry syndEntry(String title, String link, String description, Date date) {
    SyndEntry entry = new SyndEntryImpl();
    entry.setLink(link);
    entry.setTitle(title);
    SyndContentImpl content = new SyndContentImpl();
    content.setValue(description);
    entry.setDescription(content);
    entry.setPublishedDate(date);
    return entry;
}
Also used : SyndEntry(com.sun.syndication.feed.synd.SyndEntry) SyndContentImpl(com.sun.syndication.feed.synd.SyndContentImpl) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl)

Example 2 with SyndEntryImpl

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

the class UpdatedDateFilterTest method testFilter.

@Test
public void testFilter() {
    SyndEntry entry = new SyndEntryImpl();
    entry.setPublishedDate(now);
    entry.setAuthor("ANDY");
    assertTrue(fixture.isValidEntry(new RssEndpoint(), new SyndFeedImpl(), entry));
    entry = new SyndEntryImpl();
    entry.setPublishedDate(now);
    entry.setAuthor("ANDY");
    assertFalse(fixture.isValidEntry(new RssEndpoint(), new SyndFeedImpl(), entry));
    entry = new SyndEntryImpl();
    entry.setPublishedDate(now);
    entry.setAuthor("FRED");
    assertTrue(fixture.isValidEntry(new RssEndpoint(), new SyndFeedImpl(), entry));
}
Also used : SyndEntry(com.sun.syndication.feed.synd.SyndEntry) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl) SyndFeedImpl(com.sun.syndication.feed.synd.SyndFeedImpl) Test(org.junit.Test)

Example 3 with SyndEntryImpl

use of com.sun.syndication.feed.synd.SyndEntryImpl 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 4 with SyndEntryImpl

use of com.sun.syndication.feed.synd.SyndEntryImpl 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)

Example 5 with SyndEntryImpl

use of com.sun.syndication.feed.synd.SyndEntryImpl in project OpenClinica by OpenClinica.

the class RssReaderServlet method feedHtml.

String feedHtml(SyndFeed feed) {
    HtmlBuilder htmlBuilder = new HtmlBuilder();
    htmlBuilder.h1().close().append(resword.getString("news")).h1End().ul().close();
    List<SyndEntryImpl> theFeeds = feed.getEntries();
    for (int i = 0; i < (theFeeds.size() >= 4 ? 4 : theFeeds.size()); i++) {
        SyndEntryImpl syndFeed = theFeeds.get(i);
        String description = null;
        if (syndFeed.getDescription().getValue().length() > 50) {
            Integer k = 50;
            while (syndFeed.getDescription().getValue().charAt(k) != ' ') {
                k--;
            }
            description = syndFeed.getDescription().getValue().substring(0, k) + " ...";
        } else {
            description = syndFeed.getDescription().getValue();
        }
        SimpleDateFormat sdf = new SimpleDateFormat(resformat.getString("mid_date_format"));
        String theDate = sdf.format(syndFeed.getPublishedDate());
        htmlBuilder.li().close().a().href(syndFeed.getLink()).append(" target=\"_blank\"").close().append(theDate + " - " + StringEscapeUtils.escapeHtml(syndFeed.getTitle()) + " - " + description).aEnd().liEnd();
    }
    if (rssMore != null && rssMore.length() > 0) {
        return htmlBuilder.ulEnd().a().href(rssMore).append(" target=\"_blank\"").close().div().align("right").close().append(resword.getString("more") + "...").divEnd().aEnd().toString();
    } else {
        return htmlBuilder.ulEnd().toString();
    }
}
Also used : SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl) HtmlBuilder(org.jmesa.view.html.HtmlBuilder) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

SyndEntryImpl (com.sun.syndication.feed.synd.SyndEntryImpl)17 SyndEntry (com.sun.syndication.feed.synd.SyndEntry)12 SyndFeed (com.sun.syndication.feed.synd.SyndFeed)10 ArrayList (java.util.ArrayList)10 SyndFeedImpl (com.sun.syndication.feed.synd.SyndFeedImpl)9 SyndContentImpl (com.sun.syndication.feed.synd.SyndContentImpl)8 SyndContent (com.sun.syndication.feed.synd.SyndContent)7 FeedException (com.sun.syndication.io.FeedException)4 Date (java.util.Date)4 SyndFeedOutput (com.sun.syndication.io.SyndFeedOutput)3 IOException (java.io.IOException)3 SQLException (java.sql.SQLException)3 FeedEntryModel (com.gitblit.models.FeedEntryModel)2 SyndCategory (com.sun.syndication.feed.synd.SyndCategory)2 OutputStreamWriter (java.io.OutputStreamWriter)2 OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)2 Filter (org.opennms.web.filter.Filter)2 Post (com.erudika.scoold.core.Post)1 Question (com.erudika.scoold.core.Question)1 GitBlitException (com.gitblit.GitBlitException)1