public class PropertyResourceBundleReader
extends java.lang.Object
The PropertyResourceBundleReader is used by the ResourceBundleDataBean and Member Subsystem commands to find property files and reorganize the information of property files to different formats. To find a property file, three parameters are needed:
After these parameters are set and the data bean is activated, the information in the property file can be retrieved using the following methods:
public PropertyResourceBundle getPropertyResourceBundle()
public SortedMap getPropertySortedMap()
If you have a property file named UserRegistration_en_US.properties that contains the
following content (the number can be anything, but must be in ascendent order):
Note:
For example:
If you have a property file named UserRegistration_en_US.properties, which contains the
following content:
. . .
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
| -- 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 Hashtables (each field corresponding to one small
hashtable).
. . .
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
. . .
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CLASSNAME
The 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 default 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 an option.
|
Constructor and Description |
---|
PropertyResourceBundleReader() |
Modifier and Type | Method and Description |
---|---|
CommandContext |
getCommandContext()
Gets the command context.
|
java.lang.String |
getDelimiter()
Gets the delimiter for the property file.
|
java.lang.String |
getFoundPropertyFilePath()
Gets the path for the property file that was found.
|
java.util.Locale |
getLocale()
Gets the Locale.
|
java.lang.String |
getPathSeparator()
Gets the path separator, that is used to separate the store directory
and the property file name.
|
java.lang.String |
getPropertyFileName()
Gets the name of property file.
|
java.util.Hashtable |
getPropertyHashtable()
Gets the property file as a
Hashtable . |
java.util.PropertyResourceBundle |
getPropertyResourceBundle()
Gets the property file as a
PropertyResourceBundle object. |
java.util.SortedMap |
getPropertySortedMap()
Gets 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
belonging to this store.
|
java.util.PropertyResourceBundle |
getTextPropertyResourceBundle()
Gets 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 separator.
|
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 separator.
|
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 separator.
|
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, that is used to separate the store directory
and the property file name.
|
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.
|
public static final java.lang.String COPYRIGHT
public static final java.lang.String CLASSNAME
public static final java.lang.String DEFAULT_PATH_SEPARATOR
store1/UserRegistration_en_US.properties
".public static final java.lang.String DEFAULT_DELIMITER
age.Options=0;Not Available|1;10-19 years|2;20-29 years
"|" is the delimiter.
If no delimiter is set, this default one will be used.public static final java.lang.String DEFAULT_SEPARATOR
age.Options=0;Not Available|1;10-19 years|2;20-29 years
"1;10-19 years" is an option, ";" is the separator.
If no separator is set, this default one will be used.public static final java.util.Locale DEFALUT_LOCALE
public void setPropertyFileName(java.lang.String astrPropertyFileName)
astrPropertyFileName
- The name of property filepublic java.lang.String getPropertyFileName()
public void setStoreDirectory(java.lang.String astrStoreDirectory)
store31
and
the parent directory of store31
directory is included in the class path,
then this method should be called to set the store directory to store31
.
If the store directory is not set, ResourceBundleDataBean will try to get it
from the commandContext.astrStoreDirectory
- The name of store directorypublic java.lang.String getStoreDirectory()
public void setLocale(java.util.Locale alcLocale)
alcLocale
- The Localepublic java.util.Locale getLocale()
public void setCommandContext(CommandContext acommandContext)
acommandContext
- The command context.public CommandContext getCommandContext()
public void setDelimiter(java.lang.String astrDelimiter)
age.Options=0;Not Available|1;10-19 years|2;20-29 years
"|" is the delimiter.
If no Delimiter is set, the databean will use the default
one: "|".astrDelimiter
- The delimiter for the property filepublic java.lang.String getDelimiter()
age.Options=0;Not Available|1;10-19 years|2;20-29 years
"|" is the delimiter.public void setSeparator(java.lang.String astrSeparator)
age.Options=0;Not Available|1;10-19 years|2;20-29 years
"1;10-19 years" is an option, ";" is the separator.
If no separator is set, the databean will use the default
one: ";".astrSeparator
- The separator for the property filepublic java.lang.String getSeparator()
age.Options=0;Not Available|1;10-19 years|2;20-29 years
"1;10-19 years" is an option, ";" is the separator.
If no separator is set, the databean will use the default
one: ";".public void setPathSeparator(java.lang.String astrPathSeparator)
"store1/UserRegistration"
"/" is the path separator.astrPathSeparator
- The path separatorpublic java.lang.String getPathSeparator()
"store1/UserRegistration"
"/" is the path separator.public void read()
Locale.US
.astrPropertyFileName
- The base name of the property file you want to look up. For example, "UserRegistration"
is the property file name for "UserRegistration_en_US.properties" or
"UserRegistration_fr_FR.properties".astrStoreDirectory
- Different stores may have different 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, this parameter must be set.
store1
and store2
. Then we need to create two directories which contain 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, this parameter needs to be set to store1
.commandContext
- The PropertyResourceBundleReader uses the command context to get the current store and find the store directory
from its store relations.alcLocale
- Locale is used to find property files for different languages.astrDelimiter
- The delimiter for the property file. The delimiter is used to separate different options.
For example, in the following property definition:
age.Options=0;Not Available|1;10-19 years|2;20-29 years
"|" is the delimiter.
If no delimiter is set, the default one "|" will be used.astrSeparator
- 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 definition:
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 default one ";" will be used.public java.lang.String getFoundPropertyFilePath()
store1/UserRegistration_en_US.properties
.public java.util.PropertyResourceBundle getPropertyResourceBundle()
PropertyResourceBundle
object.public java.util.PropertyResourceBundle getTextPropertyResourceBundle()
PropertyResourceBundle
object. The name of the 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".public java.util.SortedMap getPropertySortedMap()
SortedMap
. The key of the SortedMap
is the ordering
number of the field. The value is a Hashtable
containing attribute names and values of the
field.SortedMap
which contains information from the property file.public java.util.Hashtable getPropertyHashtable()
Hashtable
. The key of the Hashtable
is the name of
the field. The value is a Hashtable
containing attribute names and values for the field.SortedMap
which contains information from the property file.public static java.util.Hashtable readProperties(java.lang.String astrPropertyFileName)
astrPropertyFileName
- The property file name.public static java.util.Hashtable readProperties(java.lang.String astrPropertyFileName, java.util.Locale alcLocale)
astrPropertyFileName
- The base name of the property file.alcLocale
- The Locale used to find the property file.public static java.util.Hashtable readProperties(java.lang.String astrPropertyFileName, java.util.Locale alcLocale, java.lang.String astrDelimiter, java.lang.String astrSeparator)
astrPropertyFileName
- The base name of the property file.alcLocale
- The Locale used to find the property file.astrDelimiter
- The delimiter used to parse the property file.astrSeparator
- The separator used to parse the property file.public static java.util.SortedMap readSortedProperties(java.lang.String astrPropertyFileName)
astrPropertyFileName
- The base name of the property file.public static java.util.SortedMap readSortedProperties(java.lang.String astrPropertyFileName, java.util.Locale alcLocale)
astrPropertyFileName
- The base name of the property file.alcLocale
- The Locale used to find the property file.public static java.util.SortedMap readSortedProperties(java.lang.String astrPropertyFileName, java.util.Locale alcLocale, java.lang.String astrDelimiter, java.lang.String astrSeparator)
astrPropertyFileName
- The base name of the property file.alcLocale
- The Locale used to find the property file.astrDelimiter
- The delimiter used to parse the property file.astrSeparator
- The separator used to parse the property file.