com.sun.syndication.feed.rss.Item Java Examples
The following examples show how to use
com.sun.syndication.feed.rss.Item.
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: MusicController.java From computoser with GNU Affero General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") @Override protected List<Item> buildFeedItems(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { List<Piece> pieces = (List<Piece>) model.get("pieces"); List<Item> items = new ArrayList<Item>(pieces.size()); for (Piece piece : pieces) { Item item = new Item(); item.setAuthor("Computoser"); item.setPubDate(piece.getGenerationTime().toDate()); item.setLink(baseUrl + "/track/" + piece.getId()); item.setTitle(piece.getTitle()); items.add(item); } return items; }
Example #2
Source File: TaleUtils.java From tale with MIT License | 5 votes |
/** * 获取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 #3
Source File: GeoRSSData.java From sis with Apache License 2.0 | 5 votes |
/** * Saves the GeoRSS entry to file. * * @param item * the Item object from Java ROME API containing the GeoRSS entry * @param geoRSSModule * the Java ROME API GeoRSSModule to parse geo location * @param directory * the path of the directory in which to save the file */ public void saveToFile(Item item, GeoRSSModule geoRSSModule, String directory) { if (!new File(directory).exists()) new File(directory).mkdirs(); try { BufferedWriter writer = new BufferedWriter(new FileWriter(directory + filename)); if (item.getTitle() != null) { writer.write("title;" + item.getTitle().replace('\n', ' ')); writer.newLine(); } if (item.getLink() != null) { writer.write("link;" + item.getLink().replace('\n', ' ')); writer.newLine(); } if (item.getSource() != null) { writer.write("source;" + item.getSource().getValue().replace('\n', ' ')); writer.newLine(); } if (item.getAuthor() != null) { writer.write("author;" + item.getAuthor().replace('\n', ' ')); writer.newLine(); } if (item.getDescription() != null) { writer.write("description;" + item.getDescription().getValue().replace('\n', ' ')); writer.newLine(); } writer.write("pubDate;" + item.getPubDate().toString()); writer.newLine(); writer.write("lat;" + geoRSSModule.getPosition().getLatitude()); writer.newLine(); writer.write("lon;" + geoRSSModule.getPosition().getLongitude()); writer.close(); } catch (IOException e) { e.printStackTrace(); } }
Example #4
Source File: SensUtils.java From SENS with GNU General Public License v3.0 | 4 votes |
/** * 生成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 #5
Source File: HaloUtils.java From stone with GNU General Public License v3.0 | 4 votes |
/** * 生成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 #6
Source File: MaydayUtil.java From mayday with GNU General Public License v3.0 | 4 votes |
/** * 生成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 #7
Source File: HaloUtils.java From blog-sharon with Apache License 2.0 | 4 votes |
/** * 生成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); }