cds.util
Class Macro

java.lang.Object
  extended bycds.util.Macro

public class Macro
extends java.lang.Object

Manages macro substitution in a string.
The string can contain parameters like $PARAM ou ${PARAM}, where the parameter designation character ('$' by default) can be changed.
Several ways will feed the macro object with the values for such parameters. A substitution returns the the string with the values replacing the corresponding parameters.

Version:
1.0 Apr 2003
1.1 May 2003 substitute: bug fixed for the last copy, use pCopyBegin, not p2
Author:
Marc Wenger/CDS

Field Summary
private static char DELIM_CHAR_BEGIN
           
private static char DELIM_CHAR_END
           
private static char ESC_CHAR
           
private  char param_char
           
private static char PARAM_CHAR
           
(package private)  java.util.Hashtable paramList
           
 
Constructor Summary
Macro()
          Empty constructor.
Macro(java.util.Hashtable ht)
          Constructor receiving a hastable of parameters
Macro(Macro mac)
          Constructor receiving a Macro object for its initialization
 
Method Summary
 void addParam(java.util.Hashtable ht)
          Adds a Hashtable of parameters to this macro object
 void addParam(java.lang.String name, java.lang.String value)
          Adds a parameter tothe current hashtable
 java.lang.String[] getParameters(java.lang.String str)
          Returns the list of parameters contained in a string.
static java.lang.String[] getParameters(java.lang.String str, char parameterChar)
          Returns the list of parameters contained in a string.
 char setParameterChar(char c)
          Change the character used to define a parameter (default is '$')
 java.lang.String substitute(java.lang.String str)
          Substitute the defined parameters in the given string
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PARAM_CHAR

private static final char PARAM_CHAR
See Also:
Constant Field Values

DELIM_CHAR_BEGIN

private static final char DELIM_CHAR_BEGIN
See Also:
Constant Field Values

DELIM_CHAR_END

private static final char DELIM_CHAR_END
See Also:
Constant Field Values

ESC_CHAR

private static final char ESC_CHAR
See Also:
Constant Field Values

param_char

private char param_char

paramList

java.util.Hashtable paramList
Constructor Detail

Macro

public Macro()
Empty constructor. Parameters will have to be added later with the addParam() methods.


Macro

public Macro(java.util.Hashtable ht)
Constructor receiving a hastable of parameters

Parameters:
ht - Hashtable of parameters

Macro

public Macro(Macro mac)
Constructor receiving a Macro object for its initialization

Method Detail

setParameterChar

public char setParameterChar(char c)
Change the character used to define a parameter (default is '$')

Parameters:
c - new char to use for defining a parameter
Returns:
the old parameter definition char

addParam

public void addParam(java.util.Hashtable ht)
Adds a Hashtable of parameters to this macro object

Parameters:
ht - Hashtable of parameters

addParam

public void addParam(java.lang.String name,
                     java.lang.String value)
Adds a parameter tothe current hashtable

Parameters:
name - name of the parameter
value - value of the parameter (string to substitute)

substitute

public java.lang.String substitute(java.lang.String str)
                            throws java.text.ParseException
Substitute the defined parameters in the given string

Parameters:
str - String containing parameters to substitute
Returns:
the string after parameter substitution
Throws:
java.text.ParseException - if a parameter is absent or braces are not closed

getParameters

public java.lang.String[] getParameters(java.lang.String str)
Returns the list of parameters contained in a string.
This method uses the same algorithm than substitute() to recognize the parameters and return their names in an array. It is based on an defined macro object.

Parameters:
str - string to analyse
Returns:
an array of all the parameters found in the string

getParameters

public static java.lang.String[] getParameters(java.lang.String str,
                                               char parameterChar)
Returns the list of parameters contained in a string.
This static method uses the same algorithm than substitute() to recognize the parameters and return their names in an array.

Parameters:
str - string to analyse
parameterChar - defines a particular character for parameter designation
Returns:
an array of all the parameters found in the string