rsslibj

系统 1416 0
RSS是一个标准的XML文件,Rss阅读器可以读取这个XML文件获得文章的信息,使用户可以通过Rss阅读器
而非浏览器阅读Blog,我们只要动态生成这个XML文件便可以了。RSSLibJ是一个专门读取和生成RSS的小
巧实用的Java库,大小仅25k,可以从 http://sourceforge.net/projects/rsslibj/ 下载rsslibj-

1_0RC2.jar和它需要的EXMLjar两个文件,然后复制到web/WEB-INF/lib/下。
 
 

下载下来之后把 扩张名.zip 改为 .jar 就行了。

Java代码 复制代码
  1. import  com.rsslibj.elements.Channel;   
  2. public   class  Writer {   
  3.      public   static   void  main(String[] args)    
  4.              throws  InstantiationException, ClassNotFoundException,    
  5.             IllegalAccessException {   
  6.         Channel channel= new  Channel();   
  7.         channel.setDescription( "This is my sample channel." );   
  8.         channel.setLink( "http://localhost/" );   
  9.         channel.setTitle( "My Channel" );   
  10.         channel.setImage( "http://localhost/" ,    
  11.                  "The Channel Image" ,    
  12.                  "http://localhost/foo.jpg" );   
  13.         channel.setTextInput( "http://localhost/search" ,    
  14.                  "Search The Channel Image" ,    
  15.                  "The Channel Image" ,    
  16.                  "s" );   
  17.         channel.addItem( "http://localhost/item1" ,   
  18.                  "The First Item covers details on the first item>" ,   
  19.                  "The First Item" )   
  20.                 .setDcContributor( "Joseph B. Ottinger" );   
  21.         channel.addItem( "http://localhost/item2" ,   
  22.                  "The Second Item covers details on the second item" ,   
  23.                  "The Second Item" )   
  24.                 .setDcCreator( "Jason Bell" );   
  25.         System.out.println( "The feed in RDF: " +channel.getFeed( "rss" ));   
  26.     }   
  27. }  
Java代码 复制代码
  1. import  com.rsslibj.elements.Channel;   
  2. public   class  Writer {   
  3.      public   static   void  main(String[] args)    
  4.              throws  InstantiationException, ClassNotFoundException,    
  5.             IllegalAccessException {   
  6.         Channel channel= new  Channel();   
  7.         channel.setDescription( "This is my sample channel." );   
  8.         channel.setLink( "http://localhost/" );   
  9.         channel.setTitle( "My Channel" );   
  10.         channel.setImage( "http://localhost/" ,    
  11.                  "The Channel Image" ,    
  12.                  "http://localhost/foo.jpg" );   
  13.         channel.setTextInput( "http://localhost/search" ,    
  14.                  "Search The Channel Image" ,    
  15.                  "The Channel Image" ,    
  16.                  "s" );   
  17.         channel.addItem( "http://localhost/item1" ,   
  18.                  "The First Item covers details on the first item>" ,   
  19.                  "The First Item" )   
  20.                 .setDcContributor( "Joseph B. Ottinger" );   
  21.         channel.addItem( "http://localhost/item2" ,   
  22.                  "The Second Item covers details on the second item" ,   
  23.                  "The Second Item" )   
  24.                 .setDcCreator( "Jason Bell" );   
  25.         System.out.println( "The feed in RDF: " +channel.getFeed( "rss" ));   
  26.     }   
  27. }  
      import com.rsslibj.elements.Channel;
public class Writer {
    public static void main(String[] args) 
            throws InstantiationException, ClassNotFoundException, 
            IllegalAccessException {
        Channel channel=new Channel();
        channel.setDescription("This is my sample channel.");
        channel.setLink("http://localhost/");
        channel.setTitle("My Channel");
        channel.setImage("http://localhost/", 
                "The Channel Image", 
                "http://localhost/foo.jpg");
        channel.setTextInput("http://localhost/search", 
                "Search The Channel Image", 
                "The Channel Image", 
                "s");
        channel.addItem("http://localhost/item1",
                "The First Item covers details on the first item>",
                "The First Item")
                .setDcContributor("Joseph B. Ottinger");
        channel.addItem("http://localhost/item2",
                "The Second Item covers details on the second item",
                "The Second Item")
                .setDcCreator("Jason Bell");
        System.out.println("The feed in RDF: "+channel.getFeed("rss"));
    }
}

    
 
Java代码 复制代码
  1. Channel channel =  new  Channel();    
  2. channel.setDescription(account.getDescription());    
  3. baseUrl = baseUrl.substring( 0 , n);    
  4. channel.setLink( "http://server-name/home.c?accountId="  + accountId);    
  5. channel.setTitle(account.getTitle());    
  6. List articles = facade.getArticles(accountId, account.getMaxPerPage(),  1 );    
  7. Iterator it = articles.iterator();    
  8. while (it.hasNext()) {    
  9.     Article article = (Article)it.next();    
  10.     channel.addItem( "http://server-name/article.c?articleId="  + article.getArticleId(),    
  11.         article.getSummary(), article.getTitle()    
  12.     );    
  13. }    
  14. // 输出xml:    
  15. response.setContentType( "text/xml" );    
  16. PrintWriter pw = response.getWriter();    
  17. pw.print(channel.getFeed( "rss" ));    
  18. pw.close();   
Java代码 复制代码
  1. Channel channel =  new  Channel();    
  2. channel.setDescription(account.getDescription());    
  3. baseUrl = baseUrl.substring( 0 , n);    
  4. channel.setLink( "http://server-name/home.c?accountId="  + accountId);    
  5. channel.setTitle(account.getTitle());    
  6. List articles = facade.getArticles(accountId, account.getMaxPerPage(),  1 );    
  7. Iterator it = articles.iterator();    
  8. while (it.hasNext()) {    
  9.     Article article = (Article)it.next();    
  10.     channel.addItem( "http://server-name/article.c?articleId="  + article.getArticleId(),    
  11.         article.getSummary(), article.getTitle()    
  12.     );    
  13. }    
  14. // 输出xml:    
  15. response.setContentType( "text/xml" );    
  16. PrintWriter pw = response.getWriter();    
  17. pw.print(channel.getFeed( "rss" ));    
  18. pw.close();   
      Channel channel = new Channel(); 
channel.setDescription(account.getDescription()); 
baseUrl = baseUrl.substring(0, n); 
channel.setLink("http://server-name/home.c?accountId=" + accountId); 
channel.setTitle(account.getTitle()); 
List articles = facade.getArticles(accountId, account.getMaxPerPage(), 1); 
Iterator it = articles.iterator(); 
while(it.hasNext()) { 
    Article article = (Article)it.next(); 
    channel.addItem("http://server-name/article.c?articleId=" + article.getArticleId(), 
        article.getSummary(), article.getTitle() 
    ); 
} 
// 输出xml: 
response.setContentType("text/xml"); 
PrintWriter pw = response.getWriter(); 
pw.print(channel.getFeed("rss")); 
pw.close(); 

    
 
Java代码 复制代码
  1. import  com.rsslibj.elements.Channel;   
  2.   
  3. public  classWriter{   
  4.      public   static   void  main(String[] args)    
  5.          throws  InstantiationException,ClassNotFoundException,IllegalAccessException {   
  6.            
  7.         Channel channel =  new  Channel();   
  8.         channel.setDescription( "Thisismysamplechannel." );   
  9.         channel.setLink( "/" );   
  10.         channel.setTitle( "MyChannel" );   
  11.         channel.setImage( "/" "TheChannelImage" "/foo.jpg" );   
  12.         channel.setTextInput( "/search" "SearchTheChannelImage" "TheChannelImage" "s" );   
  13.         channel.addItem( "/item1" "TheFirstItemcoversdetailsonthefirstitem>" ,    
  14.                  "TheFirstItem" ).setDcContributor( "JosephB.Ottinger" );   
  15.         channel.addItem( "/item2" "TheSecondItemcoversdetailsontheseconditem" ,   
  16.                  "TheSecondItem" ).setDcCreator( "JasonBell" );   
  17.         System.out.println( "ThefeedinRDF:"  channel.getFeed( "rdf" ));   
  18.     }   
  19. }  

rsslibj


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论