{key} - insert the value of the tag that corresponds to key .
{%key} - insert the display value of the tag corresponding to key if one is available, otherwise just insert the value (this is an extension) .
?{condition1 'value1' | condition2 'value2' | 'value3'} - use value1 if condition1 is satisfied, else use value2 if condition2 is satisfied, finally use value3 if no condition is satisfied. Condition can be either explicit - in JOSM search syntax - or implicit: The value is used when all tags referenced inside exist.
!{search_expression 'template'} - search_expression is evaluated and first matching primitive is used as context for template. Useful for example to get tags of parent relation.
\ - use a backslash to escape special characters '{', '}', '?', '!'. E.g. What is this? It is a {type}\!.
{special:everything} - prints all available values, output is implementation dependent.
{special:id} - prints the ID of the OSM element.
{special:localName} - prints the localized name, that is the value of name:lang for your language if it is available, or the value of name if it is not.
try {
JosmTemplateParser parser = new JosmTemplateParser(new ByteArrayInputStream(filterString.getBytes()));
List<Formatter> formatters = parser.formatters();
.....
} catch (ParseException pex) {
...
} catch (Error err) {
...
}
Your OSM elements object must either implement the Meta interface or be wrapped in an object that implements it. The object can then be passed to the Formatter.format method, resp. Util.listFormat.
Currently there is no documentation of the grammar outside of Name template details which however has multiple errors and inconsistencies.
Note that the {special:localName} template simply returns the value of the name tag.
You can either download the jar from github or add the following to your build.gradle
...
repositories {
...
mavenCentral()
...
}
...
dependencies {
...
compile 'ch.poole.osm:JosmTemplateParser:0.3.0'
...
}