Polish contribution
See gh-31700
This commit is contained in:
@@ -18,12 +18,10 @@ package org.springframework.core.io.support;
|
||||
|
||||
import java.beans.PropertyEditorSupport;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -54,6 +52,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
* @author Yanming Zhou
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.1.2
|
||||
* @see org.springframework.core.io.Resource
|
||||
* @see ResourcePatternResolver
|
||||
@@ -112,33 +111,30 @@ public class ResourceArrayPropertyEditor extends PropertyEditorSupport {
|
||||
|
||||
|
||||
/**
|
||||
* Treat the given text as a location pattern or comma delimited location patterns and convert it to a Resource array.
|
||||
* Treat the given text as a location pattern or comma delimited location patterns
|
||||
* and convert it to a Resource array.
|
||||
*/
|
||||
@Override
|
||||
public void setAsText(String text) {
|
||||
String pattern = resolvePath(text).trim();
|
||||
if (pattern.indexOf(',') > 0) {
|
||||
List<Resource> resources = new ArrayList<>();
|
||||
for (String locationPattern : StringUtils.commaDelimitedListToStringArray(pattern)) {
|
||||
try {
|
||||
for (Resource resource : this.resourcePatternResolver.getResources(locationPattern)) {
|
||||
resources.add(resource);
|
||||
}
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new IllegalArgumentException(
|
||||
"Could not resolve resource location pattern [" + locationPattern + "]: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
setValue(resources.toArray());
|
||||
String[] locationPatterns = StringUtils.commaDelimitedListToStringArray(pattern);
|
||||
if (locationPatterns.length == 1) {
|
||||
setValue(getResources(locationPatterns[0]));
|
||||
}
|
||||
else {
|
||||
try {
|
||||
setValue(this.resourcePatternResolver.getResources(pattern));
|
||||
} catch (IOException ex) {
|
||||
throw new IllegalArgumentException(
|
||||
"Could not resolve resource location pattern [" + pattern + "]: " + ex.getMessage());
|
||||
}
|
||||
Resource[] resources = Arrays.stream(locationPatterns).map(String::trim)
|
||||
.map(this::getResources).flatMap(Arrays::stream).toArray(Resource[]::new);
|
||||
setValue(resources);
|
||||
}
|
||||
}
|
||||
|
||||
private Resource[] getResources(String locationPattern) {
|
||||
try {
|
||||
return this.resourcePatternResolver.getResources(locationPattern);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new IllegalArgumentException(
|
||||
"Could not resolve resource location pattern [" + locationPattern + "]: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user