Skip to main content

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.

Pre-requisites
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, feedreader.properties which stores all the feeds in the below given format:
feedUrl<feed url number>=<url>
Example:
feedUrl1=http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/world/rss.xml
feedUrl2=http://www.ndtv.com/convergence/ndtv/rssnat.asp

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

InputStream fileInputStream = this.getClass()
   .getClassLoader()
   .getResourceAsStream("feedreader.properties");
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, 
      line.length()));
}
...
Iterator keyIterator = settingsMap.keySet()
   .iterator();
String key;
while(keyIterator.hasNext()) {
   key = keyIterator.next();
   if(key.startsWith("feedurl")) {
      feedList.add(settingsMap.get(key));
   }
}
Now, we have the feed urls and other settings in the SettingsManager class.

The Ticket Window
The class FeedReader.java, 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.setContentType("text/html");
feedPane.setEditable(false);
feedPane.setBackground(new Color(255, 255, 204));
feedPane.add(getCloseButton());//Creates a close botton

Positioning
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++){
      if(childList.item(j).getNodeName().equals("title"))
         title = childList.item(j).getTextContent();
      else if(childList.item(j).getNodeName()
            .equals("description"))
         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);
   totalFeedCount++;
   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())
      .nextInt(totalFeedCount);
} else {
feedCounter++;
if(feedCounter>=totalFeedCount)
   feedCounter = 0;
}
FeedBean feedBean = (FeedBean)feedMap.get(feedCounter);
feed = generateFeedHTML(feedBean);
feedPane.setText(feed);
setVisible(true);
//Animate
for(int i=1;i<=settingsManager.getFeedPanelHeight(); i++) {
   setBounds(feedPanelLeft, r.height - i - 2, 
      settingsManager.getFeedPanelWidth() - 2, i);
   Thread.sleep(30);
}
Thread.sleep(settingsManager.getMessageDuration());
if(isRunning) {
   setVisible(false);
   Thread.sleep(settingsManager.getMessageFrequency());
}
Downloads
The working Desktop News Reader can be downloaded here.

Don't forget to update the feedreader.properties file to include your proxy settings. Open the above jar file using WinZip, feedreader.properties 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.

Comments

Popular posts from this blog

HDFC Bank introduces Missed Call Service to know Account Balance

Missed call is a powerful business tool in developing countries like India where customers give a miss call to specific phone numbers for getting account details, providing feedback, voting etc. On receiving a missed call from a registered phone number, the underlying app performs a phone number lookup and sends the data to the caller via text message(SMS) or records the call details for future processing.HDFC Bank recently introduced missed call service for its retail customers which allows to retrieve bank account details, mini statement etc. by simply giving a miss call to their toll free numbers.Following services are now available: 1800 270 3333 - Account Balance 1800 270 3355 - Mini Statement 1800 270 3366 - Request for new Cheque Book 1800 270 3377 - Request for Bank account statement Also you can download HDFC Mobile Banking Application by giving a missed call to : 1800 270 3344. Other banks providing missed call serviceAxis bank(known as Axis Dial) - 09225892258Bank of India…

Induction Cooker Showing an Error Code? Induction Cooker Error Codes Explained

Are you searching for Induction Cook-top error codes? Here you can find the error codes of all popular induction cooktops and how to troubleshoot it.

These are for your reference only, do not try to open your cooktop without proper safety measures, we advise you to call the service person if any servicing is needed.

If you want to know how Induction Cook-top works, read our previous article titled What is Induction Cooker? How Induction Cooker Works?.

Whirlpool Induction Cooker Error CodesError CodeErrorSolutionF0An internal error was detected.Disconnect power. Wait 5 seconds before reconnecting power. If the symbol appears again, call for service.F2The surface cooking area is too hot and has turned off.Remove the pans from the surface cooking area. "F2" will disappear when the surface cooking area has cooled. If you turn the surface cooking area back on and "F2" reappears, the cooktop is still too hot. Turn off the surface cooking area and allow it to cool.F4The po…

LICHFL - Generating Home Loan Statements Online

Generating an online statement from LIC Housing Finance Ltd is very easy, simply follow the below steps to create an online account with LICHFL and generate statements online! You may use the online generated statement as a proof for principal paid for a housing loan(under section 80C) and interest paid(under section 24) while filing income tax returns.Want to know how to save maximum income tax? Read our most read article how to save maximum income tax(opens in new tab).Before reading further, make sure you have the following information with you: Your Loan Account NumberSanctioned AmountStep 1 - Open LICHFL websiteVisit LICHFL website and click on the 'New Customers? Click Here' link(refer the below screenshot). Step 2 - Enter your loan account detailsFill in the following details: New Loan NumberSanctioned AmountDate of BirthSecurity Codeand click on the Submit button. Step 3 - Enter your personal detailsEnter your email address, a username and password and click on submi…