org.apache.cocoon.i18n
Class XMLResourceBundleFactory

java.lang.Object
  |
  +--org.apache.avalon.framework.component.DefaultComponentSelector
        |
        +--org.apache.cocoon.i18n.XMLResourceBundleFactory
All Implemented Interfaces:
org.apache.avalon.framework.component.Component, org.apache.avalon.framework.component.ComponentSelector, org.apache.avalon.framework.component.Composable, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.activity.Disposable, org.apache.avalon.framework.logger.Loggable, org.apache.avalon.framework.thread.ThreadSafe

public class XMLResourceBundleFactory
extends org.apache.avalon.framework.component.DefaultComponentSelector
implements org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.component.Composable, org.apache.avalon.framework.logger.Loggable, org.apache.avalon.framework.activity.Disposable, org.apache.avalon.framework.thread.ThreadSafe

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

Version:
$Id: XMLResourceBundleFactory.java,v 1.5.2.1 2002/05/30 11:56:46 kpiroumian Exp $
Author:
Mike Engelhart, Neeme Praks, Oleg Podolsky

Inner Class Summary
static class XMLResourceBundleFactory.ConfigurationKeys
          Constants for configuration keys
 
Field Summary
protected  boolean cacheAtStartup
          Should we load bundles to cache on startup or not?
protected  java.util.Map cacheNotFound
          Cache for the names of the bundles that were not found
protected  java.lang.String directory
          Root directory to all bundle names
protected  org.apache.log.Logger logger
          The logger
protected  org.apache.avalon.framework.component.ComponentManager manager
          Component Manager
 
Constructor Summary
XMLResourceBundleFactory()
          Default constructor.
 
Method Summary
 boolean cacheAtStartup()
          Should we load bundles to cache on startup or not?
 void compose(org.apache.avalon.framework.component.ComponentManager manager)
           
 void configure(org.apache.avalon.framework.configuration.Configuration configuration)
          Configure the component.
 void dispose()
           
 java.lang.String getDirectory()
          Returns the root directory to all bundles.
protected  java.lang.String getFileName(java.lang.String name, java.util.Locale loc)
          Maps a bundle name and locale to a full path in the filesystem.
protected  java.util.Locale getParentLocale(java.util.Locale loc)
          Returns the next locale up the parent hierarchy.
protected  boolean isNotFoundBundle(java.lang.String fileName)
          Checks if the bundle is in the "not-found" cache.
 void release(org.apache.avalon.framework.component.Component component)
           
 org.apache.avalon.framework.component.Component select(java.lang.String name, java.util.Locale locale)
          Select a bundle based on bundle name and locale.
 org.apache.avalon.framework.component.Component select(java.lang.String name, java.util.Locale loc, boolean cacheAtStartup)
          Select a bundle based on bundle name and locale.
 org.apache.avalon.framework.component.Component select(java.lang.String name, java.lang.String localeName)
          Select a bundle based on bundle name and locale name.
protected  org.apache.avalon.framework.component.Component selectCached(java.lang.String fileName)
          Selects a bundle from the cache.
 org.apache.avalon.framework.component.Component selectFromFilename(java.lang.String fileName)
          Select a bundle based on source XML file name.
 org.apache.avalon.framework.component.Component selectFromFilename(java.lang.String fileName, boolean cacheAtStartup)
          Select a bundle based on source XML file name.
protected  org.apache.avalon.framework.component.Component selectParent(java.lang.String name, java.util.Locale loc)
          Select the parent bundle of the current bundle, based on bundle name and locale.
protected  org.apache.avalon.framework.component.Component selectParent(java.lang.String name, java.util.Locale loc, boolean cacheAtStartup)
          Select the parent bundle of the current bundle, based on bundle name and locale.
 void setLogger(org.apache.log.Logger logger)
          Set the logger.
protected  void updateCache(java.lang.String fileName, XMLResourceBundle bundle)
          Checks if the bundle is in the "not-found" cache.
 
Methods inherited from class org.apache.avalon.framework.component.DefaultComponentSelector
checkWriteable, getComponentMap, hasComponent, makeReadOnly, put, select
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cacheAtStartup

protected boolean cacheAtStartup
Should we load bundles to cache on startup or not?

directory

protected java.lang.String directory
Root directory to all bundle names

cacheNotFound

protected java.util.Map cacheNotFound
Cache for the names of the bundles that were not found

logger

protected org.apache.log.Logger logger
The logger

manager

protected org.apache.avalon.framework.component.ComponentManager manager
Component Manager
Constructor Detail

XMLResourceBundleFactory

public XMLResourceBundleFactory()
Default constructor.
Method Detail

compose

public void compose(org.apache.avalon.framework.component.ComponentManager manager)
Specified by:
compose in interface org.apache.avalon.framework.component.Composable

dispose

public void dispose()
Specified by:
dispose in interface org.apache.avalon.framework.activity.Disposable

setLogger

public void setLogger(org.apache.log.Logger logger)
Set the logger.
Specified by:
setLogger in interface org.apache.avalon.framework.logger.Loggable
Parameters:
logger - the logger

configure

public void configure(org.apache.avalon.framework.configuration.Configuration configuration)
               throws org.apache.avalon.framework.configuration.ConfigurationException
Configure the component.
Specified by:
configure in interface org.apache.avalon.framework.configuration.Configurable
Parameters:
configuration - the configuration

select

public org.apache.avalon.framework.component.Component select(java.lang.String name,
                                                              java.util.Locale locale)
                                                       throws org.apache.avalon.framework.component.ComponentException
Select a bundle based on bundle name and locale.
Parameters:
name - bundle name
locale - locale
Returns:
the bundle
Throws:
org.apache.avalon.framework.component.ComponentException - if a bundle is not found

select

public org.apache.avalon.framework.component.Component select(java.lang.String name,
                                                              java.util.Locale loc,
                                                              boolean cacheAtStartup)
                                                       throws org.apache.avalon.framework.component.ComponentException
Select a bundle based on bundle name and locale.
Parameters:
name - bundle name
locale - locale
cacheAtStartup - cache all the keys when constructing?
Returns:
the bundle
Throws:
org.apache.avalon.framework.component.ComponentException - if a bundle is not found

selectParent

protected org.apache.avalon.framework.component.Component selectParent(java.lang.String name,
                                                                       java.util.Locale loc)
Select the parent bundle of the current bundle, based on bundle name and locale.
Parameters:
name - bundle name
locale - locale
Returns:
the bundle

selectParent

protected org.apache.avalon.framework.component.Component selectParent(java.lang.String name,
                                                                       java.util.Locale loc,
                                                                       boolean cacheAtStartup)
Select the parent bundle of the current bundle, based on bundle name and locale.
Parameters:
name - bundle name
locale - locale
cacheAtStartup - cache all the keys when constructing?
Returns:
the bundle

select

public org.apache.avalon.framework.component.Component select(java.lang.String name,
                                                              java.lang.String localeName)
                                                       throws org.apache.avalon.framework.component.ComponentException
Select a bundle based on bundle name and locale name.
Parameters:
name - bundle name
localeName - locale name
Returns:
the bundle
Throws:
org.apache.avalon.framework.component.ComponentException - if a bundle is not found

selectFromFilename

public org.apache.avalon.framework.component.Component selectFromFilename(java.lang.String fileName)
                                                                   throws org.apache.avalon.framework.component.ComponentException
Select a bundle based on source XML file name.
Parameters:
fileName - file name
Returns:
the bundle
Throws:
org.apache.avalon.framework.component.ComponentException - if a bundle is not found

selectFromFilename

public org.apache.avalon.framework.component.Component selectFromFilename(java.lang.String fileName,
                                                                          boolean cacheAtStartup)
                                                                   throws org.apache.avalon.framework.component.ComponentException
Select a bundle based on source XML file name.
Parameters:
fileName - file name
cacheAtStartup - cache all the keys when constructing?
Returns:
the bundle
Throws:
org.apache.avalon.framework.component.ComponentException - if a bundle is not found

release

public void release(org.apache.avalon.framework.component.Component component)
Overrides:
release in class org.apache.avalon.framework.component.DefaultComponentSelector

getParentLocale

protected java.util.Locale getParentLocale(java.util.Locale loc)
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

getFileName

protected java.lang.String getFileName(java.lang.String name,
                                       java.util.Locale loc)
Maps a bundle name and locale to a full path in the filesystem. If you need a different mapping, then just override this method.
Parameters:
locale - the locale
Returns:
the parent locale

selectCached

protected org.apache.avalon.framework.component.Component selectCached(java.lang.String fileName)
Selects a bundle from the cache.
Parameters:
fileName - file name of the bundle
Returns:
the cached bundle; null, if not found

isNotFoundBundle

protected boolean isNotFoundBundle(java.lang.String fileName)
Checks if the bundle is in the "not-found" cache.
Parameters:
fileName - file name of the bundle
Returns:
true, if the bundle wasn't found already before; otherwise, false.

updateCache

protected void updateCache(java.lang.String fileName,
                           XMLResourceBundle bundle)
Checks if the bundle is in the "not-found" cache.
Parameters:
fileName - file name of the bundle
Returns:
true, if the bundle wasn't found already before; otherwise, false.

getDirectory

public java.lang.String getDirectory()
Returns the root directory to all bundles.
Returns:
the directory path

cacheAtStartup

public boolean cacheAtStartup()
Should we load bundles to cache on startup or not?
Returns:
true if pre-loading all resources; false otherwise


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