Apache Velocity: Is there a standard way of verifying the correctness of a template from the command line?

99封情书 提交于 2019-11-30 20:24:20

There is a tool distributed with Velocity called TemplateTool, which dumps all the references and it can be used to validate the syntax of the template.

However, you must have the context setup correctly to verify any template. So the best verification is to write your own tool with your own context.

To catch Velocity syntax errors, your approach is probably the best.

However, it will ignore invalid macro arguments and non-existent references. In Velocity 1.6 there is a strict mode that you can set which will throw an exception for bad macro parameters (e.g. the wrong number) or for bad references (e.g. $abc.badMethod() ). This assumes you are populating the context of the templates used in your testing tool the same as when the templates are used in production.

In December 2010 someone published a tool for validating Velocity. I tried it out and it works fine. It uses Velocity 1.6.4, but maybe that can be swapped out for a different version if needed.

http://code.google.com/p/velocity-validator/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!