org.apache.turbine.services.localization
Class TurbineLocalizationService

java.lang.Object
  |
  +--org.apache.turbine.services.BaseInitable
        |
        +--org.apache.turbine.services.BaseService
              |
              +--org.apache.turbine.services.TurbineBaseService
                    |
                    +--org.apache.turbine.services.localization.TurbineLocalizationService
All Implemented Interfaces:
Initable, LocalizationService, Service

public class TurbineLocalizationService
extends TurbineBaseService
implements LocalizationService

This class has been added 17.01.2000 by [jm],mediaphil digital media. Please contact me if you have any questions, which ARE NOT ANSWERED by the Java Localization/Internationalization Documentation. 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:
- getBundle("MyBundleName")
- getBundle("MyBundleName", httpAcceptLanguageHeader)
- getBundle("MyBundleName", RunData)
- getBundle("MyBundleName", Locale)

Version:
$Id$
Author:
Jonas Maurus, Jon S. Stevens, Frank Y. Kim

Field Summary
private static java.util.Hashtable bundles
          The ResourceBundles in this service.
private static java.lang.String defaultBundle
          The name of the default bundle to use.
 
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
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(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, 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.
 void init()
          Called the first time the Service is used.
 void setBundle(java.lang.String defaultBundle)
          This method sets the name of the defaultBundle.
 
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
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 
Methods inherited from interface org.apache.turbine.services.Service
getConfiguration, getProperties, setName, setServiceBroker
 
Methods inherited from interface org.apache.turbine.services.Initable
getInit, init, setInitableBroker, shutdown
 

Field Detail

bundles

private static java.util.Hashtable bundles
The ResourceBundles in this service. Key=bundle name Value=Hashtable containing ResourceBundles keyed by Locale.

defaultBundle

private static java.lang.String defaultBundle
The name of the default bundle to use.
Constructor Detail

TurbineLocalizationService

public TurbineLocalizationService()
Constructor.
Method Detail

init

public void init()
          throws InitializationException
Called the first time the Service is used.
Specified by:
init in interface Initable
Overrides:
init in class TurbineBaseService
Following copied from interface: org.apache.turbine.services.Initable
Throws:
InitializationException, - if initialization of this class was not successful.

getBundle

public java.util.ResourceBundle getBundle()
This method returns a ResourceBundle given the bundle name "DEFAULT" and the default Locale information supplied in TurbineProperties.
Specified by:
getBundle in interface LocalizationService
Returns:
A localized ResourceBundle.

getBundle

public 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.
Specified by:
getBundle in interface LocalizationService
Parameters:
bundleName - Name of bundle.
Returns:
A localized ResourceBundle.

getBundle

public 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.
Specified by:
getBundle in interface LocalizationService
Parameters:
bundleName - Name of bundle.
languageHeader - A String with the language header.
Returns:
A localized ResourceBundle.

getBundle

public 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.
Specified by:
getBundle in interface LocalizationService
Parameters:
data - Turbine information.
Returns:
A localized ResourceBundle.

getBundle

public 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.
Specified by:
getBundle in interface LocalizationService
Parameters:
bundleName - Name of bundle.
data - Turbine information.
Returns:
A localized ResourceBundle.

getBundle

public 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.
Specified by:
getBundle in interface LocalizationService
Parameters:
bundleName - Name of bundle.
locale - A Locale.
Returns:
A localized ResourceBundle.

setBundle

public void setBundle(java.lang.String defaultBundle)
This method sets the name of the defaultBundle.
Specified by:
setBundle in interface LocalizationService
Parameters:
defaultBundle - Name of default bundle.


Copyright © 1999-2001 Apache Software Foundation. All Rights Reserved.