1 package org.codehaus.plexus.interpolation;
2
3 /*
4 * Copyright 2001-2008 Codehaus Foundation.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 import java.util.List;
20
21 /**
22 * Interpolator interface. Based on existing RegexBasedInterpolator interface.
23 *
24 * @author cstamas
25 */
26 public interface Interpolator extends BasicInterpolator {
27
28 /**
29 * Add a new {@link ValueSource} to the stack used to resolve expressions
30 * in this interpolator instance.
31 * @param valueSource {@link ValueSource}.
32 */
33 void addValueSource(ValueSource valueSource);
34
35 /**
36 * Remove the specified {@link ValueSource} from the stack used to resolve
37 * expressions in this interpolator instance.
38 * @param valueSource {@link ValueSource}.
39 */
40 void removeValuesSource(ValueSource valueSource);
41
42 /**
43 * Add a new post-processor to handle final processing after
44 * recursively-interpolated value is determined.
45 * @param postProcessor {@link InterpolationPostProcessor}.
46 */
47 void addPostProcessor(InterpolationPostProcessor postProcessor);
48
49 /**
50 * Remove the given post-processor.
51 * @param postProcessor {@link InterpolationPostProcessor}.
52 */
53 void removePostProcessor(InterpolationPostProcessor postProcessor);
54
55 /**
56 * See {@link Interpolator#interpolate(String, String, RecursionInterceptor)}.
57 * <p>
58 * This method triggers the use of a {@link SimpleRecursionInterceptor}
59 * instance for protection against expression cycles.</p>
60 *
61 * @param input The input string to interpolate
62 *
63 * @param thisPrefixPattern An optional pattern that should be trimmed from
64 * the start of any expressions found in the input.
65 * @return interpolated string.
66 * @throws InterpolationException in case of an error.
67 */
68 String interpolate(String input, String thisPrefixPattern) throws InterpolationException;
69
70 /**
71 * Attempt to resolve all expressions in the given input string, using the
72 * given pattern to first trim an optional prefix from each expression. The
73 * supplied recursion interceptor will provide protection from expression
74 * cycles, ensuring that the input can be resolved or an exception is
75 * thrown.
76 * <b>return an empty String if input is null</b>
77 * @param input The input string to interpolate
78 *
79 * @param thisPrefixPattern An optional pattern that should be trimmed from
80 * the start of any expressions found in the input.
81 *
82 * @param recursionInterceptor Used to protect the interpolation process
83 * from expression cycles, and throw an
84 * exception if one is detected.
85 * @return interpolated string.
86 * @throws InterpolationException in case of an error.
87 */
88 String interpolate(String input, String thisPrefixPattern, RecursionInterceptor recursionInterceptor)
89 throws InterpolationException;
90
91 /**
92 * Return any feedback messages and errors that were generated - but
93 * suppressed - during the interpolation process. Since unresolvable
94 * expressions will be left in the source string as-is, this feedback is
95 * optional, and will only be useful for debugging interpolation problems.
96 *
97 * @return a {@link List} that may be interspersed with {@link String} and
98 * {@link Throwable} instances.
99 */
100 List getFeedback();
101
102 /**
103 * Clear the feedback messages from previous interpolate(..) calls.
104 */
105 void clearFeedback();
106
107 /**
108 * @return state of the cacheAnswers
109 */
110 boolean isCacheAnswers();
111
112 /**
113 * @param cacheAnswers true/false.
114 */
115 void setCacheAnswers(boolean cacheAnswers);
116
117 void clearAnswers();
118 }