com.ibm.commerce.usermanagement.commands
Class PropertyResourceBundleReader

java.lang.Object
  |
  +--com.ibm.commerce.usermanagement.commands.PropertyResourceBundleReader

public class PropertyResourceBundleReader
extends java.lang.Object

Read property file and output it as a Hashtable or SortedMap.

Hashtable

The Method readProperties is used to read from the property file with the following format and return results as a Hashtable. The 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:

SortedMap

The Method readSortedProperties is used to read from the property file with the following format and return results as a SortedMap. The SortedMap 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 (The number can be anything as long as they following the ascendent order):

 . . .
 100.Name=children
 100.Label=Number Of Children
 100.Displayed=yes
 100.Required=no
 100.Size=5
  
 105.Name=age
 105.Label=Age
 105.Displayed=yes
 105.Required=no
 105.Options=0;Not Provided|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
  
 110.Name=gender
 110.Label=Gender
 110.Displayed=yes
 110.Required=no
 110.Options=N;Not Provided|M;Male|F;Female

 Following are sample codes showing how to use SortedMap:

	ResourceBundleDataBean bnResourceBundle= new ResourceBundleDataBean();
	if (strProfileType != null && strProfileType.equals(ECUserConstants.EC_USER_PROFILE_BUSINESS))
		bnResourceBundle.setPropertyFileName("UserRegistrationB2B");
	else
		bnResourceBundle.setPropertyFileName("UserRegistration");
	com.ibm.commerce.beans.DataBeanManager.activate(bnResourceBundle, request);
	SortedMap smpFields = bnResourceBundle.getPropertySortedMap();
	Iterator entryIterator = smpFields.entrySet().iterator();
	Map.Entry textentry = (Map.Entry) entryIterator.next();
	Hashtable hshText = (Hashtable) textentry .getValue();


Field Summary
static java.lang.String CLASSNAME
           
static java.lang.String COPYRIGHT
           
 
Constructor Summary
PropertyResourceBundleReader()
           
 
Method Summary
static java.util.Hashtable readProperties(java.lang.String astrPropertyFileName)
          Gets the Hashtable from the properties file using the specified property file name.
static java.util.Hashtable readProperties(java.lang.String astrPropertyFileName, java.util.Locale alcLocale)
          Gets the Hashtable from the properties file using the specified property file name and locale.
static java.util.Hashtable readProperties(java.lang.String astrPropertyFileName, java.util.Locale alcLocale, java.lang.String astrDelimiter, java.lang.String astrSeparator)
          Gets the Hashtable from the properties file using the specified property file name, locale, delimiter and separater.
static java.util.SortedMap readSortedProperties(java.lang.String astrPropertyFileName)
          Gets the SortedMap from the properties file using the specified property file name.
static java.util.SortedMap readSortedProperties(java.lang.String astrPropertyFileName, java.util.Locale alcLocale)
          Gets the SortedMap from the properties file using the specified property file name and locale.
static java.util.SortedMap readSortedProperties(java.lang.String astrPropertyFileName, java.util.Locale alcLocale, java.lang.String astrDelimiter, java.lang.String astrSeparator)
          Gets the SortedMap from the properties file using the specified property file name, locale, delimiter and separater.
 java.util.SortedMap sortProperties(java.util.Hashtable ahshProperties)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASSNAME

public static final java.lang.String CLASSNAME

COPYRIGHT

public static final java.lang.String COPYRIGHT
Constructor Detail

PropertyResourceBundleReader

public PropertyResourceBundleReader()
Method Detail

readProperties

public static java.util.Hashtable readProperties(java.lang.String astrPropertyFileName)
Gets the Hashtable from the properties file using the specified property file name.

readProperties

public static java.util.Hashtable readProperties(java.lang.String astrPropertyFileName,
                                                 java.util.Locale alcLocale)
Gets the Hashtable from the properties file using the specified property file name and locale.

readProperties

public static java.util.Hashtable readProperties(java.lang.String astrPropertyFileName,
                                                 java.util.Locale alcLocale,
                                                 java.lang.String astrDelimiter,
                                                 java.lang.String astrSeparator)
Gets the Hashtable from the properties file using the specified property file name, locale, delimiter and separater.

readSortedProperties

public static java.util.SortedMap readSortedProperties(java.lang.String astrPropertyFileName)
Gets the SortedMap from the properties file using the specified property file name.

readSortedProperties

public static java.util.SortedMap readSortedProperties(java.lang.String astrPropertyFileName,
                                                       java.util.Locale alcLocale)
Gets the SortedMap from the properties file using the specified property file name and locale.

readSortedProperties

public static java.util.SortedMap readSortedProperties(java.lang.String astrPropertyFileName,
                                                       java.util.Locale alcLocale,
                                                       java.lang.String astrDelimiter,
                                                       java.lang.String astrSeparator)
Gets the SortedMap from the properties file using the specified property file name, locale, delimiter and separater.

sortProperties

public java.util.SortedMap sortProperties(java.util.Hashtable ahshProperties)