Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.cantaloop.cgimlet
Class PropertyParser  view PropertyParser download PropertyParser.java

java.lang.Object
  extended byorg.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:
@version@ ($Revision: 1.10 $)

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) 55 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.
private static void parsePropertyString(java.lang.String value, java.util.List fragments, java.util.List propertyRefs)
          Taken from ant (www.jakarta.apache.org/ant) This method will parse a string containing ${value} style property values into two lists.
 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)).


PropertyParser

public PropertyParser(org.dom4j.QName elemName)
Shorthand for:
PropertyParser(elemName, "name", "value").


PropertyParser

public PropertyParser(org.dom4j.QName elemName,
                      java.lang.String keyAttr,
                      java.lang.String valueAttr)
Creates a new customized PropertyParser instance.

Method Detail

getProperties

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


parse

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


apply

public java.util.Properties apply(org.dom4j.Element root)
Shorthand for:
initProperties(root);
replaceProperties(root);
getProperties();


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() 55 .


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.


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.


parsePropertyString

private static void parsePropertyString(java.lang.String value,
                                        java.util.List fragments,
                                        java.util.List propertyRefs)
                                 throws CodeGenerationException
Taken from ant (www.jakarta.apache.org/ant) This method will parse a string containing ${value} style property values into two lists. The first list is a collection of text fragments, while the other is a set of string property names. null entries in the first list indicate a property reference from the second list.