- All Implemented Interfaces:
Serializable
ResourceBundle
. This is designed to be compatible with the
use of JSTL classes and taglibs.- Author:
- AO Industries, Inc.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Listeners may be registered to be notified as messages are looked-up. -
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
addListener
(Resources.Listener listener) Adds a listener.Gets the baseName being accessed by these resources.getMessage
(String key) Gets the message with the given key in the current thread's locale.getMessage
(String key, Object... args) Gets the message with the given key in the current thread's locale, optionallymessage-formatted
.getMessage
(Locale locale, String key) Gets the message with the given key in the provided locale.getMessage
(Locale locale, String key, Object... args) Gets the message with the given key in the provided locale, optionallymessage-formatted
.Gets the prefix applied to all keys directly used on these resources or an empty string when there is no prefix.Gets the bundle for the current thread's locale.getResourceBundle
(Locale locale) Gets the bundle for the provided locale.static Resources
getResources
(SerializableBiFunction<String, Locale, ResourceBundle> bundleAccessor, Class<?> clazz) Accesses the resources in theDEFAULT_SUBPACKAGE
sub-package of the given class namedDEFAULT_NAME
withclazz.getSimpleName() + '.'
as the prefix.static Resources
getResources
(SerializableBiFunction<String, Locale, ResourceBundle> bundleAccessor, Package pack) Accesses the resources in theDEFAULT_SUBPACKAGE
sub-package of the given package namedDEFAULT_NAME
.static Resources
getResources
(SerializableBiFunction<String, Locale, ResourceBundle> bundleAccessor, Package pack, String name) Accesses the resources in the given package (or sub-package) with the given name and no prefix.static Resources
getResources
(SerializableBiFunction<String, Locale, ResourceBundle> bundleAccessor, Package pack, String name, String prefix) Accesses the resources in the given package (or sub-package) with the given name and prefix.static Resources
getResources
(SerializableBiFunction<String, Locale, ResourceBundle> bundleAccessor, String baseName) Deprecated.Please use one of the class- or package-relative techniques in locating the resource bundle, as they will correctly locate the resources after packages are renamed by code obfuscation.static Resources
getResources
(SerializableBiFunction<String, Locale, ResourceBundle> bundleAccessor, String baseName, String prefix) Deprecated.Please use one of the class- or package-relative techniques in locating the resource bundle, as they will correctly locate the resources after packages are renamed by code obfuscation.static Resources
getResources
(Class<?> clazz) Deprecated.Please usegetResources(com.aoapps.lang.function.SerializableBiFunction, java.lang.Class)
instead.static Resources
getResources
(Package pack) Deprecated.Please usegetResources(com.aoapps.lang.function.SerializableBiFunction, java.lang.Package)
instead.static Resources
getResources
(Package pack, String name) Deprecated.static Resources
getResources
(Package pack, String name, String prefix) Deprecated.static Resources
getResources
(String baseName) Deprecated.Please usegetResources(com.aoapps.lang.function.SerializableBiFunction, java.lang.String)
instead.static Resources
getResources
(String baseName, String prefix) Deprecated.static void
removeListener
(Resources.Listener listener) Removes all occurrences of the provided listener.
-
Field Details
-
DEFAULT_SUBPACKAGE
The default sub-package that should contain resource bundles. Sub-packages are used so that resource bundles may be opened without exposing the entire package to reflection.- See Also:
-
DEFAULT_NAME
The default bundle name.- See Also:
-
-
Method Details
-
getResources
@Deprecated public static Resources getResources(SerializableBiFunction<String, Locale, ResourceBundle> bundleAccessor, String baseName, String prefix) Deprecated.Please use one of the class- or package-relative techniques in locating the resource bundle, as they will correctly locate the resources after packages are renamed by code obfuscation.getResources(com.aoapps.lang.function.SerializableBiFunction, java.lang.Class)
getResources(com.aoapps.lang.function.SerializableBiFunction, java.lang.Package)
getResources(com.aoapps.lang.function.SerializableBiFunction, java.lang.Package, java.lang.String)
getResources(com.aoapps.lang.function.SerializableBiFunction, java.lang.Package, java.lang.String, java.lang.String)
Accesses the resources with the given base name and prefix.- Parameters:
bundleAccessor
- Bi-function lookup for bundle, which will typically be the static method referenceResourceBundle::getBundle
.As of Java 9, bundle access is affected by module descriptors. To access the bundle with caller permissions, pass a small lambda that performs the bundle access. This will typically be the static method reference
ResourceBundle::getBundle
, but may be of any arbitrary complexity. The bundle accessor is invoked for every message lookup, so the implementation should take care to perform well.When
null
, the bundle is looked-up via a direct call toResourceBundle.getBundle(java.lang.String, java.util.Locale)
, which requiresopens …;
inmodule-info.java
.
-
getResources
Deprecated.Please usegetResources(com.aoapps.lang.function.SerializableBiFunction, java.lang.String, java.lang.String)
instead.As of Java 9, bundle access is affected by module descriptors. The bundle is looked-up via a direct call to
ResourceBundle.getBundle(java.lang.String, java.util.Locale)
, which requiresopens …;
inmodule-info.java
.Accesses the resources with the given base name and prefix. -
getResources
@Deprecated public static Resources getResources(SerializableBiFunction<String, Locale, ResourceBundle> bundleAccessor, String baseName) Deprecated.Please use one of the class- or package-relative techniques in locating the resource bundle, as they will correctly locate the resources after packages are renamed by code obfuscation.getResources(com.aoapps.lang.function.SerializableBiFunction, java.lang.Class)
getResources(com.aoapps.lang.function.SerializableBiFunction, java.lang.Package)
getResources(com.aoapps.lang.function.SerializableBiFunction, java.lang.Package, java.lang.String)
getResources(com.aoapps.lang.function.SerializableBiFunction, java.lang.Package, java.lang.String, java.lang.String)
Accesses the resources with the given base name and no prefix.- Parameters:
bundleAccessor
- Bi-function lookup for bundle, which will typically be the static method referenceResourceBundle::getBundle
.As of Java 9, bundle access is affected by module descriptors. To access the bundle with caller permissions, pass a small lambda that performs the bundle access. This will typically be the static method reference
ResourceBundle::getBundle
, but may be of any arbitrary complexity. The bundle accessor is invoked for every message lookup, so the implementation should take care to perform well.When
null
, the bundle is looked-up via a direct call toResourceBundle.getBundle(java.lang.String, java.util.Locale)
, which requiresopens …;
inmodule-info.java
.
-
getResources
Deprecated.Please usegetResources(com.aoapps.lang.function.SerializableBiFunction, java.lang.String)
instead.As of Java 9, bundle access is affected by module descriptors. The bundle is looked-up via a direct call to
ResourceBundle.getBundle(java.lang.String, java.util.Locale)
, which requiresopens …;
inmodule-info.java
.Accesses the resources with the given base name and no prefix. -
getResources
public static Resources getResources(SerializableBiFunction<String, Locale, ResourceBundle> bundleAccessor, Package pack, String name, String prefix) Accesses the resources in the given package (or sub-package) with the given name and prefix. The base name is derived aspack.getName() + '.' + name
.By default, resources are expected to be in a sub-package named
DEFAULT_SUBPACKAGE
. A sub-package is used because the module system does not allow opening for reflection separately from opening for resources. By using a separate sub-package, the resource bundles may be opened up without exposing the entire package to reflection.Note: Being accessed relative to the package, the resources can still be correctly located after packages are renamed by code obfuscation.
- Parameters:
bundleAccessor
- Bi-function lookup for bundle, which will typically be the static method referenceResourceBundle::getBundle
.As of Java 9, bundle access is affected by module descriptors. To access the bundle with caller permissions, pass a small lambda that performs the bundle access. This will typically be the static method reference
ResourceBundle::getBundle
, but may be of any arbitrary complexity. The bundle accessor is invoked for every message lookup, so the implementation should take care to perform well.When
null
, the bundle is looked-up via a direct call toResourceBundle.getBundle(java.lang.String, java.util.Locale)
, which requiresopens …;
inmodule-info.java
.name
- The name of the resource within the package, whennull
defaults toDEFAULT_SUBPACKAGE + "." + DEFAULT_NAME
(to be withinDEFAULT_SUBPACKAGE
sub-package).
-
getResources
Deprecated.Please usegetResources(com.aoapps.lang.function.SerializableBiFunction, java.lang.Package, java.lang.String, java.lang.String)
instead.As of Java 9, bundle access is affected by module descriptors. The bundle is looked-up via a direct call to
ResourceBundle.getBundle(java.lang.String, java.util.Locale)
, which requiresopens …;
inmodule-info.java
.Accesses the resources in the given package (or sub-package) with the given name and prefix. The base name is derived aspack.getName() + '.' + name
.By default, resources are expected to be in a sub-package named
DEFAULT_SUBPACKAGE
. A sub-package is used because the module system does not allow opening for reflection separately from opening for resources. By using a separate sub-package, the resource bundles may be opened up without exposing the entire package to reflection.Note: Being accessed relative to the package, the resources can still be correctly located after packages are renamed by code obfuscation.
- Parameters:
name
- The name of the resource within the package, whennull
defaults toDEFAULT_SUBPACKAGE + "." + DEFAULT_NAME
(to be withinDEFAULT_SUBPACKAGE
sub-package).
-
getResources
public static Resources getResources(SerializableBiFunction<String, Locale, ResourceBundle> bundleAccessor, Package pack, String name) Accesses the resources in the given package (or sub-package) with the given name and no prefix. The base name is derived aspack.getName() + '.' + name
.By default, resources are expected to be in a sub-package named
DEFAULT_SUBPACKAGE
. A sub-package is used because the module system does not allow opening for reflection separately from opening for resources. By using a separate sub-package, the resource bundles may be opened up without exposing the entire package to reflection.Note: Being accessed relative to the package, the resources can still be correctly located after packages are renamed by code obfuscation.
- Parameters:
bundleAccessor
- Bi-function lookup for bundle, which will typically be the static method referenceResourceBundle::getBundle
.As of Java 9, bundle access is affected by module descriptors. To access the bundle with caller permissions, pass a small lambda that performs the bundle access. This will typically be the static method reference
ResourceBundle::getBundle
, but may be of any arbitrary complexity. The bundle accessor is invoked for every message lookup, so the implementation should take care to perform well.When
null
, the bundle is looked-up via a direct call toResourceBundle.getBundle(java.lang.String, java.util.Locale)
, which requiresopens …;
inmodule-info.java
.name
- The name of the resource within the package, whennull
defaults toDEFAULT_SUBPACKAGE + "." + DEFAULT_NAME
(to be withinDEFAULT_SUBPACKAGE
sub-package).
-
getResources
Deprecated.Please usegetResources(com.aoapps.lang.function.SerializableBiFunction, java.lang.Package, java.lang.String)
instead.As of Java 9, bundle access is affected by module descriptors. The bundle is looked-up via a direct call to
ResourceBundle.getBundle(java.lang.String, java.util.Locale)
, which requiresopens …;
inmodule-info.java
.Accesses the resources in the given package (or sub-package) with the given name and no prefix. The base name is derived aspack.getName() + '.' + name
.By default, resources are expected to be in a sub-package named
DEFAULT_SUBPACKAGE
. A sub-package is used because the module system does not allow opening for reflection separately from opening for resources. By using a separate sub-package, the resource bundles may be opened up without exposing the entire package to reflection.Note: Being accessed relative to the package, the resources can still be correctly located after packages are renamed by code obfuscation.
- Parameters:
name
- The name of the resource within the package, whennull
defaults toDEFAULT_SUBPACKAGE + "." + DEFAULT_NAME
(to be withinDEFAULT_SUBPACKAGE
sub-package).
-
getResources
public static Resources getResources(SerializableBiFunction<String, Locale, ResourceBundle> bundleAccessor, Package pack) Accesses the resources in theDEFAULT_SUBPACKAGE
sub-package of the given package namedDEFAULT_NAME
. The base name is derived aspack.getName() + "." + DEFAULT_SUBPACKAGE + "." + DEFAULT_NAME
(to be withinDEFAULT_SUBPACKAGE
sub-package).Resources are expected to be in a sub-package named
DEFAULT_SUBPACKAGE
. A sub-package is used because the module system does not allow opening for reflection separately from opening for resources. By using a separate sub-package, the resource bundles may be opened up without exposing the entire package to reflection.Note: Being accessed relative to the package, the resources can still be correctly located after packages are renamed by code obfuscation.
- Parameters:
bundleAccessor
- Bi-function lookup for bundle, which will typically be the static method referenceResourceBundle::getBundle
.As of Java 9, bundle access is affected by module descriptors. To access the bundle with caller permissions, pass a small lambda that performs the bundle access. This will typically be the static method reference
ResourceBundle::getBundle
, but may be of any arbitrary complexity. The bundle accessor is invoked for every message lookup, so the implementation should take care to perform well.When
null
, the bundle is looked-up via a direct call toResourceBundle.getBundle(java.lang.String, java.util.Locale)
, which requiresopens …;
inmodule-info.java
.
-
getResources
Deprecated.Please usegetResources(com.aoapps.lang.function.SerializableBiFunction, java.lang.Package)
instead.As of Java 9, bundle access is affected by module descriptors. The bundle is looked-up via a direct call to
ResourceBundle.getBundle(java.lang.String, java.util.Locale)
, which requiresopens …;
inmodule-info.java
.Accesses the resources in theDEFAULT_SUBPACKAGE
sub-package of the given package namedDEFAULT_NAME
. The base name is derived aspack.getName() + "." + DEFAULT_SUBPACKAGE + "." + DEFAULT_NAME
(to be withinDEFAULT_SUBPACKAGE
sub-package).Resources are expected to be in a sub-package named
DEFAULT_SUBPACKAGE
. A sub-package is used because the module system does not allow opening for reflection separately from opening for resources. By using a separate sub-package, the resource bundles may be opened up without exposing the entire package to reflection.Note: Being accessed relative to the package, the resources can still be correctly located after packages are renamed by code obfuscation.
-
getResources
public static Resources getResources(SerializableBiFunction<String, Locale, ResourceBundle> bundleAccessor, Class<?> clazz) Accesses the resources in theDEFAULT_SUBPACKAGE
sub-package of the given class namedDEFAULT_NAME
withclazz.getSimpleName() + '.'
as the prefix. The base name is derived asclazz.getPackage().getName() + "." + DEFAULT_SUBPACKAGE + "." + DEFAULT_NAME
(to be withinDEFAULT_SUBPACKAGE
sub-package).Resources are expected to be in a sub-package named
DEFAULT_SUBPACKAGE
. A sub-package is used because the module system does not allow opening for reflection separately from opening for resources. By using a separate sub-package, the resource bundles may be opened up without exposing the entire package to reflection.Note: Being accessed relative to the package, the resources may still be correctly located after packages are renamed by code obfuscation. However, if classes are also renamed, the prefix will change and the build system must also alter the contents of the underlying
*.properties
files correspondingly.When rewriting the contents of the underlying properties files is not possible, it may be best either use hard-coded prefix (may leak original class name, thus thwarting obfuscation a bit) or use a per-class properties file (tedious, also requires build system coordination).
- Parameters:
bundleAccessor
- Bi-function lookup for bundle, which will typically be the static method referenceResourceBundle::getBundle
.As of Java 9, bundle access is affected by module descriptors. To access the bundle with caller permissions, pass a small lambda that performs the bundle access. This will typically be the static method reference
ResourceBundle::getBundle
, but may be of any arbitrary complexity. The bundle accessor is invoked for every message lookup, so the implementation should take care to perform well.When
null
, the bundle is looked-up via a direct call toResourceBundle.getBundle(java.lang.String, java.util.Locale)
, which requiresopens …;
inmodule-info.java
.clazz
- This class is used for determining the package and prefix only. It will typically be the class that is using the resource, not the class that implementsResourceBundle
.
-
getResources
Deprecated.Please usegetResources(com.aoapps.lang.function.SerializableBiFunction, java.lang.Class)
instead.As of Java 9, bundle access is affected by module descriptors. The bundle is looked-up via a direct call to
ResourceBundle.getBundle(java.lang.String, java.util.Locale)
, which requiresopens …;
inmodule-info.java
.Accesses the resources in theDEFAULT_SUBPACKAGE
sub-package of the given class namedDEFAULT_NAME
withclazz.getSimpleName() + '.'
as the prefix. The base name is derived asclazz.getPackage().getName() + "." + DEFAULT_SUBPACKAGE + "." + DEFAULT_NAME
(to be withinDEFAULT_SUBPACKAGE
sub-package).Resources are expected to be in a sub-package named
DEFAULT_SUBPACKAGE
. A sub-package is used because the module system does not allow opening for reflection separately from opening for resources. By using a separate sub-package, the resource bundles may be opened up without exposing the entire package to reflection.Note: Being accessed relative to the package, the resources may still be correctly located after packages are renamed by code obfuscation. However, if classes are also renamed, the prefix will change and the build system must also alter the contents of the underlying
*.properties
files correspondingly.When rewriting the contents of the underlying properties files is not possible, it may be best either use hard-coded prefix (may leak original class name, thus thwarting obfuscation a bit) or use a per-class properties file (tedious, also requires build system coordination).
- Parameters:
clazz
- This class is used for determining the package and prefix only. It will typically be the class that is using the resource, not the class that implementsResourceBundle
.
-
addListener
Adds a listener. Does not check for duplicates. If a listener is added more than once, it will simply by called multiple times. -
removeListener
Removes all occurrences of the provided listener. -
getBaseName
Gets the baseName being accessed by these resources. -
getPrefix
Gets the prefix applied to all keys directly used on these resources or an empty string when there is no prefix. -
getResourceBundle
Gets the bundle for the provided locale. Direct use of this bundle will not have any prefix applied. -
getResourceBundle
Gets the bundle for the current thread's locale. Direct use of this bundle will not have any prefix applied.- See Also:
-
getMessage
Gets the message with the given key in the provided locale, optionally
message-formatted
. If missing, will generate a Struts-like value including the locale and (prefix + key).Substitutes arguments in the text where it finds {0}, {1}, {2}, … Message formatting is not performed when
args
isnull
or empty.- Parameters:
key
- This will be combined with anyprefix
-
getMessage
Gets the message with the given key in the provided locale. If missing, will generate a Struts-like value including the locale and (prefix + key).- Parameters:
key
- This will be combined with anyprefix
-
getMessage
Gets the message with the given key in the current thread's locale, optionally
message-formatted
. If missing, will generate a Struts-like value including the locale and (prefix + key).Substitutes arguments in the text where it finds {0}, {1}, {2}, … Message formatting is not performed when
args
isnull
or empty.- Parameters:
key
- This will be combined with anyprefix
- See Also:
-
getMessage
Gets the message with the given key in the current thread's locale. If missing, will generate a Struts-like value including the locale and (prefix + key).- Parameters:
key
- This will be combined with anyprefix
- See Also:
-