|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.turbine.services.BaseInitable | +--org.apache.turbine.services.BaseService | +--org.apache.turbine.services.TurbineBaseService | +--org.apache.turbine.services.localization.TurbineLocalizationService
This class is the single point of access to all localization resources. It caches different ResourceBundles for different Locales.
Usage example:
LocalizationService ls = (LocalizationService) TurbineServices
.getInstance().getService(LocalizationService.SERVICE_NAME);
Then call one of four methods to retrieve a ResourceBundle:
Field Summary | |
private java.lang.String[] |
bundleNames
The list of default bundles to search. |
private java.util.Hashtable |
bundles
The ResourceBundles in this service. |
private java.lang.String |
defaultCountry
The name of the default country to use. |
private java.lang.String |
defaultLanguage
The name of the default language to use. |
private java.util.Locale |
defaultLocale
The name of the default locale to use (includes language and country). |
Fields inherited from class org.apache.turbine.services.BaseService |
configuration, name, properties, serviceBroker |
Fields inherited from class org.apache.turbine.services.BaseInitable |
initableBroker, isInitialized |
Fields inherited from interface org.apache.turbine.services.localization.LocalizationService |
ACCEPT_LANGUAGE, SERVICE_NAME |
Constructor Summary | |
TurbineLocalizationService()
Constructor. |
Method Summary | |
java.util.ResourceBundle |
getBundle()
This method returns a ResourceBundle given the bundle name "DEFAULT" and the default Locale information supplied in TurbineProperties. |
java.util.ResourceBundle |
getBundle(javax.servlet.http.HttpServletRequest req)
This method returns a ResourceBundle given the Locale information supplied in the HTTP "Accept-Language" header which is stored in HttpServletRequest. |
java.util.ResourceBundle |
getBundle(RunData data)
This method returns a ResourceBundle given the Locale information supplied in the HTTP "Accept-Language" header which is stored in RunData. |
java.util.ResourceBundle |
getBundle(java.lang.String bundleName)
This method returns a ResourceBundle given the bundle name and the default Locale information supplied in TurbineProperties. |
java.util.ResourceBundle |
getBundle(java.lang.String bundleName,
javax.servlet.http.HttpServletRequest req)
This method returns a ResourceBundle given the bundle name and the Locale information supplied in the HTTP "Accept-Language" header which is stored in HttpServletRequest. |
java.util.ResourceBundle |
getBundle(java.lang.String bundleName,
java.util.Locale locale)
This method returns a ResourceBundle for the given bundle name and the given Locale. |
java.util.ResourceBundle |
getBundle(java.lang.String bundleName,
RunData data)
This method returns a ResourceBundle given the bundle name and the Locale information supplied in the HTTP "Accept-Language" header which is stored in RunData. |
java.util.ResourceBundle |
getBundle(java.lang.String bundleName,
java.lang.String languageHeader)
This method returns a ResourceBundle given the bundle name and the Locale information supplied in the HTTP "Accept-Language" header. |
java.lang.String |
getDefaultBundleName()
Retrieves the name of the default bundle (as specified in the config file). |
java.util.Locale |
getLocale(javax.servlet.http.HttpServletRequest req)
Attempts to pull the Accept-Language header out of
the HttpServletRequest object and then parse it. |
java.util.Locale |
getLocale(java.lang.String header)
This method parses the Accept-Language header and
attempts to create a Locale out of it. |
java.lang.String |
getString(java.lang.String bundleName,
java.util.Locale locale,
java.lang.String key)
Tries very hard to return a value, looking first in the specified bundle, then searching list of default bundles (giving precedence to earlier bundles over later bundles). |
protected java.lang.String |
getStringOrNull(java.util.ResourceBundle rb,
java.lang.String key)
Gets localized text from a bundle if it's there. |
void |
init()
Called the first time the Service is used. |
protected void |
initBundleNames(java.lang.String[] ignored)
Initialize list of default bundle names. |
void |
setBundle(java.lang.String defaultBundle)
This method sets the name of the first bundle in the search list (the "default" bundle). |
Methods inherited from class org.apache.turbine.services.TurbineBaseService |
init, init, init, shutdown |
Methods inherited from class org.apache.turbine.services.BaseService |
getConfiguration, getName, getProperties, getServiceBroker, setName, setServiceBroker |
Methods inherited from class org.apache.turbine.services.BaseInitable |
getInit, getInitableBroker, setInit, setInitableBroker |
Methods inherited from class java.lang.Object |
|
Methods inherited from interface org.apache.turbine.services.Service |
getConfiguration, getName, getProperties, setName, setServiceBroker |
Methods inherited from interface org.apache.turbine.services.Initable |
getInit, init, setInitableBroker, shutdown |
Field Detail |
private java.util.Hashtable bundles
private java.lang.String[] bundleNames
private java.util.Locale defaultLocale
private java.lang.String defaultLanguage
private java.lang.String defaultCountry
Constructor Detail |
public TurbineLocalizationService()
Method Detail |
public void init() throws InitializationException
init
in interface Initable
init
in class TurbineBaseService
org.apache.turbine.services.Initable
InitializationException,
- if initialization of this
class was not successful.protected void initBundleNames(java.lang.String[] ignored)
names
- Ignored.public java.lang.String getDefaultBundleName()
getDefaultBundleName
in interface LocalizationService
LocalizationService.getDefaultBundleName()
public java.util.ResourceBundle getBundle()
getBundle
in interface LocalizationService
public java.util.ResourceBundle getBundle(java.lang.String bundleName)
getBundle
in interface LocalizationService
bundleName
- Name of bundle.public java.util.ResourceBundle getBundle(java.lang.String bundleName, java.lang.String languageHeader)
getBundle
in interface LocalizationService
bundleName
- Name of bundle.languageHeader
- A String with the language header.public java.util.ResourceBundle getBundle(javax.servlet.http.HttpServletRequest req)
getBundle
in interface LocalizationService
req
- HttpServletRequest.public java.util.ResourceBundle getBundle(java.lang.String bundleName, javax.servlet.http.HttpServletRequest req)
getBundle
in interface LocalizationService
bundleName
- Name of the bundle to use if the request's
locale cannot be resolved.req
- HttpServletRequest.public java.util.ResourceBundle getBundle(RunData data)
data
- Turbine information.public java.util.ResourceBundle getBundle(java.lang.String bundleName, RunData data)
bundleName
- Name of bundle.data
- Turbine information.public java.util.ResourceBundle getBundle(java.lang.String bundleName, java.util.Locale locale)
getBundle
in interface LocalizationService
bundleName
- Name of bundle.locale
- A Locale.public void setBundle(java.lang.String defaultBundle)
setBundle
in interface LocalizationService
defaultBundle
- Name of default bundle.public final java.util.Locale getLocale(javax.servlet.http.HttpServletRequest req)
LocalizationService
Accept-Language
header out of
the HttpServletRequest
object and then parse it.
If the header is not present, it will return a
null
Locale
.getLocale
in interface LocalizationService
LocalizationService.getLocale(HttpServletRequest)
public java.util.Locale getLocale(java.lang.String header)
LocalizationService
Accept-Language
header and
attempts to create a Locale
out of it.getLocale
in interface LocalizationService
LocalizationService.getLocale(String)
public java.lang.String getString(java.lang.String bundleName, java.util.Locale locale, java.lang.String key)
LocalizationService
getString
in interface LocalizationService
java.util.MissingResourceException
- Specified key cannot be matched.LocalizationService.getString(String, Locale, String)
protected final java.lang.String getStringOrNull(java.util.ResourceBundle rb, java.lang.String key)
null
(ignoring a possible
MissingResourceException
).
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |