The Abdera trunk now includes an implementation of the URI Template specification. The implementation has been extended to support the concept of "IRI Templates" capable of generating both URI's and IRI's.
Template objects are immutable and threadsafe. Static, constant instances can be declared and reused as many times as necessary.
There are three basic ways of expanding a Template into a URI/IRI:
You can use a java.util.Map:
You can use a custom Context implementation:
Or, you can use the public fields and getters of a Java object:
When using a Java object, there are times when the name of the template variable and the name of the method or field do not match up. For that, a VarName annotation (JDK 1.5+) is provided:
If a particular Java object is intended primarily to provide the expansion values for a Template, an Annotation has been provided to associate a template directly with the object.
You can then expand the object into a URI without having to create a Template object instance:
The URI Template implementation has a built in "explain" mechanism that can be used to explain the template for debugging and documentation purposes.