1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.feedparser.example;
18
19 import org.apache.commons.feedparser.*;
20 import org.apache.commons.feedparser.impl.*;
21 import org.apache.commons.feedparser.network.*;
22
23 import java.io.*;
24 import java.net.*;
25 import java.util.*;
26
27 /***
28 * Example use of the FeedParser
29 *
30 * @author <a href="mailto:burton@apache.org">Kevin A. Burton (burtonator)</a>
31 * @version $Id: HelloFeedParser.java 155416 2005-02-26 13:00:10Z dirkv $
32 */
33 public class HelloFeedParser {
34
35 public static void main( String[] args ) throws Exception {
36
37
38 FeedParser parser = FeedParserFactory.newFeedParser();
39
40
41 FeedParserListener listener = new DefaultFeedParserListener() {
42
43 public void onChannel( FeedParserState state,
44 String title,
45 String link,
46 String description ) throws FeedParserException {
47
48 System.out.println( "Found a new channel: " + title );
49
50 }
51
52 public void onItem( FeedParserState state,
53 String title,
54 String link,
55 String description,
56 String permalink ) throws FeedParserException {
57
58 System.out.println( "Found a new published article: " + permalink );
59
60 }
61
62 public void onCreated( FeedParserState state, Date date ) throws FeedParserException {
63 System.out.println( "Which was created on: " + date );
64 }
65
66 };
67
68
69
70 String resource = "http://peerfear.org/rss/index.rss";
71
72 if ( args.length == 1 )
73 resource = args[0];
74
75 System.out.println( "Fetching resource:" + resource );
76
77
78 ResourceRequest request = ResourceRequestFactory.getResourceRequest( resource );
79
80
81 InputStream is = request.getInputStream();
82
83
84 parser.parse( listener, is, resource );
85
86 }
87
88 }
89