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 modifiable URI substitute. 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:
  • Constructor Details

    • 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 name
      userInfo - User name and authorization information
      host - Host name
      port - Port number
      path - Path
      query - Query
      fragment - Fragment
      Throws:
      URISyntaxException - if the produced URI is not well-formed
  • Method Details

    • uri

      public static MutableUri uri(String uri) throws URISyntaxException
      Factory method for avoiding typing new MutableUri("http://...").
      Parameters:
      uri - URL encoded URI
      Returns:
      a new MutableUri instance
      Throws:
      URISyntaxException - if the given Uri is not well-formed
    • asURI

      public URI asURI()
      Returns the equivalent URI instance.
      Returns:
      the equivalent URI instance.
    • 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 URISyntaxException
      Update 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 immutable List. The toString method 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 is null. 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 is null. 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:
      compareTo in interface Comparable<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:
    • 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:
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • 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.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object