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.XmlReader;
22  
23  import java.net.URL;
24  
25  /***
26   * It Reads and prints any RSS/Atom feed type.
27   * <p>
28   * @author Alejandro Abdelnur
29   *
30   */
31  public class FeedReader {
32  
33      public static void main(String[] args) {
34          boolean ok = false;
35          if (args.length==1) {
36              try {
37                  URL feedUrl = new URL(args[0]);
38                  SyndFeedInput input = new SyndFeedInput();
39  
40                  SyndFeed feed = input.build(new XmlReader(feedUrl));
41  
42                  System.out.println(feed);
43  
44                  ok = true;
45              }
46              catch (Exception ex) {
47                  ex.printStackTrace();
48                  System.out.println("ERROR: "+ex.getMessage());
49              }
50          }
51  
52          if (!ok) {
53              System.out.println();
54              System.out.println("FeedReader reads and prints any RSS/Atom feed type.");
55              System.out.println("The first parameter must be the URL of the feed to read.");
56              System.out.println();
57          }
58      }
59  
60  }