Re: Parsing Properties files
Lars George <[email protected]> Mon, 18 Jul 2005 10:39:11 -0700
| Newsgroups | gmane.comp.java.webmacro.user |
|---|---|
| Message-ID | <[email protected]> |
Hi Marc,
Yes, that is a quick solution. What I am concerned about though is
performance and caching. If you would load the properties file on each
request, that seems to be not very efficient. I understand that your
example was just to illustrate the approach. What I would like to know
is what is the most efficient way to reuse WM to cache these properties
files? Should I simply use a broker and load the file using the getUrl()
methods? What would be your first thought on this?
Thanks,
Lars
Marc Palmer wrote:
> Lars George wrote:
>
>> Hi Keats,
>>
>>> I actually had a PropertyDirective years ago that did just what you
>>> are saying, but I've lost track of the code. (It never got committed
>>> to the core because nobody expressed interest.) There is some code
>>> in the core that parses expressions from the webmacro.properties
>>> file. I can point you to that if it is helpful.
>>
>>
>>
>> Any pointer is helpful :)
>
>
> Personally, I would just write my own helper class:
>
> public class MyPropertiesHelper
> {
> private Properties props;
>
> public void load( Object filepath)
> {
> FileInputStream fis = ...;
> props.clear();
> props.load( fis);
> }
>
> public Object get(Object key)
> {
> return props.getProperty(key.toString());
> }
>
> public Object put(Object key, Object value)
> {
> return props.setProperty(key.toString(), value.toString());
> }
> }
>
>
> An -new- instance of this can then be put into your context for every
> request, or you can wrap it in a contexttoolloader/factory so that you
> automatically get a new instance for every request.
>
> ...or you add a simple factory that you put into the context instead:
>
> public class MyPropertiesFactory
> {
> public MyPropertiesHelper newInstance(Object filename)
> {
> MyPropertiesHelper h = new MyPropertiesHelper();
> h.load(filename);
> return h;
> }
> }
>
> Cheers
>
-------------------------------------------------------
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