com.sun.syndication.io.WireFeedOutput Java Examples

The following examples show how to use com.sun.syndication.io.WireFeedOutput. 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: TaleUtils.java    From tale with MIT License 5 votes vote down vote up
/**
 * 获取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();
        String  value   = Theme.article(post.getContent());

        char[] xmlChar = value.toCharArray();
        for (int i = 0; i < xmlChar.length; ++i) {
            if (xmlChar[i] > 0xFFFD) {
                //直接替换掉0xb
                xmlChar[i] = ' ';
            } else if (xmlChar[i] < 0x20 && xmlChar[i] != 't' & xmlChar[i] != 'n' & xmlChar[i] != 'r') {
                //直接替换掉0xb
                xmlChar[i] = ' ';
            }
        }

        value = new String(xmlChar);

        content.setValue(value);
        item.setContent(content);
        item.setLink(Theme.permalink(post.getCid(), post.getSlug()));
        item.setPubDate(DateKit.toDate(post.getCreated()));
        items.add(item);
    });
    channel.setItems(items);
    WireFeedOutput out = new WireFeedOutput();
    return out.outputString(channel);
}
 
Example #2
Source File: CreateFeed.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
public String publishFeedToString() throws Exception {
	if ( activeRSS != null )
		return new WireFeedOutput().outputString(activeRSS);
	else if ( activeATOM != null )
		return new WireFeedOutput().outputString(activeATOM);
	else
		return null;
}
 
Example #3
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 #4
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 #5
Source File: MaydayUtil.java    From mayday with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 生成rss
 * @param articles
 * @return
 */
public static String buildRss(List<ArticleCustom> articles)throws FeedException{
	 Assert.notEmpty(articles, "posts must not be empty");
	 Channel channel=new Channel();
	 channel.setFeedType("rss_2.0");
	 if(MaydayConst.OPTIONS.get("blog_name")==null) {
		 channel.setTitle("");
	 }else {
		 channel.setTitle(MaydayConst.OPTIONS.get("blog_name"));
	 }
	 if(MaydayConst.OPTIONS.get("blog_url")==null) {
		 channel.setLink("");
	 }else {
		 channel.setLink(MaydayConst.OPTIONS.get("blog_url"));
	 }
	 if(MaydayConst.OPTIONS.get("blog_url")==null) {
		 channel.setUri("");
	 }else {
		 channel.setUri(MaydayConst.OPTIONS.get("blog_url"));
	 }
	 if(MaydayConst.OPTIONS.get("seo_describe")==null) {
		 channel.setDescription("");
	 }else {
		 channel.setDescription(MaydayConst.OPTIONS.get("seo_describe"));
	 }
	channel.setLanguage("zh-CN");
	List<Item> items=new ArrayList<>();
	for (int i = 0; i < articles.size(); i++) {
		Item item=new Item();
		Description descr = new Description();
		item.setTitle(articles.get(i).getArticleTitle());
		item.setLink(MaydayConst.OPTIONS.get("blog_url")+"/post/"+articles.get(i).getArticleUrl());
		item.setPubDate(articles.get(i).getArticleNewstime());
		descr.setValue(articles.get(i).getArticleContent());
		item.setDescription(descr);
		items.add(item);
	}
	channel.setItems(items);
       WireFeedOutput out = new WireFeedOutput();
       return out.outputString(channel);
}
 
Example #6
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);
}