Rome介绍 java的RSS阅读,发布器
2008-07-28 13:24
211 查看
Rome是为RSS聚合而开发的一个框架,让你可以快速的开发基于java的RSS阅读,发布器,支持
RSS 0.91 Netscape
RSS 0.91 Userland
RSS 0.92
RSS 0.93
RSS 0.94
RSS 1.0
RSS 2.0
Atom 0.3
Atom 1.0
等标准。你也可以自己扩展他的Module,让他解析你自己定义的XML格式。可以说它是一种用途很广的框架,在使用它之前。你必须下载JDOM开发包,因为它是用JDOM解析XML的。
在Rome中主要包裹下面几个包
com.sun.syndication.feed
com.sun.syndication.feed.atom
与获得atom中各个节点的数据
com.sun.syndication.feed.module
modeule为各个数据模型层。可以自己扩展
com.sun.syndication.feed.rss
用与获得RSS中各个相对应的XML节点中的值
com.sun.syndication.feed.sse
com.sun.syndication.feed.synd
此包为写成RSS格式的XML设置个节点的属性
com.sun.syndication.io
此包为输入输出流。
它的UML图
图1
下面是一个例子,功能是生成RSS格式的XML
public class FeedWriter {
private static final String DATE_FORMAT = "yyyy-MM-dd";
public static void main(String[] args) {
boolean ok = false;
if (args.length==2) {
try {
String feedType = args[0];
String fileName = args[1];
DateFormat dateParser = new SimpleDateFormat(DATE_FORMAT);
SyndFeed feed = new SyndFeedImpl(); //feed流
feed.setFeedType(feedType); //设置rss版本
feed.setTitle("Sample Feed (created with Rome)"); //<title>设置标题
feed.setLink(http://www.csdn.net); //<link>
feed.setDescription("This feed has been created using Rome (Java syndication utilities");
List entries = new ArrayList();
SyndEntry entry;
SyndContent description;
entry = new SyndEntryImpl(); //子节点
entry.setTitle("Rome v1.0");
entry.setLink(http://www.csdn.net);
entry.setPublishedDate(dateParser.parse("2004-06-08"));
description = new SyndContentImpl();
description.setType("text/plain");
description.setValue("Initial release of Rome");
entry.setDescription(description);
entries.add(entry);
entry = new SyndEntryImpl();
entry.setTitle("Rome v2.0");
entry.setLink(http://ww.csdn.net);
entry.setPublishedDate(dateParser.parse("2004-06-16"));
description = new SyndContentImpl(); //描述
description.setType("text/xml");
description.setValue("Bug fixes, <xml>XML</xml> minor API changes and some new features");
entry.setDescription(description);
entries.add(entry);
entry = new SyndEntryImpl();
entry.setTitle("Rome v3.0");
entry.setLink("http://www.csdn.net");
entry.setPublishedDate(dateParser.parse("2004-07-27"));
description = new SyndContentImpl();
description.setType("text/html");
description.setValue("<p>More Bug fixes, mor API changes, some new features and some Unit testing</p>"+
"<p>For details check the <a href=/"http://www.csdn.net/">Changes Log</a></p>");
entry.setDescription(description);
entries.add(entry);
feed.setEntries(entries); //设置子节点
Writer writer = new FileWriter(fileName);
SyndFeedOutput output = new SyndFeedOutput();
output.output(feed,writer); //写到文件中去
writer.close();
System.out.println("The feed has been written to the file ["+fileName+"]");
ok = true;
}
catch (Exception ex) {
ex.printStackTrace();
System.out.println("ERROR: "+ex.getMessage());
}
}
if (!ok) {
System.out.println();
System.out.println("FeedWriter creates a RSS/Atom feed and writes it to a file.");
System.out.println("The first parameter must be the syndication format for the feed");
System.out.println(" (rss_0.90, rss_0.91, rss_0.92, rss_0.93, rss_0.94, rss_1.0 rss_2.0 or atom_0.3)");
System.out.println("The second parameter must be the file name for the feed");
System.out.println();
}
}
}
RSS 0.91 Netscape
RSS 0.91 Userland
RSS 0.92
RSS 0.93
RSS 0.94
RSS 1.0
RSS 2.0
Atom 0.3
Atom 1.0
等标准。你也可以自己扩展他的Module,让他解析你自己定义的XML格式。可以说它是一种用途很广的框架,在使用它之前。你必须下载JDOM开发包,因为它是用JDOM解析XML的。
在Rome中主要包裹下面几个包
com.sun.syndication.feed
com.sun.syndication.feed.atom
与获得atom中各个节点的数据
com.sun.syndication.feed.module
modeule为各个数据模型层。可以自己扩展
com.sun.syndication.feed.rss
用与获得RSS中各个相对应的XML节点中的值
com.sun.syndication.feed.sse
com.sun.syndication.feed.synd
此包为写成RSS格式的XML设置个节点的属性
com.sun.syndication.io
此包为输入输出流。
它的UML图
图1
下面是一个例子,功能是生成RSS格式的XML
public class FeedWriter {
private static final String DATE_FORMAT = "yyyy-MM-dd";
public static void main(String[] args) {
boolean ok = false;
if (args.length==2) {
try {
String feedType = args[0];
String fileName = args[1];
DateFormat dateParser = new SimpleDateFormat(DATE_FORMAT);
SyndFeed feed = new SyndFeedImpl(); //feed流
feed.setFeedType(feedType); //设置rss版本
feed.setTitle("Sample Feed (created with Rome)"); //<title>设置标题
feed.setLink(http://www.csdn.net); //<link>
feed.setDescription("This feed has been created using Rome (Java syndication utilities");
List entries = new ArrayList();
SyndEntry entry;
SyndContent description;
entry = new SyndEntryImpl(); //子节点
entry.setTitle("Rome v1.0");
entry.setLink(http://www.csdn.net);
entry.setPublishedDate(dateParser.parse("2004-06-08"));
description = new SyndContentImpl();
description.setType("text/plain");
description.setValue("Initial release of Rome");
entry.setDescription(description);
entries.add(entry);
entry = new SyndEntryImpl();
entry.setTitle("Rome v2.0");
entry.setLink(http://ww.csdn.net);
entry.setPublishedDate(dateParser.parse("2004-06-16"));
description = new SyndContentImpl(); //描述
description.setType("text/xml");
description.setValue("Bug fixes, <xml>XML</xml> minor API changes and some new features");
entry.setDescription(description);
entries.add(entry);
entry = new SyndEntryImpl();
entry.setTitle("Rome v3.0");
entry.setLink("http://www.csdn.net");
entry.setPublishedDate(dateParser.parse("2004-07-27"));
description = new SyndContentImpl();
description.setType("text/html");
description.setValue("<p>More Bug fixes, mor API changes, some new features and some Unit testing</p>"+
"<p>For details check the <a href=/"http://www.csdn.net/">Changes Log</a></p>");
entry.setDescription(description);
entries.add(entry);
feed.setEntries(entries); //设置子节点
Writer writer = new FileWriter(fileName);
SyndFeedOutput output = new SyndFeedOutput();
output.output(feed,writer); //写到文件中去
writer.close();
System.out.println("The feed has been written to the file ["+fileName+"]");
ok = true;
}
catch (Exception ex) {
ex.printStackTrace();
System.out.println("ERROR: "+ex.getMessage());
}
}
if (!ok) {
System.out.println();
System.out.println("FeedWriter creates a RSS/Atom feed and writes it to a file.");
System.out.println("The first parameter must be the syndication format for the feed");
System.out.println(" (rss_0.90, rss_0.91, rss_0.92, rss_0.93, rss_0.94, rss_1.0 rss_2.0 or atom_0.3)");
System.out.println("The second parameter must be the file name for the feed");
System.out.println();
}
}
}
相关文章推荐
- MQTT介绍(3)java模拟MQTT的发布,订阅
- JAVA中无锁的线程安全整数AtomicInteger介绍和使用
- Java语言介绍(04)开源项目(02)持久层框架(01)Hibernate
- java集合系列——Map介绍(七)
- java后端系统架构之会话篇:sso单点登录会话介绍
- Java语言介绍(04)开源项目(09)门户网站(01)Liferay
- Java智能图表类库JChartLib使用介绍
- 161128、Redis 4.0发布及其新功能介绍
- 手把手实现Java权限(1)-Shiro介绍
- Java Specification Requests介绍
- RoboVM 1.1 发布,Java 转原生平台代码
- 一篇不错的介绍Java Socket编程的文章
- Java概念介绍(02)Java小应用Applet
- [Java basic] 01 Java介绍以及搭建Java环境
- java-netty介绍-NIO非阻塞编程
- 【软剑攻城队】团队介绍发布!
- Java Stream(流)的分类, 四大基本流的介绍
- Java获得主流数据库的JDBC链接, 结合例子介绍常用JavaJDBC方法(草稿)
- 【JAVA IO 流介绍】
- Java StringBuilder类常用方法介绍