com.ibm.commerce.common.beans
Class ResourceBundleDataBean

com.ibm.commerce.common.beans.ResourceBundleDataBean

public class ResourceBundleDataBean

The ResourceBundleDataBean is used by JSPs to get information from property files. To find a property file, three parameters are needed:

  1. Property File Name
    The base name of the property file you want to look up. For example, "UserRegistrion" is the property file name for "UserRegistratoin_en_US.properties" or "UserRegistration_fr_FR.properties". This parameter is set by setPropertyFileName(String) method. This parameter is mandatory.
  2. Store Directory Name
    Different stores have different property files but these property file might have the same property file name. To avoid conflict, each store should have a directory to store their property files. To find a property file belong to a specific store, you need to use setStoreDirectory(String) method to set the name of the directory of that store.
    For example, there are two stores named store1 and store2. Then we nned to create two directories which contains the following files:
     store1/UserRegistration_en_US.properties
     store1/UserRegistration_fr_Fr.properties
     store2/UserRegistration_en_US.properties
     store2/UserRegistration_fr_Fr.properties
     
    To find the property files belong to store1, you need call setDirectoryName("store1") before you active the ResourceBundleDataBean.
    If the this parameter is not set, the databean will get the Store Directory from CommandContext.
    If you don't want the databean to automatically get the Store Directory from CommandContext, you can call setStoreDirectoryEnabled(false).
    If the databean can not find the property file in the store directory, it will automatically use just property file name to search this property file.
  3. Locale
    Locale is required to find property files of different languages. It can be set by setLocale(String) method. If no Locale is specified, the databean will get the Locale from CommandContext

After you set these parameters, you can get information of a property file using two methods:

  1. getPropertyHashtable()
    Returns a Hashtable which contains information converted from the property file. For the format of the Hashtable, refer to the description of this method.
  2. getPropertyResourceBundle()
    Returns a PropertyResourceBundle object from the property file.


Field Summary
static java.lang.String CLASSNAME
           
static java.lang.String ORDERNAME
           
 
Constructor Summary
ResourceBundleDataBean()
          ResourceBundleDataBean constructor.
 
Method Summary
 CommandContext getCommandContext()
           
 java.lang.String getDelimiter()
          Gets the delimiter for the property file.
 java.util.Locale getLocale()
          Gets the Locale.
 java.lang.String getPathSeparator()
          Gets the path separator.
 java.lang.String getPropertyFileName()
          Gets the name of property file
 java.util.Hashtable getPropertyHashtable()
          Return a the content of the property file as one large Hashtable.
 java.util.Hashtable getPropertyHashtable(java.util.SortedMap atmpProperty)
          Insert the method's description here.
 java.util.PropertyResourceBundle getPropertyResourceBundle()
          Return a PropertyResourceBundle object.
 java.util.SortedMap getPropertySortedMap()
          Return a the content of the property file as one large Hashtable.
 TypedProperty getRequestProperties()
           
 java.lang.String getSeparator()
          Gets the separator for the property file.
 java.lang.String getStoreDirectory()
          Gets the name of the store directory, which is used for finding property files belong to this store.
 boolean getStoreDirectoryEnabled()
          Gets a boolean which indicates if enable getting the Store Directory from the CommandContext.
static java.lang.String invokeGetMethod(java.lang.String astrClassName, java.lang.Object aobjAccessBean, java.lang.String astrParameterName)
          Insert the method's description here.
 void populate()
           
 void setCommandContext(CommandContext acommandContext)
           
 void setDelimiter(java.lang.String astrDelimiter)
          Sets the delimiter for the property file.
 void setLocale(java.util.Locale alcLocale)
          Set the Locale.
 void setPathSeparator(java.lang.String astrPathSeparator)
          Sets the path separator.
 void setPropertyFileName(java.lang.String astrPropertyFileName)
          Sets the name of property file.
 void setRequestProperties(TypedProperty areqParms)
           
 void setSeparator(java.lang.String astrSeparator)
          Sets the separator for the property file.
 void setStoreDirectory(java.lang.String astrStoreDirectory)
          Sets the name of store directory, which is used as the path to the find the property file.
 void setStoreDirectoryEnabled(boolean abStoreDirectoryEnabled)
          Sets if enable getting the Store Directory from the CommandContext.
static java.lang.String toUpOneChar(java.lang.String strAttributeName)
          Input parameter: attribute name return: method name (with uppercase first character) uppercase the first character of the attribute name in order to match with the naming convention of the underlying get/set method
 

Field Detail

CLASSNAME

public static final java.lang.String CLASSNAME

ORDERNAME

public static final java.lang.String ORDERNAME
Constructor Detail

ResourceBundleDataBean

public ResourceBundleDataBean()
ResourceBundleDataBean constructor.
Method Detail

getCommandContext

public CommandContext getCommandContext()

getDelimiter

public java.lang.String getDelimiter()
Gets the delimiter for the property file.
Delimiter is used to separate different options. For example, in the following property definiation,
 age.Options=0;Not Available|1;10-19 years|2;20-29 years
 
"|" is the delimitor.
Returns:
The delimiter for the property file

getLocale

public java.util.Locale getLocale()
Gets the Locale. The Locale will be used to find property file
Returns:
The Locale

getPathSeparator

public java.lang.String getPathSeparator()
Gets the path separator. path separator is used to separate the store directory and the property file name. For example:
 "store1/UserRegistration"
 
"/" is the path separator.
Returns:
The path separator

getPropertyFileName

public java.lang.String getPropertyFileName()
Gets the name of property file
Returns:
The name of the property file

getPropertyHashtable

public java.util.Hashtable getPropertyHashtable()

Return a the content of the property file as one large Hashtable. This Hashtable contains many field Hastables (each field corresponding to one small hashtable).

For example:

If you have a property file named UserRegistration_en_US.properties, which contains the following content:

 . . .
 children.Label=Number Of Children
 children.Displayed=yes
 children.Required=no

 age.Label=Age
 age.Displayed=yes
 age.Required=no
 age.Options=0;Not Available|1;10-19 years|2;20-29 years|3;30-39 years|4;40-49 years|5;50-59 years|6;60 years or older
 age.Operators=>Older than|<;Yonger than|!=;Not equal to

 gender.Label=Gender
 gender.Displayed=yes
 gender.Required=no
 gender.Options=Male|Female

 text1 = User Registration

 
. . .

Note:
| -- Default Delimiter (You can use setDelimiter(String) method to set a different Delimiter)
; -- Default Separator (You can use setSeparator(String) method to set a different Separator)

To read this file, following the following steps:

  1. Get the large hashtable:
     ResourceBundleDataBean bnResourceBundle= new ResourceBundleDataBean();
     bnResourceBundle.setPropertyFileName("UserRegistration");
     com.ibm.commerce.beans.DataBeanManager.activate(bnResourceBundle, request);
     Hashtable hshRegister = bnResourceBundle.getPropertyHashtable();
     
  2. Once you get the Hashtable, you can get small hashtable for each fields:
     Hashtable hshChildren = (Hashtable) hshRegister.get("children");
     Hashtable hshAge = (Hashtable) hshRegister.get("age");
     Hashtable hshGender = (Hashtable) hshRegister.get("gender");
     
    for the entry which only have attribute name, you can use the following code to get the value:
     String strTitle = (String) hshRegister.get("text1");
     
  3. Get attributes for each fields:

    • Text value is saved as String in field hashtable
      For example, the following code gets the Label for children field:
       String strChildrenLabel = (String)hshChildren.get("Label")
       
    • yes / no is saved as Boolean in field hashtable
      For example, the following code decides if childeren field should be displayed or not
       if (((Boolean)hshChildren.get("Displayed").booleanValue())
       {
        ...
       }
       
    • multiple value pairs will be store in a two dimensional String Array
      value pairs means internal value and display value, for example 0;Not Available ("0" is internal value, "Not" Available is display value) For example, the following code gets a array of all age optioins:
       String[ ][ ] ageOptions = (String[ ][ ])hshAge.get("Options");
       ageOptions[0][0] should be "0"	ageOptions[0][1] should be "Not Available"
       ageOptions[1][0] should be "1"	ageOptions[1][1] should be "10-19 years"
      
       If there is no separator, the internal value and display value will be same, for example
       String[ ][ ] genderOptions = (String[ ][ ])hshGender.get("Options");
       genderOptions[0][0] should be "Male"	genderOptions[0][1] should be "Male"
       genderOptions[1][0] should be "Famal"	genderOptions[1][1] should be "Female"
       
Returns:
A Hasthtable which contains informaiton from the property file

getPropertyHashtable

public java.util.Hashtable getPropertyHashtable(java.util.SortedMap atmpProperty)
Insert the method's description here. Creation date: (8/30/2001 10:52:29 AM)
Parameters:
atmpProperty - java.util.SortedMap
Returns:
java.util.Hashtable

getPropertyResourceBundle

public java.util.PropertyResourceBundle getPropertyResourceBundle()
Return a PropertyResourceBundle object.
Returns:
A PropertyResourceBundle object

getPropertySortedMap

public java.util.SortedMap getPropertySortedMap()

Return a the content of the property file as one large Hashtable. This Hashtable contains many field Hastables (each field corresponding to one small hashtable).

For example:

If you have a property file named UserRegistration_en_US.properties, which contains the following content:

 . . .
 children.Label=Number Of Children
 children.Displayed=yes
 children.Required=no

 age.Label=Age
 age.Displayed=yes
 age.Required=no
 age.Options=0;Not Available|1;10-19 years|2;20-29 years|3;30-39 years|4;40-49 years|5;50-59 years|6;60 years or older
 age.Operators=>Older than|<;Yonger than|!=;Not equal to

 gender.Label=Gender
 gender.Displayed=yes
 gender.Required=no
 gender.Options=Male|Female

 text1 = User Registration

 
. . .

Note:
| -- Default Delimiter (You can use setDelimiter(String) method to set a different Delimiter)
; -- Default Separator (You can use setSeparator(String) method to set a different Separator)

To read this file, following the following steps:

  1. Get the large hashtable:
     ResourceBundleDataBean bnResourceBundle= new ResourceBundleDataBean();
     bnResourceBundle.setPropertyFileName("UserRegistration");
     com.ibm.commerce.beans.DataBeanManager.activate(bnResourceBundle, request);
     Hashtable hshRegister = bnResourceBundle.getPropertyHashtable();
     
  2. Once you get the Hashtable, you can get small hashtable for each fields:
     Hashtable hshChildren = (Hashtable) hshRegister.get("children");
     Hashtable hshAge = (Hashtable) hshRegister.get("age");
     Hashtable hshGender = (Hashtable) hshRegister.get("gender");
     
    for the entry which only have attribute name, you can use the following code to get the value:
     String strTitle = (String) hshRegister.get("text1");
     
  3. Get attributes for each fields:

    • Text value is saved as String in field hashtable
      For example, the following code gets the Label for children field:
       String strChildrenLabel = (String)hshChildren.get("Label")
       
    • yes / no is saved as Boolean in field hashtable
      For example, the following code decides if childeren field should be displayed or not
       if (((Boolean)hshChildren.get("Displayed").booleanValue())
       {
        ...
       }
       
    • multiple value pairs will be store in a two dimensional String Array
      value pairs means internal value and display value, for example 0;Not Available ("0" is internal value, "Not" Available is display value) For example, the following code gets a array of all age optioins:
       String[ ][ ] ageOptions = (String[ ][ ])hshAge.get("Options");
       ageOptions[0][0] should be "0"	ageOptions[0][1] should be "Not Available"
       ageOptions[1][0] should be "1"	ageOptions[1][1] should be "10-19 years"
      
       If there is no separator, the internal value and display value will be same, for example
       String[ ][ ] genderOptions = (String[ ][ ])hshGender.get("Options");
       genderOptions[0][0] should be "Male"	genderOptions[0][1] should be "Male"
       genderOptions[1][0] should be "Famal"	genderOptions[1][1] should be "Female"
       
Returns:
A Hasthtable which contains informaiton from the property file

getRequestProperties

public TypedProperty getRequestProperties()

getSeparator

public java.lang.String getSeparator()
Gets the separator for the property file.
separator is used to separate internal value and display value in a option. For example, in the following property definiation,
 age.Options=0;Not Available|1;10-19 years|2;20-29 years
 
"1;10-19 years" is a option, ";" is the separator. If no separator is set, the databean will use the default one: ";".
Returns:
The separator for the property file

getStoreDirectory

public java.lang.String getStoreDirectory()
Gets the name of the store directory, which is used for finding property files belong to this store.
Returns:
The name of the store directory

getStoreDirectoryEnabled

public boolean getStoreDirectoryEnabled()
Gets a boolean which indicates if enable getting the Store Directory from the CommandContext. true - If Store Directory is not set, the databean will get from CommandContext false - The databean will never get the Store Directory from CommandContext
Returns:
A boolean value indicating if getting the Store Directory from the CommandContext

invokeGetMethod

public static java.lang.String invokeGetMethod(java.lang.String astrClassName,
                                               java.lang.Object aobjAccessBean,
                                               java.lang.String astrParameterName)
Insert the method's description here. Creation date: (2/26/2001 11:18:12 AM)
Parameters:
astrClassName - java.lang.String
astrParameterName - java.lang.String
Returns:
java.lang.String

populate

public void populate()

setCommandContext

public void setCommandContext(CommandContext acommandContext)

setDelimiter

public void setDelimiter(java.lang.String astrDelimiter)
Sets the delimiter for the property file.
Delimiter is used to separate different options. For example, in the following property definiation,
 age.Options=0;Not Available|1;10-19 years|2;20-29 years
 
"|" is the delimitor. If no Delimiter is set, the databean will use the default one: "|".
Parameters:
astrDelimiter - The delimiter for the property file

setLocale

public void setLocale(java.util.Locale alcLocale)
Set the Locale. This locale is used to find property file.
Parameters:
alcLocale - The Locale

setPathSeparator

public void setPathSeparator(java.lang.String astrPathSeparator)
Sets the path separator. path separator is used to separate the store directory and the property file name. For example:
 "store1/UserRegistration"
 
"/" is the path separator.
If path separator is not set, the databean will use the default one: "/" (working under Windows platform).
Parameters:
astrPathSeparator - The path separator

setPropertyFileName

public void setPropertyFileName(java.lang.String astrPropertyFileName)
Sets the name of property file. This is mandatory parameter for this DataBean.
Parameters:
astrPropertyFileName - The name of property file

setRequestProperties

public void setRequestProperties(TypedProperty areqParms)
                          throws java.lang.Exception

setSeparator

public void setSeparator(java.lang.String astrSeparator)
Sets the separator for the property file.
separator is used to separate internal value and display value in a option. For example, in the following property definiation,
 age.Options=0;Not Available|1;10-19 years|2;20-29 years
 
"1;10-19 years" is a option, ";" is the separator. If no separator is set, the databean will use the default one: ";".
Parameters:
astrSeparator - The separator for the property file

setStoreDirectory

public void setStoreDirectory(java.lang.String astrStoreDirectory)
Sets the name of store directory, which is used as the path to the find the property file. For example, if property files of a store is under the directory "store31" and the parent directory of "store31" directory is included in the class path, then this method should be called to set StoreDirectory to "store31". If the store directory is not set, ResourceBundleDataBean will try to get it from commandContext.
Parameters:
astrStoreDirectory - The name of store directory

setStoreDirectoryEnabled

public void setStoreDirectoryEnabled(boolean abStoreDirectoryEnabled)
Sets if enable getting the Store Directory from the CommandContext. true - If Store Directory is not set, the databean will get from CommandContext false - The databean will never get the Store Directory from CommandContext
Parameters:
abStoreDirectoryEnabled - A boolean value indicating if getting the Store Directory from the CommandContext

toUpOneChar

public static java.lang.String toUpOneChar(java.lang.String strAttributeName)
Input parameter: attribute name return: method name (with uppercase first character) uppercase the first character of the attribute name in order to match with the naming convention of the underlying get/set method