net.sf.mmm.util.nls.base
Class DefaultNlsResourceLocator
java.lang.Object
net.sf.mmm.util.component.base.AbstractComponent
net.sf.mmm.util.component.base.AbstractLoggableComponent
net.sf.mmm.util.nls.base.DefaultNlsResourceLocator
- All Implemented Interfaces:
- NlsResourceLocator
@Singleton
@Named
public class DefaultNlsResourceLocator
- extends AbstractLoggableComponent
- implements NlsResourceLocator
This class is used to find a
localized resource.
- Since:
- 2.0.0
- Author:
- Joerg Hohwiller (hohwille at users.sourceforge.net)
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DefaultNlsResourceLocator
public DefaultNlsResourceLocator()
- The constructor.
getLocaleForInfix
public Locale getLocaleForInfix(String localeInfix)
- This method gets the
Locale for the given
locale-infix.
- Specified by:
getLocaleForInfix in interface NlsResourceLocator
- Parameters:
localeInfix - is the locale-infix (e.g. "en_US").
- Returns:
- the Locale for the given
localeInfix.
Locale.ROOT if the given localeInfix is
invalid.
getLocaleInfixes
public String[] getLocaleInfixes(Locale locale)
- This method determines the infix-strings for localization lookup ordered
from most specific to least specific (empty string representing
Locale.ROOT). Each infix is defined as:
[_<language>[_<country>[_<variant>]]]
Please note that if a segment is empty but a following segment is present,
multiple underscores ('_') will occur.
Examples:
| locale |
result |
Locale.GERMANY |
{"_de_DE", "_de", ""} |
new Locale("", "CM") |
{"__CM", ""} |
new Locale("", "", "variant")
|
{"___variant", ""} |
- Specified by:
getLocaleInfixes in interface NlsResourceLocator
- Parameters:
locale - is the Locale.
- Returns:
- the localization-infixes ordered from most specific to least
specific. The returned array will always contain the empty string
as last entry.
findResource
public DataResource findResource(Class<?> type,
String extension,
Locale locale)
- Like
NlsResourceLocator.findResource(String, String, Locale) but using a
Class as pathAndBasicName.
- Specified by:
findResource in interface NlsResourceLocator
- Parameters:
type - is the Class identifying the path of the resource
including the filename without locale-part (infix) or
extension.extension - is the final suffix of the requested DataResource.
Typically ".properties" or ".xml".locale - is the locale for which the resource is
requested.
- Returns:
- the most specific
resource for the given
Locale.
findResource
public DataResource findResource(String pathAndBasicName,
String extension,
Locale locale)
- This method finds a localized
resource. It returns the
most specific resource for the given path:
<pathAndBasicName><infix><extension>
with
<infix> = [_<locale.getLanguage()>[_<locale.getCountry()>[_<locale.getVariant()>]]]
If a locale-specific part is NOT defined, the according part of the path is
omitted. E.g. for Locale.GERMANY the following values are tried for
<infix>:
"de_DE", "de", ""
- Specified by:
findResource in interface NlsResourceLocator
- Parameters:
pathAndBasicName - is the path of the resource including the filename
without locale-part or extension. Folders (or packages)
need to be separated with '/' and NOT with '.'. E.g.
"net/sf/mmm/util/nls/text/Hypenator".extension - is the suffix of the requested DataResource.
Typically ".properties" or ".xml". May be the empty string.locale - is the locale for which the resource is
requested.
- Returns:
- the most specific
resource for the given
Locale.
Copyright © 2001-2010 mmm-Team. All Rights Reserved.