org.apache.avalon.excalibur.i18n
Class XmlBundle

java.lang.Object
  |
  +--org.apache.avalon.framework.logger.AbstractLogEnabled
        |
        +--org.apache.avalon.excalibur.i18n.AbstractBundle
              |
              +--org.apache.avalon.excalibur.i18n.XmlBundle
All Implemented Interfaces:
Bundle, org.apache.avalon.framework.component.Component, org.apache.avalon.framework.component.Composable, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.activity.Disposable, org.apache.avalon.framework.activity.Initializable, org.apache.avalon.framework.logger.LogEnabled
Direct Known Subclasses:
FlatXmlBundle

public class XmlBundle
extends AbstractBundle
implements org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.activity.Initializable, org.apache.avalon.framework.activity.Disposable, org.apache.avalon.framework.component.Composable

Version:
$Id: XmlBundle.java,v 1.8 2002/01/04 13:21:31 cziegeler Exp $
Author:
Mike Engelhart, Neeme Praks, Oleg Podolsky

Inner Class Summary
static class XmlBundle.ConfigurationKeys
          Constants for configuration keys
 
Field Summary
protected  org.apache.avalon.framework.component.ComponentManager manager
          Component Manager
 
Fields inherited from interface org.apache.avalon.excalibur.i18n.Bundle
ROLE
 
Constructor Summary
XmlBundle()
           
 
Method Summary
protected  org.w3c.dom.Node _getNode(org.w3c.dom.Node rootNode, java.lang.String key)
          Get the node with the supplied XPath key, starting from concrete root node.
protected  org.w3c.dom.Node _getNode(java.lang.String key)
          Get the node with the supplied XPath key.
protected  java.lang.String _getString(org.w3c.dom.Node node, java.lang.String key)
          Get value by key from a concrete node.
protected  java.lang.String _getString(java.lang.String key)
          Get value by key.
protected  void cacheAll(org.w3c.dom.Node parent, java.lang.String pathToParent)
          Steps through the bundle tree and stores all text element values in bundle's cache.
protected  boolean cacheContains(java.lang.String key)
          Does the "key-cache" contain the value with such key?
protected  void cacheKey(java.lang.String key, java.lang.String value)
          Cache the key and value in "key-cache".
protected  boolean cacheNotFoundContains(java.lang.String key)
          Does the "key-not-found-cache" contain such key?
protected  void cacheNotFoundKey(java.lang.String key)
          Cache the key in "key-not-found-cache".
 void compose(org.apache.avalon.framework.component.ComponentManager manager)
           
 void configure(org.apache.avalon.framework.configuration.Configuration configuration)
           
 java.lang.String convertKey(java.lang.String userKey)
          Convert the "user view" of the lookup key to the "system view".
 void dispose()
           
 org.w3c.dom.Document getDocument()
          Gets the source DOM tree of the bundle.
protected  java.lang.String getFromCache(java.lang.String key)
          Gets the value by the key from the "key-cache".
 java.lang.String getString(java.lang.String key)
          Get value by key.
protected static java.lang.String getTextValue(org.w3c.dom.Node element)
          Get the text value of the node.
 void initialize()
          Initalize the bundle
 void initialize(org.xml.sax.InputSource inSource)
          Initalize the bundle
 void initialize(Source source)
          Initalize the bundle
 void initialize(java.lang.String uri)
          Initalize the bundle
 
Methods inherited from class org.apache.avalon.excalibur.i18n.AbstractBundle
getBundleInfo, getLastModified, getMapper, getParent, getString, setBundleInfo, setLastModified, setMapper, setParent, substitute
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

manager

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

XmlBundle

public XmlBundle()
Method Detail

compose

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

configure

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

initialize

public void initialize()
                throws java.lang.Exception
Initalize the bundle
Specified by:
initialize in interface org.apache.avalon.framework.activity.Initializable
Parameters:
document - XML source document (DOM)

initialize

public void initialize(java.lang.String uri)
                throws java.lang.Exception
Initalize the bundle
Parameters:
uri - URI of the XML source
Throws:
IOException - if an IO error occurs while reading the file
ParserConfigurationException - if no parser is configured
SAXException - if an error occurs while parsing the file

initialize

public void initialize(Source source)
                throws java.lang.Exception
Initalize the bundle
Parameters:
file - XML source file
Throws:
IOException - if an IO error occurs while reading the file
ParserConfigurationException - if no parser is configured
SAXException - if an error occurs while parsing the file

initialize

public void initialize(org.xml.sax.InputSource inSource)
                throws java.lang.Exception
Initalize the bundle
Parameters:
inStream - XML source stream
Throws:
IOException - if an IO error occurs while reading the file
ParserConfigurationException - if no parser is configured
SAXException - if an error occurs while parsing the file

convertKey

public java.lang.String convertKey(java.lang.String userKey)
Convert the "user view" of the lookup key to the "system view". Current implementation coverts dots into slashes, so common Java property names become XPath paths. E.g: this.is.java.property.key --> /this/is/java/property/key
Overrides:
convertKey in class AbstractBundle
Parameters:
key - user key
Returns:
system key

getDocument

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

cacheContains

protected boolean cacheContains(java.lang.String key)
Does the "key-cache" contain the value with such key?
Parameters:
key - the key to the value to be returned
Returns:
true if contains, false otherwise

cacheNotFoundContains

protected boolean cacheNotFoundContains(java.lang.String key)
Does the "key-not-found-cache" contain such key?
Parameters:
key - the key to the value to be returned
Returns:
true if contains, false otherwise

cacheKey

protected void cacheKey(java.lang.String key,
                        java.lang.String value)
Cache the key and value in "key-cache".
Parameters:
key - the key
value - the value

cacheNotFoundKey

protected void cacheNotFoundKey(java.lang.String key)
Cache the key in "key-not-found-cache".
Parameters:
key - the key

getFromCache

protected java.lang.String getFromCache(java.lang.String key)
Gets the value by the key from the "key-cache".
Parameters:
key - the key
Returns:
the value

cacheAll

protected void cacheAll(org.w3c.dom.Node parent,
                        java.lang.String pathToParent)
Steps through the bundle tree and stores all text element values in bundle's cache. Also stores attributes for all element nodes.
Parameters:
parent - parent node, must be an element
pathToParent - XPath to the parent node

getString

public java.lang.String getString(java.lang.String key)
                           throws java.util.MissingResourceException
Get value by key.
Parameters:
key - key
Returns:
value
Throws:
java.util.MissingResourceException - if value was not found

_getString

protected java.lang.String _getString(java.lang.String key)
Get value by key.
Parameters:
key - the key
Returns:
the value

_getString

protected java.lang.String _getString(org.w3c.dom.Node node,
                                      java.lang.String key)
Get value by key from a concrete node.
Parameters:
node - the node
key - the key
Returns:
the value

getTextValue

protected static java.lang.String getTextValue(org.w3c.dom.Node element)
Get the text value of the node.
Parameters:
node - the node
Returns:
the value

_getNode

protected org.w3c.dom.Node _getNode(java.lang.String key)
Get the node with the supplied XPath key.
Parameters:
key - the key
Returns:
the node

_getNode

protected org.w3c.dom.Node _getNode(org.w3c.dom.Node rootNode,
                                    java.lang.String key)
Get the node with the supplied XPath key, starting from concrete root node.
Parameters:
rootNode - the root node
key - the key
Returns:
the node

dispose

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


Copyright © 2001 Apache Jakarta Project. All Rights Reserved.