public class ResourceEditor
extends java.beans.PropertyEditorSupport
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 Environment
properties:
e.g. ${user.dir}
. Unresolvable placeholders are ignored by default.
Delegates to a ResourceLoader
to do the heavy lifting,
by default using a DefaultResourceLoader
.
Resource
,
ResourceLoader
,
DefaultResourceLoader
,
PropertyResolver.resolvePlaceholders(java.lang.String)
Modifier and Type | Field and Description |
---|---|
private boolean |
ignoreUnresolvablePlaceholders |
private PropertyResolver |
propertyResolver |
private ResourceLoader |
resourceLoader |
Constructor and Description |
---|
ResourceEditor()
Create a new instance of the
ResourceEditor class
using a DefaultResourceLoader and StandardEnvironment . |
ResourceEditor(ResourceLoader resourceLoader,
PropertyResolver propertyResolver)
Create a new instance of the
ResourceEditor class
using the given ResourceLoader and PropertyResolver . |
ResourceEditor(ResourceLoader resourceLoader,
PropertyResolver propertyResolver,
boolean ignoreUnresolvablePlaceholders)
Create a new instance of the
ResourceEditor class
using the given ResourceLoader . |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getAsText() |
protected java.lang.String |
resolvePath(java.lang.String path)
Resolve the given path, replacing placeholders with corresponding
property values from the
environment if necessary. |
void |
setAsText(java.lang.String text) |
private final ResourceLoader resourceLoader
private PropertyResolver propertyResolver
private final boolean ignoreUnresolvablePlaceholders
public ResourceEditor()
ResourceEditor
class
using a DefaultResourceLoader
and StandardEnvironment
.public ResourceEditor(ResourceLoader resourceLoader, PropertyResolver propertyResolver)
ResourceEditor
class
using the given ResourceLoader
and PropertyResolver
.resourceLoader
- the ResourceLoader
to usepropertyResolver
- the PropertyResolver
to usepublic ResourceEditor(ResourceLoader resourceLoader, PropertyResolver propertyResolver, boolean ignoreUnresolvablePlaceholders)
ResourceEditor
class
using the given ResourceLoader
.resourceLoader
- the ResourceLoader
to usepropertyResolver
- the PropertyResolver
to useignoreUnresolvablePlaceholders
- whether to ignore unresolvable placeholders
if no corresponding property could be found in the given propertyResolver
public void setAsText(java.lang.String text)
setAsText
in interface java.beans.PropertyEditor
setAsText
in class java.beans.PropertyEditorSupport
protected java.lang.String resolvePath(java.lang.String path)
environment
if necessary.path
- the original file pathPropertyResolver.resolvePlaceholders(java.lang.String)
,
PropertyResolver.resolveRequiredPlaceholders(java.lang.String)
public java.lang.String getAsText()
getAsText
in interface java.beans.PropertyEditor
getAsText
in class java.beans.PropertyEditorSupport