Staxで今度こそRSSフィードを纏め上げる(後は文字コード問題)

このエントリをはてなブックマークに追加このエントリをはてなブックマークに追加このエントリをdel.icio.usに追加このエントリをLivedoor Clipに追加このエントリをLivedoor Clipに追加このエントリをYahoo!ブックマークに追加このエントリをFC2ブックマークに追加このエントリをNifty Clipに追加このエントリをPOOKMARK. Airlinesに追加このエントリをBuzzurl(バザール)に追加このエントリをBuzzurl(バザール)に追加このエントリをChoixに追加このエントリをnewsingに追加このエントリをkwoutに追加
2009年5月6日 水曜日1:14:32

TarotarorgFeedPage

package org.tarotaro.java.wicket.feed;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;

import org.apache.wicket.PageParameters;
import org.apache.wicket.Response;
import org.apache.wicket.markup.MarkupStream;
import org.apache.wicket.markup.html.WebPage;

import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.FeedException;
import com.sun.syndication.io.SyndFeedOutput;

public class TarotarorgFeedPage extends WebPage {

    private FeedManager feedManager;

    /**
     * @param parameters
     */

    public TarotarorgFeedPage(PageParameters parameters) {
        this.feedManager = new FeedManager();
        for(TarotarorgFeeds f:TarotarorgFeeds.values()) {
            try {
                this.feedManager.addFeed(new URL(f.getUri()));
            } catch (MalformedURLException e) {
               
            }
        }
    }

    @Override
    protected void onRender(MarkupStream markupStream) {
        Response resp = this.getResponse();
        resp.setContentType("application/xml; charset=UTF-8");
        PrintWriter pw = new PrintWriter(resp.getOutputStream());

        SyndFeedOutput sfo = new SyndFeedOutput();
        try {
            sfo.output(this.getFeed(), pw);
        } catch (IOException e) {
            throw new RuntimeException("Error Streaming Feed",e);
        } catch (FeedException e) {
            throw new RuntimeException("Error Streaming Feed",e);
        }
    }

    private SyndFeed getFeed() {
        SyndFeed sf = this.feedManager.getFeed();
        sf.setFeedType("rss_2.0");
        sf.setLanguage("japanese");
        sf.setTitle("tarotarorg feeds");
        sf.setLink("http://tfeed.tarotarorg.staxapps.net");
        sf.setDescription("all feeds of tarotarog");

        return sf;
    }

    @Override
    public String getMarkupType() {
        return "xml";
    }   
}

  • ページ:
  • 1
  • 2
  • 3
  • 4

TrackBack URL :

コメントする

HTML convert time: 1.172 sec.