1
1
/*
2
- * Copyright 2002-2013 the original author or authors.
2
+ * Copyright 2002-2014 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -62,8 +62,8 @@ public class PropertyPlaceholderHelper {
62
62
/**
63
63
* Creates a new {@code PropertyPlaceholderHelper} that uses the supplied prefix and suffix.
64
64
* Unresolvable placeholders are ignored.
65
- * @param placeholderPrefix the prefix that denotes the start of a placeholder.
66
- * @param placeholderSuffix the suffix that denotes the end of a placeholder.
65
+ * @param placeholderPrefix the prefix that denotes the start of a placeholder
66
+ * @param placeholderSuffix the suffix that denotes the end of a placeholder
67
67
*/
68
68
public PropertyPlaceholderHelper (String placeholderPrefix , String placeholderSuffix ) {
69
69
this (placeholderPrefix , placeholderSuffix , null , true );
@@ -75,14 +75,14 @@ public PropertyPlaceholderHelper(String placeholderPrefix, String placeholderSuf
75
75
* @param placeholderSuffix the suffix that denotes the end of a placeholder
76
76
* @param valueSeparator the separating character between the placeholder variable
77
77
* and the associated default value, if any
78
- * @param ignoreUnresolvablePlaceholders indicates whether unresolvable placeholders should be ignored
79
- * ({@code true}) or cause an exception ({@code false}).
78
+ * @param ignoreUnresolvablePlaceholders indicates whether unresolvable placeholders should
79
+ * be ignored ({@code true}) or cause an exception ({@code false})
80
80
*/
81
81
public PropertyPlaceholderHelper (String placeholderPrefix , String placeholderSuffix ,
82
82
String valueSeparator , boolean ignoreUnresolvablePlaceholders ) {
83
83
84
- Assert .notNull (placeholderPrefix , "placeholderPrefix must not be null" );
85
- Assert .notNull (placeholderSuffix , "placeholderSuffix must not be null" );
84
+ Assert .notNull (placeholderPrefix , "' placeholderPrefix' must not be null" );
85
+ Assert .notNull (placeholderSuffix , "' placeholderSuffix' must not be null" );
86
86
this .placeholderPrefix = placeholderPrefix ;
87
87
this .placeholderSuffix = placeholderSuffix ;
88
88
String simplePrefixForSuffix = wellKnownSimplePrefixes .get (this .placeholderSuffix );
@@ -100,12 +100,12 @@ public PropertyPlaceholderHelper(String placeholderPrefix, String placeholderSuf
100
100
/**
101
101
* Replaces all placeholders of format {@code ${name}} with the corresponding
102
102
* property from the supplied {@link Properties}.
103
- * @param value the value containing the placeholders to be replaced.
104
- * @param properties the {@code Properties} to use for replacement.
105
- * @return the supplied value with placeholders replaced inline.
103
+ * @param value the value containing the placeholders to be replaced
104
+ * @param properties the {@code Properties} to use for replacement
105
+ * @return the supplied value with placeholders replaced inline
106
106
*/
107
107
public String replacePlaceholders (String value , final Properties properties ) {
108
- Assert .notNull (properties , "Argument 'properties' must not be null. " );
108
+ Assert .notNull (properties , "'properties' must not be null" );
109
109
return replacePlaceholders (value , new PlaceholderResolver () {
110
110
@ Override
111
111
public String resolvePlaceholder (String placeholderName ) {
@@ -117,25 +117,25 @@ public String resolvePlaceholder(String placeholderName) {
117
117
/**
118
118
* Replaces all placeholders of format {@code ${name}} with the value returned
119
119
* from the supplied {@link PlaceholderResolver}.
120
- * @param value the value containing the placeholders to be replaced.
121
- * @param placeholderResolver the {@code PlaceholderResolver} to use for replacement.
122
- * @return the supplied value with placeholders replaced inline.
120
+ * @param value the value containing the placeholders to be replaced
121
+ * @param placeholderResolver the {@code PlaceholderResolver} to use for replacement
122
+ * @return the supplied value with placeholders replaced inline
123
123
*/
124
124
public String replacePlaceholders (String value , PlaceholderResolver placeholderResolver ) {
125
- Assert .notNull (value , "Argument 'value' must not be null. " );
125
+ Assert .notNull (value , "'value' must not be null" );
126
126
return parseStringValue (value , placeholderResolver , new HashSet <String >());
127
127
}
128
128
129
129
protected String parseStringValue (
130
130
String strVal , PlaceholderResolver placeholderResolver , Set <String > visitedPlaceholders ) {
131
131
132
- StringBuilder buf = new StringBuilder (strVal );
132
+ StringBuilder result = new StringBuilder (strVal );
133
133
134
134
int startIndex = strVal .indexOf (this .placeholderPrefix );
135
135
while (startIndex != -1 ) {
136
- int endIndex = findPlaceholderEndIndex (buf , startIndex );
136
+ int endIndex = findPlaceholderEndIndex (result , startIndex );
137
137
if (endIndex != -1 ) {
138
- String placeholder = buf .substring (startIndex + this .placeholderPrefix .length (), endIndex );
138
+ String placeholder = result .substring (startIndex + this .placeholderPrefix .length (), endIndex );
139
139
String originalPlaceholder = placeholder ;
140
140
if (!visitedPlaceholders .add (originalPlaceholder )) {
141
141
throw new IllegalArgumentException (
@@ -160,15 +160,15 @@ protected String parseStringValue(
160
160
// Recursive invocation, parsing placeholders contained in the
161
161
// previously resolved placeholder value.
162
162
propVal = parseStringValue (propVal , placeholderResolver , visitedPlaceholders );
163
- buf .replace (startIndex , endIndex + this .placeholderSuffix .length (), propVal );
163
+ result .replace (startIndex , endIndex + this .placeholderSuffix .length (), propVal );
164
164
if (logger .isTraceEnabled ()) {
165
165
logger .trace ("Resolved placeholder '" + placeholder + "'" );
166
166
}
167
- startIndex = buf .indexOf (this .placeholderPrefix , startIndex + propVal .length ());
167
+ startIndex = result .indexOf (this .placeholderPrefix , startIndex + propVal .length ());
168
168
}
169
169
else if (this .ignoreUnresolvablePlaceholders ) {
170
170
// Proceed with unprocessed value.
171
- startIndex = buf .indexOf (this .placeholderPrefix , endIndex + this .placeholderSuffix .length ());
171
+ startIndex = result .indexOf (this .placeholderPrefix , endIndex + this .placeholderSuffix .length ());
172
172
}
173
173
else {
174
174
throw new IllegalArgumentException ("Could not resolve placeholder '" +
@@ -181,7 +181,7 @@ else if (this.ignoreUnresolvablePlaceholders) {
181
181
}
182
182
}
183
183
184
- return buf .toString ();
184
+ return result .toString ();
185
185
}
186
186
187
187
private int findPlaceholderEndIndex (CharSequence buf , int startIndex ) {
@@ -211,14 +211,13 @@ else if (StringUtils.substringMatch(buf, index, this.simplePrefix)) {
211
211
212
212
/**
213
213
* Strategy interface used to resolve replacement values for placeholders contained in Strings.
214
- * @see PropertyPlaceholderHelper
215
214
*/
216
215
public static interface PlaceholderResolver {
217
216
218
217
/**
219
- * Resolves the supplied placeholder name into the replacement value.
218
+ * Resolve the supplied placeholder name to the replacement value.
220
219
* @param placeholderName the name of the placeholder to resolve
221
- * @return the replacement value or {@code null} if no replacement is to be made
220
+ * @return the replacement value, or {@code null} if no replacement is to be made
222
221
*/
223
222
String resolvePlaceholder (String placeholderName );
224
223
}
0 commit comments