<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html> | |
<head> | |
<title>Apache Velocity - Velocity Overview</title> | |
<style type="text/css" media="all"> | |
@import url("./css/maven-base.css"); | |
@import url("./css/maven-theme.css"); | |
@import url("./css/site.css"); | |
</style> | |
<link rel="stylesheet" href="./css/print.css" type="text/css" media="print" /> | |
<link rel="alternate" href="http://feeds.feedburner.com/ApacheVelocitySiteNews" type="application/rss+xml" title="Apache Velocity - Velocity Overview News" /> | |
<meta name="author" content="Velocity Documentation Team" /> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
</head> | |
<body class="composite"> | |
<div id="banner"> | |
<a href="../../../" id="bannerLeft"> | |
<img src="images/velocity_project_wide.png" alt="" /> | |
</a> | |
<span id="bannerRight"> | |
<img src="images/velocity-logo.png" alt="" /> | |
</span> | |
<div class="clear"> | |
<hr/> | |
</div> | |
</div> | |
<div id="breadcrumbs"> | |
<div class="xleft"> | |
<a href="http://www.apache.org/">Apache</a> | |
> | |
<a href="../../../">Velocity</a> | |
> | |
Velocity Engine | |
</div> | |
<div class="xright"> <a href="../../devel/">Engine</a> | |
| | |
<a href="../../../tools/devel/">Tools</a> | |
| | |
<a href="../../../anakia/devel/">Anakia</a> | |
| | |
<a href="../../../texen/devel/">Texen</a> | |
| | |
<a href="../../../docbook/">DocBook</a> | |
| | |
<a href="../../../dvsl/devel/">DVSL</a> | |
</div> | |
<div class="clear"> | |
<hr/> | |
</div> | |
</div> | |
<div id="leftColumn"> | |
<div id="navcolumn"> | |
<h5>Velocity</h5> | |
<ul> | |
<li class="none"> | |
<a href="index.html">General</a> | |
</li> | |
<li class="none"> | |
<strong>Overview</strong> | |
</li> | |
<li class="none"> | |
<a href="getting-started.html">Getting Started</a> | |
</li> | |
<li class="none"> | |
<a href="webapps.html">Web Applications</a> | |
</li> | |
<li class="none"> | |
<a href="../../../download.cgi">Download</a> | |
</li> | |
<li class="none"> | |
<a href="http://wiki.apache.org/velocity/VelocityFAQ">FAQ (Wiki)</a> | |
</li> | |
</ul> | |
<h5>Docs</h5> | |
<ul> | |
<li class="none"> | |
<a href="user-guide.html">User Guide</a> | |
</li> | |
<li class="none"> | |
<a href="developer-guide.html">Developer Guide</a> | |
</li> | |
<li class="none"> | |
<a href="vtl-reference-guide.html">VTL Reference</a> | |
</li> | |
<li class="none"> | |
<a href="glossary.html">Glossary</a> | |
</li> | |
</ul> | |
<h5>Developers</h5> | |
<ul> | |
<li class="none"> | |
<a href="license.html">License</a> | |
</li> | |
<li class="none"> | |
<a href="apidocs/index.html">Javadoc</a> | |
</li> | |
<li class="none"> | |
<a href="changes-report.html">Changes</a> | |
</li> | |
<li class="none"> | |
<a href="jira-report.html">Resolved Issues</a> | |
</li> | |
<li class="none"> | |
<a href="upgrading.html">Upgrading</a> | |
</li> | |
<li class="none"> | |
<a href="jar-dependencies.html">Dependencies</a> | |
</li> | |
<li class="none"> | |
<a href="http://svn.apache.org/viewvc/velocity/engine/trunk/">Source Code Repository</a> | |
</li> | |
<li class="none"> | |
<a href="build.html">Building from Source</a> | |
</li> | |
</ul> | |
<h5>Community</h5> | |
<ul> | |
<li class="none"> | |
<a href="http://wiki.apache.org/velocity/">Wiki</a> | |
</li> | |
<li class="none"> | |
<a href="../../../news.html">Recent News</a> | |
</li> | |
<li class="none"> | |
<a href="http://wiki.apache.org/velocity/PoweredByVelocity">Powered By Velocity</a> | |
</li> | |
<li class="none"> | |
<a href="http://wiki.apache.org/velocity/VelocityEditors">IDE/Editor Plugins</a> | |
</li> | |
<li class="none"> | |
<a href="http://wiki.apache.org/velocity/PublishedArticlesAndBooks">Articles and Books</a> | |
</li> | |
<li class="none"> | |
<a href="http://wiki.apache.org/velocity/GetInvolved">Get Involved</a> | |
</li> | |
<li class="none"> | |
<a href="../../../contact.html">Mailing Lists</a> | |
</li> | |
</ul> | |
<h5>Velocity Development</h5> | |
<ul> | |
<li class="none"> | |
<a href="http://wiki.apache.org/velocity/RoadMap">Road Map</a> | |
</li> | |
<li class="none"> | |
<a href="http://wiki.apache.org/velocity/CodeStandards">Coding Standards</a> | |
</li> | |
<li class="none"> | |
<a href="http://wiki.apache.org/velocity/DocumentationGuidelines">Documentation Guidelines</a> | |
</li> | |
<li class="none"> | |
<a href="https://issues.apache.org/jira/browse/VELOCITY">Issues</a> | |
</li> | |
<li class="none"> | |
<a href="../../../who-we-are.html">Who we are</a> | |
</li> | |
</ul> | |
<h5>Translations</h5> | |
<ul> | |
<li class="none"> | |
<a href="http://www.jajakarta.org/velocity/">Site (Japanese)</a> | |
</li> | |
<li class="none"> | |
<a href="translations/user-guide_fi.html">User's Guide (Finnish)</a> | |
</li> | |
<li class="none"> | |
<a href="translations/user-guide_fr.html">User's Guide (French)</a> | |
</li> | |
<li class="none"> | |
<a href="translations/user-guide_es.html">User's Guide (Spanish)</a> | |
</li> | |
</ul> | |
<h5>Project Documentation</h5> | |
<ul> | |
<li class="collapsed"> | |
<a href="project-info.html">Project Information</a> | |
</li> | |
<li class="collapsed"> | |
<a href="project-reports.html">Project Reports</a> | |
</li> | |
</ul> | |
<a class="poweredBy" href="../../../" title="Apache Velocity" ><img class="poweredBy" alt="Apache Velocity" src="images/pbv90x30.png" /></a> | |
<a class="poweredBy" href="../../../rss/news.rss" title="Velocity News Feed" ><img class="poweredBy" alt="Velocity News Feed" src="images/feed-icon-24x24.jpg" /></a> | |
<iframe src="http://www.apache.org/ads/buttonbar.html" | |
style="border-width:0; float: left" frameborder="0" scrolling="no" | |
width="135" | |
height="265" ></iframe> | |
</div> | |
</div> | |
<div id="bodyColumn"> | |
<div id="contentBox"> | |
<div class="section"><h2><a name="Overview"></a> | |
Overview</h2> | |
<p> | |
Velocity is a template engine that can be used for many purposes. Some common types of applications | |
which use Velocity are: | |
</p> | |
<ul><li>Web applications. Web designers create HTML pages with placeholders for dynamic information. | |
The page is processed with <a class="externalLink" href="http://velocity.apache.org//tools/devel/view/">VelocityViewServlet</a> | |
or any of a | |
number of <a class="externalLink" href="http://wiki.apache.org/velocity/PoweredByVelocity">frameworks</a> | |
which support Velocity. | |
This approach to web application development | |
is called Model-View-Controller or MVC and is intended to be a direct replacement | |
for applications developed with Java Server Pages (JSPs) or PHP. | |
</li> | |
<li>Source code generation. Velocity can be used to generate Java source code, SQL, or PostScript | |
based on templates. The <a class="externalLink" href="http://wiki.apache.org/velocity/PoweredByVelocity">PoweredByVelocity</a> | |
page lists a number of open source | |
and commercial development software packages which use Velocity in this manner. | |
</li> | |
<li>Automatic emails. Many applications generate automatic emails for account signup, password reminders | |
or automatically sent reports. Using Velocity, the email template can be stored in a text | |
file rather than directly embedded in your Java code. | |
</li> | |
<li>XML transformation. Velocity provides an ant task called <a href="anakia.html">Anakia</a> | |
which reads | |
an XML file and makes it available to a Velocity template. A common application is to | |
convert documentation stored in a generic "xdoc" format into a styled HTML document. | |
</li> | |
</ul> | |
</div> | |
<div class="section"><h2><a name="How_it_Works"></a> | |
How it Works</h2> | |
<p> | |
Velocity allows web page designers and other template writers to include markup statements | |
called <em>references</em> in the page. These references are pulled from a <em>Context</em> | |
object -- essentially a hashtable that provides get and set | |
methods for retrieving and setting objects -- and the corresponding values are inserted | |
directly in a page. Velocity provides basic control statements, that can loop over a collection | |
of values (foreach) or conditionally show a block of text (if/else). The ability to | |
call arbitrary Java methods, include other files, and to create macros that can be repeatedly | |
used make this a powerful yet easy-to-use approach for creating dynamic web page or other | |
text files. | |
</p> | |
<p> | |
Velocity enforces a Model-View-Controller (MVC) style of development | |
by separating Java code from HTML template code. Unlike JSPs, | |
Velocity does not allow Java code to be embedded in pages. Unlike PHP, | |
Velocity does not implement features with other functions. The MVC | |
approach is one of Velocity's great strengths, and allows for more | |
maintainable and better-designed web pages. | |
</p> | |
<p> | |
Although MVC-style development can sometimes lead to longer incubation | |
periods for web sites, particularly if the developers involved are new | |
to MVC, this approach saves time over the long term (believe us, we have | |
been doing this for a long time now). The MVC abstraction prevents web page | |
designers from messing with a software engineer's Java code, and | |
programmers from unduly influencing the look of web sites. Velocity enforces | |
a contract that defines what roles people play in the web site development | |
process. | |
</p> | |
</div> | |
<div class="section"><h2><a name="Extending_Velocitys_Capability"></a> | |
Extending Velocity's Capability</h2> | |
<p>While Velocity is generally useful within an application as is, there are a number of ways | |
its capabilities can be extended. | |
</p> | |
<ul><li>Special types of objects, generically called "Tools", contain methods but no data. | |
When placed into the Velocity context the template can call these methods to | |
do basic tasks like formatting numbers or escaping HTML entities. | |
</li> | |
<li> | |
Velocity provides a selection of <em>resource loaders</em> that can retrieve | |
templates from text files, the classpath, even a database. But if that's not | |
enough you can write your own resource loader to retrieve in a custom manner. | |
</li> | |
<li><em>Event Handlers</em> provide hooks to perform custom actions upon certain | |
events, such as the insertion of a reference into text. | |
</li> | |
<li> | |
Advanced users can write a custom <em>Introspector</em> which retrieves | |
reference properties and methods. For example, you might create an introspector | |
that retrieves data from Lucene or other search engine indexes. | |
</li> | |
<li>Finally, for the truly adept, the grammar for Velocity is processed in a parser | |
generated by | |
<a class="externalLink" href="https://javacc.dev.java.net/">JavaCC</a> | |
(Java Compiler | |
Compiler) using the JJTree extension to create an Abstract Syntax Tree. | |
By changing the JavaCC specification file and recompiling, the Velocity syntax | |
itself can be changed. | |
</li> | |
</ul> | |
</div> | |
<div class="section"><h2><a name="Acknowledgement"></a> | |
Acknowledgement</h2> | |
<p> | |
Velocity's design concept is borrowed from <a class="externalLink" href="http://www.webmacro.org/">WebMacro</a> | |
. Those involved in the | |
Velocity project acknowledge and appreciate the development and design work | |
that went into the WebMacro project. | |
</p> | |
</div> | |
</div> | |
</div> | |
<div class="clear"> | |
<hr/> | |
</div> | |
<div id="footer"> | |
<div class="xright">© | |
2000-2008 | |
The Apache Software Foundation | |
Last Published: 2008-12-15 08:38:23 | |
</div> | |
<div class="clear"> | |
<hr/> | |
</div> | |
</div> | |
</body> | |
</html> |