用ROME创建RSS服务

1.RSS标准

RSS标准比较混乱,主要有以下3个系列

  •  RSS 0.9x / 2.0 : RSS技术诞生于1999年的网景公司(Netscape),其发布了一个0.9版本的规范。2001年,RSS技术标准的发展工作被Userland Software公司的戴夫 温那(Dave Winer)所接手。陆续发布了0.9x的系列版本。当W3C小组发布RSS 1.0后,Dave Winer不承认其有效性。并于2002年9月独自把RSS升级到了2.0版本(Really Simple Syndication),并交由哈佛大学Technology at Harvard Law进行维护。
  • RSS 1.0 : 在RSS发展过程中,为使RSS成为一个通用的规范,并进一步标准化。一个联合小组根据W3C新一代的Resource Description Framework  (RDF) 对RSS进行了重新定义,发布了RSS 1.0版,并把RSS定义为“RDF Site Summary”。现在RSS 1.0版由W3C联合小组维护。
  • Atom : Atom是一个项目的名字,主要是开发一个新的博客摘要格式以解决目前RSS存在的问题(混乱的版本号,不是一个真正的开放标准,表示方法的不一致,定义贫乏等等)。

 2.如何实现RSS

RSS标准虽然混乱,但是其本质都是XML文档。你可以只使用notepad, 按照某个RSS标准, 手写一个xml, 并提供给客户端。

现在也有许多开源项目来提供RSS的解决方案。

Rome https://rome.dev.java.net/

RSSLibJ http://enigmastation.com/rsslibj/

RSSLib4J http://devzone.stealthp.org/cms/index.php?page=RSSLib4J

使用这些解决方案可以更方便的处理RSS.

3.用 Rome 实现 RSS 服务

目前Rome最新版本为rome-0.9. 本例是在Struts的Action中实现的RSS服务.

新建一个RssAction

java 代码
  1. import other classes...   
  2. import com.sun.syndication.feed.synd.SyndFeed;   
  3. import com.sun.syndication.io.SyndFeedOutput;   
  4.   
  5. public class RssAction extends DispatchAction {   
  6.   
  7.     private static final String MIME_TYPE = "application/xml; charset=UTF-8";   
  8.        
  9.     // Rome中RSS的可选标准   
  10.     // rss_0.90, rss_0.91, rss_0.92, rss_0.93, rss_0.94, rss_1.0, rss_2.0, atom_0.3    
  11.     private static final String RSS_TYPE = "rss_2.0";   
  12.   
  13.     public ActionForward newsFeed(ActionMapping mapping,   
  14.             ActionForm form, HttpServletRequest request,   
  15.             HttpServletResponse response) throws Exception {   
  16.         NewsFeedBA newsFeedBA = new NewsFeedBA();   
  17.         newsFeedBA.doExecute();   
  18.         outputRssFeed(response, newsFeedBA.getFeed());   
  19.         return null;   
  20.     }   
  21.   
  22.     public ActionForward blogFeed(ActionMapping mapping,   
  23.             ActionForm form, HttpServletRequest request,   
  24.             HttpServletResponse response) throws Exception {   
  25.         String uid = request.getParameter("userId");   
  26.         BlogFeedBA blogFeedBA = new BlogFeedBA();   
  27.         blogFeedBA.setUserId(uid);   
  28.         blogFeedBA.doExecute();   
  29.         outputRssFeed(response, blogFeedBA.getFeed());   
  30.         return null;   
  31.     }   
  32.        
  33.     //将SyndFeed写入HttpServletResponse   
  34.     private boolean outputRssFeed(HttpServletResponse response, SyndFeed feed) {   
  35.         boolean result = false;   
  36.         feed.setFeedType(RSS_TYPE);   
  37.         response.setContentType(MIME_TYPE);   
  38.         SyndFeedOutput output = new SyndFeedOutput();   
  39.         try {   
  40.             output.output(feed, response.getWriter());   
  41.             result = true;   
  42.         } catch (IOException e) {   
  43.             e.printStackTrace();   
  44.         } catch (FeedException e) {   
  45.             e.printStackTrace();   
  46.         }   
  47.         return result;   
  48.     }   
  49. }  

然后在业务逻辑中,查询数据库,用返回的数据组织相应的Feed.

java 代码
  1. public SyndFeed createFeed(List<newsdto></newsdto> news) {   
  2.     SyndFeed feed = new SyndFeedImpl();   
  3.   
  4.     feed.setTitle("My RSS Service : news ");   
  5.     feed.setLink("http://www.myHomePage.com");   
  6.     feed.setDescription("My first RSS service .");   
  7.        
  8.     feed.setEntries(getEntries(news));   
  9.     return feed;   
  10. }   
  11.   
  12. private List<syndentry></syndentry> getEntries(List<newsdto></newsdto> news) {   
  13.     List<syndentry></syndentry> entries = new ArrayList<syndentry></syndentry>();   
  14.        SyndEntry entry;   
  15.        SyndContent description;   
  16.           
  17.        for (NewsDTO dto : news) {   
  18.            entry = new SyndEntryImpl();   
  19.            entry.setTitle(dto.getTitle());   
  20.            entry.setLink(dto.getLink());   
  21.            entry.setPublishedDate(new Date());   
  22.           
  23.            description = new SyndContentImpl();   
  24.            description.setType("text/html");   
  25.            description.setValue(dto.getContent());   
  26.               
  27.            entry.setDescription(description);   
  28.            entries.add(entry);   
  29.        }   
  30.        return entries;   
  31. }  

 在struts-config.xml中配置RssAction

xml 代码
  1. <action path="/rss" type="com.web.action.RssAction"  
  2.     parameter="method"  
  3.     scope="request">  
  4. action>  

 启动Tomcat,并访问/rss.do?method=newsFeed  就可以得到新闻的RSS

访问/rss.do?method=blogFeed&userId=123 就可以得到123的blog的RSS了。

现在IE7和Opera都集成了RSS功能。

java使用Rome解析Rss的实例 立即下载

相关推荐

rome 实现rss订阅,中文出错解决方法

在做的过程中遇到中文字符出错的问题,网上也有很多人提出来,但是好能解决的不多,如果你也遇到这个问题,请详细看本文档!

rome实现rss订阅与发布

1. 什么是RSS RSS也叫聚合RSS,是在线共享内容的一种简易方式(也叫聚合内容, 简易供稿,Really Simple Syndication(真正简单的聚合 ))。通常在时效性比较强的内容上使用RSS订阅能更快速获取信息,网站提供RSS输出,有利于让用户获取网站内容的最新更新. RSSXML的一种。所有的RSS文档都遵循XML 1.0规范,该规范发布在W3C网站上。拿一个新闻网站来说,...

iteye_10403的博客 249

Rome使用简单说明二(部分关键源码分析)

rome io包下的类之间的关系 博文链接:https://ttitfly.iteye.com/blog/49193

ROME: 强大的Java RSS与Atom Feed处理库

ROME: 强大的Java RSS与Atom Feed处理库 rome Java library for RSS and Atom feeds 项目地址: https://gitcode.com/gh_mirrors/rom/ro...

gitblog_00003的博客 477

推荐开源项目:ROME —— Java的RSS和Atom框架

在互联网信息爆炸的时代,RSS和Atom作为一种高效的信息订阅方式,仍然扮演着重要的角色。如果你正在寻找一个强大的Java库来处理这些 feeds,那么【ROME】绝对值得你的关注。 ## 项目介绍 [ROME](https://travis-ci.org/rometools/rome) 是一个功能完备的Java框架,专为RSS(Really Simple Syndication)和Atom ...

gitblog_00054的博客 619

Spring Boot 接口使用rome实现RSS 订阅

Spring Boot 入门 接口使用rome实现RSS 订阅首次接口实现RSS订阅RSS是什么环境参考博客版本问题遇到的坑正文实现结果 首次接口实现RSS订阅 公司数据对接国内某知名股票机构,需要提供接口按Rss方式返回结果,开始首次尝试实现。 RSS是什么 Really Simple Syndication 简易信息聚合(也叫聚合内容)是一种基于XML的标准。简单来说就是网站提供按Rss方式返回结果的接口,方便RSS订阅器订阅;将一些自己关注的信息整合在一起【个人理解】 环境 SpringBoot 2.

Abner_G的博客 2172

rome_RSS阅读器使用:ROME,Spring MVC,嵌入式Jetty

rome 在这篇文章中,我将展示一些创建Spring Web应用程序的准则,这些应用程序使用Jetty并使用名为ROME的外部库运行RSS来运行它。 一般 我最近创建了一个示例Web应用程序,充当RSS阅读器。 我想检查ROME以阅读RSS。 我还想使用Spring容器和MVC创建最简单的视图的应用程序。 为了快速开发,我将Jetty用作服务器,并为其使用了一个简单的Java类。所有代码都可以在...

cunfen8879的博客 328

Rss,Atom聚合规范的XML文件解析(Rome,rssutils)

NULL 博文链接:https://mengqingyu.iteye.com/blog/389271

rome-1.0RC2rss解析

rome-1.0RC2 source,jar and doc

rome rss_RSS阅读器使用:ROME,Spring MVC,嵌入式Jetty

rome rss 在这篇文章中,我将展示一些创建Spring Web应用程序的指南,这些应用程序使用Jetty并使用名为ROME的外部库运行RSS来运行它。 一般 我最近创建了一个示例Web应用程序,充当RSS阅读器。 我想检查ROME以阅读RSS。 我还想使用Spring容器和MVC创建最简单的视图的应用程序。 为了快速开发,我将Jetty用作服务器,并为其使用了一个简单的java类。 ...

最佳 Java 编程 179

RSS阅读器使用:ROME,Spring MVC,嵌入式Jetty

在这篇文章中,我将展示一些创建Spring Web应用程序的准则,使用Jetty以及使用名为ROME的外部库运行RSS来运行它。 一般 我最近创建了一个示例Web应用程序,充当RSS阅读器。 我想检查ROME以阅读RSS。 我还想使用Spring容器和MVC创建最简单的视图的应用程序。 为了快速开发,我将Jetty用作服务器,并为其使用了一个简单的java类。 所有代码都可以在GitH...

最佳 Java 编程 328

rome制作rss服务

rome制作rss服务 2011年04月01日    最近用rome做了一个rss服务,大致的内容如下,有不妥的地方,请指正:   //RssChannelDO类   public class RssChannelDO {   private String title;   private String description;   private Stri...

dqu53dqu 186

Manage RSS feeds with the Rome API

RSS is a widely used means of publishing syndicated content, from bloglines to build reports. The large number of ...

congjiu2124的博客 430

Spring boot 入门 使用rome实现RSS 订阅

引言     在本教程中,学习从spring boot应用程序创建和使用RSS和Atom提要。 您必须在各种网站上(例如我们的RSS提要)以文本或图像按钮的形式看到这一点,邀请您“通过RSS订阅”。RSS是简单的联合API - 通常称为Rich Site Summary。 RSS革新了用户与在线内容交互的方式。     与RSS类似,Atom也是基于XML的Web内容和元数据联合格式,以及用于发...

菜鸟的博客 3559
上一篇: LF and CR
下一篇: Ant配合Log4j不能输出log文件
iteye_12528
博客等级 码龄8年 4粉丝 62原创
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值