org.apache.cocoon.i18n
Class XMLResourceBundleFactory

java.lang.Object
  extended byorg.apache.cocoon.util.AbstractLogEnabled
      extended byorg.apache.cocoon.i18n.XMLResourceBundleFactory
All Implemented Interfaces:
BundleFactory, Configurable, Disposable, Serviceable, ThreadSafe

public class XMLResourceBundleFactory
extends org.apache.cocoon.util.AbstractLogEnabled
implements BundleFactory, Serviceable, Configurable, Disposable, ThreadSafe

This is the XMLResourceBundleFactory, the method for getting and creating XMLResourceBundles.

Version:
$Id: XMLResourceBundleFactory.html 1304280 2012-03-23 11:18:01Z ilgrosso $

Nested Class Summary
 
Nested classes inherited from class org.apache.cocoon.i18n.BundleFactory
BundleFactory.ConfigurationKeys
 
Field Summary
protected  Store cache
          Store of the loaded bundles
protected  ServiceManager manager
          Service Manager
protected  SourceResolver resolver
          Source resolver
 
Fields inherited from interface org.apache.cocoon.i18n.BundleFactory
ROLE
 
Constructor Summary
XMLResourceBundleFactory()
           
 
Method Summary
 void configure(Configuration configuration)
          Configure the component.
 void dispose()
          Disposes this component.
protected  String getCacheKey(String[] directories, int index, String name, Locale locale)
          Creates a cache key for the bundle.
protected  String getDirectory()
          Returns the root directory to all bundles.
protected  Locale getParentLocale(Locale locale)
          Returns the next locale up the parent hierarchy.
protected  String getSourceURI(String base, String name, Locale locale)
          Maps a bundle name and locale to a bundle source URI.
 void release(Bundle bundle)
          Releases a bundle back to the bundle factory when it's not needed anymore.
 Bundle select(String[] directories, String name, Locale locale)
          Select a bundle based on the catalogue base location, bundle name, and the locale.
 Bundle select(String name, Locale locale)
          Select a bundle based on the bundle name and the locale.
 Bundle select(String name, String locale)
          Select a bundle based on the bundle name and the locale name.
 Bundle select(String directory, String name, Locale locale)
          Select a bundle based on the catalogue base location, bundle name, and the locale.
 Bundle select(String directory, String name, String localeName)
          Select a bundle based on the catalogue base location, bundle name, and the locale name.
protected  XMLResourceBundle selectCached(String cacheKey)
          Selects a bundle from the cache, and reloads it if needed.
 void service(ServiceManager manager)
           
protected  void updateCache(String cacheKey, XMLResourceBundle bundle)
          Stores bundle in the cache.
 
Methods inherited from class org.apache.cocoon.util.AbstractLogEnabled
getLogger, setLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

manager

protected ServiceManager manager
Service Manager


resolver

protected SourceResolver resolver
Source resolver


cache

protected Store cache
Store of the loaded bundles

Constructor Detail

XMLResourceBundleFactory

public XMLResourceBundleFactory()
Method Detail

service

public void service(ServiceManager manager)
             throws ServiceException
Specified by:
service in interface Serviceable
Throws:
ServiceException

configure

public void configure(Configuration configuration)
               throws ConfigurationException
Configure the component.

Specified by:
configure in interface Configurable
Parameters:
configuration - the configuration
Throws:
ConfigurationException

dispose

public void dispose()
Disposes this component.

Specified by:
dispose in interface Disposable

getDirectory

protected String getDirectory()
Returns the root directory to all bundles.

Returns:
the directory path

select

public Bundle select(String name,
                     String locale)
              throws Exception
Select a bundle based on the bundle name and the locale name.

Specified by:
select in interface BundleFactory
Parameters:
name - bundle name
locale - locale name
Returns:
the bundle
Throws:
Exception - if a bundle is not found

select

public Bundle select(String name,
                     Locale locale)
              throws Exception
Select a bundle based on the bundle name and the locale.

Specified by:
select in interface BundleFactory
Parameters:
name - bundle name
locale - locale
Returns:
the bundle
Throws:
Exception - if a bundle is not found

select

public Bundle select(String directory,
                     String name,
                     String localeName)
              throws Exception
Select a bundle based on the catalogue base location, bundle name, and the locale name.

Specified by:
select in interface BundleFactory
Parameters:
directory - catalogue base location (URI)
name - bundle name
localeName - locale name
Returns:
the bundle
Throws:
Exception - if a bundle is not found

select

public Bundle select(String directory,
                     String name,
                     Locale locale)
              throws Exception
Select a bundle based on the catalogue base location, bundle name, and the locale.

Specified by:
select in interface BundleFactory
Parameters:
directory - catalogue base location (URI)
name - bundle name
locale - locale
Returns:
the bundle
Throws:
Exception - if a bundle is not found

select

public Bundle select(String[] directories,
                     String name,
                     Locale locale)
              throws Exception
Select a bundle based on the catalogue base location, bundle name, and the locale.

Specified by:
select in interface BundleFactory
Parameters:
directories - catalogue base location (URI)
name - bundle name
locale - locale
Returns:
the bundle
Throws:
Exception - if a bundle is not found

release

public void release(Bundle bundle)
Description copied from interface: BundleFactory
Releases a bundle back to the bundle factory when it's not needed anymore.

Specified by:
release in interface BundleFactory
Parameters:
bundle - the bundle

getParentLocale

protected Locale getParentLocale(Locale locale)
Returns the next locale up the parent hierarchy. E.g. the parent of new Locale("en","us","mac") would be new Locale("en", "us", "").

Parameters:
locale - the locale
Returns:
the parent locale

getCacheKey

protected String getCacheKey(String[] directories,
                             int index,
                             String name,
                             Locale locale)
                      throws SourceException
Creates a cache key for the bundle.

Returns:
the cache key
Throws:
SourceException

getSourceURI

protected String getSourceURI(String base,
                              String name,
                              Locale locale)
                       throws SourceException
Maps a bundle name and locale to a bundle source URI. If you need a different mapping, then just override this method.

Parameters:
base - the base URI for the catalogues
name - the name of the catalogue
locale - the locale of the bundle
Returns:
the source URI for the bundle
Throws:
SourceException

selectCached

protected XMLResourceBundle selectCached(String cacheKey)
Selects a bundle from the cache, and reloads it if needed.

Parameters:
cacheKey - caching key of the bundle
Returns:
the cached bundle; null, if not found

updateCache

protected void updateCache(String cacheKey,
                           XMLResourceBundle bundle)
Stores bundle in the cache.

Parameters:
cacheKey - caching key of the bundle
bundle - bundle to be placed in the cache


Copyright 1999-2008 The Apache Software Foundation. All Rights Reserved.