rsslibj生成rss2.0搞不定,换了rome0.8来试试

  在rsslibj中生成rss2.0用getFeed("2.0")用下载的binary不行,用cvs库中的文件更不行,老是报告nullpoint错误,而且,文档和源程序混乱。

  试用了rome,感觉更正规一些,文档丰富,设计上好像要全面一些。毕竟,它是后来者,而rsslibj在2003年就停止发布了。

  rome自身带的例子已经比较全面,可以来它来写出基本功能的rss文件,下面附网上一篇完整的例子:

转自:http://kb.csdn.net/java/Articles/200512/10b9356d-85cd-4fe0-b8ae-3eece6cdb928.html

How To Generate RSS With ROME

作者: ∣来源:JavaLobby∣原文地址∣2005-12-30

Many people have asked how I implemented RSS in Fatima (JavaPress) on Java.net since the object model for Suns Rome API is a little.. dense, and suited more for abstract aggregation in your applications like Technorati. However, Rome is extremely powerful and offers lots of transformation and organization of your RSS feeds (no matter if you generate them or you grab them). Well, below is a general class that implements everything you would need to start generating your own RSS feeds using the ROME API, and for everyone that wants to get started quick this example should help you out.

doSyndication() is where youll want to focus your attention.

NOTE: This generates both regular RSS and shows you how to generate RSS with the embed tag for Podcasts!

package net.thepostmodern.fatima.rss;

 

import com.sun.syndication.feed.synd.*;

import com.sun.syndication.io.SyndFeedOutput;

import java.io.FileWriter;

import java.io.Writer;

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.ArrayList;

import java.util.List;

import java.sql.*;

 

import net.thepostmodern.fatima.blog.*;

import net.thepostmodern.fatima.sql.ConnectionFactory;

 

 

/**

 * @author   bbjwerner

 */

public class GenerateRSS {

private static final DateFormat DATE_PARSER = new SimpleDateFormat("yyyy-MM-dd");

private static String fileName = null;

private static String feedType = null;

    private final List entries = new ArrayList();

private final List categories = new ArrayList();

    SyndEntry entry;

    SyndContent description;

SyndCategory category;

 

/**

* This method generates a seperate RSS feed for all categories in blog

* @param feedType The type of feed you wish to generate (RSS2.0, atom, ect.).

* @param fileName Filename will be category.xml, and this entry does nothing to override this.

*/

public void generateCategoryRSS(String Type, String Name) {

feedType = Type;

fileName = Name;

populateCategoryArray();

}

/**

* This method generates the RSS feeds for a complete blog with categories

* @param Type The type of feed you wish to generate (RSS2.0, atom, ect.).

* @param Name The filename to write out the format to.

*/

public void generateBlogRSS(String Type, String Name) {

feedType = Type;

fileName = Name;

this.populateArray();

}

       

        /**

* This method generates the RSS feeds for podcasting based on category (i.e. Podcast)

* @param Category The category to run as containing podcast content.

* @param Name The filename to write out the format to.

*/

        public void generatePodcastRSS(String Category, String Name) {

feedType = "rss2.0";

fileName = Name;

this.populatePodcastArray(Category);

}

public GenerateRSS() {

   

}

private void populateArray() {

 

    final ConnectionFactory thisFactory = new ConnectionFactory();

ResultSet blogEntries = null;

ResultSet blogInfo = null;

    try {

blogEntries = thisFactory.executeStatement("SELECT * FROM blog_entry ORDER BY id DESC");

blogInfo = thisFactory.executeStatement("SELECT * FROM blog_info");

blogEntries.first();

blogInfo.first();

while (!blogEntries.isAfterLast()) {

   

  this.addEntry(blogEntries.getString("title"),blogInfo.getString("url") + "/blog/BlogEntry.jsp?id=" + blogEntries.getString("id"), blogEntries.getString("date"), blogEntries.getString("teaser"), CategoryBean.getCategory(blogEntries.getString("category")), blogEntries.getString("author"));

  blogEntries.next();

}

this.doSyndication(blogInfo.getString("name"), blogInfo.getString("url") + "/blog", blogInfo.getString("description"), blogInfo.getString("copyright"),fileName);

System.out.println("Did Syndication");

}

catch (Exception ex) {

System.out.println("SQLException: " + ex.getMessage());

}

finally {

   

    try {blogEntries.close(); } catch (Exception ex) { System.out.println("SQLException: " + ex.getMessage()); }

    try {blogInfo.close(); } catch (Exception ex) { System.out.println("SQLException: " + ex.getMessage()); }

    thisFactory.Close();

}

}

private void populateCategoryArray() {

 

    final ConnectionFactory thisFactory = new ConnectionFactory();

ResultSet blogEntries = null;

ResultSet blogInfo = null;

ResultSet blogCategories = null;

try {

blogCategories = thisFactory.executeStatement("SELECT * FROM blog_categories");

blogInfo = thisFactory.executeStatement("SELECT * FROM blog_info");

blogInfo.first();

blogCategories.first();

while (!blogCategories.isAfterLast()) {

   

    blogEntries = thisFactory.executeStatement("SELECT * FROM blog_entry WHERE category = '" + blogCategories.getString("id") + "' ORDER BY id DESC");

blogEntries.first();

System.out.println("************ Doing category: " + CategoryBean.getCategory(blogCategories.getString("id")));

while (!blogEntries.isAfterLast()) { 

  this.addEntry(blogEntries.getString("title"),blogInfo.getString("url") + "/blog/BlogEntry.jsp?id=" + blogEntries.getString("id"), blogEntries.getString("date"), blogEntries.getString("teaser"), CategoryBean.getCategory(blogEntries.getString("category")), blogEntries.getString("author"));

  blogEntries.next();

}

final String XMLfile = ((fileName + blogCategories.getString("category")) + ".xml");

this.doSyndication(blogCategories.getString("title"), blogInfo.getString("url") + "/blog/BlogbyCategory.jsp?id=" + blogCategories.getString("id"), blogCategories.getString("description"), blogInfo.getString("copyright"), XMLfile);

this.entries.clear();

blogCategories.next();

}

}

catch (Exception ex) {

System.out.println("Category SQLException: " + ex.getMessage());

}

finally {

   

    try {blogEntries.close(); } catch (Exception ex) { System.out.println("SQLException: " + ex.getMessage()); }

    try {blogInfo.close(); } catch (Exception ex) { System.out.println("SQLException: " + ex.getMessage()); }

    try {blogCategories.close(); } catch (Exception ex) { System.out.println("SQLException: " + ex.getMessage()); }

    thisFactory.Close();

}

}

private void populatePodcastArray(String category_string) {

   

    final ConnectionFactory thisFactory = new ConnectionFactory();

ResultSet podEntries = null;

ResultSet blogInfo = null;

    try {

    podEntries = thisFactory.executeStatement("SELECT * FROM podcasts");

blogInfo = thisFactory.executeStatement("SELECT * FROM blog_info");

podEntries.first();

blogInfo.first();

while (!podEntries.isAfterLast()) {

   

  this.addPodCast(podEntries.getString("title"),blogInfo.getString("url") + "/blog/radio/" + podEntries.getString("filename"),podEntries.getString("date"), podEntries.getString("description"), category_string, podEntries.getString("author"));

  podEntries.next();

}

this.doSyndication(blogInfo.getString("name"), blogInfo.getString("url"), blogInfo.getString("description"), blogInfo.getString("copyright"),fileName);

System.out.println("Did Syndication");

}

catch (Exception ex) {

System.out.println("SQLException: " + ex.getMessage());

}

finally {

   

    try {podEntries.close(); } catch (Exception ex) { System.out.println("SQLException: " + ex.getMessage()); }

    try {blogInfo.close(); } catch (Exception ex) { System.out.println("SQLException: " + ex.getMessage()); }

    thisFactory.Close();

}

}

 

/**

* This method adds an entry to the ArrayList() which will be published when GenerateRSS()

* is called.

* <p>

* @param title The title of the blog entry (not the blog itself)

* @param link The PermaLink that will point to your entry

* @param date The date of the blog entry

* @param blogContent The content or synopsis you wish to publish

* @param cat The category of the entry. This has been added to integrate

*        with Technorati and match WordPress functionality

* @param author The author of the entry to be published.

*

*/

private void addEntry(String title, String link, String date, String blogContent, String cat, String author) {

try {

 

        entry = new SyndEntryImpl();

    entry.setAuthor(author);

        entry.setTitle(title);

        entry.setLink(link);

        entry.setPublishedDate(DATE_PARSER.parse(date));

        description = new SyndContentImpl();

        description.setType("text/plain");

        description.setValue(blogContent);

        entry.setDescription(description);

    category = new SyndCategoryImpl();

category.setName(cat);

categories.add(category);

entry.setCategories(categories);

categories.remove(category);

entries.add(entry);

}

        catch (Exception ex) {

            ex.printStackTrace();

            System.out.println("ERROR: "+ex.getMessage());

                             }

}

private void addPodCast(String title, String mp3link, String date, String blogContent, String cat, String author) {

try {

 

        entry = new SyndEntryImpl();

entry.setAuthor(author);

        entry.setTitle(title);

        entry.setLink(mp3link);

        entry.setPublishedDate(DATE_PARSER.parse(date));

        description = new SyndContentImpl();

        description.setType("text/plain");

        description.setValue(blogContent);

        entry.setDescription(description);

    category = new SyndCategoryImpl();

category.setName(cat);

categories.add(category);

entry.setCategories(categories);

categories.remove(category);

entries.add(entry);

}

        catch (Exception ex) {

            ex.printStackTrace();

            System.out.println("ERROR: "+ex.getMessage());

                             }

}

/**

* This method is called last after you have added all your entries and have specified your

* feed type and filename. This actually does the work

* <p>

* NOTE: This has static content entered in to the fields! You must have access to the source

* code edit this method or else you will be publishing content as the Post Modern Banter Blog

* Yes, I should change this immediately. Ideally, it would take values from the web.xml file itself.

* <p>

* @throws Exception

*/

private void doSyndication(String title, String link, String description_loc, String copyright, String xml) {

 

            try {

 

                final SyndFeed feed = new SyndFeedImpl();

                feed.setFeedType(feedType);

 

                feed.setTitle(title);

                feed.setLink(link);

                feed.setDescription(description_loc);

   feed.setCopyright(copyright);

                feed.setEntries(entries);

  

 

                final Writer writer = new FileWriter(xml);

                final SyndFeedOutput output = new SyndFeedOutput();

                output.output(feed,writer);

                writer.close();

 

                System.out.println("************* The feed has been written to the file ["+xml+"]");

 

            }

            catch (Exception ex) {

                ex.printStackTrace();

                System.out.println("ERROR: "+ex.getMessage());

                                 }

       

}

 

}

--------------------------------------------------------------------------------

作者的其他文章

Atlas 实现机制浅析 [3]

Atlas 实现机制浅析 [3]

live messenger与稀疏文件—Sparse File Bit

live messenger与稀疏文件—Sparse File Bit

又开学了!

自己制作的Rss阅读器(1)

代码整理

DNN中的Skinning系统

DNN中的Skinning系统

Windows Defender (Beta 2)

more..

其他相关文章

more... 搜索

本文关键字

技术: "JSP" "XML"

产品:

人物:

企业:"SUN"

热门关键字

技术

  数据库  XML  JSP  模式

  测试  Servlet

产品

  Tomcat  Struts

  WebLogic  Eclipse  Ant

企业

  SUN  Apache  IBM  Oracle

  microsoft

热点文章

JSF and AJAX

Java 5.0 多线程编程实践

Hibernate; Easy, Scalable Paging of Large Data

使用AJAX和J2EE创建功能强大的瘦客户端

开源数据库系统

J2EE中使用Spring AOP框架和EJB组件

Get Started with Multithreading in .NET

Exadel宣布AJAX在Studio Pro 3.5中支持JSF

IntelliJ IDEA: Detecting Probable NPEs

IntelliJ IDEA: i18n support

Java J2EE Lite with Spring Framework

比较完整全面的分页

甲骨文曾试图收购MySQL 继续其开源之路

Four Ways to Use Excel as an Internet Reporting Tool

关于权限模块的设想

最新文章

Exadel宣布AJAX在Studio Pro 3.5中支持JSF

Oracle收购BerkeleyDB

BEA宣布开放Kodo源代码—Java持久化API

甲骨文曾试图收购MySQL 继续其开源之路

利用J2EE部署CRM BEA和Siebel共推SOA

Java Web Application开发日志之二--“Ignore how they were created”,工厂方法模式应用

比较完整全面的分页

OSGi Alliance开设面向公众的邮件列表

关于权限模块的设想

oscache使用和研究

开源产品学习方法论

Rife的Continuations

eXtremeComponent在中文环境下的使用

webwork 2.2 中如何给Collection赋值

Get Started with Multithreading in .NET

It seems that I have lost the motive of learning english

  I only hear the common conversation sentences in Lp5800 on the way go to work  in some mornings.It was less than ten minutes the time for learning it.

  I have lost the motive of learning english.

  For me,english was only a tool before.How can I turn it into a interesting thing of mine?Maybe,it should be a window for me to view outside world?

  However,I must learn it persistently.

一篇日记可以属于不同的目标

  例如,我有一篇日记“在eclipse中改变文件的binary/ascii属性”http://www.learndiary.com/disDiaryContentAction.do?searchDiaryID=1482&goalID=1482&naviStr=a10ag419a0419,里面是讲在eclipse里的cvs设置,涉及到“jsp图形开发环境的学习”http://www.learndiary.com/disGoalContentAction.do?goalID=419&naviStr=a10

和“学习cvs”http://www.learndiary.com/disGoalContentAction.do?goalID=398&naviStr=a10ac0ae0

两个学习目标。

  一篇日记按道理来讲是可以属于不同的目标的,怎么样恰当而系统的实现它,实现它有没有意义?这些需要进一步的思考。

开始Struts的日记。

今天终于对《Jakarta Struts编程》看了一个大概,

准备搭建一个环境进行进一步学习。

我将下载的status-1.2.7.tar.gz解压缩后,

把lib目录中的status.jar、jstl.jar和standard.jar拷贝到了WEB-INF的lib目录中,

起动服务器后,竟然一个劲儿的抛出异常,

郁闷死……

最后,把所有的jar文件都拷贝到WEB-INF的lib目录后,

才解决了问题。

回过头再看书,才发现,

书上已经写的很明白了,只怪当时没有注意到。

看来,看书还是要仔细一些。

又或是,水平不够,所以注意不到书上说的内容的重要性。

很惊叹孩子的记忆力和故事表达力

  这两天晚上,8:30分我就让孩子上床睡觉,她当然是睡不着的,于是,我就给她讲故事。讲的内容是她平时看的动画片:小鼹鼠的故事,如小鼹鼠和小老鹰,小鼹鼠和伞...

  没有想到,我讲着讲着,她会接着我讲的故事讲上一段,而且有声有色,故事情节也不差。我真是惊叹,原来以为她看动画片只是好玩,看了就忘了,没有想到她竟然记下来了。

  要知道,她还不到3岁呢。

  也许,孩子的智力开发得比较早,我们是不是给她的学校教育应该适当超前点?当然,想把她培养成“神童”是不可取的,中国原来的实践证明“神童”不是培养的,原来培养的“神童”多是失败的例子。

  孩子的童年应该主要是习惯和品德的塑造,书本的学习应该是其次的,我认为如此。

孩子的咳嗽

  白天不咳,晚上睡觉的时候容易咳,热了要咳,所以被子不能盖厚了;冷了也要咳,所以要挨着大人一起睡,这样也可以预防她晚上踢被子。晚上孩子有时咳起来,咳嗽声就像鼓一样在心上敲。

  总的说来,我们孩子的衣服要比我们大人穿得少点才行。因为她的火气好像比较大,而且一天又不停的运动。

目标内容的页面需要精心设计

  像www.43things.com,目标完成的人可以充当指导后来者的“老师”,这个页面可以展示哪些人加入了这个目标。可以展示征对这个目标的提问。征对这个目标投放了相应的google广告。所以,这个页面在43things.com的rss订阅中只给了链接也是有它的深意的。因为,网页上可以方便提供更丰富的信息,比如广告。

不要排斥广告

  恰当的广告是对社会的一种贡献。它可以沟通供求双方。像www.43things.com,征对某一个目标,投放对应的google广告,这样,给了实现这个目标的人一个辅助目标实现的选择。也使商家的服务得到认识,使他们实现自己的理想和追求。

  我今天就收了两封讲网络联合赚钱的群发邮件。从而联想到学习日记也可以做成这种联盟的形式,自助建站,等等。自助建站的域名可以是:***.learndiary.com的形式。

  所以,广告也有好处,不要因为过度广告的招人讨厌而全面否定它。