Coverage Report - org.apache.commons.feedparser.example.HelloFeedParser
 
Classes in this File Line Coverage Branch Coverage Complexity
HelloFeedParser
0%
0/11
0%
0/2
1.25
HelloFeedParser$1
0%
0/7
N/A
1.25
 
 1  
 /*
 2  
  * Copyright 1999,2004 The Apache Software Foundation.
 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 org.apache.commons.feedparser.example;
 18  
 
 19  
 import java.io.InputStream;
 20  
 import java.util.Date;
 21  
 
 22  
 import org.apache.commons.feedparser.DefaultFeedParserListener;
 23  
 import org.apache.commons.feedparser.FeedParser;
 24  
 import org.apache.commons.feedparser.FeedParserException;
 25  
 import org.apache.commons.feedparser.FeedParserFactory;
 26  
 import org.apache.commons.feedparser.FeedParserListener;
 27  
 import org.apache.commons.feedparser.FeedParserState;
 28  
 import org.apache.commons.feedparser.network.ResourceRequest;
 29  
 import org.apache.commons.feedparser.network.ResourceRequestFactory;
 30  
 
 31  
 /**
 32  
  * Example use of the FeedParser
 33  
  *
 34  
  * @author <a href="mailto:burton@apache.org">Kevin A. Burton (burtonator)</a>
 35  
  * @version $Id: HelloFeedParser.java 373622 2006-01-30 22:53:00Z mvdb $
 36  
  */
 37  0
 public class HelloFeedParser {
 38  
 
 39  
     public static void main( String[] args ) throws Exception {
 40  
 
 41  
         //create a new FeedParser...
 42  0
         FeedParser parser = FeedParserFactory.newFeedParser();
 43  
 
 44  
         //create a listener for handling our callbacks
 45  0
         FeedParserListener listener = new DefaultFeedParserListener() {
 46  
 
 47  
                 public void onChannel( FeedParserState state,
 48  
                                        String title,
 49  
                                        String link,
 50  
                                        String description ) throws FeedParserException {
 51  
 
 52  0
                     System.out.println( "Found a new channel: " + title );
 53  
 
 54  0
                 }
 55  
 
 56  
                 public void onItem( FeedParserState state,
 57  
                                     String title,
 58  
                                     String link,
 59  
                                     String description,
 60  
                                     String permalink ) throws FeedParserException {
 61  
 
 62  0
                     System.out.println( "Found a new published article: " + permalink );
 63  
                     
 64  0
                 }
 65  
 
 66  
                 public void onCreated( FeedParserState state, Date date ) throws FeedParserException {
 67  0
                     System.out.println( "Which was created on: " + date );
 68  0
                 }
 69  
 
 70  
             };
 71  
 
 72  
         //specify the feed we want to fetch
 73  
 
 74  0
         String resource = "http://peerfear.org/rss/index.rss";
 75  
 
 76  0
         if ( args.length == 1 )
 77  0
             resource = args[0];
 78  
 
 79  0
         System.out.println( "Fetching resource:" + resource );
 80  
         
 81  
         //use the FeedParser network IO package to fetch our resource URL
 82  0
         ResourceRequest request = ResourceRequestFactory.getResourceRequest( resource );
 83  
 
 84  
         //grab our input stream
 85  0
         InputStream is = request.getInputStream();
 86  
 
 87  
         //start parsing our feed and have the above onItem methods called
 88  0
         parser.parse( listener, is, resource );
 89  
 
 90  0
     }
 91  
 
 92  
 }
 93