public final class UriBuilder extends BaseUriBuilder
de.weltraumschaf.commons.uri.BaseUriBuilder.| Modifier and Type | Field and Description |
|---|---|
private String |
authority |
private String |
fragment |
private String |
host |
private MultivaluedMap<String,String> |
matrixParams |
private StringBuilder |
path |
private String |
port |
private StringBuilder |
query |
private MultivaluedMap<String,String> |
queryParams |
private String |
scheme |
private String |
ssp |
private String |
userInfo |
| Modifier | Constructor and Description |
|---|---|
|
UriBuilder()
Create new implementation of
BaseUriBuilder. |
private |
UriBuilder(UriBuilder that) |
| Modifier and Type | Method and Description |
|---|---|
private URI |
_build(boolean encode,
boolean encodeSlashInPath,
Object... values) |
private URI |
_buildFromMap(boolean encode,
boolean encodeSlashInPath,
Map<String,?> values) |
private void |
appendPath(Path path) |
private void |
appendPath(String path) |
private void |
appendPath(String segments,
boolean isSegment) |
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.
|
private void |
checkSsp() |
UriBuilder |
clone()
Create a copy of the BaseUriBuilder preserving its state.
|
private String |
create() |
private URI |
createURI(String uri) |
private String |
encode(String s,
UriComponent.Type type) |
private void |
encodeMatrix() |
private void |
encodeQuery() |
UriBuilder |
fragment(String fragment)
Set the URI fragment.
|
private Path |
getPath(AnnotatedElement ae) |
UriBuilder |
host(String host)
Set the URI host.
|
UriBuilder |
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.
|
BaseUriBuilder |
path(Class resource)
Append the path from a Path-annotated class to the existing path.
|
UriBuilder |
path(Method method)
Append the path from a
javax.ws.rs.Path-annotated method to the existing path. |
UriBuilder |
path(String path)
Append path to the existing path.
|
UriBuilder |
port(int port)
Set the URI port.
|
UriBuilder |
queryParam(String name,
Object... values)
Append a query parameter to the existing set of query parameters.
|
UriBuilder |
replaceMatrix(String matrix)
Set the matrix parameters of the current final segment of the current URI path.
|
UriBuilder |
replaceMatrixParam(String name,
Object... values)
Replace the existing value(s) of a matrix parameter on the current final segment of the URI path.
|
UriBuilder |
replacePath(String path)
Set the URI path.
|
UriBuilder |
replaceQuery(String query)
Set the URI query string.
|
UriBuilder |
replaceQueryParam(String name,
Object... values)
Replace the existing value(s) of a query parameter.
|
UriBuilder |
resolveTemplate(String name,
Object value)
Resolve a URI template with a given
name in this BaseUriBuilder instance using a supplied value. |
UriBuilder |
resolveTemplate(String name,
Object value,
boolean encodeSlashInPath)
Resolve a URI template with a given
name in this BaseUriBuilder instance using a supplied value. |
private UriBuilder |
resolveTemplate(String name,
Object value,
boolean encode,
boolean encodeSlashInPath) |
UriBuilder |
resolveTemplateFromEncoded(String name,
Object value)
Resolve a URI template with a given
name in this BaseUriBuilder instance using a supplied encoded
value. |
UriBuilder |
resolveTemplates(Map<String,Object> templateValues)
Resolve one or more URI templates in this
BaseUriBuilder instance using supplied name-value pairs. |
UriBuilder |
resolveTemplates(Map<String,Object> templateValues,
boolean encodeSlashInPath)
Resolve one or more URI templates in this
BaseUriBuilder instance using supplied name-value pairs. |
private UriBuilder |
resolveTemplates(Map<String,Object> templateValues,
boolean encode,
boolean encodeSlashInPath) |
UriBuilder |
resolveTemplatesFromEncoded(Map<String,Object> templateValues)
Resolve one or more URI templates in this
BaseUriBuilder instance using supplied name-value pairs. |
UriBuilder |
scheme(String scheme)
Set the URI scheme.
|
UriBuilder |
schemeSpecificPart(String ssp)
Set the URI scheme-specific-part (see
java.net.URI). |
private void |
schemeSpecificPart(UriParser parser)
Set scheme specific part from the URI parser.
|
UriBuilder |
segment(String... segments)
Append path segments to the existing path.
|
String |
toTemplate()
Get the URI template string represented by this URI builder.
|
UriBuilder |
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. |
UriBuilder |
uri(URI uri)
Copies the non-null components of the supplied URI to the BaseUriBuilder replacing any existing values for those
components.
|
UriBuilder |
userInfo(String ui)
Set the URI user-info.
|
fromLink, fromPath, fromResource, fromUri, fromUri, newInstanceprivate String scheme
private String ssp
private String authority
private String userInfo
private String host
private String port
private final StringBuilder path
private MultivaluedMap<String,String> matrixParams
private final StringBuilder query
private MultivaluedMap<String,String> queryParams
private String fragment
public UriBuilder()
BaseUriBuilder.private UriBuilder(UriBuilder that)
public UriBuilder clone()
#build(Object...) method.clone in class BaseUriBuilderpublic UriBuilder uri(URI uri)
uri in class BaseUriBuilderuri - the URI to copy components from.public UriBuilder uri(String uriTemplate)
uriTemplate string and copies the parsed components of the supplied URI to the BaseUriBuilder
replacing any existing values for those components.uri in class BaseUriBuilderuriTemplate - a URI template that will be used to initialize the BaseUriBuilder, may contain URI parameters.private void schemeSpecificPart(UriParser parser)
parser - initialized URI parser.public UriBuilder scheme(String scheme)
scheme in class BaseUriBuilderscheme - 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 UriBuilder schemeSpecificPart(String ssp)
java.net.URI). This method will overwrite any existing values for
authority, user-info, host, port and path.schemeSpecificPart in class BaseUriBuilderssp - the URI scheme-specific-part, may contain URI template parameters.public UriBuilder userInfo(String ui)
userInfo in class BaseUriBuilderui - the URI user-info, may contain URI template parameters. A null value will unset userInfo
component of the URI.public UriBuilder host(String host)
host in class BaseUriBuilderhost - 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).public UriBuilder port(int port)
port in class BaseUriBuilderport - the URI port, a value of -1 will unset an explicit port.public UriBuilder replacePath(String path)
replacePath in class BaseUriBuilderpath - the path, may contain URI template parameters. A null value will unset the path component of
the URI.public UriBuilder path(String path)
path in class BaseUriBuilderpath - the path, may contain URI template parameters.public BaseUriBuilder path(Class resource) throws IllegalArgumentException
path in class BaseUriBuilderresource - 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.public UriBuilder 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.path in class BaseUriBuildermethod - a method whose javax.ws.rs.Path value will be used to obtain the path to append to the
existing path.private Path getPath(AnnotatedElement ae)
public UriBuilder segment(String... segments) throws IllegalArgumentException
segment in class BaseUriBuildersegments - the path segment values, each may contain URI template parameters.IllegalArgumentException - if segments or any element of segments is null.public UriBuilder replaceMatrix(String matrix)
replaceMatrix in class BaseUriBuildermatrix - 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 UriBuilder matrixParam(String name, Object... values)
matrixParam in class BaseUriBuildername - 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 UriBuilder replaceMatrixParam(String name, Object... values)
replaceMatrixParam in class BaseUriBuildername - 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 UriBuilder replaceQuery(String query)
replaceQuery in class BaseUriBuilderquery - the URI query string, may contain URI template parameters. A null value will remove all
query parameters.public UriBuilder queryParam(String name, Object... values)
queryParam in class BaseUriBuildername - 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 UriBuilder replaceQueryParam(String name, Object... values)
replaceQueryParam in class BaseUriBuildername - 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 UriBuilder resolveTemplate(String name, Object value) throws IllegalArgumentException
name in this BaseUriBuilder instance using a supplied value.
In case a null template name or value is entered a IllegalArgumentException is thrown.resolveTemplate in class BaseUriBuildername - 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 UriBuilder 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.resolveTemplate in class BaseUriBuildername - 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 UriBuilder 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.resolveTemplateFromEncoded in class BaseUriBuildername - name of the URI template.value - encoded value to be used to resolve the template.private UriBuilder resolveTemplate(String name, Object value, boolean encode, boolean encodeSlashInPath)
public UriBuilder resolveTemplates(Map<String,Object> templateValues) throws IllegalArgumentException
BaseUriBuilder instance using supplied name-value pairs.
A call to the method with an empty parameter map is ignored.resolveTemplates in class BaseUriBuildertemplateValues - 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 UriBuilder 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.resolveTemplates in class BaseUriBuildertemplateValues - 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 UriBuilder 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.resolveTemplatesFromEncoded in class BaseUriBuildertemplateValues - a map of URI template names and their values.private UriBuilder resolveTemplates(Map<String,Object> templateValues, boolean encode, boolean encodeSlashInPath)
public UriBuilder fragment(String fragment)
fragment in class BaseUriBuilderfragment - the URI fragment, may contain URI template parameters. A null value will remove any
existing fragment.private void checkSsp()
private void appendPath(Path path)
private void appendPath(String path)
private void appendPath(String segments, boolean isSegment)
private void encodeMatrix()
private void encodeQuery()
private String encode(String s, UriComponent.Type type)
public 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.
buildFromMap in class BaseUriBuildervalues - a map of URI template parameter names and values.BaseUriBuilder.buildFromMap(java.util.Map, boolean),
BaseUriBuilder.buildFromEncodedMap(java.util.Map)public URI buildFromMap(Map<String,?> values, boolean encodeSlashInPath)
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.
buildFromMap in class BaseUriBuildervalues - 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.BaseUriBuilder.buildFromMap(java.util.Map),
BaseUriBuilder.buildFromEncodedMap(java.util.Map)public 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.buildFromEncodedMap in class BaseUriBuildervalues - 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.BaseUriBuilder.buildFromMap(java.util.Map),
BaseUriBuilder.buildFromMap(java.util.Map, boolean)private URI _buildFromMap(boolean encode, boolean encodeSlashInPath, Map<String,?> values)
public URI build(Object... 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.
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.
build in class BaseUriBuildervalues - a list of URI template parameter values.BaseUriBuilder.build(Object[], boolean),
BaseUriBuilder.buildFromEncoded(Object...)public URI build(Object[] values, boolean encodeSlashInPath)
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.
build in class BaseUriBuildervalues - 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.BaseUriBuilder.build(Object[]),
BaseUriBuilder.buildFromEncoded(Object...)public URI buildFromEncoded(Object... 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 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 BaseUriBuildervalues - a list of URI template parameter values.BaseUriBuilder.build(Object[]),
BaseUriBuilder.build(Object[], boolean)public String toTemplate()
toTemplate in class BaseUriBuilderprivate String create()
Copyright © 2014 Sven Strittmatter. All Rights Reserved.