Class GlobalMessageUtil


  • public class GlobalMessageUtil
    extends Object
    • Field Detail

      • FAILOVER_LOCALE

        public static final Locale FAILOVER_LOCALE
        Used when the preferred locale (as defined by the user) is not available.
    • Constructor Detail

      • GlobalMessageUtil

        public GlobalMessageUtil()
    • Method Detail

      • formatErrorMessage

        public static String formatErrorMessage​(String key,
                                                String msg)
      • setLocale

        public static void setLocale​(Locale newLocale)
      • getLocale

        public static Locale getLocale()
      • calculateString

        public static String calculateString​(String[] pkgNames,
                                             String key,
                                             Object[] parameters,
                                             Class<?> resourceClass,
                                             String bundleName,
                                             boolean fallbackOnRoot)
      • calculateString

        public static String calculateString​(String[] pkgNames,
                                             String key,
                                             Object[] parameters,
                                             Class<?> resourceClass,
                                             String bundleName,
                                             boolean logNotFoundError,
                                             boolean fallbackOnRoot)
        Returns the localized string for the given key and parameters in a bundle defined by the the concatenation of the package names defined in packageName and @code bundleName} (the first valid combination of packageName + bundleName wins), sing the provided resourceClass's class loader.
        Parameters:
        pkgNames - an array of packages potentially containing the localized messages the first one found to contain the messages is the one that is used to localize the message
        key - the message key being looked up
        parameters - parameters within the looked up message
        resourceClass - the class whose class loader is used to getch the resource bundle
        bundleName - the name of the message bundle
        logNotFoundError - determines whether an error is logged when the localized string cannot be found - it can be used to suppress the log in cases where it is known that various combinations of parameters will be tried to fetch the message, to avoid unnecessary error logging.
        fallbackOnRoot - if true, and a ResourceBundle cannot be found for a given Locale, falls back on the ROOT Locale
        Returns:
        the localized string for the given key and parameters in a bundle defined by the the concatenation of the package names defined in packageName and @code bundleName} (the first valid combination of packageName + @code bundleName} wins), sing the provided resourceClass's class loader
      • getBundle

        public static ResourceBundle getBundle​(String packagePath,
                                               Class<?> resourceClass)
                                        throws MissingResourceException
        Retrieve a resource bundle of the default or fail-over locales.
        Parameters:
        packagePath - The package to search in
        resourceClass - the class to use to resolve the bundle
        Returns:
        The resource bundle
        Throws:
        MissingResourceException - in case both resource bundles couldn't be found.
      • getBundle

        public static ResourceBundle getBundle​(Locale locale,
                                               String packagePath,
                                               Class<?> resourceClass,
                                               boolean fallbackOnRoot)
        Returns a ResourceBundle corresponding to the given Locale package and resource class. Falls-back on the ROOT Locale, if the fallbackOnRoot flag is true and the requested Locale is not available.
        Parameters:
        locale - the Locale for which the ResourceBundle is being requested
        packagePath -
        resourceClass -
        fallbackOnRoot - if true, and a ResourceBundle cannot be found for the requested Locale, falls back on the ROOT Locale
        Returns:
        a ResourceBundle corresponding to the given Locale package and resource class
      • getLocaleString

        protected static String getLocaleString​(Locale locale)
        Returns a string corresponding to the locale (Example: "en", "en_US").
        Parameters:
        locale - The Locale whose string representation it being returned
        Returns:
        a string corresponding to the locale (Example: "en", "en_US").
      • isMissingKey

        protected static boolean isMissingKey​(String string)
        Returns true if the given string is null or is in the format of a missing key: !key!.
        Parameters:
        string -
        Returns:
        true if the given string is null or is in the format of a missing key: !key!.