public class JerseyUriBuilder extends UriBuilder
UriBuilder
.Constructor and Description |
---|
JerseyUriBuilder()
Create new implementation of
UriBuilder . |
Modifier and Type | Method and Description |
---|---|
URI |
build(Object... values)
Build a URI, using the supplied values in order to replace any URI template parameters.
|
URI |
build(Object[] values,
boolean encodeSlashInPath)
Build a URI, using the supplied values in order to replace any URI template parameters.
|
URI |
buildFromEncoded(Object... values)
Build a URI.
|
URI |
buildFromEncodedMap(Map<String,?> values)
Build a URI.
|
URI |
buildFromMap(Map<String,?> values)
Build a URI.
|
URI |
buildFromMap(Map<String,?> values,
boolean encodeSlashInPath)
Build a URI.
|
JerseyUriBuilder |
clone()
Create a copy of the UriBuilder preserving its state.
|
JerseyUriBuilder |
fragment(String fragment)
Set the URI fragment.
|
JerseyUriBuilder |
host(String host)
Set the URI host.
|
boolean |
isAbsolute()
Check whether or not the URI represented by this
UriBuilder is absolute. |
JerseyUriBuilder |
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.
|
UriBuilder |
path(Class resource)
Append the path from a Path-annotated class to the existing path.
|
JerseyUriBuilder |
path(Class resource,
String methodName)
Append the path from a Path-annotated method to the existing path.
|
JerseyUriBuilder |
path(Method method)
Append the path from a
Path -annotated method to the existing path. |
JerseyUriBuilder |
path(String path)
Append path to the existing path.
|
JerseyUriBuilder |
port(int port)
Set the URI port.
|
JerseyUriBuilder |
queryParam(String name,
Object... values)
Append a query parameter to the existing set of query parameters.
|
JerseyUriBuilder |
replaceMatrix(String matrix)
Set the matrix parameters of the current final segment of the current URI path.
|
JerseyUriBuilder |
replaceMatrixParam(String name,
Object... values)
Replace the existing value(s) of a matrix parameter on the current final segment of the URI path.
|
JerseyUriBuilder |
replacePath(String path)
Set the URI path.
|
JerseyUriBuilder |
replaceQuery(String query)
Set the URI query string.
|
JerseyUriBuilder |
replaceQueryParam(String name,
Object... values)
Replace the existing value(s) of a query parameter.
|
JerseyUriBuilder |
resolveTemplate(String name,
Object value)
Resolve a URI template with a given
name in this UriBuilder instance using a supplied value. |
JerseyUriBuilder |
resolveTemplate(String name,
Object value,
boolean encodeSlashInPath)
Resolve a URI template with a given
name in this UriBuilder instance using a supplied value. |
JerseyUriBuilder |
resolveTemplateFromEncoded(String name,
Object value)
Resolve a URI template with a given
name in this UriBuilder instance using a supplied encoded value. |
JerseyUriBuilder |
resolveTemplates(Map<String,Object> templateValues)
Resolve one or more URI templates in this
UriBuilder instance using supplied name-value pairs. |
JerseyUriBuilder |
resolveTemplates(Map<String,Object> templateValues,
boolean encodeSlashInPath)
Resolve one or more URI templates in this
UriBuilder instance using supplied name-value pairs. |
JerseyUriBuilder |
resolveTemplatesFromEncoded(Map<String,Object> templateValues)
Resolve one or more URI templates in this
UriBuilder instance using supplied name-value pairs. |
JerseyUriBuilder |
scheme(String scheme)
Set the URI scheme.
|
JerseyUriBuilder |
schemeSpecificPart(String ssp)
Set the URI scheme-specific-part (see
URI ). |
JerseyUriBuilder |
segment(String... segments)
Append path segments to the existing path.
|
JerseyUriBuilder |
setQueryParamStyle(JerseyQueryParamStyle queryParamStyle) |
String |
toString() |
String |
toTemplate()
Get the URI template string represented by this URI builder.
|
JerseyUriBuilder |
uri(String uriTemplate)
Parses the
uriTemplate string and copies the parsed components of the supplied URI to the UriBuilder
replacing any existing values for those components. |
JerseyUriBuilder |
uri(URI uri)
Copies the non-null components of the supplied URI to the UriBuilder replacing any existing values for those
components.
|
JerseyUriBuilder |
userInfo(String ui)
Set the URI user-info.
|
fromLink, fromMethod, fromPath, fromResource, fromUri, fromUri, newInstance
public JerseyUriBuilder()
UriBuilder
.public JerseyUriBuilder clone()
UriBuilder
UriBuilder.build(Object...)
method.clone
in class UriBuilder
public JerseyUriBuilder uri(URI uri)
UriBuilder
uri
in class UriBuilder
uri
- the URI to copy components from.public JerseyUriBuilder uri(String uriTemplate)
UriBuilder
uriTemplate
string and copies the parsed components of the supplied URI to the UriBuilder
replacing any existing values for those components.uri
in class UriBuilder
uriTemplate
- a URI template that will be used to initialize the UriBuilder, may contain URI parameters.public JerseyUriBuilder scheme(String scheme)
UriBuilder
scheme
in class UriBuilder
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.public JerseyUriBuilder schemeSpecificPart(String ssp)
UriBuilder
URI
). This method will overwrite any existing values for
authority, user-info, host, port and path.schemeSpecificPart
in class UriBuilder
ssp
- the URI scheme-specific-part, may contain URI template parameters.public JerseyUriBuilder userInfo(String ui)
UriBuilder
userInfo
in class UriBuilder
ui
- the URI user-info, may contain URI template parameters. A null
value will unset userInfo component
of the URI.public JerseyUriBuilder host(String host)
UriBuilder
host
in class UriBuilder
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 (user info
or port
).public JerseyUriBuilder port(int port)
UriBuilder
port
in class UriBuilder
port
- the URI port, a value of -1 will unset an explicit port.public JerseyUriBuilder replacePath(String path)
UriBuilder
replacePath
in class UriBuilder
path
- the path, may contain URI template parameters. A null
value will unset the path component of the
URI.public JerseyUriBuilder path(String path)
UriBuilder
path
in class UriBuilder
path
- the path, may contain URI template parameters.public UriBuilder path(Class resource) throws IllegalArgumentException
UriBuilder
path
in class UriBuilder
resource
- a resource whose Path
value will be used to obtain the path to append.IllegalArgumentException
- if resource is null
, or if resource is not annotated with
Path
.public JerseyUriBuilder path(Class resource, String methodName)
UriBuilder
path(Method)
, it can only be used in cases where there is a single method with the specified name that is
annotated with Path
.path
in class UriBuilder
resource
- the resource containing the method.methodName
- the name of the method whose Path
value will be used to obtain the path to append.public JerseyUriBuilder path(Method method)
UriBuilder
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.path
in class UriBuilder
method
- a method whose Path
value will be used to obtain the path to append to the existing
path.public JerseyUriBuilder segment(String... segments) throws IllegalArgumentException
UriBuilder
segment
in class UriBuilder
segments
- the path segment values, each may contain URI template parameters.IllegalArgumentException
- if segments or any element of segments is null
.public JerseyUriBuilder replaceMatrix(String matrix)
UriBuilder
replaceMatrix
in class UriBuilder
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.public JerseyUriBuilder matrixParam(String name, Object... values)
UriBuilder
matrixParam
in class UriBuilder
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.public JerseyUriBuilder replaceMatrixParam(String name, Object... values)
UriBuilder
replaceMatrixParam
in class UriBuilder
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.public JerseyUriBuilder replaceQuery(String query)
UriBuilder
replaceQuery
in class UriBuilder
query
- the URI query string, may contain URI template parameters. A null
value will remove all query
parameters.public JerseyUriBuilder queryParam(String name, Object... values)
UriBuilder
queryParam
in class UriBuilder
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.public JerseyUriBuilder setQueryParamStyle(JerseyQueryParamStyle queryParamStyle)
public JerseyUriBuilder replaceQueryParam(String name, Object... values)
UriBuilder
replaceQueryParam
in class UriBuilder
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.public JerseyUriBuilder resolveTemplate(String name, Object value) throws IllegalArgumentException
UriBuilder
name
in this UriBuilder
instance using a supplied value.
In case a null
template name or value is entered a IllegalArgumentException
is thrown.resolveTemplate
in class UriBuilder
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
.public JerseyUriBuilder resolveTemplate(String name, Object value, boolean encodeSlashInPath)
UriBuilder
name
in this UriBuilder
instance using a supplied value.
In case a null
template name or value is entered a IllegalArgumentException
is thrown.resolveTemplate
in class UriBuilder
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.public JerseyUriBuilder resolveTemplateFromEncoded(String name, Object value)
UriBuilder
name
in this UriBuilder
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.resolveTemplateFromEncoded
in class UriBuilder
name
- name of the URI template.value
- encoded value to be used to resolve the template.public JerseyUriBuilder resolveTemplates(Map<String,Object> templateValues) throws IllegalArgumentException
UriBuilder
UriBuilder
instance using supplied name-value pairs.
A call to the method with an empty parameter map is ignored.resolveTemplates
in class UriBuilder
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
.public JerseyUriBuilder resolveTemplates(Map<String,Object> templateValues, boolean encodeSlashInPath) throws IllegalArgumentException
UriBuilder
UriBuilder
instance using supplied name-value pairs.
A call to the method with an empty parameter map is ignored.resolveTemplates
in class UriBuilder
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
.public JerseyUriBuilder resolveTemplatesFromEncoded(Map<String,Object> templateValues)
UriBuilder
UriBuilder
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.resolveTemplatesFromEncoded
in class UriBuilder
templateValues
- a map of URI template names and their values.public JerseyUriBuilder fragment(String fragment)
UriBuilder
fragment
in class UriBuilder
fragment
- the URI fragment, may contain URI template parameters. A null
value will remove any existing
fragment.public URI buildFromMap(Map<String,?> values)
UriBuilder
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(valueMap, true)
. To
override this behavior use buildFromMap(valueMap, false)
instead.
buildFromMap
in class UriBuilder
values
- a map of URI template parameter names and values.UriBuilder.buildFromMap(java.util.Map, boolean)
,
UriBuilder.buildFromEncodedMap(java.util.Map)
public URI buildFromMap(Map<String,?> values, boolean encodeSlashInPath)
UriBuilder
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
UriBuilder.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.
buildFromMap
in class UriBuilder
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.UriBuilder.buildFromMap(java.util.Map)
,
UriBuilder.buildFromEncodedMap(java.util.Map)
public URI buildFromEncodedMap(Map<String,?> values) throws IllegalArgumentException, UriBuilderException
UriBuilder
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.buildFromEncodedMap
in class UriBuilder
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.UriBuilder.buildFromMap(java.util.Map)
,
UriBuilder.buildFromMap(java.util.Map, boolean)
public URI build(Object... values)
UriBuilder
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 UriBuilder.build(Object[], boolean)
build(values, true)}. To override this behavior use
build(values, false)
instead.
build
in class UriBuilder
values
- a list of URI template parameter values.UriBuilder.build(Object[], boolean)
,
UriBuilder.buildFromEncoded(Object...)
public URI build(Object[] values, boolean encodeSlashInPath)
UriBuilder
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
UriBuilder.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.
build
in class UriBuilder
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.UriBuilder.build(Object[])
,
UriBuilder.buildFromEncoded(Object...)
public URI buildFromEncoded(Object... values)
UriBuilder
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".
buildFromEncoded
in class UriBuilder
values
- a list of URI template parameter values.UriBuilder.build(Object[])
,
UriBuilder.build(Object[], boolean)
public String toTemplate()
UriBuilder
toTemplate
in class UriBuilder
public boolean isAbsolute()
UriBuilder
is absolute.
A URI is absolute if, and only if, it has a scheme component.true
if, and only if, the URI represented by this UriBuilder
is absolute.Copyright © 2007-2024, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.