com.atlassian.confluence.web
Class UrlBuilder

java.lang.Object
  extended by com.atlassian.confluence.web.UrlBuilder

public final class UrlBuilder
extends java.lang.Object

A builder which can construct URLs by adding parameters. Not thread-safe.

Since:
3.0

Constructor Summary
UrlBuilder(java.lang.String baseUrl)
          Constructs a UTF-8 URL builder with the given base URL.
UrlBuilder(java.lang.String baseUrl, java.lang.String encoding)
          Constructs a builder with the given base URL, which should already be URL-encoded.
 
Method Summary
 UrlBuilder add(java.lang.String name, boolean value)
          Adds a parameter to the URL.
 UrlBuilder add(java.lang.String name, int value)
          Adds a parameter to the URL.
 UrlBuilder add(java.lang.String name, long value)
          Adds a parameter to the URL.
 UrlBuilder add(java.lang.String name, java.lang.String value)
          Adds a parameter to the URL.
 UrlBuilder add(java.lang.String name, java.lang.String[] values)
          Retrieving parameters from a ServletRequest will provide you with String array values.
 UrlBuilder addAll(java.util.Map<java.lang.String,java.lang.Object> params)
          Add multiple parameters to the URL from a map.
 UrlBuilder addAnchor(java.lang.String anchor)
          Sets an anchor for the URL.
 java.lang.String toString()
           
 java.lang.String toUrl()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UrlBuilder

public UrlBuilder(java.lang.String baseUrl)
Constructs a UTF-8 URL builder with the given base URL. See UrlBuilder(String, String)

Parameters:
baseUrl - The base URL

UrlBuilder

public UrlBuilder(java.lang.String baseUrl,
                  java.lang.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 appended
encoding - Encoding to use, e.g. UTF-8
Method Detail

add

public UrlBuilder add(java.lang.String name,
                      java.lang.String value)
               throws java.lang.IllegalArgumentException
Adds a parameter to the URL.

Parameters:
name - the name of the parameter
value - the value of the parameter
Returns:
this object
Throws:
java.lang.IllegalArgumentException - if either the name or value is null

add

public UrlBuilder add(java.lang.String name,
                      java.lang.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 parameter
values - one or more values for the parameter
Returns:
this builder
Throws:
java.lang.IllegalArgumentException - if the name or values are null null

add

public UrlBuilder add(java.lang.String name,
                      long value)
               throws java.lang.IllegalArgumentException
Adds a parameter to the URL.

Parameters:
name - Parameter name (part before =)
value - Parameter value (part after =)
Returns:
This object
Throws:
java.lang.IllegalArgumentException - When things are null
See Also:
add(String, String)

add

public UrlBuilder add(java.lang.String name,
                      int value)
               throws java.lang.IllegalArgumentException
Adds a parameter to the URL.

Parameters:
name - Parameter name (part before =)
value - Parameter value (part after =)
Returns:
This object
Throws:
java.lang.IllegalArgumentException - When things are null
See Also:
add(String, String)

add

public UrlBuilder add(java.lang.String name,
                      boolean value)
               throws java.lang.IllegalArgumentException
Adds a parameter to the URL.

Parameters:
name - Parameter name (part before =)
value - Parameter value (part after =)
Returns:
This object
Throws:
java.lang.IllegalArgumentException - When things are null
See Also:
add(String, String)

addAnchor

public UrlBuilder addAnchor(java.lang.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(java.util.Map<java.lang.String,java.lang.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

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toUrl

public java.lang.String toUrl()


Copyright © 2003-2014 Atlassian. All Rights Reserved.