📄
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0035)http://www.javaeye.com/topic/214644 -->
<HTML dir=ltr xml:lang="zh-CN"
xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>自动生成Rss - 企业应用 - Java - JavaEye论坛</TITLE>
<META http-equiv=Content-Type content="text/html; charset=UTF-8">
<META
content="前几天写了个解析Rss文件的一个例子,这几天写了个基于Rome生成Rss文件的工具类,发布上来共享下。希望对大家有所帮助。 工具类里用的Jar包为Rome.jar,JDom.jar,感兴趣的朋友可以自己下载,也可以从我的上篇文件里下载到。 存在两个POJO类:ChannelItem类和ChannelEItem类,ChanneEItem类继承自ChannelItem类,多一个Enclos ..."
name=description>
<META content="rome,rss生成 企业应用 Java" name=keywords><LINK
href="/images/favicon.ico" type=image/x-icon rel="shortcut icon"><LINK
title=JavaEye论坛 href="/rss/board/Java" type=application/rss+xml
rel=alternate><LINK media=screen
href="自动生成Rss - 企业应用 - Java - JavaEye论坛.files/forum.css" type=text/css
rel=stylesheet>
<SCRIPT src="自动生成Rss - 企业应用 - Java - JavaEye论坛.files/application.js"
type=text/javascript></SCRIPT>
<LINK media=screen
href="自动生成Rss - 企业应用 - Java - JavaEye论坛.files/SyntaxHighlighter.css"
type=text/css rel=stylesheet>
<SCRIPT src="自动生成Rss - 企业应用 - Java - JavaEye论坛.files/shCoreCommon.js"
type=text/javascript></SCRIPT>
<SCRIPT src="自动生成Rss - 企业应用 - Java - JavaEye论坛.files/hotkey.js"
type=text/javascript></SCRIPT>
<SCRIPT src="自动生成Rss - 企业应用 - Java - JavaEye论坛.files/dragdrop.js"
type=text/javascript></SCRIPT>
<META content="MSHTML 6.00.2900.3395" name=GENERATOR></HEAD>
<BODY>
<DIV id=page>
<DIV class=clearfix id=header>
<UL id=user_nav>
<LI class=last><A href="http://www.javaeye.com/index/help">帮助</A> </LI>
<LI><A href="http://www.javaeye.com/logout">退出</A> </LI>
<LI><A href="http://jsczxy2.javaeye.com/admin/profile">设置</A> </LI>
<LI><A href="http://jsczxy2.javaeye.com/admin/mygroups">我的圈子</A> </LI>
<LI><A href="http://jsczxy2.javaeye.com/admin">我的博客</A> </LI>
<LI><A href="http://jsczxy2.javaeye.com/admin/messages">收件箱 (0)</A> </LI>
<LI class=highlight><SPAN>欢迎 jsczxy2 !</SPAN> </LI></UL>
<DIV id=branding><A href="http://www.javaeye.com/"><IMG
title=JavaEye-最棒的软件开发交流社区 alt=JavaEye3.0
src="自动生成Rss - 企业应用 - Java - JavaEye论坛.files/logo.gif"></A> </DIV>
<DIV id=ad>
</DIV></DIV>
<DIV class=clearfix id=content>
<DIV id=main>
<DIV class=clearfix>
<DIV class=crumbs><A href="http://www.javaeye.com/forums">论坛首页</A> <SPAN
class=arrow>→</SPAN> <A
href="http://www.javaeye.com/forums/board/Java">Java版</A> <SPAN
class=arrow>→</SPAN> <A href="http://www.javaeye.com/forums/tag/J2EE">企业应用</A>
<SPAN class=arrow>→</SPAN>
<H1>自动生成Rss</H1></DIV></DIV>
<DIV id=forum_tag_list><A href="http://www.javaeye.com/forums/board/Java">全部</A>
<A href="http://www.javaeye.com/forums/tag/Hibernate">Hibernate</A> <A
href="http://www.javaeye.com/forums/tag/Spring">Spring</A> <A
href="http://www.javaeye.com/forums/tag/Struts">Struts</A> <A
href="http://www.javaeye.com/forums/tag/Webwork">Webwork</A> <A
href="http://www.javaeye.com/forums/tag/iBATIS">iBATIS</A> <A
href="http://www.javaeye.com/forums/tag/J2EE">企业应用</A> <A
href="http://www.javaeye.com/forums/tag/Design-Pattern">设计模式</A> <A
href="http://www.javaeye.com/forums/tag/DAO">DAO</A> <A
href="http://www.javaeye.com/forums/tag/Object-Domain">领域模型</A> <A
href="http://www.javaeye.com/forums/tag/OO">OO</A> <A
href="http://www.javaeye.com/forums/tag/Tomcat">Tomcat</A> <A
href="http://www.javaeye.com/forums/tag/SOA">SOA</A> <A
href="http://www.javaeye.com/forums/tag/JBoss">JBoss</A> <A
href="http://www.javaeye.com/forums/tag/J2ME">J2ME</A> </DIV>
<DIV class=actions>
<DIV class=buttons><A class=new_post title=发表回复
href="http://www.javaeye.com/forums/39/topics/214644/posts/new"></A></DIV>
<DIV class=wrapper>
<DIV id=forum_advert_b0></DIV>
<DIV class=info>浏览 323 次</DIV></DIV></DIV>
<TABLE id=forum_main cellSpacing=1>
<THEAD>
<TR>
<TH class=topic_title colSpan=2>
<DIV class=wrapper><A
href="http://www.javaeye.com/topic/214644">主题:自动生成Rss</A></DIV>
<DIV id=topic_rate_box>精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖
(0)</DIV></TH></TR>
<TR>
<TD class=first_col>作者</TD>
<TD class=last_col>正文</TD></TR></THEAD>
<TBODY id=posts>
<TR id=p_600267>
<TD class=postauthor>
<UL>
<LI class=name>jackzhangyunjie
<LI>等级: <IMG title=一星会员 alt=一星会员
src="自动生成Rss - 企业应用 - Java - JavaEye论坛.files/star1.gif">
<LI><A href="http://jackzhangyunjie.javaeye.com/" target=_blank><IMG
title="jackzhangyunjie的博客: 阿杰的Blog" alt=用户头像
src="自动生成Rss - 企业应用 - Java - JavaEye论坛.files/user-logo.gif"></A>
<LI>性别: <IMG title=男
src="自动生成Rss - 企业应用 - Java - JavaEye论坛.files/icon_minigender_1.gif">
<LI>文章: 38
<LI>积分: 100
<LI>来自: 郑州
<LI><IMG src="自动生成Rss - 企业应用 - Java - JavaEye论坛.files/offline.gif">
</LI></UL></TD>
<TD class=postcontent>
<DIV class=postactions>
<DIV class=description>时间:2008-07-14 关键字:
<STRONG>rome,rss生成</STRONG></DIV>
<DIV class=links><A
href="http://www.javaeye.com/forums/39/topics/214644/posts/600267/quote">引用</A>
<A
href="http://jsczxy2.javaeye.com/admin/user_favorites?user_favorite%5Btitle%5D=%E8%87%AA%E5%8A%A8%E7%94%9F%E6%88%90Rss&user_favorite%5Burl%5D=http%3A%2F%2Fwww.javaeye.com%2Ftopic%2F214644"
target=_blank>收藏</A> </DIV></DIV>
<DIV class="postbody clearfix">
<DIV id=related_topics>相关文章: <SPAN class=close><A title=关闭
onclick="$('related_topics').hide();return false;"
href="http://www.javaeye.com/topic/214644#"> </A></SPAN>
<UL>
<LI><A href="http://www.javaeye.com/topic/20717"
target=_blank>使用WebWork和Rome轻松暴露RSS</A>
<LI><A href="http://www.javaeye.com/topic/117505"
target=_blank>ROME解析RSS(代码)</A> </LI></UL><BR><SPAN>推荐圈子: <A
href="http://tapestrying.group.javaeye.com/"
target=_blank>Tapestry</A></SPAN> <BR><A
href="http://www.javaeye.com/wiki/topic/214644" target=_blank>更多相关推荐</A>
</DIV>
<SCRIPT type=text/javascript> new Draggable("related_topics"); </SCRIPT>
前几天写了个解析Rss文件的一个例子,这几天写了个基于Rome生成Rss文件的工具类,发布上来共享下。希望对大家有所帮助。
<BR><BR> 工具类里用的Jar包为Rome.jar,JDom.jar,感兴趣的朋友可以自己下载,也可以从我的上篇文件里下载到。
<BR><BR> 存在两个POJO类:ChannelItem类和ChannelEItem类,ChanneEItem类继承自ChannelItem类,多一个Enclosure属性,用于存在流媒体文件的类里使用。
<BR><BR> 具体代码如下,ChannelItem类: <BR><BR><PRE class=java name="code">import java.util.Date;
/**
* 频道下的子信息
* 此类无流媒体播放文件
* @author jackZhang
*
*/
public class ChannelItem{
private String title;//Rss文件中Item的标题
private String link;//Rss文件中Item对应的连接
private String description;//Item的描述
private Date pubDate;//Item发布的时间
private String author;//Item作者
private String category;//Item所属的频道范畴
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Date getPubDate() {
return pubDate;
}
public void setPubDate(Date pubDate) {
this.pubDate = pubDate;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
}
</PRE><BR><BR>ChannelEItem类,具体代码: <BR><BR><PRE class=java name="code">/**
* 用于添加频道的子项
* 当存在流媒体播放文件时使用此类
*
* @author jackZhang
*
*/
public class ChannelEItem extends ChannelItem{
private String enclosure;//流媒体文件
public String getEnclosure() {
return enclosure;
}
public void setEnclosure(String enclosure) {
this.enclosure = enclosure;
}
}
</PRE><BR><BR>以下是具体的Rss生成器封装类RssBuildFactory,具体代码: <BR><PRE class=java name="code">import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.sun.syndication.feed.synd.SyndCategory;
import com.sun.syndication.feed.synd.SyndCategoryImpl;
import com.sun.syndication.feed.synd.SyndContent;
import com.sun.syndication.feed.synd.SyndContentImpl;
import com.sun.syndication.feed.synd.SyndEnclosure;
import com.sun.syndication.feed.synd.SyndEnclosureImpl;
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndEntryImpl;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.feed.synd.SyndFeedImpl;
import com.sun.syndication.io.SyndFeedOutput;
import com.yx.xml.bo.ChannelEItem;
import com.yx.xml.bo.ChannelItem;
/**
* 用于生成Rss文件
* @author jackZhang
*
*/
public class RssBuildFactory {
private SyndFeed feed;
@SuppressWarnings("unchecked")
private List entries;
private SyndEntry entry ;
@SuppressWarnings("unchecked")
public RssBuildFactory(){
feed = new SyndFeedImpl();
feed.setFeedType("rss_2.0");
entries = new ArrayList();
}
/**
* 创建一个频道
* @param title 频道标题
* @param link 频道对应的连接
* @param description 频道描述
* @param language 频道所用语言
* @param pubDate 频道发布时期
* @param copyright 版权所有
* @throws Exception
*/
public void buildChannel(String title,String link,String description,String language,Date pubDate,String copyright) throws RuntimeException {
feed.setTitle(title);
feed.setLink(link);
feed.setDescription(description);
feed.setLanguage(language);
feed.setPublishedDate(pubDate);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -