KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jperdian > rss2 > RssClient


1 /**
2  * RSS framework and reader
3  * Copyright (C) 2004 Christian Robert
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package org.jperdian.rss2;
21
22 import java.net.URL JavaDoc;
23
24 import org.jperdian.rss2.dom.RssChannel;
25
26 /**
27  * Implementation of a connector that can be used to read RSS channel data
28  * and transform them into a valid RSS DOM object
29  *
30  * @author Christian Robert
31  */

32
33 public class RssClient {
34
35   private RssParser myParser = new RssParser();
36   private URL JavaDoc myURL = null;
37   private String JavaDoc myKeywords = "";
38   private String JavaDoc myTitle = "";
39   
40   /**
41    * Creates a new client that receives it's data from the given URL
42    * @param url
43    * the <code>URL</code> from which to receive the data
44    */

45   public RssClient(URL JavaDoc url) {
46     this(url, "", "");
47   }
48   
49   /**
50    * Creates a new client that receives it's data from the given URL
51    * @param url
52    * the <code>URL</code> from which to receive the data
53    * @param keywords
54    * the keywords that can later be used for sorting
55    * @param title
56    * the title to be used for display
57    */

58   public RssClient(URL JavaDoc url, String JavaDoc keywords, String JavaDoc title) {
59     this.setURL(url);
60     this.setKeywords(keywords);
61     this.setTitle(title);
62   }
63   
64   /**
65    * Reads the data from the remote RSS source and create a new
66    * <code>RssChannel</code> object that contains the data that has been read
67    * @return
68    * the data in RSS DOM format
69    * @throws RssException
70    * thrown if the data is not in valid RSS format or the connection
71    * is unreachable
72    */

73   public final RssChannel getData() throws RssException {
74     RssChannel channel = new RssChannel(this);
75     channel.setClient(this);
76     this.loadData(channel);
77     return channel;
78   }
79   
80   /**
81    * Loads the data into the given <code>RssChannel</code>
82    */

83   public void loadData(RssChannel channel) throws RssException {
84     this.getParser().parse(this.getURL(), channel);
85     channel.setDataLoaded(true);
86     channel.setLastUpdate(System.currentTimeMillis());
87   }
88   
89   
90   // --------------------------------------------------------------------------
91
// -- Property access methods ---------------------------------------------
92
// --------------------------------------------------------------------------
93

94   /**
95    * Gets the <code>RssParser</code> through which the messages are analyzed
96    */

97   protected RssParser getParser() {
98     return this.myParser;
99   }
100   
101   /**
102    * Sets the <code>URL</code> from which to read the data
103    */

104   protected void setURL(URL JavaDoc url) {
105     this.myURL = url;
106   }
107
108   /**
109    * Gets the <code>URL</code> from which to read the data
110    */

111   public URL JavaDoc getURL() {
112     return this.myURL;
113   }
114   
115   /**
116    * Sets the keywords to be used for sorting the current client
117    */

118   protected void setKeywords(String JavaDoc keywords) {
119     this.myKeywords = keywords;
120   }
121
122   /**
123    * Gets the keywords to be used for sorting the current client
124    */

125   public String JavaDoc getKeywords() {
126     return this.myKeywords;
127   }
128   
129   /**
130    * Sets the title to be used for sorting the current client
131    */

132   protected void setTitle(String JavaDoc title) {
133     this.myTitle = title;
134   }
135
136   /**
137    * Gets the title to be used for sorting the current client
138    */

139   public String JavaDoc getTitle() {
140     return this.myTitle;
141   }
142   
143 }
Popular Tags