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

Lon Varscsak varscsak at smarthealth.com
Wed Apr 8 17:58:05 PDT 2009


Aha!  That did the trick.
Thanks a bunch!

-Lon

On Wed, Apr 8, 2009 at 5:32 PM, Terence Parr <parrt at cs.usfca.edu> wrote:

> Hi Lon, that is very strange. Perhaps i messed up and I ignore the
> template's listener and go straight for the listener of the group. try
> setting the listener of the group you're using even if it's the default
> group.
> Thanks,
> Ter
>
> On Apr 8, 2009, at 1:47 PM, Lon Varscsak wrote:
>
>  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
>> _______________________________________________
>> stringtemplate-interest mailing list
>> stringtemplate-interest at antlr.org
>> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20090408/ac559a77/attachment.html 


More information about the stringtemplate-interest mailing list