Skip to content

Instantly share code, notes, and snippets.

@acdcjunior
Created June 2, 2014 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acdcjunior/89eb264236284d0d6935 to your computer and use it in GitHub Desktop.
Save acdcjunior/89eb264236284d0d6935 to your computer and use it in GitHub Desktop.
Example configuration file for velocityTools for Apache Velocity
<!--
Notes:
- Using this file, the tools are "$dateTool" etc. not "$date" as default -- if needed, change the <key>.
- Apparently, this format is deprecated in Velocity Tools 2.0, but still works. I didn't manage to get the new
format working (http://velocity.apache.org/tools/devel/config-xml.html) so...
-->
<toolbox>
<xhtml>true</xhtml>
<tool>
<key>msg</key>
<scope>request</scope>
<parameter name="bundles" value="mensagens" />
<parameter name="defaultBundle" value="mensagens" />
<parameter name="locale" value="pt_BR" />
<class>org.apache.velocity.tools.generic.ResourceTool</class>
</tool>
<tool>
<key>escapeTool</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.EscapeTool</class>
</tool>
<tool>
<key>dateTool</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.DateTool</class>
<parameter name="format" value="dd/MM/yyyy" />
</tool>
<tool>
<key>displayTool</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.DisplayTool</class>
</tool>
<tool>
<key>mathTool</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.MathTool</class>
</tool>
<tool>
<key>iterTool</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.IteratorTool</class>
</tool>
<tool>
<key>sortTool</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.SortTool</class>
</tool>
<tool>
<key>listTool</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.ListTool</class>
</tool>
</toolbox>
@acdcjunior
Copy link
Author

This could be used by adding the property toolboxConfigLocation to the ViewResolver declaration in your application context XML file.

<bean id="viewResolver"
               class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver">
    <property name="cache" value="true" />
    <property name="prefix" value="" />
    <property name="suffix" value=".html" />
    <property name="layoutUrl" value="layout/layout.html" />

    <property name="toolboxConfigLocation" value="/WEB-INF/velocityTools.xml" />
    <property name="contentType" value="text/html;charset=UTF-8" />
</bean>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment