Parsing Properties files

Lars George <[email protected]> Fri, 15 Jul 2005 12:22:59 -0700
Newsgroups gmane.comp.java.webmacro.user
Message-ID <[email protected]>
Hi,

Has someone of you written a parser for standard Java properties files, 
ie. so we can use .properties files to read in as templates?

I am interested to get a i18n framework going where the actual content 
is stored in properties files for easy localization. But I do not want 
to use the ResourceBundle framework of Java, which is clunky and a bit 
cumbersome. I rather would like to include those .properties directly 
into a template and have WebMacro parse it into context variables. For 
example:

hello.wm:
---------

#include "/res/$languagecode/hello.properties"

Hello $msg1!

hello.properties:
-----------------
msg1=World


This is very simple example, this could be extended to have the 
properties include figure out what is available and fall back to default 
file as performed by the ResourceBundle class, eg.

#include-res "res/hello.properties" $languagecode

Assume $languagecode="FR", then it would try to load and parse 
hello_fr.properties, if that is missing it is using hello.properties.

The advantage is to rely on Webmacro for caching and reloads, while the 
ResourceBundle cannot reload files ones they are loaded.

A parser could simply use a Properties class to read the file and add it 
to the context, even as a hashmap, so access would be like this

$hello.msg1

or the include directive could allow for a name that is given to the 
hashmap.

My main question is what to watch out for writing my own directive. 
Especially in terms of efficiency and caching.

Any pointers?

Thanks,
Lars



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click