1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.betwixt.examples.rss;
19
20 import java.io.File;
21 import java.util.Iterator;
22
23 import org.apache.commons.betwixt.io.BeanReader;
24
25
26
27
28
29
30
31
32
33
34
35 public class RSSApplication {
36
37
38
39
40 public static void main(String args[]) throws Exception {
41 if (args.length != 1) {
42 System.err.println("Usage: <filename>");
43 System.exit(1);
44 }
45
46 RSSApplication rssApplication = new RSSApplication();
47 System.out.println(rssApplication.plainTextSummary(args[0]));
48 System.exit(0);
49 }
50
51 private BeanReader reader = new BeanReader();
52
53 public RSSApplication() throws Exception {
54 configure();
55 }
56
57 private void configure() throws Exception {
58 reader.registerBeanClass( Channel.class );
59 }
60
61 public String plainTextSummary(String filename) throws Exception {
62 return plainTextSummary(new File(filename));
63 }
64
65 public String plainTextSummary(File file) throws Exception {
66 Channel channel = (Channel) reader.parse(file);
67 return plainTextSummary(channel);
68 }
69
70
71 public String plainTextSummary(Channel channel) {
72 StringBuffer buffer = new StringBuffer();
73 buffer.append("channel: ");
74 buffer.append(channel.getTitle());
75 buffer.append('\n');
76 buffer.append("url: ");
77 buffer.append(channel.getLink());
78 buffer.append('\n');
79 buffer.append("copyright: ");
80 buffer.append(channel.getCopyright());
81 buffer.append('\n');
82
83 for (Iterator it = channel.getItems().iterator(); it.hasNext(); ) {
84 Item item = (Item) it.next();
85 buffer.append('\n');
86 buffer.append("title: ");
87 buffer.append(item.getTitle());
88 buffer.append('\n');
89 buffer.append("link: ");
90 buffer.append(item.getLink());
91 buffer.append('\n');
92 buffer.append("description: ");
93 buffer.append(item.getDescription());
94 buffer.append('\n');
95 }
96
97 return buffer.toString();
98 }
99 }