最近想幫相簿製作 RSS Feed,研究了一下,
找到一個 java 的 Open Source 
RSS4j
提供 RSS 製作與剖析,參考作者的 Sample Code,很快地就整合到相簿的管理介面裡了。以後每次 Publish 一個相簿,RSS 都會自動更新了。
簡單說明一下如何利用 RSS4j 來製作 RSS
1.先去下載 RSS4j 回來,解開後把 rss4j.jar 放到 WEB-INF/lib 下面。
2.再到 Apache Xerces 下載最新的 xerces2-j ,解開後將裡面的 jar 檔都一併放到 WEB-INF/lib 下面。
3.剩下的就是寫 code 整合到相簿的管理介面中了。
| 
12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 `
 | 
    String photo_root = this.getServletContext().getRealPath("/");String rss_file = photo_root + File.separator + "rss.xml";
 
 // 產生 RSS XML Document
 RssDocument doc = new RssDocument();
 doc.setVersion(RssDocument.VERSION_10);
 
 // 產生相簿這個 Channel
 RssChannel channel = new RssChannel();
 channel.setChannelTitle("我的相簿");
 channel.setChannelLink("http://broso.twbbs.org/photo");
 channel.setChannelDescription("隨想意誌 我的相簿");
 channel.setChannelUri("http://broso.twbbs.org/photo");
 doc.addChannel(channel);
 
 
 for (int i=0;i<photo_album.size();i++) {
 ....
 ....
 // 將每個相簿加入 RSS 中
 RssChannelItem item1 = new RssChannelItem();
 item1.setItemTitle(Title);
 item1.setItemLink("http://broso.twbbs.org/photo/"+DirName);
 item1.setItemDescription( Date);
 channel.addItem(item1);
 }
 
 // 產生 RSS XML
 File file = new File(rss_file);
 try {
 RssGenerator.generateRss(doc, file);
 System.out.println("RSS file written.");
 } catch (RssGenerationException e) {
 System.out.println(e.getMessage());
 e.printStackTrace();
 out.println(e.getMessage());
 return;
 } catch (Exception e) {
 System.out.println(e.getMessage());
 e.printStackTrace();
 out.println(e.getMessage());
 return;
 }
 
 | 
4.搞定!!