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 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:

    1. Property File Name:
      The base name of the property file you want to retrieve. For example, "UserRegistration" is the property file name for "UserRegistration_en_US.properties" and "UserRegistration_fr_FR.properties". This parameter is mandatory, and can be set by calling the setPropertyFileName(String) method.
    2. Store Directory Name:
      Different stores can have their own property files, and can reuse the same property file name. To avoid naming conflicts, each store should have a directory to store their property files. To find a property file belong to a specific store, you must set the store directory using the setStoreDirectory(String) method.
      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. *
    3. Locale:
      Locale is used to find property files for different languages. It can be set using the setLocale(String) method. If Locale is not set, the databean will get the Locale from the command context.

    After these parameters are set and the data bean is activated, the information in the property file can be retrieved using the following methods:

    1. public PropertyResourceBundle getPropertyResourceBundle()
      This method can be used for any format of property file. It returns PropertyResourceBundle object.
    2. 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 that contains the following content (the number can be anything, but must be in 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)

    3. 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).

      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

      Fields 
      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.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      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.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • COPYRIGHT

        public static final java.lang.String COPYRIGHT
        IBM copyright.
        See Also:
        Constant Field Values
      • CLASSNAME

        public static final java.lang.String CLASSNAME
        The 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 default delimiter 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, 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 an 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 an 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.
    • Constructor Detail

      • PropertyResourceBundleReader

        public PropertyResourceBundleReader()
    • Method Detail

      • setPropertyFileName

        public void setPropertyFileName(java.lang.String astrPropertyFileName)
        Sets the name of property file. This is a 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 are 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 the store directory to store31. If the store directory is not set, ResourceBundleDataBean will try to get it from the 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 belonging 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 definition: 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: "|".
        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 definition, age.Options=0;Not Available|1;10-19 years|2;20-29 years "|" is the delimiter.
        Returns:
        The delimiter for the property file
      • setSeparator

        public void setSeparator(java.lang.String astrSeparator)
        Sets the separator for the property file.
        The separator is used to separate the internal value and the display value for an 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 an 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.
        The separator is used to separate the internal value and the display value for an 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 an 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, that 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, that 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 separator.
        The 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 the store directory. If the property can not be found and the command context is not null, the PropertyResourceBundleReader will get the current store from the 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 directly from the classpath without using a store directory. If locale is null and command context is not null, the PropertyResourceBundleReader will get the Locale from CommandContext. If the command context is also null, then it will use the default locale Locale.US.
        Parameters:
        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.
        For example, there are two stores named 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.
      • getFoundPropertyFilePath

        public java.lang.String getFoundPropertyFilePath()
        Gets the path for the property file that was found. For example, store1/UserRegistration_en_US.properties.
        Returns:
        The found property file path; null if property file was not found.
      • getPropertyResourceBundle

        public java.util.PropertyResourceBundle getPropertyResourceBundle()
        Gets the property file as a PropertyResourceBundle object.
        Returns:
        A PropertyResourceBundle object
      • getTextPropertyResourceBundle

        public java.util.PropertyResourceBundle getTextPropertyResourceBundle()
        Gets the text property file as a 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".
        Returns:
        A PropertyResourceBundle object
      • getPropertySortedMap

        public java.util.SortedMap getPropertySortedMap()
        Gets the property file as a 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.
        Returns:
        A SortedMap which contains information from the property file.
      • getPropertyHashtable

        public java.util.Hashtable getPropertyHashtable()
        Gets the property file as a 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.
        Returns:
        A SortedMap which contains information from 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 separator.
        Parameters:
        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.
        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 separator.
        Parameters:
        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.
        Returns:
        The content of property file in the format of SortedMap.