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

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

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

    Rory's Blog
    Happy study,Happy work,Happy life
    posts - 22,  comments - 46,  trackbacks - 0
    Rss,Atom,基本上是Web2.0的基本特征,今天終于有時間決定實現一下。對于動態的Rss,Atom其實就是選取最新的內容,迭迨一下生成一個固定格式的xml文件就可以了。其實也很簡單。
    ?????? 我用webwork2,用freemarker做模版,在網上找了一個標準的Rss2.0格式就生成我的模版文件rss.ftl
    <?xml?version="1.0"?encoding="UTF-8"?>
    <rss?version="2.0">
    <channel>
    <title><![CDATA[我的小站]]></title>
    <link>http://leaf.jdk.cn/</link>
    <description><![CDATA[泡出好心情,泡出好技術]]></description>
    <language>zh-cn</language>
    <copyright><![CDATA[Copyright?2006?PaoPao?v4.0]]></copyright>
    <webMaster><![CDATA[rory.cn@gmail.com?(Rory?Ye)]]></webMaster>
    <generator>PaoPao?v4.0</generator>?
    ????
    <image>
    ????????
    <title>我的小站</title>?
    ????????
    <url>http://leaf.jdk.cn/logo.gif</url>?
    ????????
    <link>http://leaf.jdk.cn</link>?
    ????????
    <description>莫多泡泡2006</description>?
    ????
    </image>
    ????
    <#list?blogs?as?blog>
    ????
    <item>
    ????????
    <link>http://leaf.jdk.cn/entry.action?entryId=${blog.id}</link>
    ????????
    <title><![CDATA[${blog.title}]]></title>
    ????????
    <author>${blog.authorMail}(${blog.author})</author>
    ????????
    <category><![CDATA[?${blog.categories}?]]></category>
    ????????
    <pubDate>${blog.pubDate}</pubDate>
    ????????
    <guid>http://leaf.jdk.cn/entry.action?id=${blog.id}</guid>????
    ????????
    <description><![CDATA[${blog.content}]]></description>
    ????
    </item>
    ????
    </#list>
    </channel>
    </rss>
    我在rss.action里面去取blogs就可以了。
    ????public?String?execute()?throws?Exception?{
    ????????PaginationSupport?ps?
    =?blogManager.getBlogsByPage(0);
    ????????blogs?
    =?new?ArrayList();
    ????????
    ????????
    for(Iterator?ite?=?ps.getItems().iterator();?ite.hasNext();){
    ????????????Blog?blog?
    =?(Blog)ite.next();
    ????????????WrapRssBlog?wrapBlog?
    =?new?WrapRssBlog();
    ????????????wrapBlog.setId(blog.getId());
    ????????????wrapBlog.setAuthor(blog.getAuthor().getNickname());
    ????????????wrapBlog.setAuthorMail(blog.getAuthor().getMail());
    ????????????wrapBlog.setTitle(blog.getTitle());
    ????????????wrapBlog.setContent(StringUtil.extractText(blog.getContent()));
    ????????????wrapBlog.setPubDate(DateUtil.formatRssDate(blog.getPostTime()));
    ????????????StringBuffer?sb?
    =?new?StringBuffer();
    ????????????
    for(Iterator?ite2?=?blog.getCategories().iterator();?ite2.hasNext();){
    ????????????????Category?cate?
    =?(Category)?ite2.next();
    ????????????????sb.append(
    "?")
    ??????????????????.append(cate.getName());
    ????????????}
    ????????????wrapBlog.setCategories(sb.toString());
    ????????????blogs.add(wrapBlog);
    ????????}
    ????????
    return?super.execute();
    ????}
    這里把blog包裝了一下,主要是處理了一下日期,內容,還有把分類拼成字符串。關于日期的處理,參考了飛云小俠寫的rss日期的研究。實現代碼如下。
    ????public?static?String?formatRssDate(Date?date){
    ????????SimpleDateFormat?sdf?
    =?new?SimpleDateFormat("EEE,?d?MMM?yyyy?HH:mm:ss?z",Locale.US);
    ????????
    //TODO?TimeZone
    ????????SimpleTimeZone?zone?=?new?SimpleTimeZone(8,"GMT");
    ????????sdf.setTimeZone(zone);
    ????????
    return?sdf.format(date);
    ????}
    這樣就得到了這樣的日期
    Thu, 6 Apr 2006 16:01:36 GMT
    做好了這些,配置一下action
    ????????<action?name="rss"?class="cn.jdk.leaf.action.RssAction">????????
    ????????????
    <result?name="success"?type="freemarker">/WEB-INF/pages/rss.ftl</result>
    ????????
    </action>
    不過像這樣配置的話,你訪問http://xxx.xxx.com/rss.action看到的不是一個xml
    因為返回結果的contentType是text/html.而不是xml,這樣是不行的。看了一下webwork源碼。原來可以這樣簡單的解決。改成這樣配置就可以了。
    ????????<action?name="rss"?class="cn.jdk.leaf.action.RssAction">
    ????????????
    <result?name="success"?type="freemarker">
    ????????????????
    <param?name="location">/WEB-INF/pages/rss.ftl</param>
    ????????????????
    <param?name="contentType">application/xml</param>
    ????????????
    </result>
    ????????
    </action>

    簡單吧。其實你還可以把這個contentType改成其他類型的。比如excle的。這樣用戶執行就可以得到一個xls文件。哈哈。
    posted on 2006-04-10 22:40 莫多 閱讀(1336) 評論(2)  編輯  收藏 所屬分類: Webwork

    FeedBack:
    # re: webwork+freemarker輕松實現Rss,Atom
    2007-03-30 16:27 | 曉菲

    Rory老師:您好!

    我是電子工業出版社博文視點的編輯曉菲,有幸在網上拜讀到您的大作,得知您比較喜歡RSS與Atom方面的知識。博文視點現在正在尋找《RSS and Atom in Action》一書的譯者,不知您是否有興趣。

    如果您愿意與博文視點關于此書進行更進一步的溝通,敬請您與我聯系,我的郵箱地址是:xiaofei@broadview.com.cn

    Thanks  回復  更多評論
      
    # re: webwork+freemarker輕松實現Rss,Atom
    2008-02-23 11:24 | nika
    This is website.a lot of guys can service for you , most skilled levelers and The price of power leveling. Give all customers the best and cheap price. The best and securest way to power level your character to your desired high level fast. the website already have done near a number of orders for wow power leveling and offers professional powerleveling service on most popular MMOGs.   回復  更多評論
      

    <2006年4月>
    2627282930311
    2345678
    9101112131415
    16171819202122
    23242526272829
    30123456

    常用鏈接

    留言簿(1)

    隨筆分類(27)

    隨筆檔案(22)

    Friends

    搜索

    •  

    積分與排名

    • 積分 - 62214
    • 排名 - 845

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 中国一级特黄高清免费的大片中国一级黄色片 | 亚洲人成77777在线播放网站| 中国亚洲呦女专区| 91情侣在线精品国产免费| 亚洲一区二区三区免费观看 | 99久久精品免费视频| 国产成人青青热久免费精品| 亚洲色在线无码国产精品不卡| 国产成人1024精品免费| 国产桃色在线成免费视频| 中文字幕 亚洲 有码 在线| 两个人的视频高清在线观看免费 | 中文字幕亚洲第一| 亚洲综合色一区二区三区| 成年人视频在线观看免费| 欧美亚洲国产SUV| 亚洲国产综合久久天堂| 久久国产乱子精品免费女| 免费jjzz在线播放国产| 亚洲日本久久久午夜精品| 女人让男人免费桶爽30分钟| 久久精品国产亚洲精品2020| 4444www免费看| 亚洲人成在线播放网站岛国| 88av免费观看| 亚洲精品无码久久| 亚洲成a人片在线观看老师| 丝袜足液精子免费视频| 亚洲欧洲精品在线| 国产又粗又猛又爽又黄的免费视频 | 三年片在线观看免费观看大全中国| 亚洲av无码专区在线观看素人| 丁香花在线观看免费观看图片| 亚洲综合日韩中文字幕v在线| 毛片免费全部播放一级| 国产一级在线免费观看| 亚洲一区在线观看视频| 久久亚洲精品无码播放| 国产91免费视频| 免费在线观看一区| 亚洲黄色三级视频|