|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.commons.resources.impl.ResourcesBase org.apache.commons.resources.impl.CollectionResourcesBase
public abstract class CollectionResourcesBase
Abstract base classes for
Resources
implementations that
store their name-value mappings for each supported Locale
in a URL-accessible resource file with a common base URL. Subclasses
need only override loadLocale()
to manage the details of
loading the name-value mappings for a particular Locale.
Constructor Summary | |
---|---|
CollectionResourcesBase(String name,
String base)
Create a new Resources instance with the specified
logical name and base URL. |
Method Summary | |
---|---|
void |
destroy()
This method must be called when the manager of this resource decides that it's no longer needed. |
Locale |
getDefaultLocale()
Return the default locale. |
Iterator |
getKeys()
Return an Iterator over the defined keys in this
Resources instance. |
protected List |
getLocaleList(Locale locale)
Return a List of Locales that should be searched
when locating resources for the specified Locale. |
protected Map |
getLocaleMap(Locale locale)
Return the Map to be used to resolve name-value
mappings for the specified Locale . |
protected abstract Map |
getLocaleMap(String baseUrl,
Locale locale)
Return a Map containing the name-value mappings for
the specified base URL and requested Locale , if there
are any. |
protected String |
getLocaleSuffix(Locale locale)
Return the Locale -specific suffix for the specified
Locale . |
Object |
getObject(String key,
Locale locale)
Return the content for the specified key as an
Object, localized based on the specified locale . |
void |
setDefaultLocale(Locale defaultLocale)
Set the default locale. |
Methods inherited from class org.apache.commons.resources.impl.ResourcesBase |
---|
getBufferSize, getBytes, getInputStream, getName, getReader, getString, init, isReturnNull, setBufferSize, setReturnNull |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CollectionResourcesBase(String name, String base)
Create a new Resources
instance with the specified
logical name and base URL.
name
- Logical name of the new instancebase
- Base URL of the resource files that contain the per-Locale
name-value mappings for this Resources
instanceMethod Detail |
---|
public void setDefaultLocale(Locale defaultLocale)
defaultLocale
- The default Locale.public Locale getDefaultLocale()
public Iterator getKeys()
ResourcesBase
Return an Iterator
over the defined keys in this
Resources
instance.
getKeys
in interface Resources
getKeys
in class ResourcesBase
ResourcesBase.getKeys()
public Object getObject(String key, Locale locale)
Return the content for the specified key
as an
Object, localized based on the specified locale
.
getObject
in interface Resources
getObject
in class ResourcesBase
key
- Identifier for the requested contentlocale
- Locale with which to localize retrieval,
or null
for the default Locale
ResourcesException
- if an error occurs retrieving or
returning the requested content
ResourcesKeyException
- if the no value for the specified
key was found, and isReturnNull()
returns
false
public void destroy()
This method must be called when the manager of this resource
decides that it's no longer needed. After this method is called,
no further calls to any of the getXxx()
methods are
allowed.
destroy
in interface Resources
destroy
in class ResourcesBase
ResourcesException
- if an error occurs during finalizationprotected List getLocaleList(Locale locale)
Return a List
of Locales that should be searched
when locating resources for the specified Locale. The returned
list will start with the specified Locale itself, followed by Locales
that do not specify variant, country, or language modifiers. For
example, if you pass in a Locale for the en_US_POSIX
combination, the returned list will have Locale instances for
the following country/language/variant combinations:
en_US_POSIX
en_US
en
The search order calculated by this method makes it easy for
Resources
implementations to implement hierarchical search
strategies similar to that employed by the standard Java class
java.util.ResourceBundle
.
locale
- Locale on which to base the list calculation
protected Map getLocaleMap(Locale locale)
Return the Map
to be used to resolve name-value
mappings for the specified Locale
. Caching is utilized
to ensure that a call to getLocaleMap(base,locale)
occurs only once per Locale
.
locale
- Locale for which to return a name-value mappings Map
protected abstract Map getLocaleMap(String baseUrl, Locale locale)
Return a Map
containing the name-value mappings for
the specified base URL and requested Locale
, if there
are any. If there are no defined mappings for the specified
Locale
, return an empty Map
instead.
Concrete subclasses must override this method to perform the
appropriate lookup. A typical implementation will construct an
absolute URL based on the specified base URL and Locale
,
retrieve the specified resource file (if any), and parse it into
a Map
structure.
Caching of previously retrieved Map
s (if any) should
be performed by callers of this method. Therefore, this method should
always attempt to retrieve the specified resource and load it
appropriately.
baseUrl
- Base URL of the resource files for this
Resources
instancelocale
- Locale
for which name-value mappings
are requested
protected String getLocaleSuffix(Locale locale)
Return the Locale
-specific suffix for the specified
Locale
. If the specified Locale
has
zero-length language and country components, the returned suffix
will also have zero length. Otherwise, it will contain an
underscore character followed by the non-zero-length language,
country, and variant properties (separated by underscore characters).
locale
- Locale
for which a suffix string
is requested
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |