rome制作rss服务

rome制作rss服务
2011年04月01日
   最近用rome做了一个rss服务,大致的内容如下,有不妥的地方,请指正:
  //RssChannelDO类
  public class RssChannelDO {
  private String title;
  private String description;
  private String link;
  private String uri;[size=x-large;][/size][size=large][/size]
  @SuppressWarnings("unchecked")
  private List items;
  private String language;
  private String copyright;
  private Date pubDate;
  private String feedType;
  private String encoding;
  public String getTitle() {
  return title;
  }
  public void setTitle(String title) {
  this.title = title;
  }
  public String getDescription() {
  return description;
  }
  public void setDescription(String description) {
  this.description = description;
  }
  public String getLink() {
  return link;
  }
  public void setLink(String link) {
  this.link = link;
  }
  public String getUri() {
  return uri;
  }
  public void setUri(String uri) {
  this.uri = uri;
  }
  @SuppressWarnings("unchecked")
  public List getItems() {
  return items;
  }
  @SuppressWarnings("unchecked")
  public void setItems(List items) {
  this.items = items;
  }
  public String getLanguage() {
  return language;
  }
  public void setLanguage(String language) {
  this.language = language;
  }
  public String getCopyright() {
  return copyright;
  }
  public void setCopyright(String copyright) {
  this.copyright = copyright;
  }
  public Date getPubDate() {
  return pubDate;
  }
  public void setPubDate(Date pubDate) {
  this.pubDate = pubDate;
  }
  public String getFeedType() {
  return feedType;
  }
  public void setFeedType(String feedType) {
  this.feedType = feedType;
  }
  public String getEncoding() {
  return encoding;
  }
  public void setEncoding(String encoding) {
  this.encoding = encoding;
  }
  }
  // /
  //RssChannelItemDO类
  public class RssChannelItemDO {
  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;
  //articleDO.getArticlePages().get(0).get
  }
  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;
  }
  }
  // /
  public class RssChannelEItemDO extends RssChannelItemDO{
  private String enclosure;// 流媒体文件
  public String getEnclosure()
  {
  return enclosure;
  }
  public void setEnclosure(String enclosure)
  {
  this.enclosure = enclosure;
  }
  }
  // /
  public interface RssServiceBase {
  /**
  * rss服务发布接口
  *
  * @param rssSiteId
  * 网站服务ID
  * @param channel
  * 频道名
  * @param itemList
  * 频道中所包含的项
  * @param rssType
  * rss协议类型
  * @param encoding
  * 编码类型
  * @param layOut
  * 排版类型 默认为0,用于以后扩展
  */
  public boolean rssBuild(String rssSiteId,RssChannelDO channel,
  ArrayList itemList,String rssType,String encoding,int layOut);
  }
  //
  public class RssFactory implements RssServiceBase{
  private SyndFeed feed; //创建RSS
  @SuppressWarnings("unchecked")
  private List entries; //生成item集合
  private SyndEntry entry; //生成item
  @SuppressWarnings("unused")
  private RssChannelDO rssChannel; //频道域
  @SuppressWarnings("unchecked")
  private static Map rssMap=new HashMap(); //保存所对应的rss服务内容,当map中有时,无需再创建,直接读取
  private static RssFactory rssFactory;
  @SuppressWarnings("unchecked")
  private RssFactory() {
  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);
  feed.setCopyright(copyright);
  }
  /**
  * 添加频道的子内容
  *
  * @param item
  * {@link ChannelItem}
  * @throws Exception
  */
  @SuppressWarnings("unchecked")
  public void buildItems(RssChannelItemDO item) throws RuntimeException {
  entry = new SyndEntryImpl();
  // 设置新闻标题
  entry.setTitle(item.getTitle());
  // 设置新闻的连接地址
  entry.setLink(item.getLink());
  // 设置新闻简介
  SyndContent content = new SyndContentImpl();
  content.setType("text/plain");
  content.setValue(item.getDescription());
  entry.setDescription(content);
  // 设置发布时间
  entry.setPublishedDate(item.getPubDate());
  // 设置频道所属的范围
  SyndCategory cate = new SyndCategoryImpl();
  cate.setName(item.getCategory());
  List cateList = new ArrayList();
  cateList.add(cate);
  entry.setCategories(cateList);
  // 设置作者
  entry.setAuthor(item.getAuthor());
  // 将新闻项添加至数组中
  entries.add(entry);
  }
  /**
  * 添加频道的内容项
  *
  * @param item
  * {@link ChannelEItem}此类继承自ChannelItem类
  * @throws Exception
  */
  @SuppressWarnings("unchecked")
  public void buildItems(RssChannelEItemDO item) throws RuntimeException {
  entry = new SyndEntryImpl();
  // 设置新闻标题
  entry.setTitle(item.getTitle());
  // 设置新闻的连接地址
  entry.setLink(item.getLink());
  // 设置新闻简介
  SyndContent content = new SyndContentImpl();
  content.setValue(item.getDescription());
  entry.setDescription(content);
  // 设置发布时间
  entry.setPublishedDate(item.getPubDate());
  // 设置频道所属的范围
  SyndCategory cate = new SyndCategoryImpl();
  cate.setName(item.getCategory());
  List cateList = new ArrayList();
  cateList.add(cate);
  entry.setCategories(cateList);
  // 设置作者
  entry.setAuthor(item.getAuthor());
  // 设置流媒体播放文件
  SyndEnclosure en = new SyndEnclosureImpl();
  en.setUrl(item.getEnclosure());
  List enList = new ArrayList();
  enList.add(en);
  entry.setEnclosures(enList);
  // 将新闻项添加至数组中
  entries.add(entry);
  }
  /**
  * rss服务发布接口
  *
  * @param rssSiteId
  * 网站服务ID
  * @param channel
  * 频道名
  * @param itemList
  * 频道中所包含的项
  * @param rssType
  * rss协议类型
  * @param encoding
  * 编码类型
  * @param layOut
  * 排版类型 默认为0,用于以后扩展
  */
  public boolean rssBuild(String rssSiteId,RssChannelDO channel,
  ArrayList itemList,String rssType,String encoding,int layOut)
  {
  buildChannel(channel.getTitle(),channel.getLink(), channel.getDescription(),
  channel.getLanguage(),channel.getPubDate(),channel .getCopyright());
  String rss=null;
  int size=itemList.size();
  for(int i=0;i
  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值