[stringtemplate-interest] How to detect if there's an error in a template

Lon Varscsak varscsak at smarthealth.com
Wed Apr 8 13:47:17 PDT 2009


We have a system that uses StringTemplate to merge templates that are
created and stored in a database by different users.  It works great, I love
StringTemplate. :)
However, I'd like to write a little interface that can "validate" the
template to at least ensure that it's not going to throw errors when this
template makes it into production.  StringTemplate prints out these
wonderful exceptions that I can't figure out how to trap.

When I do:

StringTemplate template = new StringTempate(myDatabaseTemplate);

and have a myDatabaseTemplate that is malformed, a bunch of exceptions are
being printed to the output, but they are not being thrown in a way I can
catch them.

I've tried creating a StringTemplateErrorListner object and it never reaches
my object:

StringTemplate messageTemplate = new StringTemplate();

ErrorListener errorListener = new ErrorListener(); //this
implements StringTemplateErrorListener



messageTemplate.setErrorListener(errorListener);

messageTemplate.setTemplate(messageToTest); //ErrorListener doesn't get
stuff called, but errors are printed out.


I would expect my ErrorListener object to be getting "error" or "warning"
called, but it doesn't.


Is there anyway to "validate" a template (this template is a String in
memory)?


Thanks,


Lon


P.S. -- This is using Java 1.5, and StringTemplate 3.2
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20090408/9a2153c0/attachment.html 


More information about the stringtemplate-interest mailing list