abstract class BaseUriBuilder extends Object
javax.ws.rs.Path#value for an
explanation of URI templates.
Builder methods perform contextual encoding of characters not permitted in the corresponding URI component following
the rules of the
application/x-www-form-urlencoded
media type for query parameters and
RFC 3986 for all other components. Note that only characters not
permitted in a particular component are subject to encoding so, e.g., a path supplied to one of the path
methods may contain matrix parameters or multiple path segments since the separators are legal characters and will
not be encoded. Percent encoded values are also recognized where allowed and will not be double encoded.
URI templates are allowed in most components of a URI but their value is restricted to a particular component. E.g.
BaseUriBuilder.fromPath("{arg1}").build("foo#bar");
would result in encoding of the '#' such that the resulting URI is "foo%23bar". To create a URI "foo#bar" use
BaseUriBuilder.fromPath("{arg1}").fragment("{arg2}").build("foo", "bar")
instead. URI template names and delimiters are never encoded but their values are encoded when a URI is built.
Template parameter regular expressions are ignored when building a URI, i.e. no validation is performed.URI| Modifier | Constructor and Description |
|---|---|
protected |
BaseUriBuilder()
Protected constructor, use one of the static
fromXxx(...) methods to obtain an instance. |
| Modifier and Type | Method and Description |
|---|---|
(package private) abstract URI |
build(Object... values)
Build a URI, using the supplied values in order to replace any URI template parameters.
|
(package private) abstract URI |
build(Object[] values,
boolean encodeSlashInPath)
Build a URI, using the supplied values in order to replace any URI template parameters.
|
(package private) abstract URI |
buildFromEncoded(Object... values)
Build a URI.
|
(package private) abstract URI |
buildFromEncodedMap(Map<String,?> values)
Build a URI.
|
(package private) abstract URI |
buildFromMap(Map<String,?> values)
Build a URI.
|
(package private) abstract URI |
buildFromMap(Map<String,?> values,
boolean encodeSlashInPath)
Build a URI.
|
abstract BaseUriBuilder |
clone()
Create a copy of the BaseUriBuilder preserving its state.
|
(package private) abstract BaseUriBuilder |
fragment(String fragment)
Set the URI fragment.
|
(package private) static BaseUriBuilder |
fromLink(Link link)
Create a new instance initialized from a Link.
|
(package private) static BaseUriBuilder |
fromPath(String path)
Create a new instance representing a relative URI initialized from a URI path.
|
(package private) static BaseUriBuilder |
fromResource(Class<?> resource)
Create a new instance representing a relative URI initialized from a root resource class.
|
(package private) static BaseUriBuilder |
fromUri(String uriTemplate)
Create a new instance initialized from an existing URI.
|
(package private) static BaseUriBuilder |
fromUri(URI uri)
Create a new instance initialized from an existing URI.
|
(package private) abstract BaseUriBuilder |
host(String host)
Set the URI host.
|
(package private) abstract BaseUriBuilder |
matrixParam(String name,
Object... values)
Append a matrix parameter to the existing set of matrix parameters of the current final segment of the URI path.
|
protected static BaseUriBuilder |
newInstance()
Creates a new instance of BaseUriBuilder.
|
(package private) abstract BaseUriBuilder |
path(Class resource)
Append the path from a Path-annotated class to the existing path.
|
(package private) abstract BaseUriBuilder |
path(Method method)
Append the path from a
javax.ws.rs.Path-annotated method to the existing path. |
(package private) abstract BaseUriBuilder |
path(String path)
Append path to the existing path.
|
(package private) abstract BaseUriBuilder |
port(int port)
Set the URI port.
|
(package private) abstract BaseUriBuilder |
queryParam(String name,
Object... values)
Append a query parameter to the existing set of query parameters.
|
(package private) abstract BaseUriBuilder |
replaceMatrix(String matrix)
Set the matrix parameters of the current final segment of the current URI path.
|
(package private) abstract BaseUriBuilder |
replaceMatrixParam(String name,
Object... values)
Replace the existing value(s) of a matrix parameter on the current final segment of the URI path.
|
(package private) abstract BaseUriBuilder |
replacePath(String path)
Set the URI path.
|
(package private) abstract BaseUriBuilder |
replaceQuery(String query)
Set the URI query string.
|
(package private) abstract BaseUriBuilder |
replaceQueryParam(String name,
Object... values)
Replace the existing value(s) of a query parameter.
|
(package private) abstract BaseUriBuilder |
resolveTemplate(String name,
Object value)
Resolve a URI template with a given
name in this BaseUriBuilder instance using a supplied value. |
(package private) abstract BaseUriBuilder |
resolveTemplate(String name,
Object value,
boolean encodeSlashInPath)
Resolve a URI template with a given
name in this BaseUriBuilder instance using a supplied value. |
(package private) abstract BaseUriBuilder |
resolveTemplateFromEncoded(String name,
Object value)
Resolve a URI template with a given
name in this BaseUriBuilder instance using a supplied encoded
value. |
(package private) abstract BaseUriBuilder |
resolveTemplates(Map<String,Object> templateValues)
Resolve one or more URI templates in this
BaseUriBuilder instance using supplied name-value pairs. |
(package private) abstract BaseUriBuilder |
resolveTemplates(Map<String,Object> templateValues,
boolean encodeSlashInPath)
Resolve one or more URI templates in this
BaseUriBuilder instance using supplied name-value pairs. |
(package private) abstract BaseUriBuilder |
resolveTemplatesFromEncoded(Map<String,Object> templateValues)
Resolve one or more URI templates in this
BaseUriBuilder instance using supplied name-value pairs. |
(package private) abstract BaseUriBuilder |
scheme(String scheme)
Set the URI scheme.
|
(package private) abstract BaseUriBuilder |
schemeSpecificPart(String ssp)
Set the URI scheme-specific-part (see
java.net.URI). |
(package private) abstract BaseUriBuilder |
segment(String... segments)
Append path segments to the existing path.
|
(package private) abstract String |
toTemplate()
Get the URI template string represented by this URI builder.
|
(package private) abstract BaseUriBuilder |
uri(String uriTemplate)
Parses the
uriTemplate string and copies the parsed components of the supplied URI to the BaseUriBuilder
replacing any existing values for those components. |
(package private) abstract BaseUriBuilder |
uri(URI uri)
Copies the non-null components of the supplied URI to the BaseUriBuilder replacing any existing values for those
components.
|
(package private) abstract BaseUriBuilder |
userInfo(String ui)
Set the URI user-info.
|
protected BaseUriBuilder()
fromXxx(...) methods to obtain an instance.protected static BaseUriBuilder newInstance()
static BaseUriBuilder fromUri(URI uri)
uri - a URI that will be used to initialize the BaseUriBuilder.IllegalArgumentException - if uri is null.static BaseUriBuilder fromUri(String uriTemplate)
uriTemplate - a URI template that will be used to initialize the BaseUriBuilder, may contain URI parameters.IllegalArgumentException - if uriTemplate is not a valid URI template or is null.static BaseUriBuilder fromLink(Link link)
link - a Link that will be used to initialize the BaseUriBuilder, only its URI is used.IllegalArgumentException - if link is nullstatic BaseUriBuilder fromPath(String path) throws IllegalArgumentException
path - a URI path that will be used to initialize the BaseUriBuilder, may contain URI template parameters.IllegalArgumentException - if path is null.static BaseUriBuilder fromResource(Class<?> resource)
resource - a root resource whose javax.ws.rs.Path value will be used to initialize the
BaseUriBuilder.IllegalArgumentException - if resource is not annotated with javax.ws.rs.Path or resource is
null.public abstract BaseUriBuilder clone()
#build(Object...) method.abstract BaseUriBuilder uri(URI uri)
uri - the URI to copy components from.IllegalArgumentException - if the uri parameter is null.abstract BaseUriBuilder uri(String uriTemplate)
uriTemplate string and copies the parsed components of the supplied URI to the BaseUriBuilder
replacing any existing values for those components.uriTemplate - a URI template that will be used to initialize the BaseUriBuilder, may contain URI parameters.IllegalArgumentException - if uriTemplate is not a valid URI template or is null.abstract BaseUriBuilder scheme(String scheme)
scheme - the URI scheme, may contain URI template parameters. A null value will unset the URI
scheme, but will not unset the any scheme-specific-part components.IllegalArgumentException - if scheme is invalid.abstract BaseUriBuilder schemeSpecificPart(String ssp)
java.net.URI). This method will overwrite any existing values for
authority, user-info, host, port and path.ssp - the URI scheme-specific-part, may contain URI template parameters.IllegalArgumentException - if ssp cannot be parsed or is null.abstract BaseUriBuilder userInfo(String ui)
ui - the URI user-info, may contain URI template parameters. A null value will unset userInfo
component of the URI.abstract BaseUriBuilder host(String host)
host - the URI host, may contain URI template parameters. A null value will unset the host component
of the URI, but will not unset other authority component parts ( #userInfo(String) user info or
#port(int) port).IllegalArgumentException - if host is invalid.abstract BaseUriBuilder port(int port)
port - the URI port, a value of -1 will unset an explicit port.IllegalArgumentException - if port is invalid.abstract BaseUriBuilder replacePath(String path)
path - the path, may contain URI template parameters. A null value will unset the path component of
the URI.abstract BaseUriBuilder path(String path)
path - the path, may contain URI template parameters.IllegalArgumentException - if path is null.abstract BaseUriBuilder path(Class resource)
resource - a resource whose javax.ws.rs.Path value will be used to obtain the path to append.IllegalArgumentException - if resource is null, or if resource is not annotated with
javax.ws.rs.Path.abstract BaseUriBuilder path(Method method)
javax.ws.rs.Path-annotated method to the existing path. When constructing the
final path, a '/' separator will be inserted between the existing path and the supplied path if necessary.method - a method whose javax.ws.rs.Path value will be used to obtain the path to append to the
existing path.IllegalArgumentException - if method is null or is not annotated with a javax.ws.rs.Path.abstract BaseUriBuilder segment(String... segments)
segments - the path segment values, each may contain URI template parameters.IllegalArgumentException - if segments or any element of segments is null.abstract BaseUriBuilder replaceMatrix(String matrix)
matrix - the matrix parameters, may contain URI template parameters. A null value will remove all
matrix parameters of the current final segment of the current URI path.IllegalArgumentException - if matrix cannot be parsed.abstract BaseUriBuilder matrixParam(String name, Object... values)
name - the matrix parameter name, may contain URI template parameters.values - the matrix parameter value(s), each object will be converted. to a String using its
toString() method. Stringified values may contain URI template parameters.IllegalArgumentException - if name or values is null.abstract BaseUriBuilder replaceMatrixParam(String name, Object... values)
name - the matrix parameter name, may contain URI template parameters.values - the matrix parameter value(s), each object will be converted. to a String using its
toString() method. Stringified values may contain URI template parameters. If values is empty or
null then all current values of the parameter are removed.IllegalArgumentException - if name is null.abstract BaseUriBuilder replaceQuery(String query)
query - the URI query string, may contain URI template parameters. A null value will remove all
query parameters.IllegalArgumentException - if query cannot be parsed.abstract BaseUriBuilder queryParam(String name, Object... values)
name - the query parameter name, may contain URI template parameters.values - the query parameter value(s), each object will be converted to a String using its
toString() method. Stringified values may contain URI template parameters.IllegalArgumentException - if name or values is null.abstract BaseUriBuilder replaceQueryParam(String name, Object... values)
name - the query parameter name, may contain URI template parameters.values - the query parameter value(s), each object will be converted to a String using its
toString() method. Stringified values may contain URI template parameters. If values is empty or
null then all current values of the parameter are removed.IllegalArgumentException - if name is null.abstract BaseUriBuilder fragment(String fragment)
fragment - the URI fragment, may contain URI template parameters. A null value will remove any
existing fragment.abstract BaseUriBuilder resolveTemplate(String name, Object value)
name in this BaseUriBuilder instance using a supplied value.
In case a null template name or value is entered a IllegalArgumentException is thrown.name - name of the URI template.value - value to be used to resolve the template.IllegalArgumentException - if the resolved template name or value is null.abstract BaseUriBuilder resolveTemplate(String name, Object value, boolean encodeSlashInPath)
name in this BaseUriBuilder instance using a supplied value.
In case a null template name or value is entered a IllegalArgumentException is thrown.name - name of the URI template.value - value to be used to resolve the template.encodeSlashInPath - if true, the slash ('/') characters in template values will be encoded
if the template is placed in the URI path component, otherwise the slash characters will not be encoded in path
templates.IllegalArgumentException - if the resolved template name or value is null.abstract BaseUriBuilder resolveTemplateFromEncoded(String name, Object value)
name in this BaseUriBuilder instance using a supplied encoded
value.
A template with a matching name will be replaced by the supplied value. Value is converted to String
using its toString() method and is then encoded to match the rules of the URI component to which they
pertain. All % characters in the stringified values that are not followed by two hexadecimal numbers will be
encoded.
In case a null template name or encoded value is entered a IllegalArgumentException is thrown.name - name of the URI template.value - encoded value to be used to resolve the template.IllegalArgumentException - if the resolved template name or encoded value is null.abstract BaseUriBuilder resolveTemplates(Map<String,Object> templateValues)
BaseUriBuilder instance using supplied name-value pairs.
A call to the method with an empty parameter map is ignored.templateValues - a map of URI template names and their values.IllegalArgumentException - if the name-value map or any of the names or values in the map is null.abstract BaseUriBuilder resolveTemplates(Map<String,Object> templateValues, boolean encodeSlashInPath) throws IllegalArgumentException
BaseUriBuilder instance using supplied name-value pairs.
A call to the method with an empty parameter map is ignored.templateValues - a map of URI template names and their values.encodeSlashInPath - if true, the slash ('/') characters in template values will be encoded
if the template is placed in the URI path component, otherwise the slash characters will not be encoded in path
templates.IllegalArgumentException - if the name-value map or any of the names or values in the map is null.abstract BaseUriBuilder resolveTemplatesFromEncoded(Map<String,Object> templateValues)
BaseUriBuilder instance using supplied name-value pairs.
All templates with their name matching one of the keys in the supplied map will be replaced by the value in the
supplied map. Values are converted to String using their toString() method and are then encoded
to match the rules of the URI component to which they pertain. All % characters in the stringified values that
are not followed by two hexadecimal numbers will be encoded.
A call to the method with an empty parameter map is ignored.templateValues - a map of URI template names and their values.IllegalArgumentException - if the name-value map or any of the names or values in the map is null.abstract URI buildFromMap(Map<String,?> values)
String using their toString() method and are then encoded to match the rules of the URI component
to which they pertain. All '%' characters in the stringified values will be encoded. The state of the
builder is unaffected; this method may be called multiple times on the same builder instance.
NOTE: By default all '/' characters in the stringified values will be encoded in path templates, i.e. the
result is identical to invoking #buildFromMap(java.util.Map, boolean) buildFromMap(valueMap, true). To
override this behavior use buildFromMap(valueMap, false) instead.
values - a map of URI template parameter names and values.IllegalArgumentException - if there are any URI template parameters without a supplied value, or if a
template parameter value is null.UriBuilderException - if a URI cannot be constructed based on the current state of the builder.buildFromMap(java.util.Map, boolean),
buildFromEncodedMap(java.util.Map)abstract URI buildFromMap(Map<String,?> values, boolean encodeSlashInPath) throws IllegalArgumentException, UriBuilderException
String using their toString() method and are then encoded to match the rules of the URI component
to which they pertain. All '%' characters in the stringified values will be encoded. The state of the
builder is unaffected; this method may be called multiple times on the same builder instance.
The encodeSlashInPath parameter may be used to override the default encoding of '/' characters in
the stringified template values in cases when the template is part of the URI path component when using the
#buildFromMap(java.util.Map) method. If the encodeSlashInPath parameter is set to true
(default), the slash ('/') characters in parameter values will be encoded if the template is placed in
the URI path component. If set to false the default encoding behavior is overridden an slash characters
in template values will not be encoded when used to substitute path templates.
values - a map of URI template parameter names and values.encodeSlashInPath - if true, the slash ('/') characters in parameter values will be encoded
if the template is placed in the URI path component, otherwise the slash characters will not be encoded in path
templates.IllegalArgumentException - if there are any URI template parameters without a supplied value, or if a
template parameter value is null.UriBuilderException - if a URI cannot be constructed based on the current state of the builder.buildFromMap(java.util.Map),
buildFromEncodedMap(java.util.Map)abstract URI buildFromEncodedMap(Map<String,?> values) throws IllegalArgumentException, UriBuilderException
String using their toString() method and are then encoded to match the rules of the URI component
to which they pertain. All % characters in the stringified values that are not followed by two hexadecimal
numbers will be encoded. The state of the builder is unaffected; this method may be called multiple times on the
same builder instance.values - a map of URI template parameter names and values.IllegalArgumentException - if there are any URI template parameters without a supplied value, or if a
template parameter value is null.UriBuilderException - if a URI cannot be constructed based on the current state of the builder.buildFromMap(java.util.Map),
buildFromMap(java.util.Map, boolean)abstract URI build(Object... values) throws IllegalArgumentException, UriBuilderException
String using their toString() method and are then encoded to match the rules of the URI component
to which they pertain. All '%' characters in the stringified values will be encoded. The state of the builder is
unaffected; this method may be called multiple times on the same builder instance.
All instances of the same template parameter will be replaced by the same value that corresponds to the position of the first instance of the template parameter. e.g. the template "{a}/{b}/{a}" with values {"x", "y", "z"} will result in the the URI "x/y/x", not "x/y/z".
NOTE: By default all '/' characters in the stringified values will be encoded in path templates, i.e. the
result is identical to invoking #build(Object[], boolean) build(values, true)}. To override this behavior
use build(values, false) instead.
values - a list of URI template parameter values.IllegalArgumentException - if there are any URI template parameters without a supplied value, or if a value
is null.UriBuilderException - if a URI cannot be constructed based on the current state of the builder.build(Object[], boolean),
buildFromEncoded(Object...)abstract URI build(Object[] values, boolean encodeSlashInPath) throws IllegalArgumentException, UriBuilderException
String using their toString() method and are then encoded to match the rules of the URI component
to which they pertain. All '%' characters in the stringified values will be encoded. The state of the builder is
unaffected; this method may be called multiple times on the same builder instance.
All instances of the same template parameter will be replaced by the same value that corresponds to the position of the first instance of the template parameter. e.g. the template "{a}/{b}/{a}" with values {"x", "y", "z"} will result in the the URI "x/y/x", not "x/y/z".
The encodeSlashInPath parameter may be used to override the default encoding of '/' characters in
the stringified template values in cases when the template is part of the URI path component when using the
#build(Object[]) method. If the encodeSlashInPath parameter is set to true (default), the
slash ('/') characters in parameter values will be encoded if the template is placed in the URI path
component. If set to false the default encoding behavior is overridden an slash characters in template
values will not be encoded when used to substitute path templates.
values - a list of URI template parameter values.encodeSlashInPath - if true, the slash ('/') characters in parameter values will be encoded
if the template is placed in the URI path component, otherwise the slash characters will not be encoded in path
templates.IllegalArgumentException - if there are any URI template parameters without a supplied value, or if a value
is null.UriBuilderException - if a URI cannot be constructed based on the current state of the builder.build(Object[]),
buildFromEncoded(Object...)abstract URI buildFromEncoded(Object... values) throws IllegalArgumentException, UriBuilderException
String using their toString() method and are then encoded to match the rules of the
URI component to which they pertain. All % characters in the stringified values that are not followed by two
hexadecimal numbers will be encoded. The state of the builder is unaffected; this method may be called multiple
times on the same builder instance.
All instances of the same template parameter will be replaced by the same value that corresponds to the position of the first instance of the template parameter. e.g. the template "{a}/{b}/{a}" with values {"x", "y", "z"} will result in the the URI "x/y/x", not "x/y/z".
values - a list of URI template parameter values.IllegalArgumentException - if there are any URI template parameters without a supplied value, or if a value
is null.UriBuilderException - if a URI cannot be constructed based on the current state of the builder.build(Object[]),
build(Object[], boolean)abstract String toTemplate()
Copyright © 2014 Sven Strittmatter. All Rights Reserved.