KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > betwixt > examples > rss > RSSApplication


1 /*
2  * Copyright 2004,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
18 package org.apache.commons.betwixt.examples.rss;
19
20 import java.io.File JavaDoc;
21 import java.util.Iterator JavaDoc;
22
23 import org.apache.commons.betwixt.io.BeanReader;
24
25
26 /**
27  * <p>Example application using Betwixt to process RSS 0.91.
28  * The intention is to provide illumination and education
29  * rather than providing a .</p>
30  *
31  * @author Robert Burrell Donkin
32  * @version $Revision: 1.5 $ $Date: 2004/06/13 21:32:47 $
33  */

34
35 public class RSSApplication {
36
37     /**
38      *
39      */

40     public static void main(String JavaDoc args[]) throws Exception JavaDoc {
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 JavaDoc {
54         configure();
55     }
56     
57     private void configure() throws Exception JavaDoc {
58         reader.registerBeanClass( Channel.class );
59     }
60     
61     public String JavaDoc plainTextSummary(String JavaDoc filename) throws Exception JavaDoc {
62         return plainTextSummary(new File JavaDoc(filename));
63     }
64     
65     public String JavaDoc plainTextSummary(File JavaDoc file) throws Exception JavaDoc {
66         Channel channel = (Channel) reader.parse(file);
67         return plainTextSummary(channel);
68     }
69     
70     
71     public String JavaDoc plainTextSummary(Channel channel) {
72         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
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 JavaDoc 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 }
100
Popular Tags