com.ibm.commerce.common.beans

Class ResourceBundleDataBean

  • java.lang.Object
    • com.ibm.commerce.common.beans.ResourceBundleDataBean
  • All Implemented Interfaces:
    com.ibm.commerce.beans.DataBean, com.ibm.commerce.beans.InputDataBean, com.ibm.commerce.beans.SmartDataBean, ResourceBundleInputDataBean, ResourceBundleSmartDataBean, java.io.Serializable


    public class ResourceBundleDataBean
    extends java.lang.Object
    implements ResourceBundleSmartDataBean, ResourceBundleInputDataBean
    The ResourceBundleDataBean is used by JSP files to get information from property files.
    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. Otherwise, the databean will first look up the property file from the store relations of the current store(STOREREL table). The store relation type used is: "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 property file can be read 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, which contains the following content (The number can be anything as long as they follow the ascending 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)

      The following sample code illustrates how to use the 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();

    3. public Hashtable getPropertyHashtable()
      This method is used to read from the property file and return the results as a Hashtable of Hashtables. The Hashtable contains many field Hashtables (each field corresponding to one small hashtable).
      The format of the property file would look as follows (example for UserRegistration_en_US.properties: 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

    If there are multiple stores on the site, and each wishes to have its own version of the properties files. Then this can be achieved using the store path concept. For example, if there are two stores - store 201 and store 202, and each has the need for the same file 'UserRegistration'. Then the file layout may look like the following: wcstores.war/WEB-INF/classes/UserRegistration_en_US.properties wcstores.war/WEB-INF/classes/store201/UserRegistration_en_US.properties wcstores.war/WEB-INF/classes/store202/ Notice that there is a default version of the UserRegistration_en_US.properties file in the classpath, and store 201 overrides this default version in path 'store201'. Store 202 does not have its own version of the file, so references will resolve to the default version of the file. To read the property file, use the following code: ResourceBundleDataBean bnResourceBundle= new ResourceBundleDataBean(); bnResourceBundle.setPropertyFileName("UserRegistration"); com.ibm.commerce.beans.DataBeanManager.activate(bnResourceBundle, request); PropertyResourceBundle properties = bnResourceBundle.getPropertyResourceBundle(); Assuming the current store is store 201, then the first place that will be looked is in the store path for this store. The path is 'store201/UserRegistration_en_US.properties'. The file will be found and returned. If the file was not found, then the store relations table would be checked. And the file will be searched on the store paths for each of the relative stores. If still the file is not found, then it will be picked up from the classpath. In our case, there is a default version of the file directly on the classpath, and that would be resolved.
    Another choice is explicitly specify the directory. In this way, if the property file is not found in this directory, the data bean will return null instead of continue search "wcstores.war/WEB-INF/classes/" directory. bnResourceBundle.setStoreDirectory("store201"); com.ibm.commerce.beans.DataBeanManager.activate(bnResourceBundle, request); PropertyResourceBundle properties = bnResourceBundle.getPropertyResourceBundle(); For store 202, which does not have its own property file, it is possible to reuse the file from store 201. The way is by simply creating a store relationship with that store. Simply insert an entry in the STORREL table with relationship type '-16', which indicates property file relationship. STRELTYP_ID RELATEDSTORE_ID STORE_ID SEQUENCE STATE ----------- --------------- ----------- ------------------------ ----------- -16 201 202 +1.00000000000000E+000 1 The STRELTYP_ID '-16' is defined in STRELTYP NAME STRELTYP_ID ------------------------------------------------------------ ----------- com.ibm.commerce.propertyFiles -16 After the store relation is created, the following code will find the property file under store201 for current store202. com.ibm.commerce.beans.DataBeanManager.activate(bnResourceBundle, request); PropertyResourceBundle properties = bnResourceBundle.getPropertyResourceBundle();

    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static java.lang.String CLASSNAME
      The fully qualified class name.
      static java.lang.String COPYRIGHT
      IBM copyright.
      • Fields inherited from interface com.ibm.commerce.beans.DataBean

        emptyString
    • Constructor Summary

      Constructors 
      Constructor and Description
      ResourceBundleDataBean()
      ResourceBundleDataBean constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      com.ibm.commerce.command.CommandContext getCommandContext()
      Gets the command context of this data bean.
      java.lang.String getDelimiter()
      Gets the delimiter for the property file.
      java.util.Locale getLocale()
      Gets the Locale.
      java.lang.String getPathSeparator()
      Gets the path separator.
      java.lang.String getPropertyFileName()
      Gets the name of the property file
      java.util.Hashtable getPropertyHashtable()
      Return the content of the property file as a Hashtable of Hashtables.
      java.util.Hashtable getPropertyHashtable(java.util.SortedMap atmpProperty)
      Helper method to convert the Hashtable of Hashtables format to the SortedMap format.
      java.util.PropertyResourceBundle getPropertyResourceBundle()
      Returns a PropertyResourceBundle object.
      java.util.SortedMap getPropertySortedMap()
      Returns the content of the property file as a SortedMap.
      com.ibm.commerce.datatype.TypedProperty getRequestProperties()
      Gets the request properties;
      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.
      boolean getStoreDirectoryEnabled()
      Gets a boolean which indicates whether or not the store directory should be fetched from the command context.
      java.util.PropertyResourceBundle getTextPropertyResourceBundle()
      Returns a PropertyResourceBundle object of the text property file.
      static java.lang.String invokeGetMethod(java.lang.String astrClassName, java.lang.Object aobjAccessBean, java.lang.String astrParameterName)
      Invoke the specified getter method from the specified accessbean, and return the result.
      void populate()
      Populate the databean.
      void setCommandContext(com.ibm.commerce.command.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 the property file; this parameter must be set before populating the data bean.
      void setRequestProperties(com.ibm.commerce.datatype.TypedProperty areqParms)
      Sets the request properties.
      void setSeparator(java.lang.String astrSeparator)
      Sets the separator for the property file.
      void setStoreDirectory(java.lang.String astrStoreDirectory)
      Sets the store directory, which is used as the path to find the property file.
      void setStoreDirectoryEnabled(boolean abStoreDirectoryEnabled)
      Sets if enable getting the Store Directory from the CommandContext.
      static java.lang.String toUpOneChar(java.lang.String strAttributeName)
      This helper method is used to change the first character of the input parameter to upper case.
      • Methods inherited from class java.lang.Object

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

      • CLASSNAME

        public static final java.lang.String CLASSNAME
        The fully qualified class name.
        See Also:
        Constant Field Values
      • COPYRIGHT

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

      • ResourceBundleDataBean

        public ResourceBundleDataBean()
        ResourceBundleDataBean constructor.
    • Method Detail

      • getCommandContext

        public com.ibm.commerce.command.CommandContext getCommandContext()
        Gets the command context of this data bean.
        Specified by:
        getCommandContext in interface com.ibm.commerce.beans.SmartDataBean
        Returns:
        The command context.
      • 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.
        Specified by:
        getDelimiter in interface ResourceBundleSmartDataBean
        Returns:
        The delimiter for the property file
      • getLocale

        public java.util.Locale getLocale()
        Gets the Locale. The Locale will be used to find property file.
        Specified by:
        getLocale in interface ResourceBundleSmartDataBean
        Returns:
        The Locale.
      • getPathSeparator

        public java.lang.String getPathSeparator()
        Gets the path separator. The path separator is used to separate the store directory and the property file name. For example: "store1/UserRegistration" "/" is the path separator.
        Specified by:
        getPathSeparator in interface ResourceBundleSmartDataBean
        Returns:
        The path separator
      • getPropertyHashtable

        public java.util.Hashtable getPropertyHashtable()
        Return the content of the property file as a Hashtable of Hashtables.
        Specified by:
        getPropertyHashtable in interface ResourceBundleSmartDataBean
        Returns:
        A Hashtable of Hashtables which contains information from the property file
      • getPropertyHashtable

        public java.util.Hashtable getPropertyHashtable(java.util.SortedMap atmpProperty)
        Helper method to convert the Hashtable of Hashtables format to the SortedMap format. This method is for IBM Internal use only.
        Parameters:
        atmpProperty - The property StoredMap format.
        Returns:
        The property Hashtable format
      • getPropertyResourceBundle

        public java.util.PropertyResourceBundle getPropertyResourceBundle()
        Returns a PropertyResourceBundle object.
        Specified by:
        getPropertyResourceBundle in interface ResourceBundleSmartDataBean
        Returns:
        A PropertyResourceBundle object
      • getPropertySortedMap

        public java.util.SortedMap getPropertySortedMap()
        Returns the content of the property file as a SortedMap.
        Returns:
        SortedMap The contents of the property file stored as a SortedMap.
      • getRequestProperties

        public com.ibm.commerce.datatype.TypedProperty getRequestProperties()
        Gets the request properties;
        Specified by:
        getRequestProperties in interface com.ibm.commerce.beans.InputDataBean
        Returns:
        The request properties;
      • getSeparator

        public java.lang.String getSeparator()
        Gets the separator for the property file. The separator is used to separate internal values 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, the default value ';' will be used.
        Specified by:
        getSeparator in interface ResourceBundleSmartDataBean
        Returns:
        The separator for the property file
      • getStoreDirectory

        public java.lang.String getStoreDirectory()
        Gets the name of the store directory, which is used for finding property files belonging to this store.
        Specified by:
        getStoreDirectory in interface ResourceBundleSmartDataBean
        Returns:
        The name of the store directory
      • getStoreDirectoryEnabled

        public boolean getStoreDirectoryEnabled()
        Gets a boolean which indicates whether or not the store directory should be fetched from the command context.
        • If the value is true and the store directory is not set, then the databean will get the store directory from the command context.
        • If the value is false then the databean will never get the value from the command context.
        Specified by:
        getStoreDirectoryEnabled in interface ResourceBundleSmartDataBean
        Returns:
        true if the store directory should be fetched from the command context; false otherwise.
      • getTextPropertyResourceBundle

        public java.util.PropertyResourceBundle getTextPropertyResourceBundle()
        Returns a PropertyResourceBundle object of the text property file. The name of the text property file is the name of the property file plus "Text" suffix.
        Returns:
        A PropertyResourceBundle object of the text property file.
      • invokeGetMethod

        public static java.lang.String invokeGetMethod(java.lang.String astrClassName,
                                                       java.lang.Object aobjAccessBean,
                                                       java.lang.String astrParameterName)
        Invoke the specified getter method from the specified accessbean, and return the result. This method is for IBM Internal use only.
        Parameters:
        astrClassName - The fully qualified class name of the access bean.
        aobjAccessBean - The access bean instance.
        astrParameterName - The name of the parameter to get.
        Returns:
        The value of the parameter.
      • populate

        public void populate()
        Populate the databean.
        Specified by:
        populate in interface com.ibm.commerce.beans.SmartDataBean
      • setCommandContext

        public void setCommandContext(com.ibm.commerce.command.CommandContext acommandContext)
        Sets the command context.
        Specified by:
        setCommandContext in interface com.ibm.commerce.beans.SmartDataBean
        Parameters:
        acommandContext - The command context.
      • setDelimiter

        public void setDelimiter(java.lang.String astrDelimiter)
        Sets the delimiter for the property file. The delimiter is used to separate different options. 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 value '|'.
        Specified by:
        setDelimiter in interface ResourceBundleInputDataBean
        Parameters:
        astrDelimiter - The delimiter for the property file
      • setLocale

        public void setLocale(java.util.Locale alcLocale)
        Set the Locale. This Locale is used to find property file.
        Specified by:
        setLocale in interface ResourceBundleInputDataBean
        Parameters:
        alcLocale - The Locale
      • setPathSeparator

        public void setPathSeparator(java.lang.String astrPathSeparator)
        Sets the path separator. The path separator is used to separate the store directory and the property file name. "store1/UserRegistration" '/' is the path separator. If the path separator is not set, the databean will use the default value '/'
        Specified by:
        setPathSeparator in interface ResourceBundleInputDataBean
        Parameters:
        astrPathSeparator - The path separator
      • setPropertyFileName

        public void setPropertyFileName(java.lang.String astrPropertyFileName)
        Sets the name of the property file; this parameter must be set before populating the data bean.
        Specified by:
        setPropertyFileName in interface ResourceBundleInputDataBean
        Parameters:
        astrPropertyFileName - The name of the property file
      • setRequestProperties

        public void setRequestProperties(com.ibm.commerce.datatype.TypedProperty areqParms)
                                  throws java.lang.Exception
        Sets the request properties.
        Specified by:
        setRequestProperties in interface com.ibm.commerce.beans.InputDataBean
        Parameters:
        areqParms - The request properties.
        Throws:
        java.lang.Exception - Any exception happens.
      • setSeparator

        public void setSeparator(java.lang.String astrSeparator)
        Sets the separator for the property file. The separator is used to separate internal values and display values in an option. 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 value ';'.
        Specified by:
        setSeparator in interface ResourceBundleInputDataBean
        Parameters:
        astrSeparator - The separator for the property file
      • setStoreDirectory

        public void setStoreDirectory(java.lang.String astrStoreDirectory)
        Sets the store directory, which is used as the path to 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 the command context.
        Specified by:
        setStoreDirectory in interface ResourceBundleInputDataBean
        Parameters:
        astrStoreDirectory - The store directory
      • setStoreDirectoryEnabled

        public void setStoreDirectoryEnabled(boolean abStoreDirectoryEnabled)
        Sets if enable getting the Store Directory from the CommandContext. true - If Store Directory is not set, the databean will get from CommandContext false - The databean will never get the Store Directory from CommandContext
        Specified by:
        setStoreDirectoryEnabled in interface ResourceBundleInputDataBean
        Parameters:
        abStoreDirectoryEnabled - A boolean value indicating if getting the Store Directory from the CommandContext
      • toUpOneChar

        public static java.lang.String toUpOneChar(java.lang.String strAttributeName)
        This helper method is used to change the first character of the input parameter to upper case. This method is for IBM Internal use only.
        Parameters:
        strAttributeName - The attribute name.
        Returns:
        The attribute name with the first character changed to uppercase.