Spring Framework

org.springframework.beans.propertyeditors
Class URIEditor

java.lang.Object
  extended by java.beans.PropertyEditorSupport
      extended by org.springframework.beans.propertyeditors.URIEditor
All Implemented Interfaces:
java.beans.PropertyEditor

public class URIEditor
extends java.beans.PropertyEditorSupport

Editor for java.net.URI, to directly populate a URI property instead of using a String property as bridge.

Supports Spring-style URI notation: any fully qualified standard URI ("file:", "http:", etc) and Spring's special "classpath:" pseudo-URL, which will be resolved to a corresponding URI.

By default, this editor will encode Strings into URIs. For instance, a space will be encoded into %20. This behavior can be changed by calling the URIEditor(boolean) constructor.

Note: A URI is more relaxed than a URL in that it does not require a valid protocol to be specified. Any scheme within a valid URI syntax is allowed, even without a matching protocol handler being registered.

Since:
2.0.2
Author:
Juergen Hoeller
See Also:
URI, URLEditor

Constructor Summary
URIEditor()
          Create a new, encoding URIEditor, converting "classpath:" locations into standard URIs (not trying to resolve them into physical resources).
URIEditor(boolean encode)
          Create a new URIEditor, converting "classpath:" locations into standard URIs (not trying to resolve them into physical resources).
URIEditor(java.lang.ClassLoader classLoader)
          Create a new URIEditor, using the given ClassLoader to resolve "classpath:" locations into physical resource URLs.
URIEditor(java.lang.ClassLoader classLoader, boolean encode)
          Create a new URIEditor, using the given ClassLoader to resolve "classpath:" locations into physical resource URLs.
 
Method Summary
protected  java.net.URI createURI(java.lang.String value)
          Create a URI instance for the given (resolved) String value.
 java.lang.String getAsText()
           
 void setAsText(java.lang.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

URIEditor

public URIEditor()
Create a new, encoding URIEditor, converting "classpath:" locations into standard URIs (not trying to resolve them into physical resources).


URIEditor

public URIEditor(boolean encode)
Create a new URIEditor, converting "classpath:" locations into standard URIs (not trying to resolve them into physical resources).

Parameters:
encode - indicates whether Strings will be encoded or not

URIEditor

public URIEditor(java.lang.ClassLoader classLoader)
Create a new URIEditor, using the given ClassLoader to resolve "classpath:" locations into physical resource URLs.

Parameters:
classLoader - the ClassLoader to use for resolving "classpath:" locations (may be null to indicate the default ClassLoader)

URIEditor

public URIEditor(java.lang.ClassLoader classLoader,
                 boolean encode)
Create a new URIEditor, using the given ClassLoader to resolve "classpath:" locations into physical resource URLs.

Parameters:
classLoader - the ClassLoader to use for resolving "classpath:" locations (may be null to indicate the default ClassLoader)
encode - indicates whether Strings will be encoded or not
Method Detail

setAsText

public void setAsText(java.lang.String text)
               throws java.lang.IllegalArgumentException
Specified by:
setAsText in interface java.beans.PropertyEditor
Overrides:
setAsText in class java.beans.PropertyEditorSupport
Throws:
java.lang.IllegalArgumentException

createURI

protected java.net.URI createURI(java.lang.String value)
                          throws java.net.URISyntaxException
Create a URI instance for the given (resolved) String value.

The default implementation encodes the value into a RFC 2396 compliant URI.

Parameters:
value - the value to convert into a URI instance
Returns:
the URI instance
Throws:
java.net.URISyntaxException - if URI conversion failed

getAsText

public java.lang.String getAsText()
Specified by:
getAsText in interface java.beans.PropertyEditor
Overrides:
getAsText in class java.beans.PropertyEditorSupport

Spring Framework