Saturday, May 19, 2007

Reading RSS feeds with Java

If you were interested in incorporating RSS feeds into your java code you might want to have a look at Project Rome which is an open source java library for handling RSS feeds. Rome is currently in version 0.9 can be found at https://rome.dev.java.net/

I wrote a simple sample program which reads a given RSS feed and display some of the feed entries along with some attributes. It will also display the RSS version, as there are different versions of RSS. http://en.wikipedia.org/wiki/RSS_(file_format)

This simple program is the following:


import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndImageImpl;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.XmlReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import com.sun.syndication.feed.synd.SyndContentImpl;


/*
* 2 Required Jar files
* rome-0.9.jar retrieved from http://rome.dev.java.net/
* jdom.jar retrieved from http://www.jdom.org/
*/

public class RSSReader
{

public static void iterateRSSFeed(String rssFeedUrl)
{
try
{
//open up a connection to the rss feed

URLConnection feedUrl = new URL(rssFeedUrl).openConnection();

//Create Feed Object
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(feedUrl));

System.out.println("Examining rss feed:"+rssFeedUrl+"\n");

System.out.println("Feed type="+feed.getFeedType());

//Iterate through object to get details
List list = feed.getEntries();

System.out.println("Feed image="+feed.getImage());
if (feed.getImage()!=null)
{
SyndImageImpl image = (SyndImageImpl)feed.getImage();
String imageInfo = "Image url:"+image.getUrl()+"\n";
System.out.println(imageInfo);
}
for (int i=0 ; i < list.size(); i++){

//display entry attributes
SyndEntry entry = (SyndEntry)list.get(i);
String display = "Entry:"+i;
display += "\ntitle:"+entry.getTitle();
display += "\nlink:"+entry.getLink();
display += "\nauthor:"+entry.getAuthor();
display += "\npublished:"+entry.getPublishedDate();
display += "\nupdated:"+entry.getUpdatedDate();
display += "\ndescription:"+entry.getDescription();

display += "\ncontent size:"+entry.getContents().size();
if (entry.getContents().size()==1)
{
SyndContentImpl imp = (SyndContentImpl)entry.getContents().get(0);
display += "\ncontent value:"+imp.getValue();
}
display += "\n";
System.out.println(display);

}

}
catch(Exception e)
{
e.printStackTrace();
}

}


public static void main(String[] args) {

//James Gosling's blog
String rssFeedUrl = "http://blogs.sun.com/jag/feed/entries/rss";

//Mark Cuban's blog
//rssFeedUrl = "http://www.blogmaverick.com/rss.xml";

//rssFeedUrl = "http://techinitiatives.blogspot.com/feeds/posts/default";

//RSS 2.0
//rssFeedUrl = "http://weather.yahooapis.com/forecastrss?p=FRXX0076&u=c";

iterateRSSFeed(rssFeedUrl);


}
}

Wednesday, May 2, 2007

Developing Knowledge-Based Client Relationships

I just finished Ross Dawson's "Developing Knowledge-Based Client Relationships". I found it useful in understanding more of the business side of consulting and client relationships.

The book provides a couple of interesting definitions. "Information is anything that can be digitized, while knowledge is the capacity to act effectively, an attribute unique to people."p.96

Strategy in these types of client relationships is to evolve where the vendor and client integrate/collaborate at a high level to create higher levels of value creation.

A vendor should strive to avoid black box/commodity work and strive for the higher level knowledge based/collaborative solutions.

This was a good book for illuminating how to deal with clients strategically. Similar to "The Trusted Advisor". This was a good read before I dive back into more technical reads. :-)