View Javadoc

1   /*
2    * Copyright 2004 Sun Microsystems, Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }