net.mchaplin.commons.i18n
Class PropertyResourceHelper

java.lang.Object
  extended by net.mchaplin.commons.WmindObject
      extended by net.mchaplin.commons.i18n.PropertyResourceHelper
All Implemented Interfaces:
PropertyResourceHelperI

public class PropertyResourceHelper
extends WmindObject
implements PropertyResourceHelperI

Helper Class for reading messages from properties file. Keeps in memory ResourceBundle instances.

Author:
mchaplin@users.sourceforge.net $Header: $Revision: $Date:

Field Summary
 
Fields inherited from class net.mchaplin.commons.WmindObject
EX_CAUSE, EX_STACK, log, METHOD_CALL, propertyHelper, STACK_PREFIX
 
Constructor Summary
PropertyResourceHelper()
          Constructor for use with multiple resource bundles
PropertyResourceHelper(java.util.ResourceBundle resource)
          Constructor for usage with a unique resource bundle
PropertyResourceHelper(java.lang.String resource, java.lang.String locale)
          Constructor for usage with a unique resource bundle
 
Method Summary
 java.lang.String getMessage(java.lang.String key)
          To be used in unique resource bundle mode
 java.lang.String getMessage(java.lang.String propsFile, java.lang.String key)
          Retrieve a message in a properties file according to the given key
 java.lang.String getMessage(java.lang.String propsFile, java.lang.String key, java.lang.String locale)
          Retrieve a message in a properties file according to the given key & locale
 java.util.Map<java.lang.String,java.util.ResourceBundle> getMessageResources()
           
 void reset()
          For container use
static void writeBundleToDisk(java.lang.String fileName, java.util.HashMap<java.lang.String,java.lang.String> values)
          Write a ResourceBundle from Disk
 
Methods inherited from class net.mchaplin.commons.WmindObject
printInheritance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertyResourceHelper

public PropertyResourceHelper()
Constructor for use with multiple resource bundles


PropertyResourceHelper

public PropertyResourceHelper(java.lang.String resource,
                              java.lang.String locale)
Constructor for usage with a unique resource bundle

Parameters:
resource - resource bundle name
locale - ISO-639 locale to use

PropertyResourceHelper

public PropertyResourceHelper(java.util.ResourceBundle resource)
Constructor for usage with a unique resource bundle

Parameters:
resource - ResourceBundle instance to use
Method Detail

getMessage

public java.lang.String getMessage(java.lang.String key)
To be used in unique resource bundle mode

Specified by:
getMessage in interface PropertyResourceHelperI
Parameters:
key - key to lookup value for
Returns:
value of given key

getMessage

public java.lang.String getMessage(java.lang.String propsFile,
                                   java.lang.String key)
Retrieve a message in a properties file according to the given key

Specified by:
getMessage in interface PropertyResourceHelperI
Parameters:
propsFile - name of the property file to load message from
key - name of the key identifying the message
Returns:
message identified by key or ""

getMessage

public java.lang.String getMessage(java.lang.String propsFile,
                                   java.lang.String key,
                                   java.lang.String locale)
Retrieve a message in a properties file according to the given key & locale

Specified by:
getMessage in interface PropertyResourceHelperI
Parameters:
propsFile - name of the property file to load message from
key - name of the key identifying the message
locale - ISO-639 locale to use
Returns:
message identified by key or ""

writeBundleToDisk

public static void writeBundleToDisk(java.lang.String fileName,
                                     java.util.HashMap<java.lang.String,java.lang.String> values)
Write a ResourceBundle from Disk

Parameters:
fileName - file name of target Bundle.
values - Hashtable of key/values pair, which will be written in key=value format

getMessageResources

public java.util.Map<java.lang.String,java.util.ResourceBundle> getMessageResources()
Specified by:
getMessageResources in interface PropertyResourceHelperI

reset

public void reset()
Description copied from interface: PropertyResourceHelperI
For container use

Specified by:
reset in interface PropertyResourceHelperI
See Also:
net.mchaplin.ioc.ComponentI#reset()


Copyright © 2004-2005 mchaplin.net. All Rights Reserved.