org.apache.jackrabbit.core.config
Class ConfigurationParser

java.lang.Object
  extended by org.apache.jackrabbit.core.config.ConfigurationParser
Direct Known Subclasses:
RepositoryConfigurationParser

public class ConfigurationParser
extends Object

Configuration parser base class. This class provides the basic functionality for parsing Jackrabbit configuration files. Subclasses extend this functionality with knowledge of the exact structure of the different configuration files. Each configuration parser instance contains a set of parser variables that are used for variable replacement in the configuration file.


Field Summary
static String CLASS_ATTRIBUTE
          Name of the bean implementation class configuration attribute.
static String NAME_ATTRIBUTE
          Name of the bean parameter name configuration attribute.
static String PARAM_ELEMENT
          Name of the bean parameter configuration element.
static String VALUE_ATTRIBUTE
          Name of the bean parameter value configuration attribute.
 
Constructor Summary
ConfigurationParser(Properties variables)
          Creates a new configuration parser with the given parser variables.
 
Method Summary
protected  String getAttribute(Element element, String name)
          Returns the value of the named attribute of the given element.
protected  String getAttribute(Element element, String name, String def)
          Returns the value of the named attribute of the given element.
protected  Element getElement(Element parent, String name)
          Returns the named child of the given parent element.
protected  Element getElement(Element parent, String name, boolean required)
          Returns the named child of the given parent element.
protected  EntityResolver getEntityResolver()
          Returns the entity resolver to be used when parsing configuration documents.
protected  ErrorHandler getErrorHandler()
          Returns the error handler to be used when parsing configuration documents.
 Properties getVariables()
          Returns the variables.
protected  BeanConfig parseBeanConfig(Element element)
          Parses a named bean configuration from the given element.
protected  BeanConfig parseBeanConfig(Element parent, String name)
          Parses a named bean configuration from the given element.
protected  Properties parseParameters(Element element)
          Parses the configuration parameters of the given element.
protected  Element parseXML(InputSource xml)
          Parses the given XML document and returns the DOM root element.
protected  Element parseXML(InputSource xml, boolean validate)
          Parses the given XML document and returns the DOM root element.
protected  Document postParseModificationHook(Document document)
          A post-processing hook for the parsed repository or workspace configuration documents.
protected  String replaceVariables(String value)
          Performs variable replacement on the given string value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PARAM_ELEMENT

public static final String PARAM_ELEMENT
Name of the bean parameter configuration element.

See Also:
Constant Field Values

CLASS_ATTRIBUTE

public static final String CLASS_ATTRIBUTE
Name of the bean implementation class configuration attribute.

See Also:
Constant Field Values

NAME_ATTRIBUTE

public static final String NAME_ATTRIBUTE
Name of the bean parameter name configuration attribute.

See Also:
Constant Field Values

VALUE_ATTRIBUTE

public static final String VALUE_ATTRIBUTE
Name of the bean parameter value configuration attribute.

See Also:
Constant Field Values
Constructor Detail

ConfigurationParser

public ConfigurationParser(Properties variables)
Creates a new configuration parser with the given parser variables.

Parameters:
variables - parser variables
Method Detail

getVariables

public Properties getVariables()
Returns the variables.

Returns:
the variables.

parseBeanConfig

protected BeanConfig parseBeanConfig(Element parent,
                                     String name)
                              throws ConfigurationException
Parses a named bean configuration from the given element. Bean configuration uses the following format:
   <BeanName class="...">
     <param name="..." value="..."/>
     ...
   </BeanName>
 

The returned bean configuration object contains the configured class name and configuration parameters. Variable replacement is performed on the parameter values.

Parameters:
parent - parent element
name - name of the bean configuration element
Returns:
bean configuration,
Throws:
ConfigurationException - if the configuration element does not exist or is broken

parseBeanConfig

protected BeanConfig parseBeanConfig(Element element)
                              throws ConfigurationException
Parses a named bean configuration from the given element. Bean configuration uses the following format:
   <BeanName class="...">
     <param name="..." value="..."/>
     ...
   </BeanName>
 

The returned bean configuration object contains the configured class name and configuration parameters. Variable replacement is performed on the parameter values.

Parameters:
element -
Returns:
bean configuration,
Throws:
ConfigurationException - if the configuration element does not exist or is broken

parseParameters

protected Properties parseParameters(Element element)
                              throws ConfigurationException
Parses the configuration parameters of the given element. Parameters are stored as <param name="..." value="..."/> child elements. This method parses all param elements, performs variable replacement on parameter values, and returns the resulting name-value pairs.

Parameters:
element - configuration element
Returns:
configuration parameters
Throws:
ConfigurationException - if a param element does not contain the name and value attributes

replaceVariables

protected String replaceVariables(String value)
                           throws ConfigurationException
Performs variable replacement on the given string value. Each ${...} sequence within the given value is replaced with the value of the named parser variable. The replacement is not done if the named variable does not exist.

Parameters:
value - original value
Returns:
value after variable replacements
Throws:
ConfigurationException - if the replacement of a referenced variable is not found

parseXML

protected Element parseXML(InputSource xml)
                    throws ConfigurationException
Parses the given XML document and returns the DOM root element. A custom entity resolver is used to make the included configuration file DTD available using the specified public identifiers. This implementation does not validate the XML.

Parameters:
xml - xml document
Returns:
root element
Throws:
ConfigurationException - if the configuration document could not be read or parsed
See Also:
ConfigurationEntityResolver

getErrorHandler

protected ErrorHandler getErrorHandler()
Returns the error handler to be used when parsing configuration documents. Subclasses can override this method to provide custom error handling.

Returns:
error handler
Since:
Apache Jackrabbit 2.0

getEntityResolver

protected EntityResolver getEntityResolver()
Returns the entity resolver to be used when parsing configuration documents. Subclasses can override this method to provide custom entity resolution rules.

Returns:
error handler
Since:
Apache Jackrabbit 2.0

postParseModificationHook

protected Document postParseModificationHook(Document document)
A post-processing hook for the parsed repository or workspace configuration documents. This hook makes it possible to make custom DOM modifications for backwards-compatibility or other reasons.

Parameters:
document - the parsed configuration document
Returns:
the configuration document after any modifications
Since:
Apache Jackrabbit 2.0

parseXML

protected Element parseXML(InputSource xml,
                           boolean validate)
                    throws ConfigurationException
Parses the given XML document and returns the DOM root element. A custom entity resolver is used to make the included configuration file DTD available using the specified public identifiers.

Parameters:
xml - xml document
validate - whether the XML should be validated
Returns:
root element
Throws:
ConfigurationException - if the configuration document could not be read or parsed
See Also:
ConfigurationEntityResolver

getElement

protected Element getElement(Element parent,
                             String name)
                      throws ConfigurationException
Returns the named child of the given parent element.

Parameters:
parent - parent element
name - name of the child element
Returns:
named child element
Throws:
ConfigurationException
ConfigurationException - if the child element is not found

getElement

protected Element getElement(Element parent,
                             String name,
                             boolean required)
                      throws ConfigurationException
Returns the named child of the given parent element.

Parameters:
parent - parent element
name - name of the child element
required - indicates if the child element is required
Returns:
named child element, or null if not found and required is false.
Throws:
ConfigurationException - if the child element is not found and required is true; or if more than one element with this name exists.

getAttribute

protected String getAttribute(Element element,
                              String name)
                       throws ConfigurationException
Returns the value of the named attribute of the given element.

Parameters:
element - element
name - attribute name
Returns:
attribute value
Throws:
ConfigurationException - if the attribute is not found

getAttribute

protected String getAttribute(Element element,
                              String name,
                              String def)
Returns the value of the named attribute of the given element. If the attribute is not found, then the given default value is returned.

Parameters:
element - element
name - attribute name
def - default value
Returns:
attribute value, or the default value


Copyright © 2004-2010 The Apache Software Foundation. All Rights Reserved.