org.apache.cocoon.i18n
Class XMLResourceBundle

java.lang.Object
  |
  +--java.util.ResourceBundle
        |
        +--org.apache.cocoon.i18n.XMLResourceBundle
All Implemented Interfaces:
org.apache.avalon.framework.component.Component, org.apache.avalon.framework.component.Composable, org.apache.avalon.framework.activity.Disposable, org.apache.avalon.framework.logger.Loggable

public class XMLResourceBundle
extends java.util.ResourceBundle
implements org.apache.avalon.framework.logger.Loggable, org.apache.avalon.framework.component.Component, org.apache.avalon.framework.component.Composable, org.apache.avalon.framework.activity.Disposable

Version:
$Id: XMLResourceBundle.java,v 1.7.2.2 2002/11/29 08:52:16 bdelacretaz Exp $
Author:
Mike Engelhart, Neeme Praks, Oleg Podolsky

Field Summary
protected static javax.xml.parsers.DocumentBuilderFactory docfactory
          DOM factory
protected  org.apache.log.Logger logger
          Logger
protected  org.apache.avalon.framework.component.ComponentManager manager
          Component Manager
protected  XMLResourceBundle parent
          Parent of the current bundle
 
Constructor Summary
XMLResourceBundle()
           
 
Method Summary
 void compose(org.apache.avalon.framework.component.ComponentManager manager)
           
 void dispose()
           
 org.w3c.dom.Document getDocument()
          Gets the source DOM tree of the bundle.
 java.util.Enumeration getKeys()
          Return an enumeration of the keys.
 java.util.Locale getLocale()
          Gets the locale of the bundle.
 java.lang.String getName()
          Gets the name of the bundle.
 java.lang.String getString(java.lang.String key, java.util.Map dictionary)
          Get value by key and substitute variables.
protected  java.lang.Object handleGetObject(java.lang.String key)
          Return an Object by key.
 void init(java.lang.String name, java.lang.String fileName, java.util.Locale locale, XMLResourceBundle parent, boolean cacheAtStartup)
          Initalize the bundle
protected static org.w3c.dom.Document loadResourceBundle(java.lang.String fileName)
          Load the DOM tree, based on the file name.
 void setLogger(org.apache.log.Logger logger)
          Set the logger.
 java.lang.String substitute(java.lang.String value, java.util.Map dictionary)
          Substitute the "variables" in the string with the values provided in the map.
 
Methods inherited from class java.util.ResourceBundle
getBundle, getBundle, getBundle, getObject, getString, getStringArray, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

docfactory

protected static javax.xml.parsers.DocumentBuilderFactory docfactory
DOM factory

parent

protected XMLResourceBundle parent
Parent of the current bundle

logger

protected org.apache.log.Logger logger
Logger

manager

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

XMLResourceBundle

public XMLResourceBundle()
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

init

public void init(java.lang.String name,
                 java.lang.String fileName,
                 java.util.Locale locale,
                 XMLResourceBundle parent,
                 boolean cacheAtStartup)
          throws java.io.IOException,
                 javax.xml.parsers.ParserConfigurationException,
                 org.xml.sax.SAXException
Initalize the bundle
Parameters:
name - name of the bundle
fileName - name of the XML source file
locale - locale
parent - parent bundle of this bundle
cacheAtStartup - cache all the keys when constructing?
Throws:
java.io.IOException - if an IO error occurs while reading the file
javax.xml.parsers.ParserConfigurationException - if no parser is configured
org.xml.sax.SAXException - if an error occurs while parsing the file

loadResourceBundle

protected static org.w3c.dom.Document loadResourceBundle(java.lang.String fileName)
                                                  throws java.io.IOException,
                                                         javax.xml.parsers.ParserConfigurationException,
                                                         org.xml.sax.SAXException
Load the DOM tree, based on the file name.
Parameters:
fileName - name of the XML source file
Returns:
the DOM tree
Throws:
java.io.IOException - if an IO error occurs while reading the file
javax.xml.parsers.ParserConfigurationException - if no parser is configured
org.xml.sax.SAXException - if an error occurs while parsing the file

getName

public java.lang.String getName()
Gets the name of the bundle.
Returns:
the name

getDocument

public org.w3c.dom.Document getDocument()
Gets the source DOM tree of the bundle.
Returns:
the DOM tree

getLocale

public java.util.Locale getLocale()
Gets the locale of the bundle.
Overrides:
getLocale in class java.util.ResourceBundle
Returns:
the locale

getString

public java.lang.String getString(java.lang.String key,
                                  java.util.Map dictionary)
                           throws java.util.MissingResourceException
Get value by key and substitute variables.
Parameters:
key - key
dictionary - map with variable values
Returns:
value with variable values substituted
Throws:
java.util.MissingResourceException - if resource was not found

substitute

public java.lang.String substitute(java.lang.String value,
                                   java.util.Map dictionary)
Substitute the "variables" in the string with the values provided in the map.
Parameters:
value - value where to search for variables
dictionary - map with variable values
Returns:
value with variable values substituted

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

handleGetObject

protected java.lang.Object handleGetObject(java.lang.String key)
                                    throws java.util.MissingResourceException
Return an Object by key. Implementation of the ResourceBundle abstract method.
Overrides:
handleGetObject in class java.util.ResourceBundle
Parameters:
key - the key
Returns:
the object

getKeys

public java.util.Enumeration getKeys()
Return an enumeration of the keys. Implementation of the ResourceBundle abstract method.
Overrides:
getKeys in class java.util.ResourceBundle
Returns:
the enumeration of keys


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