public class

UrlBuilder

extends Object
java.lang.Object
   ↳ com.google.gwt.http.client.UrlBuilder

Class Overview

Utility class to build a URL from components. TODO(jlabanca): Add a constructor that parses an existing URL

Summary

Constants
int PORT_UNSPECIFIED The port to use when no port should be specified.
Public Constructors
UrlBuilder()
Public Methods
String buildString()
Build the URL and return it as an encoded string.
UrlBuilder removeParameter(String name)
Remove a query parameter from the map.
UrlBuilder setHash(String hash)
Set the hash portion of the location (ex.
UrlBuilder setHost(String host)
Set the host portion of the location (ex.
UrlBuilder setParameter(String key, String... values)

Set a query parameter to a list of values.

UrlBuilder setPath(String path)
Set the path portion of the location (ex.
UrlBuilder setPort(int port)
Set the port to connect to.
UrlBuilder setProtocol(String protocol)
Set the protocol portion of the location (ex.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int PORT_UNSPECIFIED

The port to use when no port should be specified.

Constant Value: -2147483648 (0x80000000)

Public Constructors

public UrlBuilder ()

Public Methods

public String buildString ()

Build the URL and return it as an encoded string.

Returns
  • the encoded URL string

public UrlBuilder removeParameter (String name)

Remove a query parameter from the map.

Parameters
name the parameter name

public UrlBuilder setHash (String hash)

Set the hash portion of the location (ex. myAnchor or #myAnchor).

Parameters
hash the hash

public UrlBuilder setHost (String host)

Set the host portion of the location (ex. google.com). You can also specify the port in this method (ex. localhost:8888).

Parameters
host the host

public UrlBuilder setParameter (String key, String... values)

Set a query parameter to a list of values. Each value in the list will be added as its own key/value pair.

Example Output

?mykey=value0&mykey=value1&mykey=value2

Parameters
key the key
values the list of values

public UrlBuilder setPath (String path)

Set the path portion of the location (ex. path/to/file.html).

Parameters
path the path

public UrlBuilder setPort (int port)

Set the port to connect to.

Parameters
port the port, or PORT_UNSPECIFIED

public UrlBuilder setProtocol (String protocol)

Set the protocol portion of the location (ex. http).

Parameters
protocol the protocol