- From: James M Snell <jasnell@gmail.com>
- Date: Sun, 25 Nov 2007 22:01:35 -0800
- To: Joe Gregorio <joe@bitworking.org>
- CC: URI <uri@w3.org>
FYI... I've updated my experimental java implementation [1]. The only
operation that is currently not supported is sub. I'll update the impl
with support for that operation once Joe decides what to do with that
operation.
Example use:
Template template = new Template(
"http://example.org/{foo}{-opt|/|bar}{bar}");
Map<String,Object> map = new HashMap<String,Object>();
map.put("foo", "abc");
map.put("bar", "xyz");
System.out.println(template.expand(map));
Javadocs provided.
- James
[1] http://www.snellspace.com/public/uritemplates.zip
Joe Gregorio wrote:
> Based on everyone's feedback I've updated my proposal
> and updated the URI Template explainer service to reflect that proposal.
> Expansions are now of the form:
>
> {var=default}
>
> or
>
> {-op|arg|vars}
>
> where <op> is now a word, one of 'prefix', 'append',
> 'join', 'listjoin', 'opt', 'neg', or 'sub'. This addresses
> the concerns with readability, extensibility, embedding in XML,
> and also makes parsing easier by delimiting each part with '|'.
> In addition I've added in the 'sub' operator
> which operates on a sub-string.
>
> Here is an example using sub:
>
> URI Template
> http://example.com/user/{-sub|0-1|username}/{-sub|1|username}
> Variables
> username := 'jcgregorio'
> URI
> http://example.com/user/j/cgregorio
>
> The examples on this page have been updated
> to reflect the new syntax:
>
> http://bitworking.org/projects/URI-Templates/
>
> Other restrictions that are found in the new BNF include
> restricting var names to
>
> [a-zA-Z0-9][a-zA-Z0-9\_\.\-]*
>
> which makes disambiguating between the IdentityOperatorTemplate
> and OperatorTemplate easier now that operators are not punctuation.
> Here is the updated BNF:
>
> token arg '[^\|]*';
> token varname '[a-zA-Z0-9][a-zA-Z0-9\_\.\-]*' ;
> token vardefault '[\w\-\.\~\%]+' ;
> token num '[0-9]+';
>
> START -> Template;
> Template ->
> IdentityOperatorTemplate
> | OperatorTemplate
> ;
> IdentityOperatorTemplate-> Var
> OperatorTemplate ->
> '-append\|' arg '\|' Var
> | '-prefix\|' arg '\|' Var
> | '-join\|' arg '\|' Vars
> | '-listjoin\|' arg '\|' VarNoDefault
> | '-opt\|' arg '\|' Vars
> | '-neg\|' arg '\|' Vars
> | '-sub\|'
> num
> ( '-' num )?
> '\|' Var
> ;
>
> Vars -> Var
> (
> ',' Var
> ) * ;
> Var -> varname
> (
> '=' vardefault
> ) ? ;
> VarNoDefault -> varname;
>
>
> Here are the rest of the examples previously given
> rewritten in the new syntax:
>
> URI Template
> {-join|&|q,num}
> Variables:
> q := fred
> num := 10
> URI
> q=fred&num=10
>
> URI Template
> /foo{-prefix|/notebooks/|notebookID}
> Variables
> notebookID := stuff
> URI
> /foo/notebooks/stuff
>
> URI Template
> foo{-opt|/-/|categories}
> Variables
> opt := fred
> URI
> foo/-/
>
> URI Template
> /-/{-listjoin|/|categories}
> Variables
> categories := ['A|-B', 'C']
> URI
> /-/A%7C-B/C
>
> The python implementation and the associated explainer service have
> been updated:
>
> http://code.google.com/p/uri-templates/
>
> There are two issues that are outstanding:
>
> 1. Seven operations is a bit much. Prefix and append are both
> convenience operators that can be done using 'opt'. Is it worth
> dropping them to reduce the count to five?
> 2. The 'sub' operator could either be defined to operate on
> the octets of the variables value, or on the unicode character points
> of the equivalent utf-8 decoded string. Both have their pros and cons.
>
> Thanks,
> -joe
>
Received on Monday, 26 November 2007 06:01:48 UTC