Need to validate ftl before saving in DB
rishabh9 <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Hi,
I use the below code to validate a ftl string I get from the UI, before
saving in the DB. If an exception is thrown, I know there is a validation
error and I report it accordingly to the UI.
================= BEGIN CODE ======================
Configuration config = new Configuration();
config.setStrictSyntaxMode(true);
config.setTagSyntax(Configuration.AUTO_DETECT_TAG_SYNTAX);
StringTemplateLoader stringLoader = new StringTemplateLoader();
stringLoader.putTemplate(name, content);
config.setTemplateLoader(stringLoader);
try {
config.getTemplate(name);
} catch (IOException e) {
LOG.error("The template's body is malformed.");
throw new CustomException("The template body is malformed.", e);
}
=================== END CODE =====================
My problem is that, the above code seems to work partly. It does not
validate the directives.
For example, even if I miss out on closing a directive, the
"config.getTemplate(name)" does not throw an exception -
<#list animals as being>
${being.name}
An exception is thrown, only when a variable, like - "${being.name}" is
typed erroneously; something like - "${being"
How can I validate the the directives?
Also, Is this the correct way to completely validate a template?
I am using freemarker version 2.3.13
Regards,
Rishabh
--
View this message in context: http://n4.nabble.com/Need-to-validate-ftl-before-saving-in-DB-tp1555909p1555909.html
Sent from the freemarker-user mailing list archive at Nabble.com.
------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev