1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.sun.syndication.samples;
18
19 import java.net.URL;
20 import java.util.List;
21 import java.util.ArrayList;
22
23 import com.sun.syndication.feed.synd.SyndFeedI;
24 import com.sun.syndication.feed.synd.SyndFeed;
25 import com.sun.syndication.io.SyndFeedOutput;
26 import com.sun.syndication.io.SyndFeedInput;
27
28 /***
29 * It aggregates a list of RSS/Atom feeds (they can be of different types)
30 * into a single feed of the specified type.
31 * <p>
32 * @author Alejandro Abdelnur
33 *
34 */
35 public class FeedAggregator {
36
37 public static void main(String[] args) {
38 boolean ok = false;
39 if (args.length>=2) {
40 try {
41 String outputType = args[0];
42
43 SyndFeedI feed = new SyndFeed();
44 feed.setFeedType(outputType);
45
46 feed.setTitle("Aggregated Feed");
47 feed.setDescription("Anonymous Aggregated Feed");
48 feed.setAuthor("anonymous");
49 feed.setLink("http://www.anonymous.com");
50
51 List entries = new ArrayList();
52 feed.setEntries(entries);
53
54 for (int i=1;i<args.length;i++) {
55 URL inputUrl = new URL(args[i]);
56
57 SyndFeedInput input = new SyndFeedInput();
58 SyndFeedI inFeed = input.build(inputUrl.openStream());
59
60 entries.addAll(inFeed.getEntries());
61
62 }
63
64 SyndFeedOutput output = new SyndFeedOutput();
65 output.output(feed,System.out);
66
67 ok = true;
68 }
69 catch (Exception ex) {
70 System.out.println("ERROR: "+ex.getMessage());
71 }
72 }
73
74 if (!ok) {
75 System.out.println();
76 System.out.println("FeedAggregator aggregates different feeds into a single one.");
77 System.out.println("The first parameter must be the feed type for the aggregated feed.");
78 System.out.println(" [valid values are: rss_0.9, rss_0.91, rss_0.92, rss_0.93, ]");
79 System.out.println(" [ rss_0.94, rss_1.0, rss_2.0 & atom_0.3 ]");
80 System.out.println("The second to last parameters are the URLs of feeds to aggregate.");
81 System.out.println();
82 }
83 }
84
85 }