-
1. Re: ResourceBundle: merging multiple properties file
rannath Jul 25, 2011 11:19 PM (in response to daniele_athome)I did it like so:
public class ExpandingResourceBundle extends ResourceBundle { private DataStructure lookup; public ExpandingResourceBundle(InputStream stream) { -read in from file using stream //PropertyResourceBundle uses HashMap(Properties) to make it work -store in lookup } public ExpandingResourceBundle(Reader reader) { -read in from file using reader //PropertyResourceBundle uses HashMap(Properties) to make it work -store in lookup } public Object handleGetObject(String key) { -return Object from lookup } public Enumeration getKeys() { return keysSet() of this an all parents //from Map or equivalent in your data structure } public void addResources(InputStream stream) { -read in from file using stream //PropertyResourceBundle uses HashMap(Properties) to make it work -add to in lookup } public void addResources(Reader reader) { -read in from file using stream //PropertyResourceBundle uses HashMap(Properties) to make it work -add to in lookup } protected Set handleKeySet() { -return keySet() of this only } }
I'll leave it as an exercise for you to do the actual implementation, though I would suggest googling code samples (I built this from the suggestions at: http://stackoverflow.com/questions/1318347/how-to-use-java-property-files with some error checking adding a boolean hasKey(str) as a wrapper around Propeties(Hashtable)'s containsKey(str)).
Not sure if this is the "right" way but it definately works.
-
2. Re: ResourceBundle: merging multiple properties file
daniele_athome Jul 26, 2011 3:54 AM (in response to rannath)Hi Patrick, thanks for answering.
Actually that was the solution I tried, but after that I realized that to use the .properties file natively from a portlet <resource-bundle> tag I had to modify the Properties class of java runtime, or otherwise a class inside GateIn itself, because of the way it works.
The portlet container first looks in the <resource-bundle> tag, checking if the fully-qualified name in the tag points to a Java class or to a properties file.
If it's the latter, the resource bundle loader (whatever class it is) loads the properties file using class Properties from the Java runtime.
Actually I succeded (out of curiosity) to modify the native Properties class and it actually works, using a special property key name "include" which loads another properties file (the path taken from the property value). But it's a bit odd - I mean modifying java runtime. Properties file should have native support for external file inclusion.
Anyway, for the moment, I wrote a servlet which, at application startup, merges two or more properties files into one big properties file; so when GateIn will read bundles, it will find the whole properties files just created by the servlet.
-
3. Re: ResourceBundle: merging multiple properties file
hoang_to Aug 1, 2011 3:13 AM (in response to daniele_athome)GateIn PC supports extending resource bundle of portlets. A side of resources defined in portlet definition 's <resource-bundle> element, .properties files having path defined as "sharedResourceBundle" of ResourceBundleService are made accessible from portlet.
So to fullfill your wish, an aleternative way is to declared .properties file of your parent portlet as "sharedResourceBundle" in ResourceBundleService.
The drawback is that the shared resource are visible from every portlet
-
4. Re: ResourceBundle: merging multiple properties file
daniele_athome Aug 1, 2011 5:57 AM (in response to hoang_to)Thank you Minh, but that still doesn't fit my case, sorry.
However, I decided to apply a small patch to GateIn 3.1.0. I didn't optimize it at all, my primary concern was to modify as little code as possible (configuring the whole GateIn project in Eclipse is a very hard work).
The patch makes the class PropertiesClassLoader to load another .properties file if it finds an "include" property key. The value of that key will be used to load the other bundle file, using it as the parent bundle.
I've attached my patch to this message.
Thank you
-
01-multiproperties_bundle.diff.zip 588 bytes
-
-
5. Re: ResourceBundle: merging multiple properties file
daniele_athome Oct 26, 2012 8:29 AM (in response to daniele_athome)Here is an updated and tested version of my patch. It was tested against GateIn 3.1.0 and 3.2.0.
The patch makes the class PropertiesClassLoader to load another .properties file if it finds an "include" property key. The value of that key will be used to load the other bundle file, using it as the parent bundle.
-
01-multiproperties_bundle.diff.zip 788 bytes
-