Package net.shibboleth.shared.net

# Class URLBuilder

java.lang.Object
net.shibboleth.shared.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 Summary

Fields
Modifier and Type
Field
Description
`private String`
`fragment`
URL fragment.
`private String`
`host`
Host for the URL.
`private String`
`password`
Password in the URL.
`private String`
`path`
URL path.
`private Integer`
`port`
URL port number.
`private List<Pair<String,String>>`
`queryParams`
Parameters in the query string.
`private String`
`scheme`
URL schema (http, https, etc).
`private String`
`username`
User name in the URL.

## Constructor Summary

Constructors
Constructor
Description
`URLBuilder()`
Constructor.
`URLBuilder(String baseURL)`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`String`
`buildQueryString()`
Builds the query string for the URL.
`String`
`buildURL()`
Builds a URL from the given data.
`String`
`getFragment()`
Gets the URL fragment in its decoded form.
`String`
`getHost()`
Gets the host component of the URL.
`String`
`getPassword()`
Gets the user's password in the URL.
`String`
`getPath()`
Gets the path component of the URL.
`Integer`
`getPort()`
Gets the port component of the URL.
`List<Pair<String,String>>`
`getQueryParams()`
Gets the query string parameters for the URL.
`String`
`getScheme()`
Gets the URL scheme (http, https, etc).
`String`
`getUsername()`
Gets the user name component of the URL.
`void`
`setFragment(String newFragment)`
Sets the URL fragment in its decoded form.
`void`
`setHost(String newHost)`
Sets the host component of the URL.
`void`
`setPassword(String newPassword)`
Sets the user's password in the URL.
`void`
`setPath(String newPath)`
Sets the path component of the URL.
`void`
`setPort(Integer newPort)`
Sets the port component of the URL.
`void`
`setScheme(String newScheme)`
Sets the URL scheme (http, https, etc).
`void`
`setUsername(String newUsername)`
Sets the user name component of the URL.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## 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`:

- A null `Pair.getFirst()` is generated from a URL segment such as `?=foo`. Such pairs are ignored by `buildURL()`.
- A null `Pair.getSecond()` is generated from a URL segment such as `?foo=&bar=fred` and will be rendered as `foo&bar=fred` by `buildURL()`.

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

@Nonnull 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