public class RegexBasedInterpolator extends java.lang.Object implements Interpolator
RecursionInterceptor parameter in its interpolate(..)
call, to allow the detection of cyclical expression references.| Modifier and Type | Field and Description |
|---|---|
private boolean |
cacheAnswers |
private java.util.Map<java.lang.String,java.util.regex.Pattern> |
compiledPatterns
the key is the regex the value is the Pattern
At the class construction time the Map will contains the default Pattern
|
static java.lang.String |
DEFAULT_REGEXP |
private java.lang.String |
endRegex |
private java.util.Map |
existingAnswers |
private java.util.List<InterpolationPostProcessor> |
postProcessors |
private boolean |
reusePatterns |
private java.lang.String |
startRegex |
private java.util.List<ValueSource> |
valueSources |
| Constructor and Description |
|---|
RegexBasedInterpolator()
Setup a basic interpolator.
|
RegexBasedInterpolator(boolean reusePatterns) |
RegexBasedInterpolator(java.util.List valueSources)
Setup a basic interpolator with the specified list of value sources.
|
RegexBasedInterpolator(java.lang.String startRegex,
java.lang.String endRegex)
Setup an interpolator with no value sources, and the specified regex pattern
prefix and suffix in place of the default one.
|
RegexBasedInterpolator(java.lang.String startRegex,
java.lang.String endRegex,
java.util.List valueSources)
Setup an interpolator with the specified value sources, and the specified
regex pattern prefix and suffix in place of the default one.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addPostProcessor(InterpolationPostProcessor postProcessor)
Add a new post-processor to handle final processing after
recursively-interpolated value is determined.
|
void |
addValueSource(ValueSource valueSource)
Add a new
ValueSource to the stack used to resolve expressions
in this interpolator instance. |
void |
clearAnswers() |
void |
clearFeedback()
Clear the feedback messages from previous interpolate(..) calls.
|
java.util.List |
getFeedback()
Return any feedback messages and errors that were generated - but
suppressed - during the interpolation process.
|
private java.util.regex.Pattern |
getPattern(java.lang.String regExp) |
java.lang.String |
interpolate(java.lang.String input)
|
java.lang.String |
interpolate(java.lang.String input,
RecursionInterceptor recursionInterceptor)
|
private java.lang.String |
interpolate(java.lang.String input,
RecursionInterceptor recursionInterceptor,
java.util.regex.Pattern expressionPattern,
int realExprGroup)
Entry point for recursive resolution of an expression and all of its
nested expressions.
|
java.lang.String |
interpolate(java.lang.String input,
java.lang.String thisPrefixPattern)
|
java.lang.String |
interpolate(java.lang.String input,
java.lang.String thisPrefixPattern,
RecursionInterceptor recursionInterceptor)
Attempt to resolve all expressions in the given input string, using the
given pattern to first trim an optional prefix from each expression.
|
boolean |
isCacheAnswers() |
boolean |
isReusePatterns() |
void |
removePostProcessor(InterpolationPostProcessor postProcessor)
Remove the given post-processor.
|
void |
removeValuesSource(ValueSource valueSource)
Remove the specified
ValueSource from the stack used to resolve
expressions in this interpolator instance. |
void |
setCacheAnswers(boolean cacheAnswers) |
void |
setReusePatterns(boolean reusePatterns) |
private java.lang.String startRegex
private java.lang.String endRegex
private java.util.Map existingAnswers
private java.util.List<ValueSource> valueSources
private java.util.List<InterpolationPostProcessor> postProcessors
private boolean reusePatterns
private boolean cacheAnswers
public static final java.lang.String DEFAULT_REGEXP
private java.util.Map<java.lang.String,java.util.regex.Pattern> compiledPatterns
public RegexBasedInterpolator()
addValueSource(ValueSource) at least once
if you use this constructor!public RegexBasedInterpolator(boolean reusePatterns)
reusePatterns - already compiled patterns will be reusedpublic RegexBasedInterpolator(java.lang.String startRegex,
java.lang.String endRegex)
addValueSource(ValueSource) at least once
if you use this constructor!startRegex - start of the regular expression to useendRegex - end of the regular expression to usepublic RegexBasedInterpolator(java.util.List valueSources)
valueSources - The list of value sources to usepublic RegexBasedInterpolator(java.lang.String startRegex,
java.lang.String endRegex,
java.util.List valueSources)
startRegex - start of the regular expression to useendRegex - end of the regular expression to usevalueSources - The list of value sources to usepublic void addValueSource(ValueSource valueSource)
ValueSource to the stack used to resolve expressions
in this interpolator instance.addValueSource in interface Interpolatorpublic void removeValuesSource(ValueSource valueSource)
ValueSource from the stack used to resolve
expressions in this interpolator instance.removeValuesSource in interface Interpolatorpublic void addPostProcessor(InterpolationPostProcessor postProcessor)
addPostProcessor in interface Interpolatorpublic void removePostProcessor(InterpolationPostProcessor postProcessor)
removePostProcessor in interface Interpolatorpublic java.lang.String interpolate(java.lang.String input,
java.lang.String thisPrefixPattern,
RecursionInterceptor recursionInterceptor)
throws InterpolationException
interpolate in interface Interpolatorinput - The input string to interpolatethisPrefixPattern - An optional pattern that should be trimmed from
the start of any expressions found in the input.recursionInterceptor - Used to protect the interpolation process
from expression cycles, and throw an
exception if one is detected.InterpolationExceptionprivate java.util.regex.Pattern getPattern(java.lang.String regExp)
private java.lang.String interpolate(java.lang.String input,
RecursionInterceptor recursionInterceptor,
java.util.regex.Pattern expressionPattern,
int realExprGroup)
throws InterpolationException
InterpolationExceptionpublic java.util.List getFeedback()
getFeedback in interface InterpolatorList that may be interspersed with String and
Throwable instances.public void clearFeedback()
clearFeedback in interface Interpolatorpublic java.lang.String interpolate(java.lang.String input,
java.lang.String thisPrefixPattern)
throws InterpolationException
interpolate(String, String, RecursionInterceptor).
SimpleRecursionInterceptor
instance for protection against expression cycles.interpolate in interface Interpolatorinput - The input string to interpolatethisPrefixPattern - An optional pattern that should be trimmed from
the start of any expressions found in the input.InterpolationExceptionpublic java.lang.String interpolate(java.lang.String input)
throws InterpolationException
interpolate(String, String, RecursionInterceptor).
SimpleRecursionInterceptor
instance for protection against expression cycles. It also leaves empty the
expression prefix which would otherwise be trimmed from expressions. The
result is that any detected expression will be resolved as-is.interpolate in interface BasicInterpolatorinput - The input string to interpolateInterpolationExceptionpublic java.lang.String interpolate(java.lang.String input,
RecursionInterceptor recursionInterceptor)
throws InterpolationException
interpolate(String, String, RecursionInterceptor).
interpolate in interface BasicInterpolatorinput - The input string to interpolaterecursionInterceptor - Used to protect the interpolation process
from expression cycles, and throw an
exception if one is detected.InterpolationExceptionpublic boolean isReusePatterns()
public void setReusePatterns(boolean reusePatterns)
public boolean isCacheAnswers()
isCacheAnswers in interface Interpolatorpublic void setCacheAnswers(boolean cacheAnswers)
setCacheAnswers in interface Interpolatorpublic void clearAnswers()
clearAnswers in interface Interpolator