public class UrlBuilder extends Object
<protocol>://<host>[:<port>]/[<context>][/<module>][/<version>]<resourcePaths>[?<queryParameter>]
| Part | Description | Default | Example |
|---|---|---|---|
| protocol | The protocol. If specified, must not be null / empty. | The protocol from GWT.getHostPageBaseURL() |
http, https |
| host | The hostname. Can include a port. If specified, must not be null / empty. | The host from GWT.getHostPageBaseURL() |
127.0.0.1, www.esoves.de:8080 |
| port | The port number. If specified must be something between MIN_PORT
and MAX_PORT |
The port from GWT.getHostPageBaseURL() |
80, 8080 |
| context | The context path. If specified, must not be null / empty. In case the context starts with a '/' there won't be a double '//' in the URL. | The context from GWT.getHostPageBaseURL() |
foo, /bar, / |
| module | Some kind of REST module. If you have many resources you might want to subdivide your resources in different modules like 'admin', 'export', etc. If specified, must not be null / empty. | nothing | admin, common, export |
| version | In case you meant to include a version identifier in your resources you can specify it with this part. If specified, must not be null / empty. | nothing | r123, v4.2, 56 |
| resourcePaths | The actual resource paths. At least one path must be provided. In case the context starts with a '/' there won't be a double '//' in the URL. | nothing | [user, 0815], [/users, 0815, /groups, 12] |
| queryParameter | Query parameters. You can specify 0-n values for one parameter. If specified, the name must not be null / empty. | nothing | [foo=[bar], options=[a, b, x]] |
Here are some examples of URLs you can build with this class:
new UrlBuilder().toUrl() → http://localhost/
new UrlBuilder().toUrl() → http://localhost/
new UrlBuilder().toUrl() → http://localhost/
new UrlBuilder().toUrl() → http://localhost/
| Modifier and Type | Field and Description |
|---|---|
static int |
MAX_PORT |
static int |
MIN_PORT |
static int |
PORT_UNSPECIFIED |
protected static String |
PROTOCOL_HOSTNAME_SEPARATOR |
protected static int |
URL_MIN_LENGTH |
| Constructor and Description |
|---|
UrlBuilder()
Builds a new URL and assigns the protocol, hostname, port and context
from from
GWT.getHostPageBaseURL(). |
| Modifier and Type | Method and Description |
|---|---|
UrlBuilder |
addQueryParameter(String key,
String... values) |
UrlBuilder |
addResourcePath(String... paths) |
UrlBuilder |
clearResourcePaths() |
protected String |
defaultUrl() |
String |
getContext() |
String |
getHost() |
String |
getModule() |
int |
getPort() |
String |
getProtocol() |
Map<String,String[]> |
getQueryParams() |
List<String> |
getResourcePaths() |
String |
getVersion() |
UrlBuilder |
setContext(String context) |
UrlBuilder |
setHost(String host) |
UrlBuilder |
setModule(String module) |
UrlBuilder |
setPort(int port) |
UrlBuilder |
setProtocol(String protocol) |
UrlBuilder |
setVersion(String version) |
String |
toString() |
String |
toUrl()
Build the URL and return it as an encoded string.
|
public static final int PORT_UNSPECIFIED
public static final int MIN_PORT
public static final int MAX_PORT
protected static final int URL_MIN_LENGTH
protected static final String PROTOCOL_HOSTNAME_SEPARATOR
public UrlBuilder()
GWT.getHostPageBaseURL().protected String defaultUrl()
GWT.getHostPageBaseURL()public final String toUrl()
public UrlBuilder setProtocol(String protocol)
public String getProtocol()
public UrlBuilder setHost(String host)
public String getHost()
public UrlBuilder setPort(int port)
public int getPort()
public UrlBuilder setContext(String context)
public String getContext()
public UrlBuilder setModule(String module)
public String getModule()
public UrlBuilder setVersion(String version)
public String getVersion()
public UrlBuilder addResourcePath(String... paths)
public UrlBuilder clearResourcePaths()
public UrlBuilder addQueryParameter(String key, String... values)
Copyright © 2012 Harald Pehl. All Rights Reserved.