Re: Parsing Properties files

Marc Palmer <[email protected]> Sun, 17 Jul 2005 11:58:37 +0100
Newsgroups gmane.comp.java.webmacro.user
Organization AnyWare Ltd.
Message-ID <[email protected]>
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

-- 
Marc Palmer    [email protected]
			
Wangjammers - Java, J2ME and Web Consultants
   ~ http://www.wangjammers.org/



-------------------------------------------------------
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