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

  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 and Description
    `ResourceEditor()` Create a new instance of the `ResourceEditor` class using a `DefaultResourceLoader` and `StandardEnvironment`.
    `ResourceEditor(ResourceLoader resourceLoader)` Deprecated. as of Spring 3.1 in favor of `ResourceEditor(ResourceLoader, PropertyResolver)`
    `ResourceEditor(ResourceLoader resourceLoader, boolean ignoreUnresolvablePlaceholders)` Deprecated. as of Spring 3.1 in favor of `ResourceEditor(ResourceLoader, PropertyResolver, boolean)`
    `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

    Methods
    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)`

    - ### 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 Detail

    - #### ResourceEditor

          public ResourceEditor()

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

    - #### ResourceEditor

          @Deprecated
          public ResourceEditor(ResourceLoader resourceLoader)

      Deprecated. as of Spring 3.1 in favor of `ResourceEditor(ResourceLoader, PropertyResolver)`
      Create a new instance of the `ResourceEditor` class using the given `ResourceLoader` and a `StandardEnvironment`.
      Parameters:
        `resourceLoader` - the `ResourceLoader` to use

    - #### ResourceEditor

          @Deprecated
          public ResourceEditor(ResourceLoader resourceLoader,
                                   boolean ignoreUnresolvablePlaceholders)

      Deprecated. as of Spring 3.1 in favor of `ResourceEditor(ResourceLoader, PropertyResolver, boolean)`
      Create a new instance of the `ResourceEditor` class using the given `ResourceLoader`.
      Parameters:
        `resourceLoader` - the `ResourceLoader` to use
        `ignoreUnresolvablePlaceholders` - whether to ignore unresolvable placeholders if no corresponding property could be found

    - #### ResourceEditor

          public ResourceEditor(ResourceLoader resourceLoader,
                        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,
                        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 Detail

    - #### 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

          public String getAsText()

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