Java Code Examples for com.sun.syndication.feed.rss.Item#setContent()

The following examples show how to use com.sun.syndication.feed.rss.Item#setContent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SensUtils.java    From SENS with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 生成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 == SensConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp())) {
        channel.setTitle("");
    } else {
        channel.setTitle(SensConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp()));
    }
    if (null == SensConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp())) {
        channel.setLink("");
    } else {
        channel.setLink(SensConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
    }
    if (null == SensConst.OPTIONS.get(BlogPropertiesEnum.SEO_DESC.getProp())) {
        channel.setDescription("");
    } else {
        channel.setDescription(SensConst.OPTIONS.get(BlogPropertiesEnum.SEO_DESC.getProp()));
    }
    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(SensConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/article/" + post.getId());
        item.setPubDate(post.getCreateTime());
        items.add(item);
    }
    channel.setItems(items);
    WireFeedOutput out = new WireFeedOutput();
    return out.outputString(channel);
}
 
Example 2
Source File: HaloUtils.java    From stone with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 生成rss
 *
 * @param posts posts
 *
 * @return String
 *
 * @throws FeedException FeedException
 */
public static String getRss(List<Post> posts) throws FeedException {
    Assert.notEmpty(posts, "posts must not be empty");

    final Channel channel = new Channel("rss_2.0");
    if (null == HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp())) {
        channel.setTitle("");
    } else {
        channel.setTitle(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp()));
    }
    if (null == HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp())) {
        channel.setLink("");
    } else {
        channel.setLink(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
    }
    if (null == HaloConst.OPTIONS.get(BlogPropertiesEnum.SEO_DESC.getProp())) {
        channel.setDescription("");
    } else {
        channel.setDescription(HaloConst.OPTIONS.get(BlogPropertiesEnum.SEO_DESC.getProp()));
    }
    channel.setLanguage("zh-CN");
    final List<Item> items = new ArrayList<>();
    for (Post post : posts) {
        final Item item = new Item();
        item.setTitle(post.getPostTitle());
        final Content content = new Content();
        String value = post.getPostContent();
        final 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(BlogPropertiesEnum.BLOG_URL.getProp()) + "/archives/" + post.getPostUrl());
        item.setPubDate(post.getPostDate());
        items.add(item);
    }
    channel.setItems(items);
    final WireFeedOutput out = new WireFeedOutput();
    return out.outputString(channel);
}
 
Example 3
Source File: HaloUtils.java    From blog-sharon with Apache License 2.0 4 votes vote down vote up
/**
 * 生成rss
 *
 * @param posts posts
 * @return String
 * @throws FeedException FeedException
 */
public static String getRss(List<Post> posts) throws FeedException {
    Assert.notEmpty(posts, "posts must not be empty");

    Channel channel = new Channel("rss_2.0");
    if (null == HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp())) {
        channel.setTitle("");
    } else {
        channel.setTitle(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp()));
    }
    if (null == HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp())) {
        channel.setLink("");
    } else {
        channel.setLink(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
    }
    if (null == HaloConst.OPTIONS.get(BlogPropertiesEnum.SEO_DESC.getProp())) {
        channel.setDescription("");
    } else {
        channel.setDescription(HaloConst.OPTIONS.get(BlogPropertiesEnum.SEO_DESC.getProp()));
    }
    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(BlogPropertiesEnum.BLOG_URL.getProp()) + "/archives/" + post.getPostUrl());
        item.setPubDate(post.getPostDate());
        items.add(item);
    }
    channel.setItems(items);
    WireFeedOutput out = new WireFeedOutput();
    return out.outputString(channel);
}