Class RegexBasedInterpolator
- java.lang.Object
-
- org.codehaus.plexus.interpolation.RegexBasedInterpolator
-
- All Implemented Interfaces:
BasicInterpolator
,Interpolator
public class RegexBasedInterpolator extends java.lang.Object implements Interpolator
Expansion of the original RegexBasedInterpolator, found in plexus-utils, this interpolator provides options for setting custom prefix/suffix regex parts, and includes aRecursionInterceptor
parameter in its interpolate(..) call, to allow the detection of cyclical expression references.
-
-
Field Summary
Fields Modifier and Type Field 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 Patternstatic 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 Summary
Constructors Constructor Description RegexBasedInterpolator()
Setup a basic interpolator.RegexBasedInterpolator(boolean reusePatterns)
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.RegexBasedInterpolator(java.util.List valueSources)
Setup a basic interpolator with the specified list of value sources.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 newValueSource
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, 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.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.boolean
isCacheAnswers()
boolean
isReusePatterns()
void
removePostProcessor(InterpolationPostProcessor postProcessor)
Remove the given post-processor.void
removeValuesSource(ValueSource valueSource)
Remove the specifiedValueSource
from the stack used to resolve expressions in this interpolator instance.void
setCacheAnswers(boolean cacheAnswers)
void
setReusePatterns(boolean reusePatterns)
-
-
-
Field Detail
-
startRegex
private java.lang.String startRegex
-
endRegex
private java.lang.String endRegex
-
existingAnswers
private java.util.Map existingAnswers
-
valueSources
private java.util.List<ValueSource> valueSources
-
postProcessors
private java.util.List<InterpolationPostProcessor> postProcessors
-
reusePatterns
private boolean reusePatterns
-
cacheAnswers
private boolean cacheAnswers
-
DEFAULT_REGEXP
public static final java.lang.String DEFAULT_REGEXP
- See Also:
- Constant Field Values
-
compiledPatterns
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
-
-
Constructor Detail
-
RegexBasedInterpolator
public RegexBasedInterpolator()
Setup a basic interpolator.NOTE: You will have to call
addValueSource(ValueSource)
at least once if you use this constructor!
-
RegexBasedInterpolator
public RegexBasedInterpolator(boolean reusePatterns)
- Parameters:
reusePatterns
- already compiled patterns will be reused
-
RegexBasedInterpolator
public 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.NOTE: You will have to call
addValueSource(ValueSource)
at least once if you use this constructor!- Parameters:
startRegex
- start of the regular expression to useendRegex
- end of the regular expression to use
-
RegexBasedInterpolator
public RegexBasedInterpolator(java.util.List valueSources)
Setup a basic interpolator with the specified list of value sources.- Parameters:
valueSources
- The list of value sources to use
-
RegexBasedInterpolator
public 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.- Parameters:
startRegex
- start of the regular expression to useendRegex
- end of the regular expression to usevalueSources
- The list of value sources to use
-
-
Method Detail
-
addValueSource
public void addValueSource(ValueSource valueSource)
Add a newValueSource
to the stack used to resolve expressions in this interpolator instance.- Specified by:
addValueSource
in interfaceInterpolator
- Parameters:
valueSource
-ValueSource
.
-
removeValuesSource
public void removeValuesSource(ValueSource valueSource)
Remove the specifiedValueSource
from the stack used to resolve expressions in this interpolator instance.- Specified by:
removeValuesSource
in interfaceInterpolator
- Parameters:
valueSource
-ValueSource
.
-
addPostProcessor
public void addPostProcessor(InterpolationPostProcessor postProcessor)
Add a new post-processor to handle final processing after recursively-interpolated value is determined.- Specified by:
addPostProcessor
in interfaceInterpolator
- Parameters:
postProcessor
-InterpolationPostProcessor
.
-
removePostProcessor
public void removePostProcessor(InterpolationPostProcessor postProcessor)
Remove the given post-processor.- Specified by:
removePostProcessor
in interfaceInterpolator
- Parameters:
postProcessor
-InterpolationPostProcessor
.
-
interpolate
public java.lang.String interpolate(java.lang.String input, java.lang.String thisPrefixPattern, RecursionInterceptor recursionInterceptor) throws InterpolationException
Attempt to resolve all expressions in the given input string, using the given pattern to first trim an optional prefix from each expression. The supplied recursion interceptor will provide protection from expression cycles, ensuring that the input can be resolved or an exception is thrown.- Specified by:
interpolate
in interfaceInterpolator
- Parameters:
input
- 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.- Returns:
- interpolated string.
- Throws:
InterpolationException
- in case of an error.
-
getPattern
private java.util.regex.Pattern getPattern(java.lang.String regExp)
-
interpolate
private java.lang.String interpolate(java.lang.String input, RecursionInterceptor recursionInterceptor, java.util.regex.Pattern expressionPattern, int realExprGroup) throws InterpolationException
Entry point for recursive resolution of an expression and all of its nested expressions.- Throws:
InterpolationException
-
getFeedback
public java.util.List getFeedback()
Return any feedback messages and errors that were generated - but suppressed - during the interpolation process. Since unresolvable expressions will be left in the source string as-is, this feedback is optional, and will only be useful for debugging interpolation problems.- Specified by:
getFeedback
in interfaceInterpolator
- Returns:
- a
List
that may be interspersed withString
andThrowable
instances.
-
clearFeedback
public void clearFeedback()
Clear the feedback messages from previous interpolate(..) calls.- Specified by:
clearFeedback
in interfaceInterpolator
-
interpolate
public java.lang.String interpolate(java.lang.String input, java.lang.String thisPrefixPattern) throws InterpolationException
Seeinterpolate(String, String, RecursionInterceptor)
.This method triggers the use of a
SimpleRecursionInterceptor
instance for protection against expression cycles.- Specified by:
interpolate
in interfaceInterpolator
- Parameters:
input
- The input string to interpolatethisPrefixPattern
- An optional pattern that should be trimmed from the start of any expressions found in the input.- Returns:
- interpolated string.
- Throws:
InterpolationException
- in case of an error.
-
interpolate
public java.lang.String interpolate(java.lang.String input) throws InterpolationException
Seeinterpolate(String, String, RecursionInterceptor)
.This method triggers the use of a
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.- Specified by:
interpolate
in interfaceBasicInterpolator
- Parameters:
input
- The input string to interpolate- Returns:
- the interpolated string.
- Throws:
InterpolationException
- in case of an error.
-
interpolate
public java.lang.String interpolate(java.lang.String input, RecursionInterceptor recursionInterceptor) throws InterpolationException
Seeinterpolate(String, String, RecursionInterceptor)
.This method leaves empty the expression prefix which would otherwise be trimmed from expressions. The result is that any detected expression will be resolved as-is.
- Specified by:
interpolate
in interfaceBasicInterpolator
- Parameters:
input
- The input string to interpolaterecursionInterceptor
- Used to protect the interpolation process from expression cycles, and throw an exception if one is detected.- Returns:
- the interpolated string.
- Throws:
InterpolationException
- in case of an error.
-
isReusePatterns
public boolean isReusePatterns()
-
setReusePatterns
public void setReusePatterns(boolean reusePatterns)
-
isCacheAnswers
public boolean isCacheAnswers()
- Specified by:
isCacheAnswers
in interfaceInterpolator
- Returns:
- state of the cacheAnswers
-
setCacheAnswers
public void setCacheAnswers(boolean cacheAnswers)
- Specified by:
setCacheAnswers
in interfaceInterpolator
- Parameters:
cacheAnswers
- true/false.
-
clearAnswers
public void clearAnswers()
- Specified by:
clearAnswers
in interfaceInterpolator
-
-