1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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.SyndFeed;
25 import com.sun.syndication.feed.synd.SyndFeedI;
26 import com.sun.syndication.fetcher.FeedFetcherI;
27 import com.sun.syndication.fetcher.impl.FeedFetcherCacheI;
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 /***
33 * <p>It aggregates a list of RSS/Atom feeds (they can be of different types)
34 * into a single feed of the specified type.</p>
35 *
36 * <p>Converted from the original FeedAggregator sample</p>
37 *
38 * @author Alejandro Abdelnur
39 * @author Nick Lothian
40 *
41 */
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 SyndFeedI feed = new SyndFeed();
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 FeedFetcherCacheI feedInfoCache = HashMapFeedInfoCache.getInstance();
62 FeedFetcherI feedFetcher = new HttpURLFeedFetcher(feedInfoCache);
63
64 for (int i=1;i<args.length;i++) {
65 URL inputUrl = new URL(args[i]);
66 SyndFeedI 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 }