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