public final class UriTemplateBuilder extends Object
A utility class used for programatically generating a UriTemplate.
The class can be used as follows:
UriTemplate template = UriTemplate.buildFromTemplate("http://example.com")
.literal("/foo")
.path(var("thing1"), var("explodedThing", true))
.fragment(var("prefix", 2))
.build();
This code will return a UriTemplate with the following value:
http://example.com/foo{/thing1,explodedThing*}{#prefix:2}
| Modifier and Type | Method and Description |
|---|---|
UriTemplate |
build()
Generates a
UriTemplate instance from the builder. |
UriTemplateBuilder |
continuation(String... var)
Appends a template expression using the form-style query continuation.
|
UriTemplateBuilder |
continuation(VarSpec... var)
Appends a template expression using the form-style query continuation and
and optional modifier.
|
UriTemplateBuilder |
fragment(String... var)
Appends a template expression using the fragment operator (#).
|
UriTemplateBuilder |
fragment(VarSpec... var)
Appends a template expression using the fragment operator (#) with a
modifier.
|
UriTemplateComponent[] |
getComponents()
Returns an array of the components in the Builder.
|
UriTemplateBuilder |
label(String... var)
Appends a template expression using the label (.) operator.
|
UriTemplateBuilder |
label(VarSpec... var)
Appends a template expression using the label (.) operator and modifier.
|
UriTemplateBuilder |
literal(String string)
Appends a
Literal value to the UriTemplate. |
UriTemplateBuilder |
matrix(String... var)
Appends a template expression using the matrix (;) operator.
|
UriTemplateBuilder |
matrix(VarSpec... var)
Appends a template expression using the matrix (;) operator and modifier.
|
UriTemplateBuilder |
path(String... var)
Appends a template expression using the path (/) operator.
|
UriTemplateBuilder |
path(VarSpec... var)
Appends a template expression using the path (/) operator and modifier.
|
UriTemplateBuilder |
query(String... var)
Appends a template expression using the query (?) operator.
|
UriTemplateBuilder |
query(VarSpec... var)
Appends a template expression using the query (?) operator and
and optional modifier.
|
UriTemplateBuilder |
reserved(String... var)
Appends a template expression using the reserved operator (+).
|
UriTemplateBuilder |
reserved(VarSpec... var)
Appends a template expression using the reserved operator (+) along
with an optional modifier.
|
UriTemplateBuilder |
simple(String... var)
Appends a template expression using no operator.
|
UriTemplateBuilder |
simple(VarSpec... var)
Appends a template expression using no operator but with an optional
modifier.
|
UriTemplateBuilder |
template(String... template)
Parses the template and appends the parsed components
to the builder.
|
UriTemplateBuilder |
template(UriTemplate... template)
Parses the template and appends the parsed components
to the builder.
|
static VarSpec |
var(String varName)
Adds a variable name to the expression.
|
static VarSpec |
var(String varName,
boolean explode)
Adds a variable name to the expression with an explode modifier.
|
static VarSpec |
var(String varName,
int prefix)
Adds a variable name to the expression with a prefix modifier.
|
UriTemplateBuilder |
withDefaultDateFormat(DateFormat dateFormat)
Deprecated.
replaced by
withDefaultDateFormat |
UriTemplateBuilder |
withDefaultDateFormat(String dateFormatString) |
public UriTemplateBuilder withDefaultDateFormat(String dateFormatString)
dateFormatString - @Deprecated public UriTemplateBuilder withDefaultDateFormat(DateFormat dateFormat)
withDefaultDateFormatdateFormat - public UriTemplateBuilder literal(String string)
Literal value to the UriTemplate. The following
code:
UriTemplate template = UriTemplate.buildFromTemplate("http://example.com")
.literal("/foo")
.build();
Will generate the following template:
http://example.com/foo
Note that this particular example has no expressions, so it's not a valid URI template.
string - public UriTemplateBuilder simple(String... var)
UriTemplate template =
UriTemplate.buildFromTemplate("http://example.com/")
.simple("foo")
.build();
Will generate the following URI Template string:
http://example.com/{foo}
var - public UriTemplateBuilder simple(VarSpec... var)
import static com.damnhandy.uri.template.UriTemplateBuilder.var;
...
UriTemplate template =
UriTemplate.buildFromTemplate("http://example.com/")
.simple(var("foo",true))
.build();
Will generate the following URI Template string:
http://example.com/{foo*}
var - public UriTemplateBuilder reserved(String... var)
UriTemplate template =
UriTemplate.buildFromTemplate("http://example.com/")
.reserved("foo")
.build();
Will generate the following URI Template string:
http://example.com/{+foo}
var - public UriTemplateBuilder reserved(VarSpec... var)
import static com.damnhandy.uri.template.UriTemplateBuilder.var;
...
UriTemplate template =
UriTemplate.buildFromTemplate("http://example.com/")
.reserved(var("foo",1))
.build();
Will generate the following URI Template string:
http://example.com/{+foo:1}
var - public UriTemplateBuilder fragment(String... var) throws UriTemplateBuilderException
UriTemplate template =
UriTemplate.buildFromTemplate("http://example.com/")
.fragement("foo")
.build();
Will generate the following URI Template string:
http://example.com/{#foo}
var - UriTemplateBuilderException - if you attempt to add more than one fragment expression, a UriTemplateBuilderException will be raisedpublic UriTemplateBuilder fragment(VarSpec... var) throws UriTemplateBuilderException
import static com.damnhandy.uri.template.UriTemplateBuilder.var;
...
UriTemplate template =
UriTemplate.buildFromTemplate("http://example.com/")
.fragement(var("foo", 1))
.build();
Will generate the following URI Template string:
http://example.com/{#foo:1}
var - UriTemplateBuilderException - if you attempt to add more than one fragment expression, a UriTemplateBuilderException will be raisedpublic UriTemplateBuilder label(String... var)
UriTemplate template =
UriTemplate.buildFromTemplate("http://example.com/")
.label("foo")
.build();
Will generate the following URI Template string:
http://example.com/{.foo}
var - public UriTemplateBuilder label(VarSpec... var)
UriTemplate template =
UriTemplate.buildFromTemplate("http://example.com/")
.label(var("foo", true))
.build();
Will generate the following URI Template string:
http://example.com/{.foo*}
var - public UriTemplateBuilder matrix(String... var)
UriTemplate template =
UriTemplate.buildFromTemplate("http://example.com/")
.matrix("foo")
.build();
Will generate the following URI Template string:
http://example.com/{;foo}
var - public UriTemplateBuilder matrix(VarSpec... var)
UriTemplate template =
UriTemplate.buildFromTemplate("http://example.com/")
.matrix(var("foo", true))
.build();
Will generate the following URI Template string:
http://example.com/{;foo*}
var - public UriTemplateBuilder path(String... var)
UriTemplate template =
UriTemplate.buildFromTemplate("http://example.com")
.path("foo")
.build();
Will generate the following URI Template string:
http://example.com{/foo}
var - public UriTemplateBuilder path(VarSpec... var)
UriTemplate template =
UriTemplate.buildFromTemplate("http://example.com")
.path(var("foo", 1))
.build();
Will generate the following URI Template string:
http://example.com{/foo:1}
var - public UriTemplateBuilder query(String... var)
UriTemplate template =
UriTemplate.buildFromTemplate("http://example.com/")
.query("foo")
.build();
Will generate the following URI Template string:
http://example.com/{?foo}
var - public UriTemplateBuilder query(VarSpec... var)
import static com.damnhandy.uri.template.UriTemplateBuilder.var;
...
UriTemplate template =
UriTemplate.buildFromTemplate("http://example.com/")
.query(var("foo",1))
.build();
Will generate the following URI Template string:
http://example.com/{?foo:1}
var - public UriTemplateBuilder continuation(String... var)
UriTemplate template =
UriTemplate.buildFromTemplate("http://example.com/")
.continuation("foo")
.build();
Will generate the following URI Template string:
http://example.com/{&foo}
var - public UriTemplateBuilder continuation(VarSpec... var)
import static com.damnhandy.uri.template.UriTemplateBuilder.var;
...
UriTemplate template =
UriTemplate.buildFromTemplate("http://example.com/")
.query(var("foo",1))
.build();
Will generate the following URI Template string:
http://example.com/{&foo:1}
var - public UriTemplateBuilder template(UriTemplate... template)
import static com.damnhandy.uri.template.UriTemplateBuilder.var;
...
UriTemplate template =
UriTemplate.buildFromTemplate("http://example.com/")
.template("foo/{id}{?filter}")
.build();
Will generate the following URI Template string:
http://example.com/foo/{id}{?filter}
template - public UriTemplateBuilder template(String... template)
import static com.damnhandy.uri.template.UriTemplateBuilder.var;
...
UriTemplate template =
UriTemplate.buildFromTemplate("http://example.com/")
.template("foo/{id}{?filter}")
.build();
Will generate the following URI Template string:
http://example.com/foo/{id}{?filter}
template - public UriTemplateComponent[] getComponents()
public UriTemplate build() throws MalformedUriTemplateException
Generates a UriTemplate instance from the builder.
MalformedUriTemplateExceptionpublic static VarSpec var(String varName)
var("foo");
Will yield the following expression:
{foo}
varName - VarSpec for the specified namepublic static VarSpec var(String varName, boolean explode)
var("foo",true);
Will yield the following expression:
{foo*}
varName - explode - VarSpec for the specified nameCopyright © 2012-04-30–2016 Ryan J. McDonough. All rights reserved.