name.pehl.piriti.restlet.client
Class UrlBuilder

java.lang.Object
  extended by name.pehl.piriti.restlet.client.UrlBuilder

public class UrlBuilder
extends Object

URL Builder with dedicated support for resources. A resource URL is made up of the following parts:
<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:

Version:
$Date: 2010-02-23 14:59:55 +0100 (Di, 23. Feb 2010) $ $Revision: 77293 $
Author:
$Author: lfstad-pehl $

Field Summary
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 Summary
UrlBuilder()
          Builds a new URL and assigns the protocol, hostname, port and context from from GWT.getHostPageBaseURL().
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PORT_UNSPECIFIED

public static final int PORT_UNSPECIFIED
See Also:
Constant Field Values

MIN_PORT

public static final int MIN_PORT
See Also:
Constant Field Values

MAX_PORT

public static final int MAX_PORT
See Also:
Constant Field Values

URL_MIN_LENGTH

protected static final int URL_MIN_LENGTH
See Also:
Constant Field Values

PROTOCOL_HOSTNAME_SEPARATOR

protected static final String PROTOCOL_HOSTNAME_SEPARATOR
See Also:
Constant Field Values
Constructor Detail

UrlBuilder

public UrlBuilder()
Builds a new URL and assigns the protocol, hostname, port and context from from GWT.getHostPageBaseURL().

Method Detail

defaultUrl

protected String defaultUrl()
Returns:
GWT.getHostPageBaseURL()

toUrl

public final String toUrl()
Build the URL and return it as an encoded string.

Returns:
the encoded URL string

toString

public String toString()
Overrides:
toString in class Object

setProtocol

public UrlBuilder setProtocol(String protocol)

getProtocol

public String getProtocol()

setHost

public UrlBuilder setHost(String host)

getHost

public String getHost()

setPort

public UrlBuilder setPort(int port)

getPort

public int getPort()

setContext

public UrlBuilder setContext(String context)

getContext

public String getContext()

setModule

public UrlBuilder setModule(String module)

getModule

public String getModule()

setVersion

public UrlBuilder setVersion(String version)

getVersion

public String getVersion()

addResourcePath

public UrlBuilder addResourcePath(String... paths)

clearResourcePaths

public UrlBuilder clearResourcePaths()

getResourcePaths

public List<String> getResourcePaths()

addQueryParameter

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

getQueryParams

public Map<String,String[]> getQueryParams()


Copyright © 2012 Harald Pehl. All Rights Reserved.