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

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

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

    laoding
    本來我以為,隱身了別人就找不到我,沒有用的,像我這樣拉風的男人,無論走到哪里,都像在黑暗中的螢火蟲一樣,那樣的鮮明,那樣的出眾。我那憂郁的眼神,稀疏的胡茬,那微微隆起的將軍肚和親切的笑容......都深深吸引了眾人......
    posts - 0,  comments - 37,  trackbacks - 0

    自己去下載jar包,rsslib4j-0.2.jar,rome-0.8.jar,jdom.jar。

    表newitem如下(自己參考著建):

    CREATE TABLE `newitem` (                    
               `id` 
    varchar(20NOT NULL,                
               `title` 
    varchar(30default NULL,         
               `link` 
    varchar(100default NULL,         
               `description` 
    varchar(100default NULL,  
               `pubdate` date 
    default NULL,              
               `category` 
    varchar(30default NULL,      
               `author` 
    varchar(30default NULL,        
               `enclosure` 
    varchar(50default NULL,     
               
    PRIMARY KEY  (`id`)                       
             )

    下面是幾個要用到類

    import java.util.Date;

    public class ChannelItem {
        
        
    private String title;// Rss文件中Item的標題

        
    private String link;// Rss文件中Item對應的連接

        
    private String description;// Item的描述

        
    private Date pubDate;// Item發布的時間

        
    private String author;// Item作者

        
    private String category;// Item所屬的頻道范疇

        
    public String getTitle() {
            
    return title;
        }

        
    public void setTitle(String title) {
            
    this.title = title;
        }

        
    public String getLink() {
            
    return link;
        }

        
    public void setLink(String link) {
            
    this.link = link;
        }

        
    public String getDescription() {
            
    return description;
        }

        
    public void setDescription(String description) {
            
    this.description = description;
        }

        
    public Date getPubDate() {
            
    return pubDate;
        }

        
    public void setPubDate(Date pubDate) {
            
    this.pubDate = pubDate;
        }

        
    public String getAuthor() {
            
    return author;
        }

        
    public void setAuthor(String author) {
            
    this.author = author;
        }

        
    public String getCategory() {
            
    return category;
        }

        
    public void setCategory(String category) {
            
    this.category = category;
        }
    }


    public class ChannelEItem extends ChannelItem {
        
        
    private String enclosure;// 流媒體文件

        
    public String getEnclosure() {
            
    return enclosure;
        }

        
    public void setEnclosure(String enclosure) {
            
    this.enclosure = enclosure;
        }
    }


    import java.io.FileOutputStream;
    import java.io.OutputStreamWriter;
    import java.io.Writer;
    import java.util.ArrayList;
    import java.util.Date;
    import java.util.List;

    import com.sun.syndication.feed.synd.SyndCategory;
    import com.sun.syndication.feed.synd.SyndCategoryImpl;
    import com.sun.syndication.feed.synd.SyndContent;
    import com.sun.syndication.feed.synd.SyndContentImpl;
    import com.sun.syndication.feed.synd.SyndEnclosure;
    import com.sun.syndication.feed.synd.SyndEnclosureImpl;
    import com.sun.syndication.feed.synd.SyndEntry;
    import com.sun.syndication.feed.synd.SyndEntryImpl;
    import com.sun.syndication.feed.synd.SyndFeed;
    import com.sun.syndication.feed.synd.SyndFeedImpl;
    import com.sun.syndication.io.SyndFeedOutput;

    public class RssBuildFactory {
        
    private SyndFeed feed;

        @SuppressWarnings(
    "unchecked")
        
    private List entries;

        
    private SyndEntry entry;

        @SuppressWarnings(
    "unchecked")
        
    public RssBuildFactory() {
            feed 
    = new SyndFeedImpl();
            feed.setFeedType(
    "rss_2.0");
            entries 
    = new ArrayList();
        }

        
    /**
         * 創建一個頻道
         * 
         * 
    @param title
         *            頻道標題
         * 
    @param link
         *            頻道對應的連接
         * 
    @param description
         *            頻道描述
         * 
    @param language
         *            頻道所用語言
         * 
    @param pubDate
         *            頻道發布時期
         * 
    @param copyright
         *            版權所有
         * 
    @throws Exception
         
    */
        
    public void buildChannel(String title, String link, String description,
                String language, Date pubDate, String copyright)
                
    throws RuntimeException {
            feed.setTitle(title);
            feed.setLink(link);
            feed.setDescription(description);
            feed.setLanguage(language);
            feed.setPublishedDate(pubDate);
            feed.setCopyright(copyright);
        }

        
    /**
         * 添加頻道的子內容
         * 
         * 
    @param item
         *            {
    @link ChannelItem}
         * 
    @throws Exception
         
    */
        @SuppressWarnings(
    "unchecked")
        
    public void buildItems(ChannelItem item) throws RuntimeException {
            entry 
    = new SyndEntryImpl();
            
    // 設置新聞標題
            entry.setTitle(item.getTitle());
            
    // 設置新聞的連接地址
            entry.setLink(item.getLink());
            
    // 設置新聞簡介
            SyndContent content = new SyndContentImpl();
            content.setType(
    "text/plain");
            content.setValue(item.getDescription());
            entry.setDescription(content);
            
    // 設置發布時間
            entry.setPublishedDate(item.getPubDate());
            
    // 設置頻道所屬的范圍
            SyndCategory cate = new SyndCategoryImpl();
            cate.setName(item.getCategory());
            List cateList 
    = new ArrayList();
            cateList.add(cate);
            entry.setCategories(cateList);
            
    // 設置作者
            entry.setAuthor(item.getAuthor());
            
    // 將新聞項添加至數組中
            entries.add(entry);
        }

        
    /**
         * 添加頻道的內容項
         * 
         * 
    @param item
         *            {
    @link ChannelEItem}此類繼承自ChannelItem類
         * 
    @throws Exception
         
    */
        @SuppressWarnings(
    "unchecked")
        
    public void buildItems(ChannelEItem item) throws RuntimeException {
            entry 
    = new SyndEntryImpl();
            
    // 設置新聞標題
            entry.setTitle(item.getTitle());
            
    // 設置新聞的連接地址
            entry.setLink(item.getLink());
            
    // 設置新聞簡介
            SyndContent content = new SyndContentImpl();
            content.setValue(item.getDescription());
            entry.setDescription(content);
            
    // 設置發布時間
            entry.setPublishedDate(item.getPubDate());
            
    // 設置頻道所屬的范圍
            SyndCategory cate = new SyndCategoryImpl();
            cate.setName(item.getCategory());
            List cateList 
    = new ArrayList();
            cateList.add(cate);
            entry.setCategories(cateList);
            
    // 設置作者
            entry.setAuthor(item.getAuthor());
            
    // 設置流媒體播放文件
            SyndEnclosure en = new SyndEnclosureImpl();
            en.setUrl(item.getEnclosure());
            List enList 
    = new ArrayList();
            enList.add(en);
            entry.setEnclosures(enList);
            
    // 將新聞項添加至數組中
            entries.add(entry);
        }

        
    /**
         * 生成XML文件
         * 
         * 
    @param filePath
         *            文件保存路徑和名稱
         * 
    @throws Exception
         
    */
        
    public void buildChannel(String filePath) throws Exception {
            feed.setEntries(entries);
            SyndFeedOutput output 
    = new SyndFeedOutput();
            Writer writer;
            writer 
    = new OutputStreamWriter(new FileOutputStream(filePath), "UTF-8");
            output.output(feed, writer);
        }
    }

    public class DBConnection {

        
    public static void main(String[] args) {


            DBConnection db 
    = new DBConnection();
            Connection conn 
    = db.getConnection();
            String sql 
    = "select * from newitem";
            ResultSet rs 
    = db.getResultSet(sql, conn);
            
    try {
                
    while (rs.next()) { 
                    String title 
    = rs.getString("title");
                    System.out.println(title); 
                 }
            } 
    catch (SQLException e) {
            
                e.printStackTrace();
            } 
        
        }

        
    public Connection getConnection() {
            Connection conn 
    = null;
            
    try {
                Class.forName(
    "com.mysql.jdbc.Driver").newInstance();

                
    // 建立到MySQL的連接
                conn = DriverManager.getConnection(
                        
    "jdbc:mysql://localhost:3306/ding""root""ding");
            } 
    catch (Exception e) {
                System.out.println(
    "數據庫連接異常!");
                e.printStackTrace();
            }
            
    return conn;
        }

        
    public ResultSet getResultSet(String sql, Connection conn) {
            ResultSet rs 
    = null;
            Statement stmt 
    = null;
            
    try {
                stmt 
    = conn.createStatement();
                rs 
    = stmt.executeQuery(sql);
            } 
    catch (Exception e) {
                e.printStackTrace();
            }
            
    return rs;
        }
    }

    最后這個是測試類

    public class TestMain {

        
    /**
         * @Description 方法實現功能描述
         * 
    @param args
         *            void
         * 
    @throws 拋出異常說明
         
    */
        
    public static void main(String[] args) {
            
    new TestMain().testBuildObject();
        }

        
    public void testBuildObject() {
            
    try {

                
    // 建立數據庫的連接
                DBConnection db = new DBConnection();

                
    // 查詢Sql語句
                String querySql = "select * from newitem";
                Connection conn 
    = db.getConnection();
        
                ResultSet rs 
    = db.getResultSet(querySql, conn);

                
    // 建立Rss生成器工廠
                RssBuildFactory builder = new RssBuildFactory();

                
    // 循環遍歷數據庫記錄生成Rss中的Item項
                while (rs.next()) {
                    ChannelEItem item 
    = new ChannelEItem();
                    item.setTitle(rs.getString(
    "title"));
                    item.setLink(rs.getString(
    "link"));
                    item.setDescription(rs.getString(
    "description"));
                    item.setPubDate(rs.getDate(
    "pubdate"));
                    item.setCategory(rs.getString(
    "category"));
                    item.setAuthor(rs.getString(
    "author"));
                    item.setEnclosure(rs.getString(
    "enclosure"));
                    builder.buildItems(item);
                }

                
    // 建立Rss的Channel信息
                builder.buildChannel("laoding的測試",
                        
    "http://www.tkk7.com/laoding/""測試生成""zh-cn",
                        
    new Date(), "老丁");

                
    // 設置Rss文件的生成路徑
                builder.buildChannel("demo.xml");
                System.out.println(
    "create rss xml success!!");
            } 
    catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    執行這個測試類,控制臺輸出:

    create rss xml success!!

    表示成功,生成的demo.xml文件如下:
    <?xml version="1.0" encoding="UTF-8"?>
    <rss xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
      
    <channel>
        
    <title>laoding的測試</title>
        
    <link>http://www.tkk7.com/laoding/</link>
        
    <description>測試生成</description>
        
    <language>zh-cn</language>
        
    <copyright>老丁</copyright>
        
    <pubDate>Wed, 22 Oct 2008 09:25:56 GMT</pubDate>
        
    <dc:date>2008-10-22T09:25:56Z</dc:date>
        
    <dc:language>zh-cn</dc:language>
        
    <dc:rights>老丁</dc:rights>
        
    <item>
          
    <title>title1</title>
          
    <link>http://www.tkk7.com/laoding</link>
          
    <description>laoding's javablog</description>
          
    <enclosure url="111" />
          
    <category>1111</category>
          
    <guid>http://www.tkk7.com/laoding</guid>
          
    <dc:creator>laoding</dc:creator>
        
    </item>
        
    <item>
          
    <title>title2</title>
          
    <link>http://www.tkk7.com/laoding</link>
          
    <description>laoding's javablog</description>
          
    <enclosure url="222" />
          
    <category>2222</category>
          
    <guid>http://www.tkk7.com/laoding</guid>
          
    <dc:creator>laoding</dc:creator>
        
    </item>
        
    <item>
          
    <title>333</title>
          
    <link>33333</link>
          
    <description>3333</description>
          
    <enclosure url="333" />
          
    <category>333</category>
          
    <guid>33333</guid>
          
    <dc:creator>33</dc:creator>
        
    </item>
        
    <item>
          
    <title>444</title>
          
    <link>44444</link>
          
    <description>44444</description>
          
    <enclosure url="4444" />
          
    <category>4444</category>
          
    <guid>44444</guid>
          
    <dc:creator>4444</dc:creator>
        
    </item>
      
    </channel>
    </rss>


    這個xml文件就是符合rss格式的,發布到web工程中就可以被RSS閱讀器訂閱了,嘿嘿

    具體的應用就要靠自己去擴展了,有疑問請留言。



    posted on 2008-10-22 17:29 老丁 閱讀(1033) 評論(3)  編輯  收藏 所屬分類: RSS聚合

    FeedBack:
    # re: 創建自己的rss
    2008-10-25 22:28 | Heinvo Lee
    I appriciate your article about RSS! I'll read it in detail later...  回復  更多評論
      
    # re: 創建自己的rss[未登錄]
    2009-03-16 17:08 | snow
    到哪下載呀,在網上搜了N久找不到。  回復  更多評論
      
    # re: 創建自己的rss[未登錄]
    2009-03-16 19:33 | 老丁
    @snow
    把你的郵箱告訴我,我發給你,你是要jar包么?  回復  更多評論
      

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    本博客主為學習和復習之用,無關其他,想罵人的繞道
    Email:dkm123456@126.com
    大家一起交流進步
    QQ:283582761


    <2008年10月>
    2829301234
    567891011
    12131415161718
    19202122232425
    2627282930311
    2345678

    留言簿(4)

    我參與的團隊

    文章分類(50)

    文章檔案(48)

    相冊

    朋友

    搜索

    •  

    積分與排名

    • 積分 - 96446
    • 排名 - 600

    最新評論

    主站蜘蛛池模板: 国产福利电影一区二区三区,亚洲国模精品一区 | 一级女人18片毛片免费视频| 午夜爱爱免费视频| 亚洲videosbestsex日本| 19禁啪啪无遮挡免费网站| 亚洲五月六月丁香激情| 特级无码毛片免费视频尤物| 亚洲成A人片在线观看无码不卡| 日本免费A级毛一片| 久久久无码精品亚洲日韩蜜桃| 亚洲成人免费在线| 亚洲成综合人影院在院播放| 岛国av无码免费无禁网站| 亚洲s码欧洲m码吹潮| 免费国产一级特黄久久| 一级特级女人18毛片免费视频| 伊人久久精品亚洲午夜| 三年片在线观看免费| 亚洲精彩视频在线观看| 两个人的视频高清在线观看免费 | 国产在线精品一区免费香蕉| 亚洲大成色www永久网站| 欧洲精品99毛片免费高清观看| 亚洲国产精品久久网午夜| 四虎免费大片aⅴ入口| 一级一看免费完整版毛片| 亚洲制服中文字幕第一区| 很黄很色很刺激的视频免费| 美女黄网站人色视频免费| 亚洲成a人片在线观看日本| 日本视频一区在线观看免费| 午夜亚洲国产理论片二级港台二级| 亚洲国产精品一区二区第四页| 久久这里只精品99re免费| 亚洲中文字幕无码久久| 国产亚洲精品AA片在线观看不加载 | 亚洲小视频在线观看| 在线不卡免费视频| 中国人免费观看高清在线观看二区 | 国产免费福利体检区久久| 亚洲日本在线播放|