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