Top Description Fields Constructors Methods
org.springframework.beans.propertyeditors

public Class URIEditor

extends PropertyEditorSupport
Class Inheritance
Imports
java.beans.PropertyEditorSupport, java.io.IOException, java.net.URI, .URISyntaxException, org.springframework.core.io.ClassPathResource, org.springframework.lang.Nullable, org.springframework.util.ClassUtils, .ResourceUtils, .StringUtils

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.

Author
Juergen Hoeller
Since
2.0.2
See Also
java.net.URI, URLEditor

Field Summary

Modifier and TypeField and Description
private final ClassLoader
private final boolean

Constructor Summary

AccessConstructor and Description
public
URIEditor()

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

public
URIEditor(boolean
indicates whether Strings will be encoded or not
encode
)

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

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

Create a new URIEditor, using the given ClassLoader to resolve "classpath:" locations into physical resource URLs.

public
URIEditor(ClassLoader
the ClassLoader to use for resolving "classpath:" locations (may be null to indicate the default ClassLoader)
classLoader
,
boolean
indicates whether Strings will be encoded or not
encode
)

Create a new URIEditor, using the given ClassLoader to resolve "classpath:" locations into physical resource URLs.

Method Summary

Modifier and TypeMethod and Description
protected URI

Returns:

the URI instance
createURI
(String
the value to convert into a URI instance
value
)

Create a URI instance for the given user-specified String value.

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

classLoaderback to summary
private final ClassLoader classLoader
Annotations
@Nullable
encodeback to summary
private final boolean encode

Constructor Detail

URIEditorback to summary
public URIEditor()

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

URIEditorback to summary
public URIEditor(boolean encode)

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

Parameters
encode:boolean

indicates whether Strings will be encoded or not

Since
3.0
URIEditorback to summary
public URIEditor(ClassLoader classLoader)

Create a new URIEditor, using the given ClassLoader to resolve "classpath:" locations into physical resource URLs.

Parameters
classLoader:ClassLoader

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

URIEditorback to summary
public URIEditor(ClassLoader classLoader, boolean encode)

Create a new URIEditor, using the given ClassLoader to resolve "classpath:" locations into physical resource URLs.

Parameters
classLoader:ClassLoader

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

encode:boolean

indicates whether Strings will be encoded or not

Since
3.0

Method Detail

createURIback to summary
protected URI createURI(String value) throws URISyntaxException

Create a URI instance for the given user-specified String value.

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

Parameters
value:String

the value to convert into a URI instance

Returns:URI

the URI instance

Exceptions
URISyntaxException:
if URI conversion failed
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
setAsTextback to summary
public void setAsText(String text) throws IllegalArgumentException

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