Coverage Report - org.apache.commons.feedparser.Test
 
Classes in this File Line Coverage Branch Coverage Complexity
Test
0%
0/46
N/A
1.062
 
 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;
 18  
 
 19  
 import java.io.FileInputStream;
 20  
 
 21  
 import org.jdom.Element;
 22  
 
 23  
 /**
 24  
  * This FeedParser implementation is based on JDOM and Jaxen and is based around
 25  
  * XPath and JDOM iteration.  While the implementation is straight forward it
 26  
  * has not been optimized for performance.  A SAX based parser would certainly
 27  
  * be less memory intensive but with the downside of being harder to develop.  
 28  
  *
 29  
  * @author <a href="mailto:burton@apache.org">Kevin A. Burton (burtonator)</a>
 30  
  * @version $Id: Test.java 373614 2006-01-30 22:31:21Z mvdb $
 31  
  */
 32  0
 public class Test extends DefaultFeedParserListener
 33  
     implements FeedParserListener,
 34  
                ModContentFeedParserListener,
 35  
                XHTMLFeedParserListener {
 36  
 
 37  
     // **** FeedParserListener interface ****************************************
 38  
 
 39  
     /**
 40  
      * Called prior to event parsing to signal the parsing of a new feed.
 41  
      *
 42  
      * 
 43  
      */
 44  
     public void init() {
 45  0
         System.out.println( "init()" );
 46  0
     }
 47  
 
 48  0
     public void setContext( Object context ) {}
 49  
 
 50  
     /**
 51  
      * Called when a channel item is found.
 52  
      *
 53  
      * 
 54  
      */
 55  
     public void onChannel( FeedParserState state,
 56  
                            String title,
 57  
                            String link,
 58  
                            String description ) {
 59  
 
 60  0
         System.out.println( "onChannel: " );
 61  0
         System.out.println( "\t title: " + title );
 62  0
         System.out.println( "\t link: " + link );
 63  0
         System.out.println( "\t description: " + description );
 64  
 
 65  0
     }
 66  
     public void onChannelEnd() {
 67  0
         System.out.println( "onChannelEnd()" );
 68  0
     }
 69  
     
 70  
     /**
 71  
      * Called when an RSS image is found.
 72  
      *
 73  
      * 
 74  
      */
 75  
     public void onImage( FeedParserState state,
 76  
                          String title,
 77  
                          String link,
 78  
                          String url ) {
 79  
 
 80  0
         System.out.println( "onImage: " );
 81  0
         System.out.println( "\t title: " + title );
 82  0
         System.out.println( "\t link: " + link );
 83  0
         System.out.println( "\t url: " + url );
 84  
 
 85  0
     }
 86  
 
 87  
     public void onImageEnd() {
 88  0
         System.out.println( "onImageEnd()" );
 89  0
     }
 90  
 
 91  
     /**
 92  
      * Called when an RSS item or Atom entry is found. 
 93  
      *
 94  
      * 
 95  
      */
 96  
     public void onItem( FeedParserState state,
 97  
                         String title,
 98  
                         String link,
 99  
                         String description,
 100  
                         String permalink ) {
 101  
 
 102  0
         System.out.println( "onItem: " );
 103  0
         System.out.println( "\t title: " + title );
 104  0
         System.out.println( "\t link: " + link );
 105  0
         System.out.println( "\t description: " + description );
 106  
 
 107  0
     }
 108  
 
 109  
     public void onItemEnd() {
 110  
 
 111  0
         System.out.println( "onItemEnd()" );
 112  
 
 113  0
     }
 114  
 
 115  
     public void finished() {
 116  0
         System.out.println( "finished()" );
 117  0
     }
 118  
 
 119  
     // **** ModContentFeedParserListener interface ******************************
 120  
 
 121  
     public void onContentEncoded( FeedParserState state,
 122  
                                   String value ) {
 123  
 
 124  0
         System.out.println( "onContentEncoded: " + value.length() + " bytes" );
 125  
         
 126  0
     }
 127  
 
 128  
     public void onContentEncodedEnd() {
 129  0
         System.out.println( "onContentEncodedEnd" );
 130  0
     }
 131  
 
 132  
     public void onContentItem( FeedParserState state,
 133  
                                String format,
 134  
                                String encoding,
 135  
                                Element value ) {
 136  
 
 137  0
         System.out.println( "onContentItem" );
 138  
         
 139  0
     }
 140  
 
 141  
     public void onContentItemEnd() {
 142  0
         System.out.println( "onContentItemEnd" );
 143  0
     }
 144  
 
 145  
     // **** XHTMLBodyFeedParserListener interface *******************************
 146  
 
 147  
     public void onXHTMLBody( FeedParserState state, Element value ) {
 148  0
         System.out.println( "onXHTMLBody" );
 149  0
     }
 150  
 
 151  
     public void onXHTMLBodyEnd() {
 152  0
         System.out.println( "onXHTMLBodyEnd" );
 153  0
     }
 154  
 
 155  
     public static void main( String[] args ) {
 156  
 
 157  
         try { 
 158  
             
 159  0
             FeedParser parser = FeedParserFactory.newFeedParser();
 160  
 
 161  
             //String path = "/home/burton/.records/rss/index.rss";
 162  
             //String path = "/projects/newsmonster/xml-tests/aaronsw.xml";
 163  
             //String path = "/projects/newsmonster/xml-tests/intertwingly.rss2";
 164  
 
 165  0
             String path = "/projects/newsmonster/xml-tests/feedster.xml";
 166  
             
 167  0
             parser.parse( new Test(), new FileInputStream( path ), path );
 168  
             
 169  0
         } catch ( Throwable t ) {
 170  
             
 171  0
             t.printStackTrace();
 172  
             
 173  0
         }
 174  
         
 175  0
     }
 176  
 
 177  
 }
 178