Class UrlBuilder
- java.lang.Object
-
- org.onebusaway.presentation.client.UrlBuilder
-
public class UrlBuilder extends Object
Utility class to build a URL from components. TODO(jlabanca): Add a constructor that parses an existing URL Note that this class was copied verbatim from the com.google.gwt.http.client.URLBuilder in GWT, but modified to fix bugs with escaping (especially param values that included a & character)
-
-
Field Summary
Fields Modifier and Type Field Description static intPORT_UNSPECIFIEDThe port to use when no port should be specified.
-
Constructor Summary
Constructors Constructor Description UrlBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description StringbuildString()Build the URL and return it as an encoded string.static UrlBuildercreateFromLocation()UrlBuilderremoveParameter(String name)Remove a query parameter from the map.UrlBuildersetHash(String hash)Set the hash portion of the location (ex. myAnchor or #myAnchor).UrlBuildersetHost(String host)Set the host portion of the location (ex. google.com).UrlBuildersetParameter(String key, String... values)Set a query parameter to a list of values.UrlBuildersetPath(String path)Set the path portion of the location (ex. path/to/file.html).UrlBuildersetPort(int port)Set the port to connect to.UrlBuildersetProtocol(String protocol)Set the protocol portion of the location (ex. http).
-
-
-
Field Detail
-
PORT_UNSPECIFIED
public static final int PORT_UNSPECIFIED
The port to use when no port should be specified.- See Also:
- Constant Field Values
-
-
Method Detail
-
createFromLocation
public static UrlBuilder createFromLocation()
-
buildString
public String buildString()
Build the URL and return it as an encoded string.- Returns:
- the encoded URL string
-
removeParameter
public UrlBuilder removeParameter(String name)
Remove a query parameter from the map.- Parameters:
name- the parameter name
-
setHash
public UrlBuilder setHash(String hash)
Set the hash portion of the location (ex. myAnchor or #myAnchor).- Parameters:
hash- the hash
-
setHost
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
-
setParameter
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 keyvalues- the list of values
-
setPath
public UrlBuilder setPath(String path)
Set the path portion of the location (ex. path/to/file.html).- Parameters:
path- the path
-
setPort
public UrlBuilder setPort(int port)
Set the port to connect to.- Parameters:
port- the port, orPORT_UNSPECIFIED
-
setProtocol
public UrlBuilder setProtocol(String protocol)
Set the protocol portion of the location (ex. http).- Parameters:
protocol- the protocol
-
-