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 com.sun.syndication.feed.synd.SyndFeed;
20 import com.sun.syndication.io.SyndFeedInput;
21 import com.sun.syndication.io.SyndFeedOutput;
22 import com.sun.syndication.io.XmlReader;
23
24 import java.io.PrintWriter;
25 import java.net.URL;
26
27 /***
28 * It Converts any RSS/Atom feed type to a an RSS/Atom feed of the
29 * specified type.
30 * <p>
31 * @author Alejandro Abdelnur
32 *
33 */
34 public class FeedConverter {
35
36 public static void main(String[] args) {
37 boolean ok = false;
38 if (args.length==2) {
39 try {
40 String outputType = args[0];
41 URL feedUrl = new URL(args[1]);
42 SyndFeedInput input = new SyndFeedInput();
43
44 SyndFeed feed = input.build(new XmlReader(feedUrl));
45
46 feed.setFeedType(outputType);
47 SyndFeedOutput output = new SyndFeedOutput();
48 output.output(feed,new PrintWriter(System.out));
49
50 ok = true;
51 }
52 catch (Exception ex) {
53 System.out.println("ERROR: "+ex.getMessage());
54 }
55 }
56
57 if (!ok) {
58 System.out.println();
59 System.out.println("Converter converts between syndication feeds types.");
60 System.out.println("The first parameter must be the feed type to convert to.");
61 System.out.println(" [valid values are: rss_0.9, rss_0.91, rss_0.92, rss_0.93, ]");
62 System.out.println(" [ rss_0.94, rss_1.0, rss_2.0 & atom_0.3 ]");
63 System.out.println("The second parameter must be the URL of the feed to convert.");
64 System.out.println();
65 }
66 }
67
68 }