|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.ibm.commerce.usermanagement.commands.PropertyResourceBundleReader
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:
ResourceBundleDataBean bnResourceBundle= new ResourceBundleDataBean(); bnResourceBundle.setPropertyFileName("UserRegistration"); com.ibm.commerce.beans.DataBeanManager.activate(bnResourceBundle, request); Hashtable hshRegister = bnResourceBundle.getPropertyHashtable();
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");
String strChildrenLabel = (String)hshChildren.get("Label")
if (((Boolean)hshChildren.get("Displayed").booleanValue()) { ... }
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"
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 |
public static final java.lang.String CLASSNAME
public static final java.lang.String COPYRIGHT
Constructor Detail |
public PropertyResourceBundleReader()
Method Detail |
public static java.util.Hashtable readProperties(java.lang.String astrPropertyFileName)
public static java.util.Hashtable readProperties(java.lang.String astrPropertyFileName, java.util.Locale alcLocale)
public static java.util.Hashtable readProperties(java.lang.String astrPropertyFileName, java.util.Locale alcLocale, java.lang.String astrDelimiter, java.lang.String astrSeparator)
public static java.util.SortedMap readSortedProperties(java.lang.String astrPropertyFileName)
public static java.util.SortedMap readSortedProperties(java.lang.String astrPropertyFileName, java.util.Locale alcLocale)
public static java.util.SortedMap readSortedProperties(java.lang.String astrPropertyFileName, java.util.Locale alcLocale, java.lang.String astrDelimiter, java.lang.String astrSeparator)
public java.util.SortedMap sortProperties(java.util.Hashtable ahshProperties)
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |