org.springframework.core.io
public class: ResourceEditor [javadoc |
source]
java.lang.Object
java.beans.PropertyEditorSupport
org.springframework.core.io.ResourceEditor
All Implemented Interfaces:
PropertyEditor
Editor for
Resource
descriptors, to automatically convert
String locations
e.g.
"file:C:/myfile.txt" or
"classpath:myfile.txt") to
Resource
properties instead of using a
String location property.
The path may contain ${...} placeholders, to be resolved
as system properties: e.g. ${user.dir}.
Delegates to a ResourceLoader to do the heavy lifting,
by default using a DefaultResourceLoader .
| Methods from java.beans.PropertyEditorSupport: |
|---|
|
addPropertyChangeListener, firePropertyChange, getAsText, getCustomEditor, getJavaInitializationString, getSource, getTags, getValue, isPaintable, paintValue, removePropertyChangeListener, setAsText, setSource, setValue, supportsCustomEditor |
| Method from org.springframework.core.io.ResourceEditor Detail: |
public String getAsText() {
Resource value = (Resource) getValue();
try {
// Try to determine URL for resource.
return (value != null ? value.getURL().toExternalForm() : "");
}
catch (IOException ex) {
// Couldn't determine resource URL - return null to indicate
// that there is no appropriate text representation.
return null;
}
}
|
protected String resolvePath(String path) {
return SystemPropertyUtils.resolvePlaceholders(path);
}
Resolve the given path, replacing placeholders with
corresponding system property values if necessary. |
public void setAsText(String text) {
if (StringUtils.hasText(text)) {
String locationToUse = resolvePath(text).trim();
setValue(this.resourceLoader.getResource(locationToUse));
}
else {
setValue(null);
}
}
|