|
Cantaloop CGimlet - API Documentation, Version: 0.2.0, Date: 2002-05-13 21:30 CEST | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.cantaloop.cgimlet.PropertyParser
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.
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); |
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 |
protected org.dom4j.QName m_elemName
protected java.lang.String m_keyAttr
protected java.lang.String m_valueAttr
protected java.util.Properties m_props
Constructor Detail |
public PropertyParser(org.dom4j.Namespace ns)
PropertyParser(new QName("property", ns))
.ns
- the namespace the property-element is declared in.public PropertyParser(org.dom4j.QName elemName)
PropertyParser(elemName, "name", "value")
.elemName
- the name of the element that defines the properties.public PropertyParser(org.dom4j.QName elemName, java.lang.String keyAttr, java.lang.String valueAttr)
PropertyParser
instance.elemName
- the QName
of a element that
holds a propertykeyAttr
- the name of the attribute of the element that
holds the key of the propertyvalueAttr
- the name of the attribute of the element that
holds the value of the propertyMethod Detail |
public java.util.Properties getProperties()
Properties
valuepublic java.util.Properties parse(org.dom4j.Element root)
apply(org.dom4j.Element)
instead.
public java.util.Properties apply(org.dom4j.Element root)
initProperties(root);
replaceProperties(root);
getProperties();
root
- an Element
valueProperties
valuepublic 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()
.
root
- an Element
valuepublic void replaceProperties(org.dom4j.Element root) throws CodeGenerationException
root
. The value of all attributes and the textual
content of all text-only elements is replaced.root
- an Element
valueCodeGenerationException
- if the name of a property does not exist.public java.lang.String parsePropertyString(java.lang.String value)
value
and resolve all properties in the given
string.CodeGenerationException
if a property
cannot be resolved.value
- a String
value
|
Copyright 2001, 2002 Stefan Heimann, David Leuschner. All rights reserved. | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |