Oracle Fusion Middleware Java API Reference for Oracle Extension SDK
11g Release 2 (11.1.2.0.0)

E17493-01

oracle.javatools.util
Class MacroExpander

java.lang.Object
  extended by oracle.javatools.util.MacroExpander

public class MacroExpander
extends java.lang.Object

Parses and substitites macros with literal values or other macros.


Constructor Summary
MacroExpander()
          Initiate a parser for parsing macros of the form "${xxx}".
MacroExpander(java.lang.String startDelim, java.lang.String endDelim, boolean recursiveParse, boolean sanitizedMacroKeys)
           
 
Method Summary
 java.lang.String expand(java.lang.String macro, java.util.Map<java.lang.String,java.lang.String> macroValues)
          Expand macros substituting macro-values from a Map.
 boolean isRecursiveParse()
           
 boolean isSanitizedMacroKeys()
           
 void setRecursiveParse(boolean recursiveParse)
           
 void setSanitizedMacroKeys(boolean sanitizedMacroKeys)
          Should macro keys passed in the Map of macro values be considered to be free of the macro delimiters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MacroExpander

public MacroExpander()
Initiate a parser for parsing macros of the form "${xxx}". By default recursive parsing is true and macro keysare not sanitized.


MacroExpander

public MacroExpander(java.lang.String startDelim,
                     java.lang.String endDelim,
                     boolean recursiveParse,
                     boolean sanitizedMacroKeys)
Parameters:
startDelim - starting delimited
endDelim - ending delimiter
recursiveParse - whether substituted values should be parsed again, this allows macros within macro-values, for e.g. if macro is ${${component}} and key-value Map is
"component" == "oracle${version}"
"version" == "11"
"oracle11" = "Oracle Jdev 11".
Then fully evaluated macro value will be "Oracle Jdev 11".

Note that "${${ora}${version}}" where "ora" = "oracle" will give the same result, but is not recursive, its just a nested macro.
sanitizedMacroKeys - whether the keys in the 'macrovalues' Map passed to expand() are stripped of delimiters. Default is false.
Method Detail

expand

public java.lang.String expand(java.lang.String macro,
                               java.util.Map<java.lang.String,java.lang.String> macroValues)
Expand macros substituting macro-values from a Map.

Parameters:
macro - the macro to parse.
macroValues - a Map contain macro key-value pairs. If sanitizedMacroValues is true then the keys should not contain delimiters.
Returns:
the value after all macros have been expanded.
Throws:
java.lang.IllegalArgumentException - if the macro has syntax errors
java.util.NoSuchElementException - if a macro could not be resolved by the Map and if recursive parsing is enabled (default). If recursive parsing is disabled, the macro is left unexpanded.

setRecursiveParse

public void setRecursiveParse(boolean recursiveParse)

isRecursiveParse

public boolean isRecursiveParse()

setSanitizedMacroKeys

public void setSanitizedMacroKeys(boolean sanitizedMacroKeys)
Should macro keys passed in the Map of macro values be considered to be free of the macro delimiters.
Sanitized map:
{ [ "quick":"value1"], ["brown":"value2"], [ "fox":value3] }
Unsanitized map: (assuming delimters are ${} )
{ [ "${quick}":"value1"], ["${brown}":"value2"], [ "${fox}":value3] }

Parameters:
sanitizedMacroKeys - set to false if MacroExpander should strip delimiters from the keys before considering them for a match.

isSanitizedMacroKeys

public boolean isSanitizedMacroKeys()

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK
11g Release 2 (11.1.2.0.0)

E17493-01

Copyright © 1997, 2011, Oracle. All rights reserved.