[
https://issues.apache.org/jira/browse/GROOVY-8041?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15818207#comment-15818207
]
Jochen Theodorou commented on GROOVY-8041:
------------------------------------------
So to sum up... you cannot change the wrong template; you cannot change the
properties; and you have no influence over the code that does
template.make(params)? Not even the last one, really? If that is the case, you
will have to work with a patched groovy version and use a custom groovy version
for your application. Because there is no chance of fixing this in a normal
groovy release, since the code behaves as intended.
In the case you have influence over the code that does template.make or in the
case you patch the template engine, you could do the following... You could
work with a intermediate property...
{code:Java}
class IntermediateWrapper implements Map<String,String> {
String _name = null;
Map _properties;
public IntermediateWrapper(String name, Map<String,String> map) {_name =
name; _properties = map}
@Override String get(String key) {
if (_name!=null) key = _name+"."+key;
if (_properties.containsKey(key)) return _properties.get(key);
return new IntermediateWrapper(key, _properties);
}
....
}
def map = new IntermediateWrapper(properties)
template.make(map)
{code}
The code is untested, but the idea is to return an "incomplete" property. In
the template then "a.b" will return for a the IntermediateWrapper with name set
to "a", "a.b" means to ask IntermediateWrapper for "b", which will do a lookup
for "a.b" in the map and if the key exists return the value. Should it not
exist you get IntermediateWrapper again. If you patch the TempalteEngine, you
could do something similar
> The templating engine does not handle properly the binding parameters that
> contains dot ('.') character
> -------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-8041
> URL: https://issues.apache.org/jira/browse/GROOVY-8041
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 2.4.7
> Reporter: Bence Takács
> Assignee: Jochen Theodorou
>
> The templating engine does not handle properly the binding parameters that
> contains dot ('.') character
> The below script throws an exception while the assertion passes:
> def template = new groovy.text.SimpleTemplateEngine().createTemplate('Testing
> ${a.b}')
> def params = ['a.b':'working']
> assert params['a.b']
> println template.make(params)
> "groovy.lang.MissingPropertyException: No such property: a for class:
> SimpleTemplateScript22
> at SimpleTemplateScript22.run(SimpleTemplateScript22.groovy:1)
> at Script1.run(Script1.groovy:5)"
> The issue is valid for also StreamingTemplateEngine and GStringTemplateEngine
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)