public abstract class DelegatingResourceLocator extends java.lang.Object implements ResourceLocator
primary locator
and a series delegate locators
.Modifier and Type | Field and Description |
---|---|
protected java.net.URL |
baseURL
The cached base URL.
|
protected java.util.Map<java.lang.String,java.lang.Object> |
images
A cache of the image descriptions.
|
protected java.util.ResourceBundle |
resourceBundle
The resource bundle containing translated strings.
|
protected boolean |
shouldTranslate
Whether to translate strings by default.
|
protected java.util.Map<java.lang.String,java.lang.String> |
strings
A cache of the translated strings.
|
protected java.util.ResourceBundle |
untranslatedResourceBundle
The resource bundle containing untranslated strings.
|
protected java.util.Map<java.lang.String,java.lang.String> |
untranslatedStrings
A cache of the untranslated strings.
|
Constructor and Description |
---|
DelegatingResourceLocator()
Creates an instance.
|
Modifier and Type | Method and Description |
---|---|
protected java.lang.Object |
delegatedGetImage(java.lang.String key)
Does the work of fetching the image associated with the key,
when the image resource is not available locally.
|
protected java.lang.String |
delegatedGetString(java.lang.String key,
boolean translate)
Does the work of fetching the string associated with the key,
when the string resource is not available locally.
|
protected java.lang.Object |
doGetImage(java.lang.String key)
Does the work of fetching the image associated with the key.
|
protected java.lang.String |
doGetString(java.lang.String key,
boolean translate)
Does the work of fetching the string associated with the key.
|
protected static java.lang.String |
extensionFor(java.lang.String key)
Computes the file extension to be used with the key to specify an image resource.
|
java.net.URL |
getBaseURL()
Returns the URL from which all resources are based.
|
protected abstract ResourceLocator[] |
getDelegateResourceLocators()
Returns the delegate resource locators.
|
java.lang.Object |
getImage(java.lang.String key)
Returns the description that can be used to create the image resource associated with the key.
|
protected abstract ResourceLocator |
getPrimaryResourceLocator()
Returns the primary resource locator.
|
java.lang.String |
getString(java.lang.String key)
Returns the string resource associated with the key.
|
java.lang.String |
getString(java.lang.String key,
boolean translate)
Returns the string resource associated with the key.
|
java.lang.String |
getString(java.lang.String key,
java.lang.Object[] substitutions)
Returns a string resource associated with the key, and performs substitutions.
|
java.lang.String |
getString(java.lang.String key,
java.lang.Object[] substitutions,
boolean translate)
Returns a string resource associated with the key, and performs substitutions.
|
void |
setShouldTranslate(boolean shouldTranslate)
Sets whether strings should be translated by default.
|
boolean |
shouldTranslate()
Indicates whether strings should be translated by default.
|
protected java.net.URL baseURL
protected java.util.ResourceBundle untranslatedResourceBundle
protected java.util.ResourceBundle resourceBundle
protected java.util.Map<java.lang.String,java.lang.String> strings
protected java.util.Map<java.lang.String,java.lang.String> untranslatedStrings
protected java.util.Map<java.lang.String,java.lang.Object> images
protected boolean shouldTranslate
public DelegatingResourceLocator()
protected abstract ResourceLocator getPrimaryResourceLocator()
protected abstract ResourceLocator[] getDelegateResourceLocators()
public java.net.URL getBaseURL()
ResourceLocator
getBaseURL
in interface ResourceLocator
public java.lang.Object getImage(java.lang.String key)
ResourceLocator
getImage
in interface ResourceLocator
key
- the key of the image resource.protected java.lang.Object doGetImage(java.lang.String key) throws java.io.IOException
key
- the key of the image to fetch.java.io.IOException
- if an image doesn't exist.protected static java.lang.String extensionFor(java.lang.String key)
key
- the key for the imagine.protected java.lang.Object delegatedGetImage(java.lang.String key) throws java.util.MissingResourceException
key
- the key of the image to fetch.java.util.MissingResourceException
- if the image resource doesn't exist anywhere.getDelegateResourceLocators()
public boolean shouldTranslate()
true
if strings should be translated by default; false
otherwise.public void setShouldTranslate(boolean shouldTranslate)
shouldTranslate
- whether strings should be translated by default.public java.lang.String getString(java.lang.String key)
ResourceLocator
getString
in interface ResourceLocator
key
- the key of the string resource.public java.lang.String getString(java.lang.String key, boolean translate)
ResourceLocator
getString
in interface ResourceLocator
key
- the key of the string resource.translate
- whether the result is to be translated to the current locale.protected java.lang.String doGetString(java.lang.String key, boolean translate) throws java.util.MissingResourceException
key
- the key of the string to fetch.java.util.MissingResourceException
- if a string doesn't exist.protected java.lang.String delegatedGetString(java.lang.String key, boolean translate)
key
- the key of the string to fetch.java.util.MissingResourceException
- if the string resource doesn't exist anywhere.getDelegateResourceLocators()
public java.lang.String getString(java.lang.String key, java.lang.Object[] substitutions)
ResourceLocator
getString
in interface ResourceLocator
key
- the key of the string.substitutions
- the message substitutions.ResourceLocator.getString(String)
,
MessageFormat.format(String, Object[])
public java.lang.String getString(java.lang.String key, java.lang.Object[] substitutions, boolean translate)
ResourceLocator
getString
in interface ResourceLocator
key
- the key of the string.substitutions
- the message substitutions.translate
- whether the result is to be translated to the current locale.ResourceLocator.getString(String)
,
MessageFormat.format(String, Object[])