my recent reads..

Singapore wins!


Support Singapore YOG 2010
The perfect choice to host the inaugural Youth Olympic Games in 2010!
read more and comment..

Popflying the Oracle Community

Back last year I got all excited about Yahoo Pipes ( Web 2.0 Wake-up Call for BPEL? ) and its graphical approach to building mashups. In fact I still use a Pipes mashup as my mega-aggregated Oracle newsfeed.

Now I've discovered a new toy - Microsoft Popfly - and finally a reason to install Silverlight! I remember popfly getting mentioned in Bex Huff's roundup of mashup tools last year, but at the time it was still in restricted beta.

Popfly's still in beta, but now open to one and all. Put aside your biases for a minute and go play ... if you are like me, it will blow your mind. It may not be the final word in mashup tools, but it sure opens your mind to what should be possible.

Here's a little mashup I created 5 minutes up the learning curve. It's a cute display of the latest photos posted to the Oracle Community site:
Edit: popfly is no more; link to http://www.popfly.com/users/tardate/Oracle%20Community%20Photos.small is defunct.

Postscript: yes, you do need Silverlight installed for this to work of course. Silverlight is available for "all major browsers running on the Mac OS or Windows". If you are not prompted automatically for the Silverlight install, visit the Silverlight site.
read more and comment..

Supporting Singapore's bid to host the Youth Olympic Games 2010


I just discovered the online campaign to support Singapore’s bid for the Youth Olympic Games 2010. It would be truely great to see the event held here, and Signapore's certainly got the location, facilities, environment and culture to do a great job.

And to be fair, better chances than ever hosting the full Olympic Games!

So I've registered my support, and you'll see the logo flying on my blog from now on;-)

If you want to support the bid on your blog, just register here.

read more and comment..

On Parsing CSV and other Delimited/Quoted Formats

Parsing delimited text that may have quoted elements is a perennial requirement. Quick-and-dirty parses can be achieved with regular expressions, but for more flexible and encapsulated parsing I've been checking out the opencsv java library. Hat tip to Jakub Pawlowski for highlighting the library on his blog

A Regular Expression Approach
Just recently I released and blogged about a JDeveloper Filter Add-in, and it contains a class called ExecShell [API, source] which needs to know how to break a command line into its component arguments. The command line is of course space-delimited, but may use quotes to group an argument with embedded spaces (so a simple split on spaces won't do).

The salient code below uses the REGEX to chop theCmdLine String into theCmdArray Vector of arguments:

Vector<String> theCmdArray = new Vector<String>(0);
String REGEX = "\"([^\"]+?)\"\\s?|([^\\s]+)\\s?|\\s";
Pattern p = Pattern.compile(REGEX);
Matcher m = p.matcher(theCmdLine);
while (m.find())
{
theCmdArray.add( m.group().trim() );
}

The regular expression bears a little explaining, and is inspired by this example. Here's how it breaks down:

\"([^\"]+?)\"\\s?
Matches a group within double-quotes. Group is a lazy match on one or more characters except double-quote. Optionally followed by some whitespace
|([^\\s]+)\\s?or Matches a group delimited by whitespace, optionally followed by some whitespace
|\\sDiscards a pure whitespace match

In this case, we are using whitespace as the delimiter (appropriate for command lines). The regex can be adapted for other delimiters by replacing \\s with the delimiter. For example, to handle a comma-separated format:
String REGEX = "\"([^\"]+?)\",?|([^,]+),?|,";

Using OpenCSV
The same space-delimited parsing requirement can be met with a couple of lines and the opencsv library:
CSVReader reader = new CSVReader(new StringReader(theCmdArray), ' ');
String[] s = reader.readNext();

Simple, yet currently not so robust. Since we define the delimiter to be a single space (over-ridding the default comma), other whitespace characters (like a tab) will not be recognised. Further, repeated spaces will not be coalesced, but will each be treated as the delimiter for a new element.

Internally, CSVReader parses the input character-by-character and so adapting to handle repeated delimiters as one would be reasonably straight-forward.
read more and comment..