Search in sources :

Example 1 with SyndCategoryImpl

use of com.sun.syndication.feed.synd.SyndCategoryImpl in project xwiki-platform by xwiki.

the class SyndEntryDocumentSource method getCategories.

protected List<SyndCategory> getCategories(Document doc, Map<String, Object> params, XWikiContext context) throws XWikiException {
    String mapping = (String) params.get(FIELD_CATEGORIES);
    if (mapping == null) {
        return getDefaultCategories(doc, params, context);
    }
    List<Object> categories;
    if (isVelocityCode(mapping)) {
        categories = parseList(mapping, doc, context);
    } else {
        categories = getListValue(mapping, doc, context);
    }
    List<SyndCategory> result = new ArrayList<SyndCategory>();
    for (Object category : categories) {
        if (category instanceof SyndCategory) {
            result.add((SyndCategory) category);
        } else if (category != null) {
            SyndCategory scat = new SyndCategoryImpl();
            scat.setName(category.toString());
            result.add(scat);
        }
    }
    return result;
}
Also used : SyndCategory(com.sun.syndication.feed.synd.SyndCategory) SyndCategoryImpl(com.sun.syndication.feed.synd.SyndCategoryImpl) ArrayList(java.util.ArrayList)

Example 2 with SyndCategoryImpl

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

Aggregations

SyndCategory (com.sun.syndication.feed.synd.SyndCategory)2 SyndCategoryImpl (com.sun.syndication.feed.synd.SyndCategoryImpl)2 ArrayList (java.util.ArrayList)2 FeedEntryModel (com.gitblit.models.FeedEntryModel)1 SyndContent (com.sun.syndication.feed.synd.SyndContent)1 SyndContentImpl (com.sun.syndication.feed.synd.SyndContentImpl)1 SyndEntry (com.sun.syndication.feed.synd.SyndEntry)1 SyndEntryImpl (com.sun.syndication.feed.synd.SyndEntryImpl)1 SyndFeed (com.sun.syndication.feed.synd.SyndFeed)1 SyndFeedImpl (com.sun.syndication.feed.synd.SyndFeedImpl)1 SyndImageImpl (com.sun.syndication.feed.synd.SyndImageImpl)1 SyndFeedOutput (com.sun.syndication.io.SyndFeedOutput)1 OutputStreamWriter (java.io.OutputStreamWriter)1