1 17 package com.sun.syndication.fetcher.samples; 18 19 import java.io.PrintWriter ; 20 import java.net.URL ; 21 import java.util.ArrayList ; 22 import java.util.List ; 23 24 import com.sun.syndication.feed.synd.SyndFeedImpl; 25 import com.sun.syndication.feed.synd.SyndFeed; 26 import com.sun.syndication.fetcher.FeedFetcher; 27 import com.sun.syndication.fetcher.impl.FeedFetcherCache; 28 import com.sun.syndication.fetcher.impl.HashMapFeedInfoCache; 29 import com.sun.syndication.fetcher.impl.HttpURLFeedFetcher; 30 import com.sun.syndication.io.SyndFeedOutput; 31 32 42 public class FeedAggregator { 43 44 public static void main(String [] args) { 45 boolean ok = false; 46 if (args.length>=2) { 47 try { 48 String outputType = args[0]; 49 50 SyndFeed feed = new SyndFeedImpl(); 51 feed.setFeedType(outputType); 52 53 feed.setTitle("Aggregated Feed"); 54 feed.setDescription("Anonymous Aggregated Feed"); 55 feed.setAuthor("anonymous"); 56 feed.setLink("http://www.anonymous.com"); 57 58 List entries = new ArrayList (); 59 feed.setEntries(entries); 60 61 FeedFetcherCache feedInfoCache = HashMapFeedInfoCache.getInstance(); 62 FeedFetcher feedFetcher = new HttpURLFeedFetcher(feedInfoCache); 63 64 for (int i=1;i<args.length;i++) { 65 URL inputUrl = new URL (args[i]); 66 SyndFeed inFeed = feedFetcher.retrieveFeed(inputUrl); 67 entries.addAll(inFeed.getEntries()); 68 } 69 70 SyndFeedOutput output = new SyndFeedOutput(); 71 output.output(feed, new PrintWriter (System.out)); 72 73 ok = true; 74 } 75 catch (Exception ex) { 76 System.out.println("ERROR: "+ex.getMessage()); 77 ex.printStackTrace(); 78 } 79 } 80 81 if (!ok) { 82 System.out.println(); 83 System.out.println("FeedAggregator aggregates different feeds into a single one."); 84 System.out.println("The first parameter must be the feed type for the aggregated feed."); 85 System.out.println(" [valid values are: rss_0.9, rss_0.91, rss_0.92, rss_0.93, ]"); 86 System.out.println(" [ rss_0.94, rss_1.0, rss_2.0 & atom_0.3 ]"); 87 System.out.println("The second to last parameters are the URLs of feeds to aggregate."); 88 System.out.println(); 89 } 90 } 91 92 } 93 | Popular Tags |