public class Expander
extends java.lang.Object
Map keys are constrained to the character set [\w.] by converting characters outside of that range to underscores. The putAll methods return a map describing keys that have been renamed according to this algorithm.
References look like ${this} or ${-this} or ${!this}. If the map element ('this' in these examples) is set, these references will all expand to the same exact thing (obviously the value of the map element with key 'this'). The difference only applies if there is no map element with key 'this'. In that case, ${this} remains exactly as it was (the input Creole is not changed at all); ${-this} is removed (i.e. replace with an empty string); and ${!this} will cause the expand() method to throw.
I would much prefer to write this with Groovy, but GroovyDoc sucks and I want to provide a real API Spec for integrators to work from.
Nested definitions, like a map value containing '${ref}', are supported, but the nested values are de-referenced by the put* methods, not in the expand method. Therefore, they are dereferenced at setup time, not at expand time. Consequently, if you use putAll() call with intra-references, you must ensure that you use an order-preserving Map implementation, and that the referents' values are completely defined before the referers. Two other ways to satisfy this use-case are to use your own loop and call put*() instead of putAll(); or to move referred-to definitions into an additional map that is fed to putAll() before your main map.
The escape mechanism is \${, \$[, \$(. All that will happen is the backslash there will be removed.
Modifier and Type | Class and Description |
---|---|
static class |
Expander.PairedDelims |
Constructor and Description |
---|
Expander(Expander.PairedDelims pd) |
Modifier and Type | Method and Description |
---|---|
java.lang.StringBuilder |
expand(java.lang.CharSequence inString) |
java.lang.String |
expandToString(java.lang.CharSequence inString)
Same exact contract as expand(CharSequence), but returns a String.
|
static void |
main(java.lang.String[] sa) |
java.lang.String |
put(java.lang.String newKey,
java.lang.String newVal)
Wrapper for put(String, String, String, boolean),
with no (null) namespace and value expansion.
|
java.lang.String |
put(java.lang.String newKey,
java.lang.String newVal,
boolean expandVal)
Wrapper for put(String, String, String, boolean),
with no (null) namespace.
|
java.lang.String |
put(java.lang.String ns,
java.lang.String newKey,
java.lang.String newVal,
boolean expandVal)
N.b.
|
java.util.Map<java.lang.String,java.lang.String> |
putAll(java.util.Map<java.lang.String,java.lang.String> inMap)
Wrapper for putAll(String, Map, boolean),
with no (null) namespace and value expansion.
|
java.util.Map<java.lang.String,java.lang.String> |
putAll(java.util.Map<java.lang.String,java.lang.String> inMap,
boolean expandVals)
Wrapper for putAll(String, Map, boolean), with no (null) namespace.
|
java.util.Map<java.lang.String,java.lang.String> |
putAll(java.lang.String ns,
java.util.Map<java.lang.String,java.lang.String> inMap,
boolean expandVals)
If the specified ns is non-null, then it is used with the current
ns for this Expander instance.
|
java.util.Map<java.lang.String,java.lang.String> |
putAll(java.lang.String ns,
java.util.Properties ps,
boolean expandVals)
Exact same behavior as putAll(String, Map, boolean)
|
void |
setPrefixDelimiter(char newDelimiter) |
java.lang.String |
toString() |
public Expander(Expander.PairedDelims pd)
public void setPrefixDelimiter(char newDelimiter)
public java.lang.String put(java.lang.String newKey, java.lang.String newVal)
put(String, String, String, boolean)
public java.lang.String put(java.lang.String newKey, java.lang.String newVal, boolean expandVal)
put(String, String, String, boolean)
public java.lang.String put(java.lang.String ns, java.lang.String newKey, java.lang.String newVal, boolean expandVal)
See Class level Javadoc for details about nested values.
ns
- Namespace prefixed (with prefixDelimiter) to key.public java.util.Map<java.lang.String,java.lang.String> putAll(java.util.Map<java.lang.String,java.lang.String> inMap)
putAll(String, Map, boolean)
public java.util.Map<java.lang.String,java.lang.String> putAll(java.util.Map<java.lang.String,java.lang.String> inMap, boolean expandVals)
putAll(String, Map, boolean)
public java.util.Map<java.lang.String,java.lang.String> putAll(java.lang.String ns, java.util.Properties ps, boolean expandVals)
putAll(String, Map, boolean)
public java.util.Map<java.lang.String,java.lang.String> putAll(java.lang.String ns, java.util.Map<java.lang.String,java.lang.String> inMap, boolean expandVals)
See Class level Javadoc for details about nested values.
ns
- Namespace prefixed (with prefixDelimiter) to key.public java.lang.String expandToString(java.lang.CharSequence inString)
expand(CharSequence)
public java.lang.StringBuilder expand(java.lang.CharSequence inString)
java.lang.IllegalArgumentException
- if inString contains an unsatisfied
! reference (like ${!ref}).public static void main(java.lang.String[] sa)
public java.lang.String toString()
toString
in class java.lang.Object