Class URLBuilder

java.lang.Object
net.shibboleth.utilities.java.support.net.URLBuilder

public class URLBuilder
extends Object
Utility class for building URLs. May also be used to parse a URL into its individual components. All components will be converted UTF-8 encoding and then application/x-www-form-urlencoded when built. This class is not thread-safe.
  • Field Details

    • scheme

      @Nullable private String scheme
      URL schema (http, https, etc).
    • username

      @Nullable private String username
      User name in the URL.
    • password

      @Nullable private String password
      Password in the URL.
    • host

      @Nullable private String host
      Host for the URL.
    • port

      @Nullable private Integer port
      URL port number.
    • path

      @Nullable private String path
      URL path.
    • queryParams

      @Nonnull private List<Pair<String,​String>> queryParams
      Parameters in the query string.
    • fragment

      private String fragment
      URL fragment.
  • Constructor Details

    • URLBuilder

      public URLBuilder()
      Constructor.
    • URLBuilder

      public URLBuilder​(@Nonnull @NotEmpty String baseURL) throws MalformedURLException
      Constructor.
      Parameters:
      baseURL - URL to parse and use as basis for creating other URLs
      Throws:
      MalformedURLException - thrown if the given base URL is not well formed
  • Method Details

    • getFragment

      @Nullable public String getFragment()
      Gets the URL fragment in its decoded form.
      Returns:
      URL fragment in its decoded form
    • setFragment

      public void setFragment​(@Nullable String newFragment)
      Sets the URL fragment in its decoded form.
      Parameters:
      newFragment - URL fragment in its decoded form
    • getHost

      @Nullable public String getHost()
      Gets the host component of the URL.
      Returns:
      host component of the URL
    • setHost

      public void setHost​(@Nullable String newHost)
      Sets the host component of the URL.
      Parameters:
      newHost - host component of the URL
    • getPassword

      @Nullable public String getPassword()
      Gets the user's password in the URL.
      Returns:
      user's password in the URL
    • setPassword

      public void setPassword​(@Nullable String newPassword)
      Sets the user's password in the URL.
      Parameters:
      newPassword - user's password in the URL
    • getPath

      @Nullable public String getPath()
      Gets the path component of the URL.
      Returns:
      path component of the URL
    • setPath

      public void setPath​(@Nullable String newPath)
      Sets the path component of the URL.
      Parameters:
      newPath - path component of the URL
    • getPort

      @Nullable public Integer getPort()
      Gets the port component of the URL.
      Returns:
      port component of the URL
    • setPort

      public void setPort​(@Nullable Integer newPort)
      Sets the port component of the URL.
      Parameters:
      newPort - port component of the URL
    • getQueryParams

      @Nonnull public List<Pair<String,​String>> getQueryParams()
      Gets the query string parameters for the URL. Params may be added and removed through the List interface.

      A note on the use of nulls in the Pair:

      Returns:
      query string parameters for the URL
    • getScheme

      @Nullable public String getScheme()
      Gets the URL scheme (http, https, etc).
      Returns:
      URL scheme (http, https, etc)
    • setScheme

      public void setScheme​(@Nullable String newScheme)
      Sets the URL scheme (http, https, etc).
      Parameters:
      newScheme - URL scheme (http, https, etc)
    • getUsername

      @Nullable public String getUsername()
      Gets the user name component of the URL.
      Returns:
      user name component of the URL
    • setUsername

      public void setUsername​(@Nullable String newUsername)
      Sets the user name component of the URL.
      Parameters:
      newUsername - user name component of the URL
    • buildURL

      @Nullable public String buildURL()
      Builds a URL from the given data. The constructed URL may not be valid if sufficient information is not provided. The returned URL will be appropriately encoded using application/x-www-form-urlencoded with appropriate encoding of UTF-8 characters.
      Returns:
      URL built from the given data
    • buildQueryString

      @Nullable public String buildQueryString()
      Builds the query string for the URL.
      Returns:
      query string for the URL or null if there are now query parameters