com.ibm.commerce.usermanagement.commands
Class PropertyResourceBundleReader
java.lang.Object
com.ibm.commerce.usermanagement.commands.PropertyResourceBundleReader
- public class PropertyResourceBundleReader
- extends java.lang.Object
/**
The PropertyResourceBundleReader is used by ResourceBundleDataBean and Member Subsystem command to find property file and reoganize the information of property files to diferent formats. To find a property file, three parameters are needed:
- 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.
- Store Directory Name
Different stores have their own property files but these property files 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.
If the store directory is set, the databean will only read property file from that directory.
If the store directory is not set, the databean will first look up the property file from the store relations of the current store (STOREREL table) using store relation type ("com.ibm.commerce.propertyFiles", defined in STRELTYP table). If the property file still can not be found, the databean will look up directly from class path.
- Locale
Locale is required to find property files of different languages. It can be set by setLocale(String) method. If Locale is not set, the databean will get the Locale from command context.
After these parameters are set and data bean is actived the informaiton in property file can be get using the follwong methods:
- public PropertyResourceBundle getPropertyResourceBundle()
This method can be used for any format of property file. It returns PropertyResourceBundle object.
- public SortedMap getPropertySortedMap()
This method is used to read from the property file with the following format and return results as a SortedMap.
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
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)
- public Hashtable getPropertyHashtable()
This method 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 . . .
Field Summary |
static java.lang.String |
CLASSNAME
The full qualified class name. |
static java.lang.String |
COPYRIGHT
IBM copyright. |
static java.util.Locale |
DEFALUT_LOCALE
The default locale used to find property file. |
static java.lang.String |
DEFAULT_DELIMITER
The deault delimiter used to separate different options. |
static java.lang.String |
DEFAULT_PATH_SEPARATOR
The default separator used to separate resource property file name and its path. |
static java.lang.String |
DEFAULT_SEPARATOR
The default separator used to separate internal value and display value in a option. |
Method Summary |
CommandContext |
getCommandContext()
Gets the command context. |
java.lang.String |
getDelimiter()
Gets the delimiter for the property file. |
java.lang.String |
getFoundPropertyFilePath()
Gets the found property file path. |
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()
Gets the reading result of the property file as a Hashtable. |
java.util.PropertyResourceBundle |
getPropertyResourceBundle()
Gets the reading result of the property file as a PropertyResourceBundle object. |
java.util.SortedMap |
getPropertySortedMap()
Gets the reading result of the property file as a SortedMap. |
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. |
java.util.PropertyResourceBundle |
getTextPropertyResourceBundle()
Gets the reading result of the text property file as a PropertyResourceBundle object. |
void |
read()
Gets the SortedMap from the properties file using the specified property file name, store directory, command context, locale, delimiter and separater. |
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. |
void |
setCommandContext(CommandContext acommandContext)
Sets the command context. |
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 |
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. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
COPYRIGHT
public static final java.lang.String COPYRIGHT
- IBM copyright.
- See Also:
- Constant Field Values
CLASSNAME
public static final java.lang.String CLASSNAME
- The full qualified class name.
- See Also:
- Constant Field Values
DEFAULT_PATH_SEPARATOR
public static final java.lang.String DEFAULT_PATH_SEPARATOR
- The default separator used to separate resource property file name and its path. For example, "store1/UserRegistration_en_US.properties".
- See Also:
- Constant Field Values
DEFAULT_DELIMITER
public static final java.lang.String DEFAULT_DELIMITER
- The deault delimiter 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, this default one will be used.
- See Also:
- Constant Field Values
DEFAULT_SEPARATOR
public static final java.lang.String DEFAULT_SEPARATOR
- The default separator 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, this default one will be used.
- See Also:
- Constant Field Values
DEFALUT_LOCALE
public static final java.util.Locale DEFALUT_LOCALE
- The default locale used to find property file.
PropertyResourceBundleReader
public PropertyResourceBundleReader()
setPropertyFileName
public void setPropertyFileName(java.lang.String astrPropertyFileName)
- Sets the name of property file. This is mandatory parameter.
-
- Parameters:
- astrPropertyFileName - The name of property file
getPropertyFileName
public java.lang.String getPropertyFileName()
- Gets the name of property file
-
- Returns:
- The name of 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
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
setLocale
public void setLocale(java.util.Locale alcLocale)
- Set the Locale. This locale is used to find property file.
-
- Parameters:
- alcLocale - The Locale
getLocale
public java.util.Locale getLocale()
- Gets the Locale. The Locale will be used to find property file
-
- Returns:
- The Locale
setCommandContext
public void setCommandContext(CommandContext acommandContext)
- Sets the command context. Command context is used to get the current store.
-
- Parameters:
- acommandContext - The command context.
getCommandContext
public CommandContext getCommandContext()
- Gets the command context. Command context is used to get the current store.
-
- Returns:
- The command context.
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
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
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
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
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
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
read
public void read()
- Gets the SortedMap from the properties file using the specified property file name, store directory, command context, locale, delimiter and separater. Property file name is mandatory, the rest of parameters are optional. If the store directory is not null, the PropertyResourceBundleReader will read the property file using store directory. If the property can not be found and the command context is not null, the PropertyResourceBundleReader will get the current store from command context and derive the store directory from its store relations. If both store directory and command context are null, the PropertyResourceBundleReader will read the property file directory from class path without using store directory. If locale is null and command context is not null, the PropertyResourceBundleReader will get the Locale from CommandContext. If command context is also null, then it wil use the default locale Locale.US.
-
- Returns:
- A SortedMap contains the parsed inforamtion of the property file. The structure of the SortedMap is described in the Java Doc of this class.
getFoundPropertyFilePath
public java.lang.String getFoundPropertyFilePath()
- Gets the found property file path. For example, "store1/UserRegistration_en_US.properties". If the property file is not found, null is returned.
-
- Returns:
- The found property file path.
getPropertyResourceBundle
public java.util.PropertyResourceBundle getPropertyResourceBundle()
- Gets the reading result of the property file as a PropertyResourceBundle object.
-
- Returns:
- A PropertyResourceBundle object
getTextPropertyResourceBundle
public java.util.PropertyResourceBundle getTextPropertyResourceBundle()
- Gets the reading result of the text property file as a PropertyResourceBundle object. The name of text property file is the name of the property file plus "Text" suffix. For example, if the name of the property file is "UserRegistration", then the name of the text property file is "UserRegistrationText".
-
- Returns:
- A PropertyResourceBundle object
getPropertySortedMap
public java.util.SortedMap getPropertySortedMap()
- Gets the reading result of the property file as a SortedMap. The key of the SortedMap is the ordering number of the field. The value is a Hashtable contains attribute names and values of the field.
-
- Returns:
- A SortedMap which contains informaiton of the property file.
getPropertyHashtable
public java.util.Hashtable getPropertyHashtable()
- Gets the reading result of the property file as a Hashtable. The key of the Hashtable is the name of the field. The value is a Hashtable contains attribute names and values of the field.
-
- Returns:
- A SortedMap which contains informaiton of the property file.
readProperties
public static java.util.Hashtable readProperties(java.lang.String astrPropertyFileName)
- Gets the Hashtable from the properties file using the specified property file name.
-
- Parameters:
- astrPropertyFileName - The property file name.
- Returns:
- The content of property file in the format of Hashtable.
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.
-
- Parameters:
- astrPropertyFileName - The base name of the property file.
- alcLocale - The Locale used to find the property file.
- Returns:
- The content of property file in the format of Hashtable.
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.
-
- Parameters:
- astrPropertyFileName - The base name of the property file.
- alcLocale - The Locale used to find the property file.
- astrDelimiter - The delimiter used to pasrse the property file.
- astrSeparator - The separator used to parse the property file.
- Returns:
- The content of property file in the format of Hashtable.
readSortedProperties
public static java.util.SortedMap readSortedProperties(java.lang.String astrPropertyFileName)
- Gets the SortedMap from the properties file using the specified property file name.
-
- Parameters:
- astrPropertyFileName - The base name of the property file.
- Returns:
- The content of property file in the format of SortedMap.
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.
-
- Parameters:
- astrPropertyFileName - The base name of the property file.
- alcLocale - The Locale used to find the property file.
- Returns:
- The content of property file in the format of SortedMap.
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.
-
- Parameters:
- astrPropertyFileName - The base name of the property file.
- alcLocale - The Locale used to find the property file.
- astrDelimiter - The delimiter used to pasrse the property file.
- astrSeparator - The separator used to parse the property file.
- Returns:
- The content of property file in the format of SortedMap.
Feedback
(C) Copyright IBM Corporation 1996, 2005. All Rights Reserved.