Author: tchemit Date: 2008-05-29 20:47:38 +0000 (Thu, 29 May 2008) New Revision: 66 Added: trunk/lutinrss/src/main/java/org/codelutin/rss/RSSIOUtil.java Log: introduction classe utilitaire pour la construction et la sauvegarde de feed Added: trunk/lutinrss/src/main/java/org/codelutin/rss/RSSIOUtil.java =================================================================== --- trunk/lutinrss/src/main/java/org/codelutin/rss/RSSIOUtil.java (rev 0) +++ trunk/lutinrss/src/main/java/org/codelutin/rss/RSSIOUtil.java 2008-05-29 20:47:38 UTC (rev 66) @@ -0,0 +1,58 @@ +package org.codelutin.rss; + +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.io.FeedException; +import com.sun.syndication.io.SyndFeedInput; +import com.sun.syndication.io.SyndFeedOutput; +import com.sun.syndication.io.XmlReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import java.net.URL; + +/** + * helper to read or save a feed + * @author tony + */ +public class RSSIOUtil { + + /** + * Load a feed from his url + * @param url location of feed + * @return the java pojo feed + * @throws java.lang.IllegalArgumentException + * @throws com.sun.syndication.io.FeedException + * @throws java.io.IOException + */ + public static SyndFeed readFeed(URL url) throws IllegalArgumentException, FeedException, IOException { + SyndFeedInput input = new SyndFeedInput(); + SyndFeed feed = input.build(new XmlReader(url)); + return feed; + } + + /** + * save a feed into a file. + * @param f + * @param feed + * @throws java.io.IOException + * @throws com.sun.syndication.io.FeedException + */ + public static void saveFeed(File f, SyndFeed feed) throws IOException, FeedException { + + Writer writer = new BufferedWriter(new FileWriter(f)); + try { + SyndFeedOutput output = new SyndFeedOutput(); + output.output(feed, writer); + } finally { + if (writer != null) { + writer.close(); + } + } + } + + protected RSSIOUtil() { + // no instance + } +}