[stringtemplate-interest] H2 test a value
Terence Parr
parrt at cs.usfca.edu
Sat Nov 26 15:19:28 PST 2005
On Nov 23, 2005, at 7:36 AM, Jesper Goertz wrote:
> I see, rest() is not needed, the filter below works fine.
>
> String templates =
> "group test;" +newline+
> "t(m,ns) ::= << <ns:{n|<if (!m.(n))><n><endif>};
> separator=\",\"> >>" +newline;
> StringTemplateGroup group = new StringTemplateGroup(new
> StringReader(templates), AngleBracketTemplateLexer.class);
>
> HashMap filter = new HashMap();
> filter.put("42", Boolean.TRUE);
> String[] numbers = new String[]{"3","11","42","87"};
>
> StringTemplate a = group.getInstanceOf("t");
> a.setAttribute("m", filter);
> a.setAttribute("ns", numbers);
>
> String expecting =" 3,11,87 ";
> String result = a.toString();
> assertEqual(result, expecting);
>
> And I found stringtemplates at www.codegeneration.net looking for a
> tool to generate wrapper classes from remote interfaces. The filter is
> needed because the wrapper methods should not throw
> java.rmi.RemoteException.
Hi. Seems to me that
t(m,ns) ::= << <ns:{n|<if (!m.(n))><n><endif>}; separator=\",\"> >>
will "work", but it's probably something you want to avoid--it's a
hack ;) If you need to filter, why shouldn't this be done in the
model/controller rather than the view? Surely the programming
language is better at filtering lists than stringtemplate and would
properly separate model from view. :)
Ter
More information about the stringtemplate-interest
mailing list