public class Rincl extends Object
Resources
via Csar
.
Rincl uses the Csar ConcernProvider
mechanism, so that an application can have access to a globally configured default Rincl implementation simply by
including that implementation's dependency. For example merely including the dependency
io.rincl:rincl-resourcebundle:x.x.x
will automatically provide resources from resource bundle property file
lookup. Classes desiring resource access may then then implement Rincled
for simplified retrieval of Resources
.
More complex configuration may be done by manual configuration using using setDefaultResourceI18nConcern(ResourceI18nConcern)
with the concern
of choice, as in the following example:
Rincl.setDefaultResourceI18nConcern(new MyResourceI18nConcern());
Csar
Constructor and Description |
---|
Rincl() |
Modifier and Type | Method and Description |
---|---|
static Optional<ResourceI18nConcern> |
getDefaultResourceI18nConcern()
Returns the default resource i18n concern.
|
static Locale |
getLocale(Locale.Category category)
Retrieves the configured locale for the given category in the current context.
|
static ResourceI18nConcern |
getResourceI18nConcern()
Returns the configured resource i18n concern for the current context.
|
static Resources |
getResources(Class<?> contextClass)
Retrieves resources for the current context for the given context class.
|
static Optional<ResourceI18nConcern> |
setDefaultResourceI18nConcern(ResourceI18nConcern resourceI18nConcern)
Sets the default resource i18n concern.
|
static void |
setLocale(Locale.Category category,
Locale locale)
Configures the locale for the current context for the given locale category.
|
static void |
setLocale(Locale locale)
Configures the locale for the current context for all locale categories.
|
public static Optional<ResourceI18nConcern> getDefaultResourceI18nConcern()
Csar.getDefaultConcern(Class)
public static Optional<ResourceI18nConcern> setDefaultResourceI18nConcern(@Nonnull ResourceI18nConcern resourceI18nConcern)
resourceI18nConcern
- The default resource i18n concern to set.null
if there was no previous concern.NullPointerException
- if the given concern is null
.Csar.registerDefaultConcern(Class, Concern)
@Nonnull public static ResourceI18nConcern getResourceI18nConcern()
If no resource i18n concern is registered for the current context, and no default resource i18n concern concern is registered, a resource i18n concern will be return that provides empty resources.
io.csar.ConcernNotFoundException
- if no resource i18n concern is configured.Csar.getConcern(Class)
,
EmptyResourceI18nConcern.INSTANCE
@Nonnull public static Resources getResources(@Nonnull Class<?> contextClass) throws ResourceConfigurationException
The context class returned by Resources.getContextClass()
may not necessarily be the context class provided here.
This is a convenience method that requests resources from the current context resource i18n concern.
contextClass
- The context with which these resources are related; usually the class of the object requesting the resource.NullPointerException
- if the given context class is null
.ResourceConfigurationException
- if there is a configuration error.getResourceI18nConcern()
,
ResourceI18nConcern.getResources(Class)
public static Locale getLocale(@Nonnull Locale.Category category)
If no category has been configured for the concern context, or there is no configured ResourceI18nConcern
, this method delegates to
Locale.getDefault(Locale.Category)
.
This method may safely be used without configuring Rincl.
category
- The category of locale to return.NullPointerException
- if the given category is null
.getResourceI18nConcern()
,
ResourceI18nConcern.getLocale(Locale.Category)
,
Locale.getDefault(Locale.Category)
public static void setLocale(@Nonnull Locale.Category category, @Nonnull Locale locale)
getLocale(Locale.Category)
will return the value set
here.
If the current context ResourceI18nConcern
is the default, or there is no configured ResourceI18nConcern
, this method updates the JVM
default locale for the category using Locale.setDefault(Locale.Category, Locale)
.
This method may safely be used without configuring Rincl.
category
- The category for which the locale should be set.locale
- The new locale value.SecurityException
- if a security manager exists and its SecurityManager.checkPermission(java.security.Permission)
method doesn't allow the
operation.NullPointerException
- if the given category and/or new locale is null
.SecurityManager.checkPermission(java.security.Permission)
,
PropertyPermission
,
Locale.setDefault(Locale.Category, Locale)
,
getLocale(Locale.Category)
public static void setLocale(@Nonnull Locale locale)
getLocale(Locale.Category)
will return the value set
here.
If the current context ResourceI18nConcern
is the default, or there is no configured ResourceI18nConcern
, this method updates the JVM
default locale using Locale.setDefault(Locale)
.
This method may safely be used without configuring Rincl.
locale
- The new locale value.SecurityException
- if a security manager exists and its SecurityManager.checkPermission(java.security.Permission)
method doesn't allow the
operation.NullPointerException
- if the given category and/or new locale is null
.SecurityManager.checkPermission(java.security.Permission)
,
PropertyPermission
,
Locale.setDefault(Locale)
,
getLocale(Locale.Category)
Copyright © 2016 GlobalMentor, Inc.. All rights reserved.