internationalization - Watch for updated properties in Wicket -


in current project need implement way texters manage wicket messages/internationalization via upload of property files.

also see question: administrating internationalized wicket applications

as suggested there, i've implemented custom istringresourceloader , added @ beginning of stringresourceloader list override properties in place:

getresourcesettings().getstringresourceloaders().add(0, new customstringresourceloader());  

this not enough, because updates can happen , need loaded @ runtime. stringresources cached wicket , updated when resourcewatcher triggered.

i found wicket adds string resources watcher: propertiesfactory in settings. method add resource watcher addtowatcher(...). method protected , whole setup suggests used development purposes , not production.

i managed use method extending propertiesfactory , creating custom version add settings:

getresourcesettings().setpropertiesfactory(new custompropertiesfactory(getresourcesettings())); getresourcesettings().setresourcepollfrequency(duration.seconds(1)); 

so question is: feel quite circuitious solution. there way watch changing properties files?

my solution problem:

getresourcesettings().getstringresourceloaders().add(0, new customresourceloader()); getresourcesettings().getresourcefinders().add(new path("/pathtoresources")); getresourcesettings().setresourcepollfrequency(duration.seconds(1)); 

this inserts customresourceloader @ beginning of list properties first checked there.

the added path tells propertiesfactory resources in given arbitrary directory outside of wicket.

i needed custom names resource files well, realized in customresourceloader:

public string loadstringresource(final class<?> clazz, final string key, final locale locale, final string style, final string variation) {     final string myresourcefilename = createcustomresourcefilename(locale);      final ipropertiesfactory pf = application.get().getresourcesettings().getpropertiesfactory();     final org.apache.wicket.resource.properties props = pf.load(clazz, myresourcefilename);     ... } 

when using propertiesfactory load files, adds them internal imodificationwatcher automatically.

it turns out part of problem was, resource files in non-standard encoding. can fixed adding special ipropertyloader propertiesfactory in settings:

((propertiesfactory) getresourcesettings().getpropertiesfactory()).getpropertiesloaders().add(0,             new utfpropertiesfilepropertiesloader("properties", "your-favorite-encoding")); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -