Class LionUtils
- java.lang.Object
-
- org.onosproject.ui.lion.LionUtils
-
public final class LionUtils extends Object
Utility methods for dealing with Localization Bundles etc.Note that each of the
getBundledResource(java.lang.String)
methods use a customResourceBundle.Control
instance which reads in the input stream using UTF-8.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ResourceBundle
getBundledResource(Class<?> c)
This method takes a class and returns aResourceBundle
which is loaded from a properties file with the same base name as the class.static ResourceBundle
getBundledResource(Class<?> c, String baseName)
This method returns aResourceBundle
which is loaded from a properties file with the specified base name from the same package as the specified class.static ResourceBundle
getBundledResource(String basename)
This method takes a fully qualified name and returns aResourceBundle
which is loaded from a properties file with that base name.static ResourceBundle
getBundledResource(String basename, Locale locale, ClassLoader classLoader)
This method takes a fully qualified name and returns aResourceBundle
which is loaded from a properties file with that base name.static Locale
localeFromString(String s)
Parses the given string into language and country codes, and returns aLocale
instance initialized with those parameters.static Locale
setupRuntimeLocale()
Sets the default locale, based on the Java properties shown below.
-
-
-
Method Detail
-
localeFromString
public static Locale localeFromString(String s)
Parses the given string into language and country codes, and returns aLocale
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 variableONOS_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 aResourceBundle
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 aResourceBundle
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 filelocale
- the localeclassLoader
- the class loader- Returns:
- the appropriate resource bundle
-
getBundledResource
public static ResourceBundle getBundledResource(Class<?> c)
This method takes a class and returns aResourceBundle
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 aResourceBundle
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 bundlebaseName
- the base name of the resource bundle- Returns:
- the associated resource bundle
-
-