Cantaloop CGimlet - API Documentation, Version: 0.2.0, Date: 2002-05-13 21:30 CEST

org.cantaloop.cgimlet
Class PropertyParser

java.lang.Object
  |
  +--org.cantaloop.cgimlet.PropertyParser

public class PropertyParser
extends java.lang.Object

A PropertyParser reads property-definitions and replaces their occurences in a XML file.

A property is defined like this:

<property name="basedir" value="."/>

This sets the property `basedir' to the value `.'. From this point on the value of the property can be accessed in all attributes and all text-only elements by writing ${basedir}.

It is an error to use a property that is not defined or to define a property a second time.

A property can also be composed of existing properties.

<property name="dir.src" value="${basedir}/src">

You can costomize the PropertyParser by setting the namespace and the name of the element that holds the properties. You can also use different name for the attributes that hold the name and the value of the property. This customization is done in the constructor.

Version:
0.2.0 ($Revision: 1.10 $)
Author:
David Leuschner, Stefan Heimann

Field Summary
protected  org.dom4j.QName m_elemName
           
protected  java.lang.String m_keyAttr
           
protected  java.util.Properties m_props
           
protected  java.lang.String m_valueAttr
           
 
Constructor Summary
PropertyParser(org.dom4j.Namespace ns)
          Shorthand for:
PropertyParser(new QName("property", ns)).
PropertyParser(org.dom4j.QName elemName)
          Shorthand for:
PropertyParser(elemName, "name", "value").
PropertyParser(org.dom4j.QName elemName, java.lang.String keyAttr, java.lang.String valueAttr)
          Creates a new customized PropertyParser instance.
 
Method Summary
 java.util.Properties apply(org.dom4j.Element root)
          Shorthand for:
initProperties(root);
replaceProperties(root);
getProperties();
 java.util.Properties getProperties()
          Returns the properties the parser has read.
 void initProperties(org.dom4j.Element root)
          Read the properties from the elements that are direct children of root.
 java.util.Properties parse(org.dom4j.Element root)
          Deprecated. use apply(org.dom4j.Element) instead.
 java.lang.String parsePropertyString(java.lang.String value)
          Parse value and resolve all properties in the given string.
Throws a CodeGenerationException if a property cannot be resolved.
 void replaceProperties(org.dom4j.Element root)
          Replace all properties in the xml tree starting with element root.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_elemName

protected org.dom4j.QName m_elemName

m_keyAttr

protected java.lang.String m_keyAttr

m_valueAttr

protected java.lang.String m_valueAttr

m_props

protected java.util.Properties m_props
Constructor Detail

PropertyParser

public PropertyParser(org.dom4j.Namespace ns)
Shorthand for:
PropertyParser(new QName("property", ns)).
Parameters:
ns - the namespace the property-element is declared in.

PropertyParser

public PropertyParser(org.dom4j.QName elemName)
Shorthand for:
PropertyParser(elemName, "name", "value").
Parameters:
elemName - the name of the element that defines the properties.

PropertyParser

public PropertyParser(org.dom4j.QName elemName,
                      java.lang.String keyAttr,
                      java.lang.String valueAttr)
Creates a new customized PropertyParser instance.
Parameters:
elemName - the QName of a element that holds a property
keyAttr - the name of the attribute of the element that holds the key of the property
valueAttr - the name of the attribute of the element that holds the value of the property
Method Detail

getProperties

public java.util.Properties getProperties()
Returns the properties the parser has read.
Returns:
a Properties value

parse

public java.util.Properties parse(org.dom4j.Element root)
Deprecated. use apply(org.dom4j.Element) instead.


apply

public java.util.Properties apply(org.dom4j.Element root)
Shorthand for:
initProperties(root);
replaceProperties(root);
getProperties();
Parameters:
root - an Element value
Returns:
a Properties value

initProperties

public void initProperties(org.dom4j.Element root)
                    throws CodeGenerationException

Read the properties from the elements that are direct children of root. If a property element has not the attributes that were given in the constructor of the PropertyParser, a CodeGenerationException is thrown.

You can get the properties that were read by calling getProperties().

Parameters:
root - an Element value

replaceProperties

public void replaceProperties(org.dom4j.Element root)
                       throws CodeGenerationException
Replace all properties in the xml tree starting with element root. The value of all attributes and the textual content of all text-only elements is replaced.
Parameters:
root - an Element value
Throws:
CodeGenerationException - if the name of a property does not exist.

parsePropertyString

public java.lang.String parsePropertyString(java.lang.String value)
Parse value and resolve all properties in the given string.
Throws a CodeGenerationException if a property cannot be resolved.
Parameters:
value - a String value
Returns:
the parsed property

Copyright 2001, 2002 Stefan Heimann, David Leuschner. All rights reserved.