Class RegexBasedInterpolator
java.lang.Object
org.codehaus.plexus.interpolation.RegexBasedInterpolator
- All Implemented Interfaces:
BasicInterpolator
,Interpolator
Expansion of the original RegexBasedInterpolator, found in plexus-utils, this
interpolator provides options for setting custom prefix/suffix regex parts,
and includes a
RecursionInterceptor
parameter in its interpolate(..)
call, to allow the detection of cyclical expression references.-
Field Summary
-
Constructor Summary
ConstructorDescriptionSetup a basic interpolator.RegexBasedInterpolator
(boolean reusePatterns) RegexBasedInterpolator
(String startRegex, String endRegex) Setup an interpolator with no value sources, and the specified regex pattern prefix and suffix in place of the default one.RegexBasedInterpolator
(String startRegex, String endRegex, 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
(List valueSources) Setup a basic interpolator with the specified list of value sources. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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
void
Clear the feedback messages from previous interpolate(..) calls.Return any feedback messages and errors that were generated - but suppressed - during the interpolation process.interpolate
(String input) interpolate
(String input, String thisPrefixPattern) interpolate
(String input, 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.interpolate
(String input, RecursionInterceptor recursionInterceptor) boolean
boolean
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 Details
-
DEFAULT_REGEXP
- See Also:
-
-
Constructor Details
-
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
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
Setup a basic interpolator with the specified list of value sources.- Parameters:
valueSources
- The list of value sources to use
-
RegexBasedInterpolator
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 Details
-
addValueSource
Add a newValueSource
to the stack used to resolve expressions in this interpolator instance.- Specified by:
addValueSource
in interfaceInterpolator
- Parameters:
valueSource
-ValueSource
.
-
removeValuesSource
Remove the specifiedValueSource
from the stack used to resolve expressions in this interpolator instance.- Specified by:
removeValuesSource
in interfaceInterpolator
- Parameters:
valueSource
-ValueSource
.
-
addPostProcessor
Add a new post-processor to handle final processing after recursively-interpolated value is determined.- Specified by:
addPostProcessor
in interfaceInterpolator
- Parameters:
postProcessor
-InterpolationPostProcessor
.
-
removePostProcessor
Remove the given post-processor.- Specified by:
removePostProcessor
in interfaceInterpolator
- Parameters:
postProcessor
-InterpolationPostProcessor
.
-
interpolate
public String interpolate(String input, 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.
-
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
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
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 String interpolate(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
-