public class ResourceEditor extends 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)
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 |
---|---|
String |
getAsText() |
protected String |
resolvePath(String path)
Resolve the given path, replacing placeholders with corresponding
property values from the
environment if necessary. |
void |
setAsText(String text) |
addPropertyChangeListener, firePropertyChange, getCustomEditor, getJavaInitializationString, getSource, getTags, getValue, isPaintable, paintValue, removePropertyChangeListener, setSource, setValue, supportsCustomEditor
public ResourceEditor()
ResourceEditor
class
using a DefaultResourceLoader
and StandardEnvironment
.public ResourceEditor(ResourceLoader resourceLoader, @Nullable PropertyResolver propertyResolver)
ResourceEditor
class
using the given ResourceLoader
and PropertyResolver
.resourceLoader
- the ResourceLoader
to usepropertyResolver
- the PropertyResolver
to usepublic ResourceEditor(ResourceLoader resourceLoader, @Nullable 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(String text)
setAsText
in interface PropertyEditor
setAsText
in class PropertyEditorSupport
protected String resolvePath(String path)
environment
if necessary.path
- the original file pathPropertyResolver.resolvePlaceholders(java.lang.String)
,
PropertyResolver.resolveRequiredPlaceholders(java.lang.String)
@Nullable public String getAsText()
getAsText
in interface PropertyEditor
getAsText
in class PropertyEditorSupport