Top Description Fields Constructors Methods
org.springframework.core.io

public Class ResourceEditor

extends PropertyEditorSupport
Class Inheritance
Imports
java.beans.PropertyEditorSupport, java.io.IOException, org.springframework.core.env.PropertyResolver, .StandardEnvironment, org.springframework.lang.Nullable, org.springframework.util.Assert, .StringUtils

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 org.springframework.core.env.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.

Authors
Juergen Hoeller, Dave Syer, Chris Beams
Since
28.12.2003
See Also
Resource, ResourceLoader, DefaultResourceLoader, PropertyResolver#resolvePlaceholders

Field Summary

Modifier and TypeField and Description
private final boolean
private PropertyResolver
private final ResourceLoader

Constructor Summary

AccessConstructor and Description
public
ResourceEditor()

Create a new instance of the ResourceEditor class using a DefaultResourceLoader and StandardEnvironment.

public
ResourceEditor(ResourceLoader
the ResourceLoader to use
resourceLoader
,
PropertyResolver
the PropertyResolver to use
propertyResolver
)

Create a new instance of the ResourceEditor class using the given ResourceLoader and PropertyResolver.

public
ResourceEditor(ResourceLoader
the ResourceLoader to use
resourceLoader
,
PropertyResolver
the PropertyResolver to use
propertyResolver
,
boolean
whether to ignore unresolvable placeholders if no corresponding property could be found in the given propertyResolver
ignoreUnresolvablePlaceholders
)

Create a new instance of the ResourceEditor class using the given ResourceLoader.

Method Summary

Modifier and TypeMethod and Description
public String
getAsText()

Overrides java.beans.PropertyEditorSupport.getAsText.

Implements java.beans.PropertyEditor.getAsText.

Gets the property value as a string suitable for presentation to a human to edit.
protected String

Returns:

the resolved file path
resolvePath
(String
the original file path
path
)

Resolve the given path, replacing placeholders with corresponding property values from the environment if necessary.

public void
setAsText(String
The string to be parsed.
text
)

Overrides java.beans.PropertyEditorSupport.setAsText.

Implements java.beans.PropertyEditor.setAsText.

Sets the property value by parsing a given String.
Inherited from java.beans.PropertyEditorSupport:
addPropertyChangeListenerfirePropertyChangegetCustomEditorgetJavaInitializationStringgetSourcegetTagsgetValueisPaintablepaintValueremovePropertyChangeListenersetSourcesetValuesupportsCustomEditor

Field Detail

ignoreUnresolvablePlaceholdersback to summary
private final boolean ignoreUnresolvablePlaceholders
propertyResolverback to summary
private PropertyResolver propertyResolver
Annotations
@Nullable
resourceLoaderback to summary
private final ResourceLoader resourceLoader

Constructor Detail

ResourceEditorback to summary
public ResourceEditor()

Create a new instance of the ResourceEditor class using a DefaultResourceLoader and StandardEnvironment.

ResourceEditorback to summary
public ResourceEditor(ResourceLoader resourceLoader, PropertyResolver propertyResolver)

Create a new instance of the ResourceEditor class using the given ResourceLoader and PropertyResolver.

Parameters
resourceLoader:ResourceLoader

the ResourceLoader to use

propertyResolver:PropertyResolver

the PropertyResolver to use

ResourceEditorback to summary
public ResourceEditor(ResourceLoader resourceLoader, PropertyResolver propertyResolver, boolean ignoreUnresolvablePlaceholders)

Create a new instance of the ResourceEditor class using the given ResourceLoader.

Parameters
resourceLoader:ResourceLoader

the ResourceLoader to use

propertyResolver:PropertyResolver

the PropertyResolver to use

ignoreUnresolvablePlaceholders:boolean

whether to ignore unresolvable placeholders if no corresponding property could be found in the given propertyResolver

Method Detail

getAsTextback to summary
public String getAsText()

Overrides java.beans.PropertyEditorSupport.getAsText.

Implements java.beans.PropertyEditor.getAsText.

Doc from java.beans.PropertyEditorSupport.getAsText.

Gets the property value as a string suitable for presentation to a human to edit.

Returns:String

The property value as a string suitable for presentation to a human to edit.

Returns null if the value can't be expressed as a string.

If a non-null value is returned, then the PropertyEditor should be prepared to parse that string back in setAsText().

Annotations
@Override
@Nullable
resolvePathback to summary
protected String resolvePath(String path)

Resolve the given path, replacing placeholders with corresponding property values from the environment if necessary.

Parameters
path:String

the original file path

Returns:String

the resolved file path

See Also
PropertyResolver#resolvePlaceholders, PropertyResolver#resolveRequiredPlaceholders
setAsTextback to summary
public void setAsText(String text)

Overrides java.beans.PropertyEditorSupport.setAsText.

Implements java.beans.PropertyEditor.setAsText.

Doc from java.beans.PropertyEditorSupport.setAsText.

Sets the property value by parsing a given String. May raise java.lang.IllegalArgumentException if either the String is badly formatted or if this kind of property can't be expressed as text.

Parameters
text:String

The string to be parsed.

Annotations
@Override