Search in sources :

Example 1 with Content

use of com.sun.syndication.feed.rss.Content in project Gemma by PavlidisLab.

the class CustomRssViewer method buildFeedItems.

@Override
protected List<Item> buildFeedItems(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) {
    @SuppressWarnings("unchecked") Map<ExpressionExperiment, String> experiments = (Map<ExpressionExperiment, String>) model.get("feedContent");
    List<Item> items = new ArrayList<>(experiments.size());
    // Set content of each expression experiment
    for (Map.Entry<ExpressionExperiment, String> entry : experiments.entrySet()) {
        ExpressionExperiment e = entry.getKey();
        String title = e.getShortName() + " (" + entry.getValue() + "): " + e.getName();
        String link = Settings.getBaseUrl() + "expressionExperiment/showExpressionExperiment.html?id=" + e.getId().toString();
        int maxLength = 500;
        if (e.getDescription().length() < 500) {
            maxLength = e.getDescription().length();
        }
        Item item = new Item();
        Content content = new Content();
        content.setValue(e.getDescription().substring(0, maxLength) + " ...");
        item.setContent(content);
        item.setTitle(title);
        item.setLink(link);
        if (e.getCurationDetails() != null) {
            item.setPubDate(e.getCurationDetails().getLastUpdated());
        }
        items.add(item);
    }
    return items;
}
Also used : Item(com.sun.syndication.feed.rss.Item) Content(com.sun.syndication.feed.rss.Content) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment)

Example 2 with Content

use of com.sun.syndication.feed.rss.Content in project tale by otale.

the class TaleUtils method getRssXml.

/**
     * 获取RSS输出
     *
     * @param articles
     * @return
     * @throws FeedException
     */
public static String getRssXml(java.util.List<Contents> articles) throws FeedException {
    Channel channel = new Channel("rss_2.0");
    channel.setTitle(TaleConst.OPTIONS.get("site_title"));
    channel.setLink(Commons.site_url());
    channel.setDescription(TaleConst.OPTIONS.get("site_description"));
    channel.setLanguage("zh-CN");
    java.util.List<Item> items = new ArrayList<>();
    articles.forEach(post -> {
        Item item = new Item();
        item.setTitle(post.getTitle());
        Content content = new Content();
        content.setValue(Theme.article(post.getContent()));
        item.setContent(content);
        item.setLink(Theme.permalink(post.getCid(), post.getSlug()));
        item.setPubDate(DateKit.getDateByUnixTime(post.getCreated()));
        items.add(item);
    });
    channel.setItems(items);
    WireFeedOutput out = new WireFeedOutput();
    return out.outputString(channel);
}
Also used : Item(com.sun.syndication.feed.rss.Item) java.util(java.util) Content(com.sun.syndication.feed.rss.Content) Channel(com.sun.syndication.feed.rss.Channel) WireFeedOutput(com.sun.syndication.io.WireFeedOutput)

Example 3 with Content

use of com.sun.syndication.feed.rss.Content in project halo by ruibaby.

the class HaloUtil method getRss.

/**
 * 生成rss
 * @param posts posts
 * @return string
 * @throws FeedException
 */
public static String getRss(List<Post> posts) throws FeedException {
    Channel channel = new Channel("rss_2.0");
    if (null == HaloConst.OPTIONS.get("site_title")) {
        channel.setTitle("");
    } else {
        channel.setTitle(HaloConst.OPTIONS.get("site_title"));
    }
    if (null == HaloConst.OPTIONS.get("site_url")) {
        channel.setLink("");
    } else {
        channel.setLink(HaloConst.OPTIONS.get("site_url"));
    }
    if (null == HaloConst.OPTIONS.get("seo_desc")) {
        channel.setDescription("");
    } else {
        channel.setDescription(HaloConst.OPTIONS.get("seo_desc"));
    }
    channel.setLanguage("zh-CN");
    List<Item> items = new ArrayList<>();
    for (Post post : posts) {
        Item item = new Item();
        item.setTitle(post.getPostTitle());
        Content content = new Content();
        String value = post.getPostContent();
        char[] xmlChar = value.toCharArray();
        for (int i = 0; i < xmlChar.length; ++i) {
            if (xmlChar[i] > 0xFFFD) {
                xmlChar[i] = ' ';
            } else if (xmlChar[i] < 0x20 && xmlChar[i] != 't' & xmlChar[i] != 'n' & xmlChar[i] != 'r') {
                xmlChar[i] = ' ';
            }
        }
        value = new String(xmlChar);
        content.setValue(value);
        item.setContent(content);
        item.setLink(HaloConst.OPTIONS.get("site_url") + "/article/" + post.getPostUrl());
        item.setPubDate(post.getPostDate());
        items.add(item);
    }
    channel.setItems(items);
    WireFeedOutput out = new WireFeedOutput();
    return out.outputString(channel);
}
Also used : Item(com.sun.syndication.feed.rss.Item) Post(cc.ryanc.halo.model.domain.Post) Content(com.sun.syndication.feed.rss.Content) Channel(com.sun.syndication.feed.rss.Channel) WireFeedOutput(com.sun.syndication.io.WireFeedOutput)

Aggregations

Content (com.sun.syndication.feed.rss.Content)3 Item (com.sun.syndication.feed.rss.Item)3 Channel (com.sun.syndication.feed.rss.Channel)2 WireFeedOutput (com.sun.syndication.io.WireFeedOutput)2 Post (cc.ryanc.halo.model.domain.Post)1 java.util (java.util)1 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)1