Apache Velocity
Petteri Hietavirta
petteri.hietavirta@gmail.com
27.10.2010
Velocity Engine
• Been around since 2000, current v1.6.4
• Can produce any text output
• Processing - no compilation
• Goo...
Performance
Similar to JSP for dynamic pages
... but much faster to develop on
Typical uses
• Web frameworks
• Code generation
• Document & email generation
Context + Template
• Templates are written in VTL - Velocity
Template Language
• Velocity context has the model and
other ...
VTL Syntax
# directives
line or block directives
built in syntax or macro declarations
$ references
variables, access to p...
Simple example
Demo with Tomcat
• Uses VelocityViewServlet
Extension points
• Macros
• Context objects included in the context
• Custom resource loader
• Custom directives
• Event h...
Velocity Tools
• Collection of useful classes
• GenericTools
• DateTool, EscapeTool, SortTool ...
• VelocityView
• Velocit...
Security
• Can you trust your template writers?
• SecurityUberSpector
Velocity oddities
• -1
• swallow
• macro output
• static methods?
• context.put("Math", Math.class);
• enums, static fields
Use case: Content Control
• More stuff in context
• Velocity Tools are not used too much
• Pushing MVC boundaries
• Not to...
References
• http://wiki.apache.org/velocity/HackingVelocity
• http://stackoverflow.com/questions/159292/how-do-i-create-a...
Upcoming SlideShare
Loading in …5
×

Introduction to Apache Velocity

2,710 views

Published on

Presentation for UK Java User Group Scotland

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,710
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
43
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Introduction to Apache Velocity

  1. 1. Apache Velocity Petteri Hietavirta petteri.hietavirta@gmail.com 27.10.2010
  2. 2. Velocity Engine • Been around since 2000, current v1.6.4 • Can produce any text output • Processing - no compilation • Good separation of logic and presentation • Easier for devs and designers
  3. 3. Performance Similar to JSP for dynamic pages ... but much faster to develop on
  4. 4. Typical uses • Web frameworks • Code generation • Document & email generation
  5. 5. Context + Template • Templates are written in VTL - Velocity Template Language • Velocity context has the model and other objects required for the processing
  6. 6. VTL Syntax # directives line or block directives built in syntax or macro declarations $ references variables, access to properties and methods
  7. 7. Simple example
  8. 8. Demo with Tomcat • Uses VelocityViewServlet
  9. 9. Extension points • Macros • Context objects included in the context • Custom resource loader • Custom directives • Event handlers • Introspectors
  10. 10. Velocity Tools • Collection of useful classes • GenericTools • DateTool, EscapeTool, SortTool ... • VelocityView • VelocityViewServlet, web specific tools ... • VelocityStruts
  11. 11. Security • Can you trust your template writers? • SecurityUberSpector
  12. 12. Velocity oddities • -1 • swallow • macro output • static methods? • context.put("Math", Math.class); • enums, static fields
  13. 13. Use case: Content Control • More stuff in context • Velocity Tools are not used too much • Pushing MVC boundaries • Not too many Velocity related problems www.contentcontrol.com
  14. 14. References • http://wiki.apache.org/velocity/HackingVelocity • http://stackoverflow.com/questions/159292/how-do-i-create-a-custom- directive-for-apache-velocity • http://wiki.apache.org/velocity/BuildingSecureWebApplications • http://wiki.apache.org/velocity/VelocityEditors • http://wiki.apache.org/velocity/PoweredByVelocity

×