Desktop RSS News Reader

Desktop News Reader is a fully configurable desktop tool developed in Java Swing to read news feeds and display as alerts.

Good knowledge in Java Swing and basic knowledge in XML.

RSS Feeds
RSS is a family of Web feed formats used to publish frequently updated content such as blog entries, news headlines, and podcasts in a standardized format. If you want to learn more about RSS, click here.

Desktop News Reader contains a property file, which stores all the feeds in the below given format:
feedUrl<feed url number>=<url>

Settings Reader
The class, is responsible for reading the settings from the property file and storing it in local variables. The code given below:

InputStream fileInputStream = this.getClass()
BufferedReader reader = new BufferedReader(
   new InputStreamReader(fileInputStream));
String line;
HashMap settingsMap = new HashMap();
while((line = reader.readLine())!= null) {
   if(line.length()>0 && line.indexOf("=")!= -1 
      && !line.startsWith("#"))
   settingsMap.put(line.substring(0, line.indexOf("="))
      .toLowerCase(), line.substring(line.indexOf("=")+1, 
Iterator keyIterator = settingsMap.keySet()
String key;
while(keyIterator.hasNext()) {
   key =;
   if(key.startsWith("feedurl")) {
Now, we have the feed urls and other settings in the SettingsManager class.

The Ticket Window
The class, which extends JWindow and implements HyperlinkListener and Runnable interfaces, is used for displaying the ticker window. The frameless window is achieved by extending the JWindow class. The news feeds appears as hyperlinks which is implemented using JEditorPane. The getJEditorPane() method contents is given below:
feedPane = new JEditorPane();
feedPane.setSize(new Dimension(0, 0));
feedPane.setBackground(new Color(255, 255, 204));
feedPane.add(getCloseButton());//Creates a close botton

The ticker window needs to be placed in the right bottom corner of the taskbar. This is achieved by using the method getMaximumWindowBounds() of GraphicsEnvironment, the code given below:
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
Rectangle r = ge.getMaximumWindowBounds();
Parsing the feed url
Now, we need to parse the urls read from the properties file and store it in a HashMap:
url = new URL(settingsManager.getFeedList().get(k));
urlConn = (HttpURLConnection) url.openConnection();
urlConn.setRequestProperty("User-Agent", "Mozilla/4.0");

Document doc = db.parse(urlConn.getInputStream());
NodeList feedList = doc.getElementsByTagName("item");

for(int i=0; i<feedList.getLength(); i++) {
   childList = feedList.item(i).getChildNodes();
   for(int j=0;j<childList.getLength(); j++){
         title = childList.item(j).getTextContent();
      else if(childList.item(j).getNodeName()
         description = childList.item(j).getTextContent();
      else if(childList.item(j).getNodeName().equals("link"))
         link = childList.item(j).getTextContent();
      else if(childList.item(j).getNodeName().equals("pubDate"))
         pubDate = childList.item(j).getTextContent();
   feedBean = new FeedBean(title, description, link, pubDate);
   feedMap.put(totalFeedCount, feedBean);
Displaying the ticker
The run() method reads one feed item at a time from the HashMap, updates the content of the JEditorPane and animates the JWindow. The duration, random selection and the position can be configured through the property file.
if(settingsManager.isMessageShuffle()) {
   feedCounter = new Random(System.currentTimeMillis())
} else {
   feedCounter = 0;
FeedBean feedBean = (FeedBean)feedMap.get(feedCounter);
feed = generateFeedHTML(feedBean);
for(int i=1;i<=settingsManager.getFeedPanelHeight(); i++) {
   setBounds(feedPanelLeft, r.height - i - 2, 
      settingsManager.getFeedPanelWidth() - 2, i);
if(isRunning) {
The working Desktop News Reader can be downloaded here.

Don't forget to update the file to include your proxy settings. Open the above jar file using WinZip, can be found in the base folder, open this file using any text editor and make necessary changes. Save and close WinZip. Open the Jar file using javaw.exe or run
java -jar DesktopNewsReader.jar
from the command prompt.
Desktop RSS News Reader Desktop RSS News Reader Reviewed by Editor on June 13, 2008 Rating: 5

No comments:

Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to our feed and get articles like this delivered automatically to your feed reader? Like our Facebook Page.

Powered by Blogger.