1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.feedparser;
18
19 import java.io.FileInputStream;
20
21 import org.jdom.Element;
22
23
24
25
26
27
28
29
30
31
32 public class Test extends DefaultFeedParserListener
33 implements FeedParserListener,
34 ModContentFeedParserListener,
35 XHTMLFeedParserListener {
36
37
38
39
40
41
42
43
44 public void init() {
45 System.out.println( "init()" );
46 }
47
48 public void setContext( Object context ) {}
49
50
51
52
53
54
55 public void onChannel( FeedParserState state,
56 String title,
57 String link,
58 String description ) {
59
60 System.out.println( "onChannel: " );
61 System.out.println( "\t title: " + title );
62 System.out.println( "\t link: " + link );
63 System.out.println( "\t description: " + description );
64
65 }
66 public void onChannelEnd() {
67 System.out.println( "onChannelEnd()" );
68 }
69
70
71
72
73
74
75 public void onImage( FeedParserState state,
76 String title,
77 String link,
78 String url ) {
79
80 System.out.println( "onImage: " );
81 System.out.println( "\t title: " + title );
82 System.out.println( "\t link: " + link );
83 System.out.println( "\t url: " + url );
84
85 }
86
87 public void onImageEnd() {
88 System.out.println( "onImageEnd()" );
89 }
90
91
92
93
94
95
96 public void onItem( FeedParserState state,
97 String title,
98 String link,
99 String description,
100 String permalink ) {
101
102 System.out.println( "onItem: " );
103 System.out.println( "\t title: " + title );
104 System.out.println( "\t link: " + link );
105 System.out.println( "\t description: " + description );
106
107 }
108
109 public void onItemEnd() {
110
111 System.out.println( "onItemEnd()" );
112
113 }
114
115 public void finished() {
116 System.out.println( "finished()" );
117 }
118
119
120
121 public void onContentEncoded( FeedParserState state,
122 String value ) {
123
124 System.out.println( "onContentEncoded: " + value.length() + " bytes" );
125
126 }
127
128 public void onContentEncodedEnd() {
129 System.out.println( "onContentEncodedEnd" );
130 }
131
132 public void onContentItem( FeedParserState state,
133 String format,
134 String encoding,
135 Element value ) {
136
137 System.out.println( "onContentItem" );
138
139 }
140
141 public void onContentItemEnd() {
142 System.out.println( "onContentItemEnd" );
143 }
144
145
146
147 public void onXHTMLBody( FeedParserState state, Element value ) {
148 System.out.println( "onXHTMLBody" );
149 }
150
151 public void onXHTMLBodyEnd() {
152 System.out.println( "onXHTMLBodyEnd" );
153 }
154
155 public static void main( String[] args ) {
156
157 try {
158
159 FeedParser parser = FeedParserFactory.newFeedParser();
160
161
162
163
164
165 String path = "/projects/newsmonster/xml-tests/feedster.xml";
166
167 parser.parse( new Test(), new FileInputStream( path ), path );
168
169 } catch ( Throwable t ) {
170
171 t.printStackTrace();
172
173 }
174
175 }
176
177 }
178