edu.umbc.cs.daml4jess
Class Macro

java.lang.Object
  |
  +--edu.umbc.cs.daml4jess.Macro

public class Macro
extends java.lang.Object

This utility class is designed to replace macros in any text as long as it conforms to the rules as specified as follow. For example, if you define HOMEPATH = /home/xyz, then you can use it as mypath = ${HOMEPATH}/bin. If you want to use the actual string ${...} itself and not as a macro reference, you should use another "$" (dollar sign) to escape, e.g, $${HOMEPATH}, in which case, HOMEPATH won't be expanded. More accurately, if you want the string "${" itself, it must be escaped. Note that '$' is not a general escape character here and is interpreted as an escape char if and only if it is in a sequence of '$' that appear before a macro definition openning string "${". For example, if a = "xy", then ${a} = "xy", $${a} = "$${a}" (escaped), $$${a} = $xy, $$$${a} = "$${a}" (escaped), $$$$$${a} = "$$xy". For now, it does not support nested macro definitions. It saves a copy of the original file with extension "._old".


Nested Class Summary
static class Macro.MacroException
          The macro error exception.
 
Constructor Summary
Macro(java.util.Properties macroDefs)
          Constructor.
 
Method Summary
static void main(java.lang.String[] args)
          main program, testing only.
 boolean resolveMacros(java.lang.String fileName)
          Resolve the macro references in the given text file.
 java.lang.String resolveMacros(java.lang.String data, int lineNo)
          Resolve the macro in the given text data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Macro

public Macro(java.util.Properties macroDefs)
Constructor.

Parameters:
macroDefs - the macro definitions, in Java proeprties format.
Method Detail

resolveMacros

public boolean resolveMacros(java.lang.String fileName)
Resolve the macro references in the given text file. The original will be saved with an extension "._old".

Parameters:
fileName - the input file.
Returns:
true if succeeded; false otherwise.

resolveMacros

public java.lang.String resolveMacros(java.lang.String data,
                                      int lineNo)
                               throws java.io.IOException,
                                      Macro.MacroException
Resolve the macro in the given text data.

Parameters:
data - the data that may contain macros.
lineNo - the current line number. Used for error reporting.
Returns:
the data with macros resolved, if any.
java.io.IOException
Macro.MacroException

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
main program, testing only. Usage: java edu.umbc.cs.daml4jess.Macro ()+

java.lang.Exception