Package com.atlassian.confluence.web
Class UrlBuilder
- java.lang.Object
-
- com.atlassian.confluence.web.UrlBuilder
-
@ParametersAreNonnullByDefault public final class UrlBuilder extends Object
A builder which can construct URLs by adding parameters. Not thread-safe.- Since:
- 3.0
-
-
Constructor Summary
Constructors Constructor Description UrlBuilder(String baseUrl)Constructs a UTF-8 URL builder with the given base URL.UrlBuilder(String baseUrl, String encoding)Constructs a builder with the given base URL, which should already be URL-encoded.UrlBuilder(String baseUrl, Charset encoding)Constructs a builder with the given base URL, which should already be URL-encoded.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description UrlBuilderadd(String name, boolean value)Adds a parameter to the URL.UrlBuilderadd(String name, int value)Adds a parameter to the URL.UrlBuilderadd(String name, long value)Adds a parameter to the URL.UrlBuilderadd(String name, String value)Adds a parameter to the URL.UrlBuilderadd(String name, String[] values)Retrieving parameters from a ServletRequest will provide you with String array values.UrlBuilderaddAll(Map<String,Object> params)Add multiple parameters to the URL from a map.UrlBuilderaddAnchor(String anchor)Sets an anchor for the URL.static @NonNull URLcreateURL(String urlString)Creates a URL from the given string.StringtoString()StringtoUrl()StringtoUrl(boolean encodeAnchor)
-
-
-
Constructor Detail
-
UrlBuilder
public UrlBuilder(String baseUrl)
Constructs a UTF-8 URL builder with the given base URL. SeeUrlBuilder(String, String)- Parameters:
baseUrl- The base URL
-
UrlBuilder
public UrlBuilder(String baseUrl, String encoding)
Constructs a builder with the given base URL, which should already be URL-encoded.- Parameters:
baseUrl- Base URL to which a query string is appendedencoding- Encoding to use, e.g. UTF-8
-
-
Method Detail
-
createURL
public static @NonNull URL createURL(String urlString)
Creates a URL from the given string. Convenience wrapper that handles checked exceptions.- Parameters:
urlString- the string to be turned into a URL- Returns:
- the created URL
- Throws:
IllegalArgumentException- if the given string is malformed- See Also:
URL(String)
-
add
public UrlBuilder add(String name, String value) throws IllegalArgumentException
Adds a parameter to the URL.- Parameters:
name- the name of the parametervalue- the value of the parameter- Returns:
- this object
- Throws:
IllegalArgumentException- if either the name or value is null
-
add
public UrlBuilder add(String name, String[] values)
Retrieving parameters from a ServletRequest will provide you with String array values. This method will let you easily add such parameters with each value in the array resulting in another 'name=' entry in the URL.- Parameters:
name- the name of the parametervalues- one or more values for the parameter- Returns:
- this builder
- Throws:
IllegalArgumentException- if the name or values are null null
-
add
public UrlBuilder add(String name, long value) throws IllegalArgumentException
Adds a parameter to the URL.- Parameters:
name- Parameter name (part before =)value- Parameter value (part after =)- Returns:
- This object
- Throws:
IllegalArgumentException- When things are null- See Also:
add(String, String)
-
add
public UrlBuilder add(String name, int value) throws IllegalArgumentException
Adds a parameter to the URL.- Parameters:
name- Parameter name (part before =)value- Parameter value (part after =)- Returns:
- This object
- Throws:
IllegalArgumentException- When things are null- See Also:
add(String, String)
-
add
public UrlBuilder add(String name, boolean value) throws IllegalArgumentException
Adds a parameter to the URL.- Parameters:
name- Parameter name (part before =)value- Parameter value (part after =)- Returns:
- This object
- Throws:
IllegalArgumentException- When things are null- See Also:
add(String, String)
-
addAnchor
public UrlBuilder addAnchor(String anchor)
Sets an anchor for the URL. Any previous anchor will be overwritten.- Parameters:
anchor- Anchor name (part after #)- Returns:
- This object
-
addAll
public UrlBuilder addAll(Map<String,Object> params)
Add multiple parameters to the URL from a map.- Parameters:
params- A map of parameters to add to the URL- Returns:
- This URL builder instance
-
toUrl
public String toUrl()
-
toUrl
public String toUrl(boolean encodeAnchor)
-
-