public final class LionUtils
extends java.lang.Object
Note that each of the getBundledResource(java.lang.String)
methods use a custom
ResourceBundle.Control
instance which reads in the input stream
using UTF-8.
Modifier and Type | Method and Description |
---|---|
static java.util.ResourceBundle |
getBundledResource(java.lang.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. |
static java.util.ResourceBundle |
getBundledResource(java.lang.Class<?> c,
java.lang.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. |
static java.util.ResourceBundle |
getBundledResource(java.lang.String basename)
This method takes a fully qualified name and returns a
ResourceBundle which is loaded from a properties file with
that base name. |
static java.util.ResourceBundle |
getBundledResource(java.lang.String basename,
java.util.Locale locale,
java.lang.ClassLoader classLoader)
This method takes a fully qualified name and returns a
ResourceBundle which is loaded from a properties file with
that base name. |
static java.util.Locale |
localeFromString(java.lang.String s)
Parses the given string into language and country codes, and returns
a
Locale instance initialized with those parameters. |
static java.util.Locale |
setupRuntimeLocale()
Sets the default locale, based on the Java properties shown below.
|
public static java.util.Locale localeFromString(java.lang.String s)
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(); // ""
s
- the locale stringpublic static java.util.Locale setupRuntimeLocale()
user.language user.countryIt 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} ...
public static java.util.ResourceBundle getBundledResource(java.lang.String basename)
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.
basename
- the (fully qualified) basename of the bundle
properties filepublic static java.util.ResourceBundle getBundledResource(java.lang.String basename, java.util.Locale locale, java.lang.ClassLoader classLoader)
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.basename
- the (fully qualified) basename of the bundle
properties filelocale
- the localeclassLoader
- the class loaderpublic static java.util.ResourceBundle getBundledResource(java.lang.Class<?> c)
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.
c
- the classpublic static java.util.ResourceBundle getBundledResource(java.lang.Class<?> c, java.lang.String baseName)
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.
c
- the class requesting the bundlebaseName
- the base name of the resource bundle