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/下。
?
rsslibj-
1_0RC2.jar
下載地址:
http://sourceforge.net/project/downloading.php?group_id=71153&use_mirror=nchc&filename=rsslibj-1_0RC2.jar&27763931
?
下載下來之后把 擴張名.zip 改為 .jar 就行了。
- 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" )); ??
- ????} ??
- }??
- 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" )); ??
- ????} ??
- }??
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")); } }
?
- 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();???
- 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();???
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();
?
- import ?com.rsslibj.elements.Channel; ??
- ??
- public ?classWriter{ ??
- ???? public ? static ? void ?main(String[]?args)? ??
- ???????? throws ?InstantiationException,ClassNotFoundException,IllegalAccessException?{ ??
- ???????? ??
- ????????Channel?channel?=? new ?Channel(); ??
- ????????channel.setDescription( "Thisismysamplechannel." ); ??
- ????????channel.setLink( "/" ); ??
- ????????channel.setTitle( "MyChannel" ); ??
- ????????channel.setImage( "/" ,? "TheChannelImage" ,? "/foo.jpg" ); ??
- ????????channel.setTextInput( "/search" ,? "SearchTheChannelImage" ,? "TheChannelImage" ,? "s" ); ??
- ????????channel.addItem( "/item1" ,? "TheFirstItemcoversdetailsonthefirstitem>" ,? ??
- ???????????????? "TheFirstItem" ).setDcContributor( "JosephB.Ottinger" ); ??
- ????????channel.addItem( "/item2" ,? "TheSecondItemcoversdetailsontheseconditem" , ??
- ???????????????? "TheSecondItem" ).setDcCreator( "JasonBell" ); ??
- ????????System.out.println( "ThefeedinRDF:" ?channel.getFeed( "rdf" )); ??
- ????} ??
- }??
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
