On 09-06-2010 at 04:08, Daniel Cane wrote:
> Please point me in the right direction on how to create a db backed resource
> bundle and us it with stripes. I found a few links to the stripes book's 
> (which
> I own -- good book) blog, but those have been removed. I have extended
> runtimeConfiguration and impl my own localizationBundleFactory, now I just 
> need
> a pointer or two on how to create a DB backed system which returns 
> ResourceBundles. 

Your best bet is to ignore the static methods in ResourceBundle, and to
create a subclass that:
- Retrieves the data from the database
- Implements the abstract methods getKeys() and getObject(String)
  Note that the methods getString(String) and getStringArray(String) use
  getObject(String) and perform a cast.

Personally I prefer to initialize such a ResourceBundle in the constructor,
but your application design is the only requirement here.

As for the database, I usually ensure that all records have the fields
matching the Locale class (language, country, and sometimes also variant), a
label and the actual text. Furthermore, I ensure all fields are set for all
records. This makes potential queries a _lot_ easier.

Any search has it's requested Locale augmented with defaults (e.g. "en"
becomes "en_US", "nl" becomes "nl_NL", "nl_BE" remains "nl_BE" and "" becomes
"en_US"). At this point I also check if the Locale is supported. After that,
the actual query is plain, and its result easily cachable:
  SELECT t.text FROM Translation t WHERE t.label=:label
   AND t.language=:language AND t.country = :country
   AND t.variant = :variant;


> BTW - my requirement is to be able to programatically append to the bundle and
> messing around with the .properties file triggers all sorts of nasty things 
> like
> spontaneous reloads.. If there is an alt solution, I'm all ears.

For performance, you'll find you do need to cache the texts your
ResourceBundle provides. By invalidating the cache, say, each half hour if
there are changes to the translations in the database.


Oscar

-- 
   ,-_  Oscar Westra van Holthe - Kind      http://www.xs4all.nl/~kindop/
  /() )
 (__ (  It takes less time to do a thing right, than it does to explain why
=/  ()  you did it wrong.  -- Henry Wadsworth Longfellow

Attachment: signature.asc
Description: Digital signature

------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to