blob: b5418e396c60b6607127658e171ab9a7a8e65a0b [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
Copyright 1999-2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- Content Stylesheet for Site -->
<!-- start the processing -->
<!-- ====================================================================== -->
<!-- GENERATED FILE, DO NOT EDIT, EDIT THE XML FILE IN xdocs INSTEAD! -->
<!-- Main Page Section -->
<!-- ====================================================================== -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<meta name="author" value="Velocity Documentation Team">
<meta name="email" value="jon@latchkey.com">
<meta name="author" value="Velocity Documentation Team">
<meta name="email" value="geirm@optonline.net">
<title>Velocity - Differences: Velocity vs. WebMacro</title>
</head>
<body bgcolor="#ffffff" text="#000000" link="#525D76">
<table border="0" width="100%" cellspacing="0">
<!-- TOP IMAGE -->
<tr>
<td align="left">
<a href="http://jakarta.apache.org"><img src="http://jakarta.apache.org/images/jakarta-logo.gif" border="0"/></a>
</td>
<td align="right">
<a href="http://jakarta.apache.org/velocity/"><img src="./images/logo.gif" alt="Velocity" border="0"/></a>
</td>
</tr>
</table>
<table border="0" width="100%" cellspacing="4">
<tr><td colspan="2">
<hr noshade="" size="1"/>
</td></tr>
<tr>
<!-- LEFT SIDE NAVIGATION -->
<td width="20%" valign="top" nowrap="true">
<!-- ============================================================ -->
<p><strong>About</strong></p>
<ul>
<li> <a href="./index.html">Overview</a>
</li>
<li> <a href="./getting-started.html">Getting Started</a>
</li>
<li> <a href="http://jakarta.apache.org/builds/jakarta-velocity/">Download</a>
</li>
<li> <a href="./install.html">Install</a>
</li>
<li> <a href="./design.html">Design</a>
</li>
<li> <a href="./contributors.html">Contributors</a>
</li>
<li> <a href="./changes.html">ChangeLog</a>
</li>
<li> <a href="./code-standards.html">Coding Standards</a>
</li>
<li> <a href="./license.html">License</a>
</li>
<li> <a href="./todo.html">TODO</a>
</li>
<li> <a href="http://issues.apache.org/bugzilla/enter_bug.cgi?product=Velocity">Report Issues</a>
</li>
</ul>
<p><strong>Community</strong></p>
<ul>
<li> <a href="./powered.html">Powered By Velocity</a>
</li>
<li> <a href="http://jakarta.apache.org/site/getinvolved.html">Get Involved</a>
</li>
<li> <a href="http://jakarta.apache.org/site/mail.html">Mailing Lists</a>
</li>
<li> <a href="http://jakarta.apache.org/site/cvsindex.html">CVS Repositories</a>
</li>
</ul>
<p><strong>Docs</strong></p>
<ul>
<li> <a href="./user-guide.html">User's Guide (English)</a>
</li>
<li> <a href="./user-guide_fi.html">User's Guide (Finnish)</a>
</li>
<li> <a href="./user-guide_fr.html">User's Guide (French)</a>
</li>
<li> <a href="./user-guide_es.html">User's Guide (Spanish)</a>
</li>
<li> <a href="./developer-guide.html">Developer's Guide</a>
</li>
<li> <a href="./vtl-reference-guide.html">VTL Reference Guide</a>
</li>
<li> <a href="./specification.html">Specification</a>
</li>
<li> <a href="./api/index.html">Javadoc</a>
</li>
</ul>
<p><strong>Tools</strong></p>
<ul>
<li> <a href="./tools/index.html">Velocity Tools</a>
</li>
<li> <a href="./anakia.html">Anakia : XML->doc tool</a>
</li>
<li> <a href="./texen.html">Texen : text generation</a>
</li>
<li> <a href="./dvsl/index.html">DVSL : XML xformation</a>
</li>
<li> <a href="./veltag.html">Veltag : JSP taglib</a>
</li>
<li> <a href="./migration.html">Migration to Velocity</a>
</li>
<li> <a href="./devtools.html">Editors and IDEs</a>
</li>
</ul>
<p><strong>Comparisons</strong></p>
<ul>
<li> <a href="./ymtd/ymtd.html">YMTD</a>
</li>
<li> <a href="./differences.html">VM/WM Differences</a>
</li>
<li> <a href="./casestudy1.html">JSP vs. Velocity</a>
</li>
<li> <a href="./casestudy2.html">XMLC vs. Velocity</a>
</li>
</ul>
<p><strong>Site Translations</strong></p>
<ul>
<li> <a href="http://jakarta.apache.org/velocity/">English</a>
</li>
<li> <a href="http://www.ingrid.org/jajakarta/velocity/velocity-1.2-rc2/docs-ja/index.html">Japanese</a>
</li>
</ul>
</td>
<td width="80%" align="left" valign="top">
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="Differences: Velocity vs. WebMacro"><strong>Differences: Velocity vs. WebMacro</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
On the mailing lists, we often get asked to explain the differences
between Velocity and WebMacro. Instead of answering the same question
over and over, we have started this document to describe some of the
differences in our approaches. In reality, both are excellent tools and
we feel that it is up to the user base to decide which one they would
like to use.
</p>
<p>
The language syntax is very close but not exactly the same. The syntaxes
were kept close for a few reasons:
</p>
<p>
1) The syntactical approach of $&lt;foo&gt; for references and
#&lt;bar&gt; for directives is a good one! It's easy for designers to
work with, people understand it, and there was no reason to reinvent the
wheel.
</p>
<p>
2) Since so many people were using the syntax, why invent another one?
Also, it makes the WebMacro to Velocity conversion much easier :) We
even have a <a href="migration.html">tool</a> to help with that.
</p>
<p>
Velocity was built new from the ground up. There isn't a snippet of
shared code. This was originally done because WebMacro was released
under a license (GPL) that is not compatible with the BSD/ASF license
and we (the original authors) needed a solution that was not under a GPL
license. Since then, WebMacro has been released under a dual GPL/ASF
license, however, that was too late, this project was already well
underway and we also felt that we have a better technical solution by
going with a generated parser instead of a hand coded one.
</p>
<p>
By starting new and fresh, we are less encumbered with some of the
baggage that WebMacro must deal with due to backwards compatibility
issues. We have fixed a few of the template language inconsistencies
that we saw creeping into WebMacro such as the fact that we do not
support using {} for code blocks (because we do not need to) and that we
use () around all #directives on the right hand side. Examples:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>#set ($bar = &quot;foo&quot;)
#if ($bar.length() &gt; 0)
stuff here
#end
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
Architecturally, the biggest difference until recently was the parser.
The Velocity parser is written using a tool called javacc, a very
popular Java-based parser generator. It was originally developed for
Sun by Metamata and is now maintained and managed by Metamata as well :
<a href="http://www.metamata.com/">www.metamata.com</a>.
</p>
<p>
The WebMacro parser was written by hand until recently and was the cause
of much pain when using WebMacro (due to many bugs in it) - their new
parser, for their 0.95 release is also written using javacc and promises
to be better (however, support for a lot of the baggage still exists).
</p>
<p>
Velocity is very simple in its architecture, as it is meant to be
nothing more than a template engine. The idea is to do one thing only
and do it well. Much in the spirit of the Unix philosophy - have a good
set of simple tools, and create bigger things using them. This has
enabled Velocity to be used as the basis for several different tools,
such as <a href="anakia.html">Anakia</a> and <a href="texen.html">Texen</a>.
</p>
<p>
Velocity is recognized that it isn't going to try to be a 'development
framework' - there are plenty around, such as <a href="http://jakarta.apache.org/turbine/">Turbine</a>.
</p>
<p>
Therefore, all facilities like 'context tool' and 'resource brokers' are
purposely left out of Velocity, acknowledging that not only will
frameworks do it, they will do it better anyway. Further, by leaving out
of the Velocity core much that should be done at the application / user
/ framework level, the Velocity core remains smaller and therefore, in
our opinion, more maintainable and extensible.
</p>
<p>
Internally, Velocity is pretty straightforward. There are no threads
created or managed for you. Templates are parsed and caches, kept in
their internal form of an 'Abstract Syntax Tree', a tree structure that
is then rapidly walked when your template is merged. Each node
corresponds to on of the syntactical elements in your template.
</p>
<p>
Internally within WebMacro, many of the methods and classes are marked
as private and/or final in order to achieve better speed. However, this
has prevented people from easily extending or overriding some of the
core funtionality and re-using some of the code. We would rather
sacrifice a few ms in favor of allowing more people to use our software
easily.
</p>
<p>
The biggest feature difference between the two are the '<a href="user-guide.html">Velocimacros</a>'. Velocimacros can be thought of
as snippets of re-usable data that can contain anything. They are parsed
just like the data in a #parse() statement would be and you can pass in
variables that can optionally have scope only within the Velocimacro.
Velocimacro's help keep the core #directive set small and
clean : you can extend the designers toolkit with libraries of Velocimacros
rather than adding elements to the syntax or having two write tools that generate
HTML (or other specific) markup.
</p>
<p>
We hope this helps. The best way to understand Velocity is to use it,
and of course nothing beats looking at the source code.
</p>
</blockquote>
</p>
</td></tr>
<tr><td><br/></td></tr>
</table>
</td>
</tr>
<!-- FOOTER -->
<tr><td colspan="2">
<hr noshade="" size="1"/>
</td></tr>
<tr><td colspan="2">
<div align="center"><font color="#525D76" size="-1"><em>
Copyright &#169; 1999-2004, The Apache Software Foundation
</em></font></div>
</td></tr>
</table>
</body>
</html>
<!-- end the processing -->