2009年5月12日火曜日

[Java>Rome]Rome plugin module for twitter search RSS

Rome plugin module for twitter search RSS(Beta version 0.1)
  • References

  • Description
    the rss output of the twitter search is including the original elements like the twitter:source and twitter:lang tags. These tags are extended by the Twitter Search, so we need to use new plugin module to get the value of these tags by using the rome rss library.
  • Setups
    • Dwonload Jar file
      http://groups.google.com/group/taapps-sourcecode-libraries/web/tskr-twitter-rss-0.1-b1.jar
    • Put the downloaded jar file into the directory
    • Restart the application

  • Sample Program
    //import
    import com.sun.syndication.fetcher.FeedFetcher;
    import com.sun.syndication.fetcher.FetcherException;
    import com.sun.syndication.fetcher.impl.HttpURLFeedFetcher;
    import com.sun.syndication.feed.synd.SyndEntry;
    import com.sun.syndication.feed.synd.SyndFeed;
    import com.sun.syndication.io.FeedException;
    import java.io.IOException;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.util.List;

    //import rome module
    import com.sun.syndication.feed.module.Module;
    //import plugin new module
    import jp.tskr.feed.module.twitter.Twitter;

    public class TwSample{
    public static void main(String[] args){
    FeedFetcher feedFetcher=new HttpURLFeedFetcher();
    try{
    String urlStr="http://search.twitter.com/search.atom?q=iphone";
    URL feedUrl=new URL(urlStr);
    SyndFeed feedFetch=feedFetcher.retrieveFeed(feedUrl);

    for(SyndEntry entry : (List) feedFetch.getEntries()){
    System.out.format("\tUpdate:[%s] URL:[%s] Title:[%s]\n",entry.getPublishedDate(),entry.getLink(),entry.getTitle());

    //calling twitter search module
    Module module=entry.getModule(Twitter.URI);
    //checking the module object whether the object is instanceof Twitter class or not
    if(module instanceof Twitter){
    Twitter twModule=(Twitter)module;
    //get the value in the twitter search rss field
    String source=twModule.getSource();
    //get the value in the twitter search rss field
    String lang=twModule.getLang();
    }
    }
    }catch(Exception e){
    //.....
    }
    }
    }