1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.apache.commons.feedparser.test; |
18 | |
|
19 | |
import junit.framework.TestCase; |
20 | |
|
21 | |
import org.apache.commons.feedparser.DefaultFeedParserListener; |
22 | |
import org.apache.commons.feedparser.FeedParser; |
23 | |
import org.apache.commons.feedparser.FeedParserException; |
24 | |
import org.apache.commons.feedparser.FeedParserFactory; |
25 | |
import org.apache.commons.feedparser.FeedParserListener; |
26 | |
import org.apache.commons.feedparser.FeedParserState; |
27 | |
import org.apache.commons.feedparser.network.ResourceRequest; |
28 | |
import org.apache.commons.feedparser.network.ResourceRequestFactory; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
public class TestAtom extends TestCase { |
36 | |
|
37 | |
public TestAtom( String name ) throws Exception { |
38 | 0 | super( name ); |
39 | 0 | } |
40 | |
|
41 | |
public void doTest( String resource ) throws Exception { |
42 | |
|
43 | 0 | FeedParser parser = FeedParserFactory.newFeedParser(); |
44 | |
|
45 | 0 | FeedParserListener listener = new DefaultFeedParserListener() { |
46 | |
|
47 | |
public void onItem( FeedParserState state, |
48 | |
String title, |
49 | |
String weblog, |
50 | |
String description, |
51 | |
String permalink ) throws FeedParserException { |
52 | |
|
53 | 0 | System.out.println( "title: " + title ); |
54 | 0 | System.out.println( "description: " + description ); |
55 | 0 | System.out.println( "permalink: " + permalink ); |
56 | |
|
57 | 0 | } |
58 | |
|
59 | 0 | public void onItemEnd() {} |
60 | |
|
61 | 0 | public void finished() {} |
62 | |
|
63 | |
|
64 | |
|
65 | |
public void onSubject( FeedParserState state, String content ) |
66 | |
throws FeedParserException { |
67 | |
|
68 | 0 | System.out.println( "subject: " + content ); |
69 | |
|
70 | 0 | } |
71 | |
|
72 | |
public void onContent( FeedParserState state, |
73 | |
String type, |
74 | |
String format, |
75 | |
String encoding, |
76 | |
String mode, |
77 | |
String value ) throws FeedParserException { |
78 | |
|
79 | 0 | System.out.println( "content (type): " + type ); |
80 | 0 | System.out.println( "content (mode): " + mode ); |
81 | 0 | System.out.println( "content (value): " + value ); |
82 | |
|
83 | 0 | } |
84 | |
|
85 | |
}; |
86 | |
|
87 | 0 | listener.setContext( this ); |
88 | |
|
89 | 0 | ResourceRequest request = ResourceRequestFactory.getResourceRequest( resource ); |
90 | |
|
91 | 0 | parser.parse( listener, request.getInputStream(), resource ); |
92 | |
|
93 | 0 | } |
94 | |
|
95 | |
public void test1() throws Exception { |
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | 0 | doTest( "file:tests/feeds/atom-1.xml" ); |
101 | |
|
102 | 0 | } |
103 | |
|
104 | |
public static void main( String[] args ) throws Exception { |
105 | |
|
106 | 0 | TestAtom test = new TestAtom( null ); |
107 | |
|
108 | |
|
109 | 0 | test.test1(); |
110 | |
|
111 | 0 | } |
112 | |
|
113 | |
} |
114 | |
|