Class LionUtils

    • Method Detail

      • localeFromString

        public static Locale localeFromString​(String s)
        Parses the given string into language and country codes, and returns a Locale instance initialized with those parameters. For example:
             Locale locale = LionUtils.localeFromString("en_GB");
             locale.getLanguage();   // "en"
             locale.getCountry();    // "GB"
        
             locale = LionUtils.localeFromString("ru");
             locale.getLanguage();   // "ru"
             locale.getCountry();    // ""
         
        Parameters:
        s - the locale string
        Returns:
        a locale instance
      • setupRuntimeLocale

        public static Locale setupRuntimeLocale()
        Sets the default locale, based on the Java properties shown below.
           user.language
           user.country
         
        It is expected that the host system will have set these properties appropriately. Note, however, that the default values can be overridden by use of the environment variable ONOS_LOCALE.

        For example, to set the Locale to French-Canadian one can invoke (from the shell)...

         $ ONOS_LOCALE=fr_CA {command-to-invoke-onos} ...
         
        Returns:
        the runtime locale
      • getBundledResource

        public static ResourceBundle getBundledResource​(String basename)
        This method takes a fully qualified name and returns a ResourceBundle which is loaded from a properties file with that base name.

        For example, supposing the jar file contains:

         org/onosproject/util/example/SomeBundle.properties
         

        Then, to correctly load the resource bundle associated with SomeBundle, call:

         String fqname = "org.onosproject.util.example.SomeBundle";
         ResourceBundle res = ResourceUtils.getBundledResource(fqname);
         

        Note that no error is thrown if the properties file does not exist. This condition will not become apparent until you try and access a property from the bundle, at which time a MissingResourceException will be thrown.

        Parameters:
        basename - the (fully qualified) basename of the bundle properties file
        Returns:
        the associated resource bundle
      • getBundledResource

        public static ResourceBundle getBundledResource​(String basename,
                                                        Locale locale,
                                                        ClassLoader classLoader)
        This method takes a fully qualified name and returns a ResourceBundle which is loaded from a properties file with that base name. The locale to use for bundle selection, and the class loader to use for the search path are also specified.
        Parameters:
        basename - the (fully qualified) basename of the bundle properties file
        locale - the locale
        classLoader - the class loader
        Returns:
        the appropriate resource bundle
      • getBundledResource

        public static ResourceBundle getBundledResource​(Class<?> c)
        This method takes a class and returns a ResourceBundle which is loaded from a properties file with the same base name as the class. Note that both the class and the properties file(s) need to be in the same jar file.

        For example, supposing the jar file contains:

         org/onosproject/util/example/SomeObject.class
         org/onosproject/util/example/SomeObject.properties
         

        Then, to correctly load the resource bundle associated with SomeObject, call:

         ResourceBundle res = ResourceUtils.getBundledResource(SomeObject.class);
         

        Note that no error is thrown if the properties file does not exist. This condition will not become apparent until you try and access a property from the bundle, at which time a MissingResourceException will be thrown.

        Parameters:
        c - the class
        Returns:
        the associated resource bundle
      • getBundledResource

        public static ResourceBundle getBundledResource​(Class<?> c,
                                                        String baseName)
        This method returns a ResourceBundle which is loaded from a properties file with the specified base name from the same package as the specified class. Note that both the class and the properties file(s) need to be in the same jar file.

        For example, supposing the jar file contains:

         org/onosproject/util/example/SomeObject.class
         org/onosproject/util/example/DisplayStrings.properties
         

        Then, to correctly load the resource bundle call:

         ResourceBundle res = ResourceUtils.getBundledResource(SomeObject.class,
                                                               "DisplayStrings");
         

        Note that no error is thrown if the properties file does not exist. This condition will not become apparent until you try and access a property from the bundle, at which time a MissingResourceException will be thrown.

        Parameters:
        c - the class requesting the bundle
        baseName - the base name of the resource bundle
        Returns:
        the associated resource bundle