Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.core.env;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -136,9 +137,7 @@ public abstract class AbstractPropertyResolver implements ConfigurablePropertyRe
|
||||
|
||||
@Override
|
||||
public void setRequiredProperties(String... requiredProperties) {
|
||||
for (String key : requiredProperties) {
|
||||
this.requiredProperties.add(key);
|
||||
}
|
||||
Collections.addAll(this.requiredProperties, requiredProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -224,6 +223,9 @@ public abstract class AbstractPropertyResolver implements ConfigurablePropertyRe
|
||||
* @see #setIgnoreUnresolvableNestedPlaceholders
|
||||
*/
|
||||
protected String resolveNestedPlaceholders(String value) {
|
||||
if (value.isEmpty()) {
|
||||
return value;
|
||||
}
|
||||
return (this.ignoreUnresolvableNestedPlaceholders ?
|
||||
resolvePlaceholders(value) : resolveRequiredPlaceholders(value));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -44,10 +44,20 @@ import org.springframework.util.ObjectUtils;
|
||||
*/
|
||||
public abstract class EnumerablePropertySource<T> extends PropertySource<T> {
|
||||
|
||||
/**
|
||||
* Create a new {@code EnumerablePropertySource} with the given name and source object.
|
||||
* @param name the associated name
|
||||
* @param source the source object
|
||||
*/
|
||||
public EnumerablePropertySource(String name, T source) {
|
||||
super(name, source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@code EnumerablePropertySource} with the given name and with a new
|
||||
* {@code Object} instance as the underlying source.
|
||||
* @param name the associated name
|
||||
*/
|
||||
protected EnumerablePropertySource(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,6 +23,8 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* {@link PropertySource} that reads keys and values from a {@code Map} object.
|
||||
* The underlying map should not contain any {@code null} values in order to
|
||||
* comply with {@link #getProperty} and {@link #containsProperty} semantics.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @author Juergen Hoeller
|
||||
@@ -31,6 +33,12 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public class MapPropertySource extends EnumerablePropertySource<Map<String, Object>> {
|
||||
|
||||
/**
|
||||
* Create a new {@code MapPropertySource} with the given name and {@code Map}.
|
||||
* @param name the associated name
|
||||
* @param source the Map source (without {@code null} values in order to get
|
||||
* consistent {@link #getProperty} and {@link #containsProperty} behavior)
|
||||
*/
|
||||
public MapPropertySource(String name, Map<String, Object> source) {
|
||||
super(name, source);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -98,7 +98,6 @@ public interface PropertyResolver {
|
||||
* @return the resolved String (never {@code null})
|
||||
* @throws IllegalArgumentException if given text is {@code null}
|
||||
* @see #resolveRequiredPlaceholders
|
||||
* @see org.springframework.util.SystemPropertyUtils#resolvePlaceholders(String)
|
||||
*/
|
||||
String resolvePlaceholders(String text);
|
||||
|
||||
@@ -109,7 +108,6 @@ public interface PropertyResolver {
|
||||
* @return the resolved String (never {@code null})
|
||||
* @throws IllegalArgumentException if given text is {@code null}
|
||||
* or if any placeholders are unresolvable
|
||||
* @see org.springframework.util.SystemPropertyUtils#resolvePlaceholders(String, boolean)
|
||||
*/
|
||||
String resolveRequiredPlaceholders(String text) throws IllegalArgumentException;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -68,6 +68,8 @@ public abstract class PropertySource<T> {
|
||||
|
||||
/**
|
||||
* Create a new {@code PropertySource} with the given name and source object.
|
||||
* @param name the associated name
|
||||
* @param source the source object
|
||||
*/
|
||||
public PropertySource(String name, T source) {
|
||||
Assert.hasText(name, "Property source name must contain at least one character");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -78,6 +78,9 @@ public abstract class SystemPropertyUtils {
|
||||
* and the "ignoreUnresolvablePlaceholders" flag is {@code false}
|
||||
*/
|
||||
public static String resolvePlaceholders(String text, boolean ignoreUnresolvablePlaceholders) {
|
||||
if (text.isEmpty()) {
|
||||
return text;
|
||||
}
|
||||
PropertyPlaceholderHelper helper = (ignoreUnresolvablePlaceholders ? nonStrictHelper : strictHelper);
|
||||
return helper.replacePlaceholders(text, new SystemPropertyPlaceholderResolver(text));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user