public abstract class UriBuilder
extends
Builder methods perform contextual encoding of characters not permitted in the corresponding URI component following the rules of the media type for query parameters and 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.
would result in encoding of the '#' such that the resulting URI is "foo%23bar". To create a URI "foo#bar" use
UriBuilder.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.
Modifier | Constructor and Description |
---|---|
protected | ()
Protected constructor, use one of the static
fromXxx(...) methods to obtain an instance.
|
Modifier and Type | Method and Description |
---|---|
abstract | (... values)
Build a URI, using the supplied values in order to replace any URI template parameters.
|
abstract | ([] values, boolean encodeSlashInPath)
Build a URI, using the supplied values in order to replace any URI template parameters.
|
abstract | (... values)
Build a URI.
|
abstract | (<,?> values)
Build a URI.
|
abstract | (<,?> values)
Build a URI.
|
abstract | (<,?> values, boolean encodeSlashInPath)
Build a URI.
|
abstract | ()
Create a copy of the UriBuilder preserving its state.
|
abstract | ( fragment)
Set the URI fragment.
|
static | ( link)
Create a new instance initialized from a Link.
|
static | (<?> resource, method)
Create a new instance representing a relative URI initialized from a
-annotated method.
|
static | ( path)
Create a new instance representing a relative URI initialized from a URI path.
|
static | (<?> resource)
Create a new instance representing a relative URI initialized from a root resource class.
|
static | ( uriTemplate)
Create a new instance initialized from an existing URI.
|
static | ( uri)
Create a new instance initialized from an existing URI.
|
abstract | ( host)
Set the URI host.
|
abstract | ( name, ... values)
Append a matrix parameter to the existing set of matrix parameters of the current final segment of the URI path.
|
protected static | ()
Creates a new instance of UriBuilder.
|
abstract | ( resource)
Append the path from a Path-annotated class to the existing path.
|
abstract | ( resource, method)
Append the path from a Path-annotated method to the existing path.
|
abstract | ( method)
Append the path from a
-annotated method to the existing path.
|
abstract | ( path)
Append path to the existing path.
|
abstract | (int port)
Set the URI port.
|
abstract | ( name, ... values)
Append a query parameter to the existing set of query parameters.
|
abstract | ( matrix)
Set the matrix parameters of the current final segment of the current URI path.
|
abstract | ( name, ... values)
Replace the existing value(s) of a matrix parameter on the current final segment of the URI path.
|
abstract | ( path)
Set the URI path.
|
abstract | ( query)
Set the URI query string.
|
abstract | ( name, ... values)
Replace the existing value(s) of a query parameter.
|
abstract | ( name, value)
Resolve a URI template with a given
name in this
UriBuilder instance using a supplied value.
|
abstract | ( name, value, boolean encodeSlashInPath)
Resolve a URI template with a given
name in this
UriBuilder instance using a supplied value.
|
abstract | ( name, value)
Resolve a URI template with a given
name in this
UriBuilder instance using a supplied encoded value.
|
abstract | (<,> templateValues)
Resolve one or more URI templates in this
UriBuilder instance using supplied name-value pairs.
|
abstract | (<,> templateValues, boolean encodeSlashInPath)
Resolve one or more URI templates in this
UriBuilder instance using supplied name-value pairs.
|
abstract | (<,> templateValues)
Resolve one or more URI templates in this
UriBuilder instance using supplied name-value pairs.
|
abstract | ( scheme)
Set the URI scheme.
|
abstract | ( ssp)
Set the URI scheme-specific-part (see
).
|
abstract | (... segments)
Append path segments to the existing path.
|
abstract | ()
Get the URI template string represented by this URI builder.
|
abstract | ( uriTemplate)
Parses the
uriTemplate string and copies the parsed components of the supplied URI to the UriBuilder replacing any existing values for those components.
|
abstract | ( uri)
Copies the non-null components of the supplied URI to the UriBuilder replacing any existing values for those components.
|
abstract | ( ui)
Set the URI user-info.
|
, , , , , , , , ,
protected UriBuilder()
fromXxx(...)
methods to obtain an instance.
protected static newInstance()
public static fromUri( uri)
uri
- a URI that will be used to initialize the UriBuilder.
- if uri is
null
.
public static fromUri( uriTemplate)
uriTemplate
- a URI template that will be used to initialize the UriBuilder, may contain URI parameters.
- if
uriTemplate
is not a valid URI template or is
null
.
public static fromLink( link)
link
- a Link that will be used to initialize the UriBuilder, only its URI is used.
- if link is
null
public static fromPath( path) throws
path
- a URI path that will be used to initialize the UriBuilder, may contain URI template parameters.
- if path is
null
.
public static fromResource(<?> resource)
resource
- a root resource whose
value will be used to initialize the UriBuilder.
- if resource is not annotated with
or resource is
null
.
public static fromMethod(<?> resource, method)
resource
- the resource containing the method.
method
- the name of the method whose
value will be used to obtain the path to append.
- if resource or method is
null
, or there is more than or less than one variant of the method annotated with
.
public abstract clone()
in class
public abstract uri( uri)
uri
- the URI to copy components from.
- if the
uri
parameter is
null
.
public abstract uri( uriTemplate)
uriTemplate
string and copies the parsed components of the supplied URI to the UriBuilder replacing any existing values for those components.
uriTemplate
- a URI template that will be used to initialize the UriBuilder, may contain URI parameters.
- if
uriTemplate
is not a valid URI template or is
null
.
public abstract scheme( 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.
- if scheme is invalid.
public abstract schemeSpecificPart( ssp)
ssp
- the URI scheme-specific-part, may contain URI template parameters.
- if ssp cannot be parsed or is
null
.
public abstract userInfo( ui)
ui
- the URI user-info, may contain URI template parameters. A
null
value will unset userInfo component of the URI.
public abstract host( 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 (
or
).
- if host is invalid.
public abstract port(int port)
port
- the URI port, a value of -1 will unset an explicit port.
- if port is invalid.
public abstract replacePath( path)
path
- the path, may contain URI template parameters. A
null
value will unset the path component of the URI.
public abstract path( path)
path
- the path, may contain URI template parameters.
- if path is
null
.
public abstract path( resource)
resource
- a resource whose
value will be used to obtain the path to append.
- if resource is
null
, or if resource is not annotated with
.
public abstract path( resource, method)
path(Method)
, it can only be used in cases where there is a single method with the specified name that is annotated with
.
resource
- the resource containing the method.
method
- the name of the method whose
value will be used to obtain the path to append.
- if resource or method is
null
, or there is more than or less than one variant of the method annotated with
.
public abstract path( method)
method
- a method whose
value will be used to obtain the path to append to the existing path.
- if method is
null
or is not annotated with a
.
public abstract segment(... segments)
segments
- the path segment values, each may contain URI template parameters.
- if segments or any element of segments is
null
.
public abstract replaceMatrix( 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.
- if matrix cannot be parsed.
public abstract matrixParam( name, ... 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 name or values is
null
.
public abstract replaceMatrixParam( name, ... 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.
- if name is
null
.
public abstract replaceQuery( query)
query
- the URI query string, may contain URI template parameters. A
null
value will remove all query parameters.
- if query cannot be parsed.
public abstract queryParam( name, ... 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 name or values is
null
.
public abstract replaceQueryParam( name, ... 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.
- if name is
null
.
public abstract fragment( fragment)
fragment
- the URI fragment, may contain URI template parameters. A
null
value will remove any existing fragment.
public abstract resolveTemplate( name, value)
name
in this
UriBuilder
instance using a supplied value. In case a
null
template name or value is entered a
is thrown.
name
- name of the URI template.
value
- value to be used to resolve the template.
- if the resolved template name or value is
null
.
public abstract resolveTemplate( name, value, boolean encodeSlashInPath)
name
in this
UriBuilder
instance using a supplied value. In case a
null
template name or value is entered a
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.
- if the resolved template name or value is
null
.
public abstract resolveTemplateFromEncoded( name, value)
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
is thrown.
name
- name of the URI template.
value
- encoded value to be used to resolve the template.
- if the resolved template name or encoded value is
null
.
public abstract resolveTemplates(<,> templateValues)
UriBuilder
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.
- if the name-value map or any of the names or values in the map is
null
.
public abstract resolveTemplates(<,> templateValues, boolean encodeSlashInPath) throws
UriBuilder
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.
- if the name-value map or any of the names or values in the map is
null
.
public abstract resolveTemplatesFromEncoded(<,> templateValues)
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.
templateValues
- a map of URI template names and their values.
- if the name-value map or any of the names or values in the map is
null
.
public abstract buildFromMap(<,?> 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 . To override this behavior use buildFromMap(valueMap, false)
instead.
values
- a map of URI template parameter names and values.
- if there are any URI template parameters without a supplied value, or if a template parameter value is
null
.
- if a URI cannot be constructed based on the current state of the builder.
public abstract buildFromMap(<,?> values, boolean encodeSlashInPath) throws ,
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 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.
- if there are any URI template parameters without a supplied value, or if a template parameter value is
null
.
- if a URI cannot be constructed based on the current state of the builder.
public abstract buildFromEncodedMap(<,?> values) throws ,
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.
- if there are any URI template parameters without a supplied value, or if a template parameter value is
null
.
- if a URI cannot be constructed based on the current state of the builder.
public abstract build(... values) throws ,
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(values, true)}. To override this behavior use build(values, false)
instead.
values
- a list of URI template parameter values.
- if there are any URI template parameters without a supplied value, or if a value is
null
.
- if a URI cannot be constructed based on the current state of the builder.
public abstract build([] values, boolean encodeSlashInPath) throws ,
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 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.
- if there are any URI template parameters without a supplied value, or if a value is
null
.
- if a URI cannot be constructed based on the current state of the builder.
public abstract buildFromEncoded(... values) throws ,
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.
- if there are any URI template parameters without a supplied value, or if a value is
null
.
- if a URI cannot be constructed based on the current state of the builder.
public abstract toTemplate()
Copyright © 1996-2013, and/or its affiliates. All Rights Reserved. Use is subject to .
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- oldu.cn 版权所有 浙ICP备2024123271号-1
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务