#142, #137 - CurieProvider can now return multiple curies.

Changed `getCurieInformation(…)` to receive a `Links` instance with the previously added links and is forced to return a collection of curies so that multiple ones can be resolved transparently.

Made Curie value class protected to be able to reuse it from extensions of DefaultCurieProvider. Switched to the custom HATEOAS UriTemplate instance instead of the standard Spring MVC one.

Polished JavaDoc of DefaultCurieProvider. Removed some of the deprecation warnings that were introduced by the upgrade to Jackson 2.3. Polished (read: reactivated) some test cases and slightly changed the internals of UriTemplate works. Added TemplateVariables.asList().
This commit is contained in:
Oliver Gierke
2014-01-21 13:58:01 +01:00
parent 4d9373abcb
commit 719a4b3af3
10 changed files with 318 additions and 25 deletions

View File

@@ -40,7 +40,7 @@ public class UriTemplate implements Iterable<TemplateVariable> {
private static final Pattern VARIABLE_REGEX = Pattern.compile("\\{([\\?\\&#/]?)([\\w\\,]+)\\}");
private final List<TemplateVariable> variables = new ArrayList<TemplateVariable>();
private final TemplateVariables variables;;
private String baseUri;
/**
@@ -53,24 +53,27 @@ public class UriTemplate implements Iterable<TemplateVariable> {
Assert.hasText(template, "Template must not be null or empty!");
Matcher matcher = VARIABLE_REGEX.matcher(template);
int baseUriEndIndex = template.length();
List<TemplateVariable> variables = new ArrayList<TemplateVariable>();
while (matcher.find()) {
if (baseUri == null) {
this.baseUri = template.substring(0, matcher.start(0));
int start = matcher.start(0);
if (start < baseUriEndIndex) {
baseUriEndIndex = start;
}
VariableType type = VariableType.from(matcher.group(1));
String[] names = matcher.group(2).split(",");
for (String name : names) {
this.variables.add(new TemplateVariable(name, type));
variables.add(new TemplateVariable(name, type));
}
}
if (this.baseUri == null) {
this.baseUri = template;
}
this.variables = new TemplateVariables(variables);
this.baseUri = template.substring(0, baseUriEndIndex);
}
/**
@@ -94,7 +97,7 @@ public class UriTemplate implements Iterable<TemplateVariable> {
* @return
*/
public List<TemplateVariable> getVariables() {
return this.variables;
return this.variables.asList();
}
/**
@@ -162,6 +165,15 @@ public class UriTemplate implements Iterable<TemplateVariable> {
return this.variables.iterator();
}
/*
* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return baseUri + variables.toString();
}
/**
* Appends the value for the given {@link TemplateVariable} to the given {@link UriComponentsBuilder}.
*