Class StringManagerBase

  • Direct Known Subclasses:
    StringManager

    public class StringManagerBase
    extends Object
    Implementation of a local string manager. Provides access to i18n messages for classes that need them.

    One StringManagerBase per resource bundle name can be created and accessed by the getManager method call.

    Example: [LocalStrings.properties] test=At {1,time} on {1,date}, there was {2} on planet {0,number,integer} StringManagerBase sm = StringManagerBase.getStringManager("LocalStrings.properties"); ..... try { .... } catch (Exception e) { String localizedMsg = sm.getString("test", new Integer(7), new java.util.Date(System.currentTimeMillis()), "a disturbance in the Force"); throw new MyException(localizedMsg, e); } Localized message: At 2:27:41 PM on Jul 8, 2002, there was a disturbance in the Force on planet 7
    Since:
    JDK1.4
    Author:
    Nazrul Islam
    • Constructor Detail

      • StringManagerBase

        protected StringManagerBase​(String resourceBundleName,
                                    ClassLoader classLoader)
        Initializes the resource bundle.
        Parameters:
        resourceBundleName - name of the resource bundle
    • Method Detail

      • getStringManager

        public static StringManagerBase getStringManager​(String resourceBundleName,
                                                         ClassLoader classLoader)
        Returns a local string manager for the given resourceBundle name.
        Parameters:
        resourceBundleName - name of the resource bundle
        Returns:
        a local string manager for the given package name
      • getString

        public String getString​(String key)
        Returns a localized string.
        Parameters:
        key - the name of the resource to fetch
        Returns:
        the localized string
      • getStringWithDefault

        public String getStringWithDefault​(String key,
                                           String defaultValue)
        Returns a localized string. If the key is not found, it will return the default given value.
        Parameters:
        key - the name of the resource to fetch
        defaultValue - the default return value if not found
        Returns:
        the localized string
      • getStringWithDefault

        public String getStringWithDefault​(String key,
                                           String defaultFormat,
                                           Object[] arguments)
        Returns a local string for the caller and format the arguments accordingly. If the key is not found, it will use the given default format.
        Parameters:
        key - the key to the local format string
        defaultFormat - the default format if not found in the resources
        arguments - the set of arguments to provide to the formatter
        Returns:
        a formatted localized string
      • getString

        public String getString​(String key,
                                Object arg1)
        Returns a local string for the caller and format the arguments accordingly.
        Parameters:
        key - the key to the local format string
        arg1 - the one argument to be provided to the formatter
        Returns:
        a formatted localized string
      • getString

        public String getString​(String key,
                                Object arg1,
                                Object arg2)
        Returns a local string for the caller and format the arguments accordingly.
        Parameters:
        key - the key to the local format string
        arg1 - first argument to be provided to the formatter
        arg2 - second argument to be provided to the formatter
        Returns:
        a formatted localized string
      • getString

        public String getString​(String key,
                                Object arg1,
                                Object arg2,
                                Object arg3)
        Returns a local string for the caller and format the arguments accordingly.
        Parameters:
        key - the key to the local format string
        arg1 - first argument to be provided to the formatter
        arg2 - second argument to be provided to the formatter
        arg3 - third argument to be provided to the formatter
        Returns:
        a formatted localized string
      • getString

        public String getString​(String key,
                                Object arg1,
                                Object arg2,
                                Object arg3,
                                Object arg4)
        Returns a local string for the caller and format the arguments accordingly.
        Parameters:
        key - the key to the local format string
        arg1 - first argument to be provided to the formatter
        arg2 - second argument to be provided to the formatter
        arg3 - third argument to be provided to the formatter
        arg4 - fourth argument to be provided to the formatter
        Returns:
        a formatted localized string
      • getString

        public String getString​(String key,
                                Object[] args)
        Returns a local string for the caller and format the arguments accordingly.
        Parameters:
        key - the key to the local format string
        args - the array of arguments to be provided to the formatter
        Returns:
        a formatted localized string