|
16 | 16 |
|
17 | 17 | package org.springframework.boot.bind;
|
18 | 18 |
|
19 |
| -import java.util.Collections; |
20 |
| -import java.util.LinkedHashMap; |
21 | 19 | import java.util.Map;
|
22 | 20 |
|
23 | 21 | import org.springframework.core.env.ConfigurableEnvironment;
|
24 |
| -import org.springframework.core.env.EnumerablePropertySource; |
25 | 22 | import org.springframework.core.env.PropertyResolver;
|
26 |
| -import org.springframework.core.env.PropertySource; |
27 | 23 | import org.springframework.core.env.PropertySources;
|
28 | 24 | import org.springframework.util.Assert;
|
29 | 25 |
|
@@ -141,68 +137,14 @@ public String resolveRequiredPlaceholders(String text)
|
141 | 137 | * {@link ConfigurableEnvironment}.
|
142 | 138 | * @param keyPrefix the key prefix used to filter results
|
143 | 139 | * @return a map of all sub properties starting with the specified key prefix.
|
144 |
| - * @see #getSubProperties(PropertySources, String) |
145 |
| - * @see #getSubProperties(PropertySources, String, String) |
| 140 | + * @see PropertySourceUtils#getSubProperties(PropertySources, String) |
| 141 | + * @see PropertySourceUtils#getSubProperties(PropertySources, String, String) |
146 | 142 | */
|
147 | 143 | public Map<String, Object> getSubProperties(String keyPrefix) {
|
148 | 144 | Assert.isInstanceOf(ConfigurableEnvironment.class, this.resolver,
|
149 | 145 | "SubProperties not available.");
|
150 | 146 | ConfigurableEnvironment env = (ConfigurableEnvironment) this.resolver;
|
151 |
| - return getSubProperties(env.getPropertySources(), this.prefix, keyPrefix); |
152 |
| - } |
153 |
| - |
154 |
| - /** |
155 |
| - * Return a Map of all values from the specified {@link PropertySources} that start |
156 |
| - * with a particular key. |
157 |
| - * @param propertySources the property sources to scan |
158 |
| - * @param keyPrefix the key prefixes to test |
159 |
| - * @return a map of all sub properties starting with the specified key prefixes. |
160 |
| - * @see #getSubProperties(PropertySources, String, String) |
161 |
| - */ |
162 |
| - public static Map<String, Object> getSubProperties(PropertySources propertySources, |
163 |
| - String keyPrefix) { |
164 |
| - return getSubProperties(propertySources, null, keyPrefix); |
165 |
| - } |
166 |
| - |
167 |
| - /** |
168 |
| - * Return a Map of all values from the specified {@link PropertySources} that start |
169 |
| - * with a particular key. |
170 |
| - * @param propertySources the property sources to scan |
171 |
| - * @param rootPrefix a root prefix to be prepended to the keyPrefex (can be |
172 |
| - * {@code null}) |
173 |
| - * @param keyPrefix the key prefixes to test |
174 |
| - * @return a map of all sub properties starting with the specified key prefixes. |
175 |
| - * @see #getSubProperties(PropertySources, String, String) |
176 |
| - */ |
177 |
| - public static Map<String, Object> getSubProperties(PropertySources propertySources, |
178 |
| - String rootPrefix, String keyPrefix) { |
179 |
| - RelaxedNames keyPrefixes = new RelaxedNames(keyPrefix); |
180 |
| - Map<String, Object> subProperties = new LinkedHashMap<String, Object>(); |
181 |
| - for (PropertySource<?> source : propertySources) { |
182 |
| - if (source instanceof EnumerablePropertySource) { |
183 |
| - for (String name : ((EnumerablePropertySource<?>) source) |
184 |
| - .getPropertyNames()) { |
185 |
| - String key = getSubKey(name, rootPrefix, keyPrefixes); |
186 |
| - if (key != null) { |
187 |
| - subProperties.put(key, source.getProperty(name)); |
188 |
| - } |
189 |
| - } |
190 |
| - } |
191 |
| - } |
192 |
| - return Collections.unmodifiableMap(subProperties); |
193 |
| - } |
194 |
| - |
195 |
| - private static String getSubKey(String name, String rootPrefixes, |
196 |
| - RelaxedNames keyPrefix) { |
197 |
| - rootPrefixes = (rootPrefixes == null ? "" : rootPrefixes); |
198 |
| - for (String rootPrefix : new RelaxedNames(rootPrefixes)) { |
199 |
| - for (String candidateKeyPrefix : keyPrefix) { |
200 |
| - if (name.startsWith(rootPrefix + candidateKeyPrefix)) { |
201 |
| - return name.substring((rootPrefix + candidateKeyPrefix).length()); |
202 |
| - } |
203 |
| - } |
204 |
| - } |
205 |
| - return null; |
| 147 | + return PropertySourceUtils.getSubProperties(env.getPropertySources(), this.prefix, keyPrefix); |
206 | 148 | }
|
207 | 149 |
|
208 | 150 | }
|
0 commit comments