@NotThreadSafe @PublicApi public final class UrlBuilder extends Object
NOTE: This class does not HTML escape the URLs. Be very careful if using this class to output a URL on the UI.
| Constructor and Description |
|---|
UrlBuilder(boolean querySnippet)
Creates a builder with a blank URL.
|
UrlBuilder(String urlFragment)
Creates a builder with the specified URL fragment.
|
UrlBuilder(String urlFragment,
boolean querySnippet)
Creates a builder with the specified URL fragment.
|
UrlBuilder(String urlFragment,
String encoding,
boolean querySnippet)
Creates a builder with the specified URL fragment.
|
UrlBuilder(UrlBuilder source)
Creates a copy of the passed builder.
|
| Modifier and Type | Method and Description |
|---|---|
UrlBuilder |
addAnchor(String value)
Add the passed anchor value to the URL while URL encoding it.
|
UrlBuilder |
addParameter(String name,
Object value)
Adds the passed parameter to the URL while URL encoding them.
|
UrlBuilder |
addParameter(String name,
String value)
Adds the parameter to the URL while URL encoding them.
|
UrlBuilder |
addParametersFromMap(Map<?,?> params)
Add multiple parameters from a map safely.
|
UrlBuilder |
addParameterUnsafe(String name,
String value)
Adds the parameter to the URL without URL encoding them.
|
UrlBuilder |
addPath(String path)
URL encodes and adds the given path to the URL.
|
UrlBuilder |
addPaths(String paths)
URL encodes and adds the given paths to the URL.
|
UrlBuilder |
addPathUnsafe(String path)
Adds the given path to the URL.
|
URI |
asURI()
Returns the URL as a URI.
|
String |
asUrlString()
Returns the URL as a String.
|
static URL |
createURL(String urlString)
Creates a URL from the given string.
|
String |
toString()
Returns the same thing as
asUrlString(), to avoid confusion. |
public UrlBuilder(boolean querySnippet)
querySnippet - whether or not this URL is complete or just a query snippetIllegalArgumentException - if the base url is null.public UrlBuilder(UrlBuilder source)
source - the builder to copy, cannot be null.IllegalArgumentException - if source is null.public UrlBuilder(String urlFragment)
urlFragment - the URL fragment for the builder. This parameter will not be escaped in the resulting URL.IllegalArgumentException - if urlFragment is null.public UrlBuilder(String urlFragment, boolean querySnippet)
urlFragment - the URL or query snippet for the builder. This parameter will not be escaped in the resulting URL.querySnippet - whether or not this URL is complete or just a query snippetIllegalArgumentException - if the urlFragment is nullpublic UrlBuilder(String urlFragment, @Nullable String encoding, boolean querySnippet)
urlFragment - the URL fragment for the builder. This parameter will not be escaped in the resulting URL.encoding - the character encoding to use for parameter names and values. Can be left null (recommended) to indicate JIRA default encoding.querySnippet - whether this URL is complete or just a query snippet.IllegalArgumentException - if urlFragment is null@Nonnull public static URL createURL(String urlString)
urlString - the string to be turned into a URLIllegalArgumentException - if the given string is malformedURL.URL(String)public UrlBuilder addPathUnsafe(String path)
addPath(String).path - the path to add to the URL. This parameter name is not escaped before it is added to the URL.public UrlBuilder addPath(String path)
path - path to be encoded and added to the URL. The path cannot be blank.IllegalArgumentException - if path is blankpublic UrlBuilder addPaths(String paths)
paths - paths to be encoded and added to the URL. E.g. "/one/two/three". Cannot be blank.IllegalArgumentException - if paths is blankpublic UrlBuilder addParameterUnsafe(String name, String value)
name - the name of the parameter. This parameter name is not escaped before it is added to the URL. This
value cannot be blank.value - the value of the parameter. This value is not escaped before it is added to the URL.IllegalArgumentException - if name is blankpublic UrlBuilder addParameter(String name, String value)
name - the name of the parameter. This value cannot be blank.value - the value of the parameter.IllegalArgumentException - if name is blankpublic UrlBuilder addParameter(String name, Object value)
name - the name of the parameter. This value cannot be blank.value - the value of the parameterIllegalArgumentException - if name is blankpublic UrlBuilder addAnchor(String value)
#myAnchor.
Note that to be compliant with standards, you will want to call this only after adding all your parameters.value - the value of the anchorIllegalArgumentException - if name is blankpublic UrlBuilder addParametersFromMap(Map<?,?> params)
params - map containing parameters to add. Must not be null.public String asUrlString()
public URI asURI()
public String toString()
asUrlString(), to avoid confusion.toString in class ObjectasUrlString()Copyright © 2002-2022 Atlassian. All Rights Reserved.