<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    OMG,到底在尋找什么..................
    (構造一個完美的J2EE系統所需要的完整知識體系)
    posts - 198,  comments - 37,  trackbacks - 0

    原帖地址:http://hedong.3322.org/newblog/archives/000051.html

    利用rome寫rss feed生成程序

      前幾天轉一個rome的介紹過來,現在拿它寫個rss feed生成程序。rome的安裝包中,有三個例程,分別是解析已有的rss feed,轉換rss feed的格式以及內容聚合方面的,這個程序可以做補充。   程序思路:在更新不很頻繁的發布網站上,可以生成一個通過http可訪問的靜態rss feed文件。為了便于調用,做成一個bean,接一個帶有絕對路徑的文件名作參數。
    mport java.io.IOException;
    import java.net.UnknownHostException;
    import java.net.URL;
    import java.util.List;
    import java.util.Date;
    import java.util.ArrayList;
    import java.io.BufferedWriter;
    import java.io.Writer;
    import java.io.FileWriter;
    
    import com.sun.syndication.feed.synd.SyndFeedI;
    import com.sun.syndication.feed.synd.SyndContentI;
    import com.sun.syndication.feed.synd.SyndFeed;
    import com.sun.syndication.feed.synd.SyndEntry;
    import com.sun.syndication.feed.synd.SyndCategory;
    import com.sun.syndication.feed.synd.SyndContent;
    import com.sun.syndication.io.SyndFeedOutput;
    import com.sun.syndication.io.SyndFeedInput;
    
    
    public class RssCreator
    {
        public RssCreator()
            throws TRIPException, UnknownHostException, IOException
        {
        }   
    
        public boolean genRss(String filename)
        {
    
            try
            {
    		。。。connect to database and locat the latest 15 records....
    		String outputType = "rss_1.0";
    		String outputFile = filename;
    		Writer outWriter = null;
    		try{
    			outWriter=new BufferedWriter(new FileWriter(outputFile));
    		}catch (Exception e){
    			//deal exception
    		}
                    SyndFeedI feed = new SyndFeed();
                    feed.setFeedType(outputType);
    
                    feed.setTitle(converttoISO(" 你的站點的名稱 "));
                    feed.setDescription(converttoISO("描述一下站點吧。"));
                    feed.setAuthor("author name");
                    feed.setLink("http://www.yoursite.com");
    
                    List entries = new ArrayList();
                    feed.setEntries(entries);
    
                    for (int i=0;i<15;i++) {
    		    SyndEntry entry = new SyndEntry();
     	           	record = search.record(hits-i);
    
                		tfield=record.field("AUTHORS");
                		sfld = chkValue(tfield.getValue());
    		    entry.setAuthor( sfld );
    
                		tfield=record.field("SUBCLASS");
                		sfld = chkValue(tfield.getValue());
    		    List cats=new ArrayList();
    		    SyndCategory cat=new SyndCategory();
    		    cat.setName(sfld);
    		    cats.add(cat);
    		    entry.setCategories(cats);
    		    
    		    //entry.setContents("什么內容呢?");
                		tfield=record.field("ABS");
                		sfld = chkValue(tfield.getValue());
    		    SyndContentI desc=new SyndContent();
    		    desc.setValue(sfld);
    		    entry.setDescription(desc);
    		    
                		tfield=record.field("URL");
                		sfld = chkValue(tfield.getValue());
    		    entry.setLink(sfld);
    		    
                		tfield=record.field("TITLE");
                		sfld = chkValue(tfield.getValue());
    		    entry.setTitle(sfld) ;
    		    //long ldate=(long)1079511514653;
                		tfield=record.field("ID");//我數據庫中,ID用的是系統時鐘
                		sfld = chkValue(tfield.getValue());
    		    Date pdate=null;
    		    pdate=new Date(new Long(sfld).longValue());
      		    entry.setPublishedDate(pdate);
     
                        entries.add(entry);
    
                    }
    
                    SyndFeedOutput output = new SyndFeedOutput();
                    output.output(feed,outWriter);
    		outWriter.close();
    
                
    		...close database....
    		return true;
            }
            catch(Exception exception)
            {
                close database
                close file
                return false
            }
            return true;
        }
        private String chkValue(String s){
        	if (s==null) return "";
        	return s;
        }
        public static String converttoGB(String s)
        {
            try
            {
                byte abyte0[] = s.getBytes("ISO-8859-1");
                return new String(abyte0, "gb2312");
            }
            catch(Exception exception)
            {
                return s;
            }
        }
        public static String converttoISO(String s)
        {
            try
            {
                byte abyte0[] = s.getBytes("gb2312");
                return new String(abyte0, "ISO-8859-1");
            }
            catch(Exception exception)
            {
                return s;
            }
        }
    
    }
      可能會遇到一些編碼問題,所以可能要用到轉換函數,寫了幾個放在代碼末尾
    posted on 2007-01-14 02:33 OMG 閱讀(597) 評論(1)  編輯  收藏 所屬分類: Ajax/RSS/Tag

    FeedBack:
    # re: 竹筍炒肉:利用rome寫rss feed生成程序
    2014-05-05 21:10 | 蔣猛
    sadasdasdasdsadsa  回復  更多評論
      

    <2007年1月>
    31123456
    78910111213
    14151617181920
    21222324252627
    28293031123
    45678910

    常用鏈接

    留言簿(1)

    隨筆分類

    隨筆檔案

    IT風云人物

    文檔

    朋友

    相冊

    經典網站

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲阿v天堂在线2017免费| 日本免费福利视频| 国产亚洲精品自在久久| 人妻巨大乳hd免费看| 亚洲av中文无码| fc2免费人成在线| 亚洲伊人久久精品影院| a级在线观看免费| 亚洲Av无码精品色午夜| 少妇无码一区二区三区免费| 亚洲精品美女视频| 成年在线网站免费观看无广告| 在线a亚洲老鸭窝天堂av高清| 国产男女性潮高清免费网站| 四虎影视在线看免费观看| 国产综合精品久久亚洲| 欧洲人免费视频网站在线| 亚洲理论片中文字幕电影| 毛片免费观看视频| 日韩在线观看免费完整版视频| 国产日韩亚洲大尺度高清| 免费A级毛片av无码| 亚洲精品无码不卡在线播放| 免费一级成人毛片| 国内永久免费crm系统z在线 | 亚洲s码欧洲m码吹潮| www.亚洲精品.com| 久久亚洲免费视频| 一区二区亚洲精品精华液| 亚洲精品WWW久久久久久| 毛片在线播放免费观看| 中文字幕在线日亚洲9| 亚洲一区二区三区国产精品| 91香蕉国产线观看免费全集| 亚洲国产精品网站在线播放| 亚洲区小说区图片区QVOD| 国产福利在线免费| 成人性做爰aaa片免费看| 亚洲色大成WWW亚洲女子| 亚洲国产美女精品久久久久∴| 成年人网站在线免费观看|