public abstract class AbstractResourceResolver extends Object implements ResourceResolver
| Modifier and Type | Field and Description |
|---|---|
protected static Object[] |
EMPTY_OBJECT_ARGS |
protected static String |
ERROR_ARGS_NULL |
protected static String |
ERROR_KEY_BLANK |
protected static String |
ERROR_LOCALE_NULL |
protected static String |
ERROR_RESOURCE_BLANK |
REF_KEY_END, REF_KEY_START| Constructor and Description |
|---|
AbstractResourceResolver() |
| Modifier and Type | Method and Description |
|---|---|
protected abstract Object |
doResolveResourceValue(String key,
Locale locale) |
protected Object |
evalResourceWithArguments(Object resource,
Map<String,Object> args) |
protected Object |
evalResourceWithArguments(Object resource,
Object[] args) |
String |
formatResource(String resource,
List<?> args)
Formats the given resource using supplied args to substitute placeholders.
|
String |
formatResource(String resource,
Map<String,Object> args)
Formats the given resource using supplied args to substitute placeholders.
|
String |
formatResource(String resource,
Object[] args)
Formats the given resource using supplied args to substitute placeholders.
|
Object |
resolveResource(String key)
Try to resolve the resource.
|
Object |
resolveResource(String key,
List<?> args)
Try to resolve the resource.
|
Object |
resolveResource(String key,
List<?> args,
Locale locale)
Try to resolve the resource.
|
Object |
resolveResource(String key,
List<?> args,
Locale locale,
Object defaultValue)
Try to resolve the resource.
|
Object |
resolveResource(String key,
List<?> args,
Object defaultValue)
Try to resolve the resource.
|
Object |
resolveResource(String key,
Locale locale)
Try to resolve the resource.
|
Object |
resolveResource(String key,
Locale locale,
Object defaultValue)
Try to resolve the resource.
|
Object |
resolveResource(String key,
Map<String,Object> args)
Try to resolve the resource.
|
Object |
resolveResource(String key,
Map<String,Object> args,
Locale locale)
Try to resolve the resource.
|
Object |
resolveResource(String key,
Map<String,Object> args,
Locale locale,
Object defaultValue)
Try to resolve the resource.
|
Object |
resolveResource(String key,
Map<String,Object> args,
Object defaultValue)
Try to resolve the resource.
|
Object |
resolveResource(String key,
Object defaultValue)
Try to resolve the resource.
|
Object |
resolveResource(String key,
Object[] args)
Try to resolve the resource.
|
Object |
resolveResource(String key,
Object[] args,
Locale locale)
Try to resolve the resource.
|
Object |
resolveResource(String key,
Object[] args,
Locale locale,
Object defaultValue)
Try to resolve the resource.
|
Object |
resolveResource(String key,
Object[] args,
Object defaultValue)
Try to resolve the resource.
|
Object |
resolveResourceValue(String key,
Locale locale)
Resolve a resource given a key and a Locale.
|
protected Object[] |
toObjectArray(List<?> args) |
protected static final String ERROR_KEY_BLANK
protected static final String ERROR_LOCALE_NULL
protected static final String ERROR_ARGS_NULL
protected static final String ERROR_RESOURCE_BLANK
protected static final Object[] EMPTY_OBJECT_ARGS
@Nonnull public Object resolveResource(@Nonnull String key) throws NoSuchResourceException
ResourceResolverresolveResource in interface ResourceResolverkey - Key to lookup, such as 'sample.SampleModel.icon'NoSuchResourceException - if no resource is found@Nonnull public Object resolveResource(@Nonnull String key, @Nonnull Locale locale) throws NoSuchResourceException
ResourceResolverresolveResource in interface ResourceResolverkey - Key to lookup, such as 'sample.SampleModel.icon'locale - Locale in which to lookupNoSuchResourceException - if no resource is found@Nonnull public Object resolveResource(@Nonnull String key, @Nonnull Object[] args) throws NoSuchResourceException
ResourceResolverresolveResource in interface ResourceResolverkey - Key to lookup, such as 'sample.SampleModel.icon'args - Arguments that will be filled in for params within the resource (params look like "{0}" within a
resource, but this might differ between implementations), or null if none.NoSuchResourceException - if no resource is found@Nonnull public Object resolveResource(@Nonnull String key, @Nonnull Object[] args, @Nonnull Locale locale) throws NoSuchResourceException
ResourceResolverresolveResource in interface ResourceResolverkey - Key to lookup, such as 'sample.SampleModel.icon'args - Arguments that will be filled in for params within the resource (params look like "{0}" within a
resource, but this might differ between implementations), or null if none.locale - Locale in which to lookupNoSuchResourceException - if no resource is found@Nonnull public Object resolveResource(@Nonnull String key, @Nonnull List<?> args) throws NoSuchResourceException
ResourceResolverresolveResource in interface ResourceResolverkey - Key to lookup, such as 'sample.SampleModel.icon'args - Arguments that will be filled in for params within the resource (params look like "{0}" within a
resource, but this might differ between implementations), or null if none.NoSuchResourceException - if no resource is found@Nonnull public Object resolveResource(@Nonnull String key, @Nonnull List<?> args, @Nonnull Locale locale) throws NoSuchResourceException
ResourceResolverresolveResource in interface ResourceResolverkey - Key to lookup, such as 'sample.SampleModel.icon'args - Arguments that will be filled in for params within the resource (params look like "{0}" within a
resource, but this might differ between implementations), or null if none.locale - Locale in which to lookupNoSuchResourceException - if no resource is found@Nullable public Object resolveResource(@Nonnull String key, @Nullable Object defaultValue)
ResourceResolverresolveResource in interface ResourceResolverkey - Key to lookup, such as 'sample.SampleModel.icon'defaultValue - Message to return if the lookup fails@Nullable public Object resolveResource(@Nonnull String key, @Nonnull Locale locale, @Nullable Object defaultValue)
ResourceResolverresolveResource in interface ResourceResolverkey - Key to lookup, such as 'sample.SampleModel.icon'locale - Locale in which to lookupdefaultValue - Message to return if the lookup fails@Nullable public Object resolveResource(@Nonnull String key, @Nonnull Object[] args, @Nullable Object defaultValue)
ResourceResolverresolveResource in interface ResourceResolverkey - Key to lookup, such as 'sample.SampleModel.icon'args - Arguments that will be filled in for params within the resource (params look like "{0}"
within a resource, but this might differ between implementations), or null if none.defaultValue - Message to return if the lookup fails@Nullable public Object resolveResource(@Nonnull String key, @Nonnull Object[] args, @Nonnull Locale locale, @Nullable Object defaultValue)
ResourceResolverresolveResource in interface ResourceResolverkey - Key to lookup, such as 'sample.SampleModel.icon'args - Arguments that will be filled in for params within the resource (params look like "{0}"
within a resource, but this might differ between implementations), or null if none.locale - Locale in which to lookupdefaultValue - Message to return if the lookup fails@Nullable public Object resolveResource(@Nonnull String key, @Nonnull List<?> args, @Nullable Object defaultValue)
ResourceResolverresolveResource in interface ResourceResolverkey - Key to lookup, such as 'sample.SampleModel.icon'args - Arguments that will be filled in for params within the resource (params look like "{0}"
within a resource, but this might differ between implementations), or null if none.defaultValue - Message to return if the lookup fails@Nullable public Object resolveResource(@Nonnull String key, @Nonnull List<?> args, @Nonnull Locale locale, @Nullable Object defaultValue)
ResourceResolverresolveResource in interface ResourceResolverkey - Key to lookup, such as 'sample.SampleModel.icon'args - Arguments that will be filled in for params within the resource (params look like "{0}"
within a resource, but this might differ between implementations), or null if none.locale - Locale in which to lookupdefaultValue - Message to return if the lookup fails@Nonnull public Object resolveResource(@Nonnull String key, @Nonnull Map<String,Object> args) throws NoSuchResourceException
ResourceResolverresolveResource in interface ResourceResolverkey - Key to lookup, such as 'sample.SampleModel.icon'args - Arguments that will be filled in for params within the resource (params look like "{:key}"
within a resource, but this might differ between implementations), or null if none.NoSuchResourceException - if no resource is found@Nonnull public Object resolveResource(@Nonnull String key, @Nonnull Map<String,Object> args, @Nonnull Locale locale) throws NoSuchResourceException
ResourceResolverresolveResource in interface ResourceResolverkey - Key to lookup, such as 'sample.SampleModel.icon'args - Arguments that will be filled in for params within the resource (params look like "{:key}"
within a resource, but this might differ between implementations), or null if none.locale - Locale in which to lookupNoSuchResourceException - if no resource is found@Nullable public Object resolveResource(@Nonnull String key, @Nonnull Map<String,Object> args, @Nullable Object defaultValue)
ResourceResolverresolveResource in interface ResourceResolverkey - Key to lookup, such as 'sample.SampleModel.icon'args - Arguments that will be filled in for params within the resource (params look like "{:key}"
within a resource, but this might differ between implementations), or null if none.defaultValue - Message to return if the lookup fails@Nullable public Object resolveResource(@Nonnull String key, @Nonnull Map<String,Object> args, @Nonnull Locale locale, @Nullable Object defaultValue)
ResourceResolverresolveResource in interface ResourceResolverkey - Key to lookup, such as 'sample.SampleModel.icon'args - Arguments that will be filled in for params within the resource (params look like "{:key}"
within a resource, but this might differ between implementations), or null if none.locale - Locale in which to lookupdefaultValue - Message to return if the lookup fails@Nonnull public Object resolveResourceValue(@Nonnull String key, @Nonnull Locale locale) throws NoSuchResourceException
ResourceResolverResolve a resource given a key and a Locale.
This method should use the default Locale if the locale argument is null. The key argument may refer to
another key if the resolved value results in a CharSequence that begins with "@[" and ends with "]". In this
case the method will use the enclosed value as the next key to be resolved. For example, given the following key/value
definitions
some.key = Hello {0}
other.key = @[some.key]
Evaluating the keys results in
assert resolveResourceValue('some.key', Locale.default) == 'Hello {0}'
assert resolveResourceValue('other.key', Locale.default) == 'Hello {0}'
resolveResourceValue in interface ResourceResolverkey - Key to lookup, such as 'sample.SampleModel.icon'locale - Locale in which to lookupNoSuchResourceException - if no message is found@Nonnull public String formatResource(@Nonnull String resource, @Nonnull List<?> args)
ResourceResolverformatResource in interface ResourceResolverresource - The resource following a predefined format.args - Arguments that will be filled in for params within the resource (params look like "{0}"
within a resource, but this might differ between implementations), or null if none.@Nonnull public String formatResource(@Nonnull String resource, @Nonnull Object[] args)
ResourceResolverformatResource in interface ResourceResolverresource - The resource following a predefined format.args - Arguments that will be filled in for params within the resource (params look like "{0}"
within a resource, but this might differ between implementations), or null if none.@Nonnull public String formatResource(@Nonnull String resource, @Nonnull Map<String,Object> args)
ResourceResolverformatResource in interface ResourceResolverresource - The resource following a predefined format.args - Arguments that will be filled in for params within the resource (params look like "{:key}"
within a resource, but this might differ between implementations), or null if none.@Nonnull protected abstract Object doResolveResourceValue(@Nonnull String key, @Nonnull Locale locale) throws NoSuchResourceException
NoSuchResourceException@Nullable protected Object evalResourceWithArguments(@Nonnull Object resource, @Nonnull Object[] args)
@Nullable protected Object evalResourceWithArguments(@Nonnull Object resource, @Nonnull Map<String,Object> args)