Package org.springframework.core.io

# Class ResourceEditor

java.lang.Object
java.beans.PropertyEditorSupport
org.springframework.core.io.ResourceEditor

All Implemented Interfaces:
  `PropertyEditor`

public class ResourceEditor extends PropertyEditorSupport
`Editor` for `Resource` descriptors, to automatically convert `String` locations for example, `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: for example, `${user.dir}`. Unresolvable placeholders are ignored by default.

Delegates to a `ResourceLoader` to do the heavy lifting, by default using a `DefaultResourceLoader`.

Since:
  28.12.2003
Author:
  Juergen Hoeller, Dave Syer, Chris Beams
See Also:
  - `Resource`
  - `ResourceLoader`
  - `DefaultResourceLoader`
  - `PropertyResolver.resolvePlaceholders(java.lang.String)`

## Constructor Summary

Constructors
Constructor
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`.

## Method Summary

Modifier and Type
Method
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)`

### Methods inherited from class java.beans.PropertyEditorSupport

`addPropertyChangeListener, firePropertyChange, getCustomEditor, getJavaInitializationString, getSource, getTags, getValue, isPaintable, paintValue, removePropertyChangeListener, setSource, setValue, supportsCustomEditor`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### ResourceEditor

public ResourceEditor()
Create a new instance of the `ResourceEditor` class using a `DefaultResourceLoader` and `StandardEnvironment`.

### ResourceEditor

public ResourceEditor(ResourceLoader resourceLoader, @Nullable PropertyResolver propertyResolver)
Create a new instance of the `ResourceEditor` class using the given `ResourceLoader` and `PropertyResolver`.

Parameters:
  `resourceLoader` - the `ResourceLoader` to use
  `propertyResolver` - the `PropertyResolver` to use

### ResourceEditor

public ResourceEditor(ResourceLoader resourceLoader, @Nullable PropertyResolver propertyResolver, boolean ignoreUnresolvablePlaceholders)
Create a new instance of the `ResourceEditor` class using the given `ResourceLoader`.

Parameters:
  `resourceLoader` - the `ResourceLoader` to use
  `propertyResolver` - the `PropertyResolver` to use
  `ignoreUnresolvablePlaceholders` - whether to ignore unresolvable placeholders if no corresponding property could be found in the given `propertyResolver`

## Method Details

### setAsText

public void setAsText(String text)

Specified by:
  `setAsText` in interface `PropertyEditor`
Overrides:
  `setAsText` in class `PropertyEditorSupport`

### resolvePath

protected String resolvePath(String path)
Resolve the given path, replacing placeholders with corresponding property values from the `environment` if necessary.

Parameters:
  `path` - the original file path
Returns:
  the resolved file path
See Also:
  - `PropertyResolver.resolvePlaceholders(java.lang.String)`
  - `PropertyResolver.resolveRequiredPlaceholders(java.lang.String)`

### getAsText

@Nullable public String getAsText()

Specified by:
  `getAsText` in interface `PropertyEditor`
Overrides:
  `getAsText` in class `PropertyEditorSupport`