Package org.forgerock.http
Class MutableUri
- java.lang.Object
-
- org.forgerock.http.MutableUri
-
- All Implemented Interfaces:
Comparable<MutableUri>
public final class MutableUri extends Object implements Comparable<MutableUri>
A MutableUri is a modifiableURIsubstitute. Unlike URIs, which are immutable, a MutableUri can have its fields updated independently. That makes it easier if you just want to change a element of an Uri.- See Also:
URI
-
-
Constructor Summary
Constructors Constructor Description MutableUri(String uri)Builds a new MutableUri using the given URL encoded String URI.MutableUri(String scheme, String userInfo, String host, int port, String path, String query, String fragment)Builds a new MutableUri using the given fields values (decoded values).MutableUri(URI uri)Builds a new MutableUri using the given URI.MutableUri(MutableUri mutableUri)Builds a new MutableUri with deep copy.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description URIasURI()Returns the equivalentURIinstance.intcompareTo(MutableUri o)booleanequals(Object o)StringgetAuthority()Returns the authority compound element.StringgetFragment()Returns the fragment element.StringgetHost()Returns the host element.StringgetPath()Returns the path element.List<String>getPathElements()Return the URI path elements as an immutableList.intgetPort()Returns the port element.StringgetQuery()Returns the path element.StringgetRawAuthority()Returns the raw (encoded) authority compound element.StringgetRawFragment()Returns the raw (encoded) fragment element.StringgetRawPath()Returns the raw (encoded) path element.StringgetRawQuery()Returns the raw (encoded) query element.StringgetRawUserInfo()Returns the raw (encoded) user info element.StringgetScheme()Returns the scheme name.StringgetUserInfo()Returns the user info element.inthashCode()MutableUrirebase(URI base)Changes the base scheme, host and port of this MutableUri to that specified in a base URI, or leaves them unchanged if the base URI isnull.MutableUrirebase(MutableUri base)Changes the base scheme, host and port of this MutableUri to that specified in a base URI, or leaves them unchanged if the base URI isnull.MutableUrirelativize(MutableUri uri)Relativizes the given URI against this URI.MutableUriresolve(MutableUri uri)Resolves the given URI against this URI.voidsetFragment(String fragment)Update the fragment (not encoded) of this MutableUri.voidsetHost(String host)Update the host name of this MutableUri.voidsetPath(String path)Update the path (not encoded) of this MutableUri.voidsetPort(int port)Update the port of this MutableUri.voidsetQuery(String query)Update the query string (not encoded) of this MutableUri.voidsetRawFragment(String rawFragment)Update the fragment (encoded) of this MutableUri.voidsetRawPath(String rawPath)Update the path (encoded) of this MutableUri.voidsetRawQuery(String rawQuery)Update the query (encoded) of this MutableUri.voidsetRawUserInfo(String rawUserInfo)Update the user info (encoded) of this MutableUri.voidsetScheme(String scheme)Update the scheme of this MutableUri.voidsetUserInfo(String userInfo)Update the user info (not encoded) of this MutableUri.StringtoASCIIString()Returns the content of this URI as a US-ASCII string.StringtoString()static MutableUriuri(String uri)Factory method for avoiding typingnew MutableUri("http://...").
-
-
-
Constructor Detail
-
MutableUri
public MutableUri(URI uri)
Builds a new MutableUri using the given URI.- Parameters:
uri- URI
-
MutableUri
public MutableUri(MutableUri mutableUri)
Builds a new MutableUri with deep copy.- Parameters:
mutableUri- URI
-
MutableUri
public MutableUri(String uri) throws URISyntaxException
Builds a new MutableUri using the given URL encoded String URI.- Parameters:
uri- URL encoded URI- Throws:
URISyntaxException- if the given Uri is not well-formed
-
MutableUri
public MutableUri(String scheme, String userInfo, String host, int port, String path, String query, String fragment) throws URISyntaxException
Builds a new MutableUri using the given fields values (decoded values).- Parameters:
scheme- Scheme nameuserInfo- User name and authorization informationhost- Host nameport- Port numberpath- Pathquery- Queryfragment- Fragment- Throws:
URISyntaxException- if the produced URI is not well-formed
-
-
Method Detail
-
uri
public static MutableUri uri(String uri) throws URISyntaxException
Factory method for avoiding typingnew MutableUri("http://...").- Parameters:
uri- URL encoded URI- Returns:
- a new MutableUri instance
- Throws:
URISyntaxException- if the given Uri is not well-formed
-
getScheme
public String getScheme()
Returns the scheme name.- Returns:
- the scheme name.
-
setScheme
public void setScheme(String scheme) throws URISyntaxException
Update the scheme of this MutableUri.- Parameters:
scheme- new scheme name- Throws:
URISyntaxException- if the new equivalent URI is invalid
-
getUserInfo
public String getUserInfo()
Returns the user info element.- Returns:
- the user info element.
-
getRawUserInfo
public String getRawUserInfo()
Returns the raw (encoded) user info element.- Returns:
- the raw user info element.
-
setUserInfo
public void setUserInfo(String userInfo) throws URISyntaxException
Update the user info (not encoded) of this MutableUri.- Parameters:
userInfo- new user info element (not encoded)- Throws:
URISyntaxException- if the new equivalent URI is invalid
-
setRawUserInfo
public void setRawUserInfo(String rawUserInfo) throws URISyntaxException
Update the user info (encoded) of this MutableUri.- Parameters:
rawUserInfo- new user info element (encoded)- Throws:
URISyntaxException- if the new equivalent URI is invalid
-
getHost
public String getHost()
Returns the host element.- Returns:
- the host element.
-
setHost
public void setHost(String host) throws URISyntaxException
Update the host name of this MutableUri.- Parameters:
host- new host element- Throws:
URISyntaxException- if the new equivalent URI is invalid
-
getPort
public int getPort()
Returns the port element.- Returns:
- the port element.
-
setPort
public void setPort(int port) throws URISyntaxExceptionUpdate the port of this MutableUri.- Parameters:
port- new port number- Throws:
URISyntaxException- if the new equivalent URI is invalid
-
getPath
public String getPath()
Returns the path element.- Returns:
- the path element.
-
getRawPath
public String getRawPath()
Returns the raw (encoded) path element.- Returns:
- the raw path element.
-
setPath
public void setPath(String path) throws URISyntaxException
Update the path (not encoded) of this MutableUri.- Parameters:
path- new path element (not encoded)- Throws:
URISyntaxException- if the new equivalent URI is invalid
-
setRawPath
public void setRawPath(String rawPath) throws URISyntaxException
Update the path (encoded) of this MutableUri.- Parameters:
rawPath- new path element (encoded)- Throws:
URISyntaxException- if the new equivalent URI is invalid
-
getQuery
public String getQuery()
Returns the path element.- Returns:
- the path element.
-
getRawQuery
public String getRawQuery()
Returns the raw (encoded) query element.- Returns:
- the raw query element.
-
setQuery
public void setQuery(String query) throws URISyntaxException
Update the query string (not encoded) of this MutableUri.- Parameters:
query- new query string element (not encoded)- Throws:
URISyntaxException- if the new equivalent URI is invalid
-
setRawQuery
public void setRawQuery(String rawQuery) throws URISyntaxException
Update the query (encoded) of this MutableUri.- Parameters:
rawQuery- new query element (encoded)- Throws:
URISyntaxException- if the new equivalent URI is invalid
-
getFragment
public String getFragment()
Returns the fragment element.- Returns:
- the fragment element.
-
getRawFragment
public String getRawFragment()
Returns the raw (encoded) fragment element.- Returns:
- the raw fragment element.
-
setFragment
public void setFragment(String fragment) throws URISyntaxException
Update the fragment (not encoded) of this MutableUri.- Parameters:
fragment- new fragment element (not encoded)- Throws:
URISyntaxException- if the new equivalent URI is invalid
-
setRawFragment
public void setRawFragment(String rawFragment) throws URISyntaxException
Update the fragment (encoded) of this MutableUri.- Parameters:
rawFragment- new framgent element (encoded)- Throws:
URISyntaxException- if the new equivalent URI is invalid
-
getAuthority
public String getAuthority()
Returns the authority compound element.- Returns:
- the authority compound element.
-
getRawAuthority
public String getRawAuthority()
Returns the raw (encoded) authority compound element.- Returns:
- the authority compound element.
-
getPathElements
public List<String> getPathElements()
Return the URI path elements as an immutableList. ThetoStringmethod of the returned object will return the URL-encoded path elements joined with"/".- Returns:
- The URI path elements as an immutable
List.
-
rebase
public MutableUri rebase(MutableUri base)
Changes the base scheme, host and port of this MutableUri to that specified in a base URI, or leaves them unchanged if the base URI isnull. This implementation only uses scheme, host and port. The remaining components of the URI remain intact.- Parameters:
base- the URI to base the other URI on.- Returns:
- this (rebased) instance
-
rebase
public MutableUri rebase(URI base)
Changes the base scheme, host and port of this MutableUri to that specified in a base URI, or leaves them unchanged if the base URI isnull. This implementation only uses scheme, host and port. The remaining components of the URI remain intact.- Parameters:
base- the URI to base the other URI on.- Returns:
- this (rebased) instance
-
compareTo
public int compareTo(MutableUri o)
- Specified by:
compareToin interfaceComparable<MutableUri>
-
relativize
public MutableUri relativize(MutableUri uri)
Relativizes the given URI against this URI.- Parameters:
uri- the uri to relativizes against this instance- Returns:
- this instance (mutated)
- See Also:
URI.relativize(URI)
-
resolve
public MutableUri resolve(MutableUri uri)
Resolves the given URI against this URI.- Parameters:
uri- the uri to resolve against this instance- Returns:
- this instance (mutated)
- See Also:
URI.resolve(URI)
-
toASCIIString
public String toASCIIString()
Returns the content of this URI as a US-ASCII string.- Returns:
- the content of this URI as a US-ASCII string.
-
-