From: Lars G. <la...@wo...> - 2005-07-18 17:39:10
|
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 > |