Package org.springframework.web.util
Class UriComponents
- java.lang.Object
- org.springframework.web.util.UriComponents
- All Implemented Interfaces:
Serializable
public abstract class UriComponents extends Object implements Serializable
Represents an immutable collection of URI components, mapping component type to String values. Contains convenience getters for all components. Effectively similar toURI, but with more powerful encoding options and support for URI template variables.- Since:
- 3.1
- Author:
- Arjen Poutsma, Juergen Hoeller, Rossen Stoyanchev
- See Also:
UriComponentsBuilder, Serialized Form
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceUriComponents.UriTemplateVariablesDefines the contract for URI Template variables
Constructor Summary
Constructors Modifier Constructor Description protectedUriComponents(String scheme, String fragment)
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voidcopyToUriComponentsBuilder(UriComponentsBuilder builder)Set all components of the given UriComponentsBuilder.UriComponentsencode()Encode all URI components using their specific encoding rules, and returns the result as a newUriComponentsinstance.abstract UriComponentsencode(String encoding)Encode all URI components using their specific encoding rules, and returns the result as a newUriComponentsinstance.UriComponentsexpand(Object... uriVariableValues)Replace all URI template variables with the values from a given array.UriComponentsexpand(Map<String,?> uriVariables)Replace all URI template variables with the values from a given map.UriComponentsexpand(UriComponents.UriTemplateVariables uriVariables)Replace all URI template variables with the values from the givenUriComponents.UriTemplateVariables.StringgetFragment()Return the fragment.abstract StringgetHost()Return the host.abstract StringgetPath()Return the path.abstract List<String>getPathSegments()Return the list of path segments.abstract intgetPort()Return the port.abstract StringgetQuery()Return the query.abstract MultiValueMap<String,String>getQueryParams()Return the map of query parameters.StringgetScheme()Return the scheme.abstract StringgetSchemeSpecificPart()Return the scheme specific part.abstract StringgetUserInfo()Return the user info.abstract UriComponentsnormalize()Normalize the path removing sequences like "path/..".StringtoString()abstract URItoUri()Return aURIfrom thisUriComponentsinstance.abstract StringtoUriString()Return a URI String from thisUriComponentsinstance.
Constructor Detail
UriComponents
protected UriComponents(String scheme, String fragment)
Method Detail
getFragment
public final String getFragment()
Return the fragment. Can benull.
getSchemeSpecificPart
public abstract String getSchemeSpecificPart()
Return the scheme specific part. Can benull.
getUserInfo
public abstract String getUserInfo()
Return the user info. Can benull.
getPort
public abstract int getPort()
Return the port.-1if no port has been set.
getPathSegments
public abstract List<String> getPathSegments()
Return the list of path segments. Empty if no path has been set.
getQueryParams
public abstract MultiValueMap<String,String> getQueryParams()
Return the map of query parameters. Empty if no query has been set.
encode
public final UriComponents encode()
Encode all URI components using their specific encoding rules, and returns the result as a newUriComponentsinstance. This method uses UTF-8 to encode.- Returns:
- the encoded URI components
encode
public abstract UriComponents encode(String encoding) throws UnsupportedEncodingException
Encode all URI components using their specific encoding rules, and returns the result as a newUriComponentsinstance.- Parameters:
encoding- the encoding of the values contained in this map- Returns:
- the encoded URI components
- Throws:
UnsupportedEncodingException- if the given encoding is not supported
expand
public final UriComponents expand(Map<String,?> uriVariables)
Replace all URI template variables with the values from a given map.The given map keys represent variable names; the corresponding values represent variable values. The order of variables is not significant.
- Parameters:
uriVariables- the map of URI variables- Returns:
- the expanded URI components
expand
public final UriComponents expand(Object... uriVariableValues)
Replace all URI template variables with the values from a given array.The given array represents variable values. The order of variables is significant.
- Parameters:
uriVariableValues- the URI variable values- Returns:
- the expanded URI components
expand
public final UriComponents expand(UriComponents.UriTemplateVariables uriVariables)
Replace all URI template variables with the values from the givenUriComponents.UriTemplateVariables.- Parameters:
uriVariables- the URI template values- Returns:
- the expanded URI components
normalize
public abstract UriComponents normalize()
Normalize the path removing sequences like "path/..".- See Also:
StringUtils.cleanPath(String)
toUriString
public abstract String toUriString()
Return a URI String from thisUriComponentsinstance.
copyToUriComponentsBuilder
protected abstract void copyToUriComponentsBuilder(UriComponentsBuilder builder)
Set all components of the given UriComponentsBuilder.- Since:
- 4.2