Class Rincl
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-provider: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 setDefaultResourceI18nConcern(ResourceI18nConcern)
with the concern of
choice, as in the following example:
Rincl.setDefaultResourceI18nConcern(new MyResourceI18nConcern());
- Author:
- Garret Wilson
- See Also:
-
Csar
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Optional<ResourceI18nConcern>
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
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 Resources
getResources
(Class<?> contextClass, Locale locale) Retrieves resources related to a specified locale for the current context for the given context class.static Resources
getResources
(Object context) Retrieves resources for the current context for the given context.static Resources
getResources
(Object context, Locale locale) Retrieves resources related to a specified locale for the current context for the given context.static Optional<ResourceI18nConcern>
setDefaultResourceI18nConcern
(ResourceI18nConcern resourceI18nConcern) Sets the default resource i18n concern.static void
Configures the locale for the current context for all locale categories.static void
setLocale
(Locale.Category category, Locale locale) Configures the locale for the current context for the given locale category.
-
Constructor Details
-
Rincl
public Rincl()
-
-
Method Details
-
getDefaultResourceI18nConcern
Returns the default resource i18n concern.- Returns:
- The default resource i18n concern.
- See Also:
-
Csar.findDefaultConcern(Class)
-
setDefaultResourceI18nConcern
public static Optional<ResourceI18nConcern> setDefaultResourceI18nConcern(@Nonnull ResourceI18nConcern resourceI18nConcern) Sets the default resource i18n concern.- Parameters:
resourceI18nConcern
- The default resource i18n concern to set.- Returns:
- The previous concern, or
null
if there was no previous concern. - Throws:
NullPointerException
- if the given concern isnull
.- See Also:
-
Csar.registerDefaultConcern(Class, Concern)
-
getResourceI18nConcern
Returns the configured resource i18n concern for the current context.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 returned that provides empty resources.
- Returns:
- The configured resource i18n concern for the current context.
- See Also:
-
Csar.getConcern(Class)
EmptyResourceI18nConcern.INSTANCE
-
getResources
@Nonnull public static Resources getResources(@Nonnull Object context) throws io.confound.config.ConfigurationException Retrieves resources for the current context for the given context.The context class returned by
Resources.getContextClass()
may not necessarily reflect the class of the context provided here.This is a convenience method that requests resources from the current context resource i18n concern.
- Parameters:
context
- The context with which these resources are related; usually the object requesting the resource.- Returns:
- Access to configured resources for the given context.
- Throws:
NullPointerException
- if the given context isnull
.io.confound.config.ConfigurationException
- if there is a configuration error.- See Also:
-
getResources
@Nonnull public static Resources getResources(@Nonnull Object context, @Nonnull Locale locale) throws io.confound.config.ConfigurationException Retrieves resources related to a specified locale for the current context for the given context.The context class returned by
Resources.getContextClass()
may not necessarily reflect the class of the context provided here.This is a convenience method that requests resources from the current context resource i18n concern.
- Parameters:
context
- The context with which these resources are related; usually the object requesting the resource.locale
- The locale for which resources should be returned for the given context.- Returns:
- Access to configured resources for the given context.
- Throws:
NullPointerException
- if the given context and/or locale isnull
.io.confound.config.ConfigurationException
- if there is a configuration error.- See Also:
-
getResources
@Nonnull public static Resources getResources(@Nonnull Class<?> contextClass) throws io.confound.config.ConfigurationException Retrieves resources for the current context for the given context class.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.
- Parameters:
contextClass
- The context with which these resources are related; usually the class of the object requesting the resource.- Returns:
- Access to configured resources for the given context class.
- Throws:
NullPointerException
- if the given context class isnull
.io.confound.config.ConfigurationException
- if there is a configuration error.- See Also:
-
getResources
@Nonnull public static Resources getResources(@Nonnull Class<?> contextClass, @Nonnull Locale locale) throws io.confound.config.ConfigurationException Retrieves resources related to a specified locale for the current context for the given context class.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.
- Parameters:
contextClass
- The context with which these resources are related; usually the class of the object requesting the resource.locale
- The locale for which resources should be returned for the given context class.- Returns:
- Access to configured resources for the given context class.
- Throws:
NullPointerException
- if the given context class and/or locale isnull
.io.confound.config.ConfigurationException
- if there is a configuration error.- See Also:
-
getLocale
Retrieves the configured locale for the given category in the current context.If no category has been configured for the concern context, or there is no configured
ResourceI18nConcern
, this method delegates toLocale.getDefault(Locale.Category)
.This method may safely be used without configuring Rincl.
- Parameters:
category
- The category of locale to return.- Returns:
- The the configured locale for the given category.
- Throws:
NullPointerException
- if the given category isnull
.- See Also:
-
setLocale
Configures the locale for the current context for the given locale category. Future calls togetLocale(Locale.Category)
will return the value set here.If the current context
ResourceI18nConcern
is the default, or there is no configuredResourceI18nConcern
, this method updates the JVM default locale for the category usingLocale.setDefault(Locale.Category, Locale)
.This method may safely be used without configuring Rincl.
- Parameters:
category
- The category for which the locale should be set.locale
- The new locale value.- Throws:
SecurityException
- if a security manager exists and itsSecurityManager.checkPermission(java.security.Permission)
method doesn't allow the operation.NullPointerException
- if the given category and/or new locale isnull
.- See Also:
-
setLocale
Configures the locale for the current context for all locale categories. Future calls togetLocale(Locale.Category)
will return the value set here.If the current context
ResourceI18nConcern
is the default, or there is no configuredResourceI18nConcern
, this method updates the JVM default locale usingLocale.setDefault(Locale)
.This method may safely be used without configuring Rincl.
- Parameters:
locale
- The new locale value.- Throws:
SecurityException
- if a security manager exists and itsSecurityManager.checkPermission(java.security.Permission)
method doesn't allow the operation.NullPointerException
- if the given category and/or new locale isnull
.- See Also:
-