blob: 3e1ae6d63140a7d6e8cdc5abc4235b7270a0cec1 [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">
<title>Velocity - Case Study: JSP vs. Velocity</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="Case Study: JSP vs. Velocity"><strong>Case Study: JSP vs. Velocity</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<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>
I just wanted to share my findings on Velocity. I use velocity as an
embedded mail templating system in our application server.
When I began this subproject, I was using JSP as the language for
generating template output for our application server. It was
horrible. There were many problems, not to mention the difficulty of
embedding a servlet engine in the app server that I could
communicate with through direct method calls instead of over a
socket. Specific to the Velocity argument was the JSP template
versus the VTL template. I'd like to show you what my JSP template
looked like. Package names have been changed to protect the
innocent. Here is an example:
----------------8&lt;---------------
&lt;%@ page session=&quot;false&quot;
import=&quot;java.util.*,
foo.events.*,
foo.emeeting.*,
foo.validation.*,
foo.util.actionevent.ActionEvent,
java.util.Date&quot;%&gt;
&lt;jsp:useBean id=&quot;meeting&quot; scope=&quot;request&quot; type=&quot;foo.IMeeting&quot;
class=&quot;foo.Meeting&quot;/&gt;
&lt;html&gt;
&lt;!-- etc --&gt;
&lt;table width=&quot;600&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;4&quot;
bgcolor=&quot;white&quot;&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;%
Iterator events = meeting.getStoredEventsIterator();
int repId = 0;
%&gt;
&lt;i&gt;&lt;b&gt;Topic: &lt;%= meeting.getTopic()%&gt;&lt;/b&gt;&lt;/i&gt;
&lt;p&gt;
&lt;%
while (events.hasNext()) {
Object event = events.next();
Participation yapper =
meeting.getParticipation(((MeetingEvent)event).getFromId());
if(event instanceof ChatEvent) {
if(&quot;R&quot;.equals(yapper.getRole()) ) {
%&gt;
&lt;font color=&quot;#000000&quot;&gt;&lt;b&gt;&lt;%=yapper.getName()%&gt;:&lt;/b&gt;&lt;/font&gt;
&lt;%
repId = yapper.getParticipantId();
} else {
%&gt;
&lt;font color=&quot;#0000f0&quot;&gt;&lt;b&gt;&lt;%=yapper.getName()%&gt;:&lt;/b&gt;&lt;/font&gt;
&lt;%
}
ChatEvent ce = (ChatEvent) event;
%&gt;
&lt;br&gt;
&lt;%
} else if(event instanceof URLPushedEvent) {
if(&quot;R&quot;.equals(yapper.getRole()) ) {
%&gt;
&lt;font color=&quot;#000000&quot;&gt;&lt;b&gt;&lt;%=yapper.getName()%&gt;:&lt;/b&gt;&lt;/font&gt;
&lt;%
} else {
%&gt;
&lt;font color=&quot;#0000f0&quot;&gt;&lt;b&gt;&lt;%=yapper.getName()%&gt;:&lt;/b&gt;&lt;/font&gt;
&lt;%
}
URLPushedEvent pe = (URLPushedEvent) event;
%&gt;
&lt;a href=&quot;&lt;%=pe.getStoredData()%&gt;&quot;&gt;&quot;&lt;%=pe.getStoredData()%&gt;&quot;&lt;/a&gt; &lt;br&gt;
&lt;%
}
}
%&gt;
&lt;hr&gt;
&lt;br&gt;&lt;%=meeting.getMeetingId()%&gt;:&lt;%=repId%&gt;&lt;br&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
----------------8&lt;---------------
Seasick yet? Now here is the Velocity template accomplishing the
same thing as above:
----------------8&lt;---------------
&lt;html&gt;
&lt;!-- etc --&gt;
&lt;table width=&quot;600&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;4&quot;
bgcolor=&quot;white&quot;&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;i&gt;&lt;b&gt;Topic: $meeting.getTopic()&lt;/b&gt;&lt;/i&gt;&lt;p&gt;
#foreach( $event in $meeting.getStoredEventsIterator() )
#set( $yapper = $meeting.getParticipation($event.getFromId()) )
#if( $event.getClass().getName().equals($urlEvent) )
#if( $repRole.equals($yapper.getRole()) )
#set( $repId = $yapper.getParticipantId() )
&lt;font color=&quot;$blk&quot;&gt;&lt;b&gt;$yapper.getName()&lt;/b&gt;&lt;/font&gt;
#else
&lt;font color=&quot;$blu&quot;&gt;&lt;b&gt;$yapper.getName()&lt;/b&gt;&lt;/font&gt;
#end
&lt;a href=&quot;$event.getStoredData()&quot;&gt;$event.getStoredData()&lt;/a&gt; &lt;br&gt;
#elseif( $event.getClass().getName().equals($chatEvent) )
#if($repRole.equals($yapper.getRole()) )
#set( $repId = $yapper.getParticipantId() )
&lt;font color=&quot;$blk&quot;&gt;&lt;b&gt;$yapper.getName()&lt;/b&gt;&lt;/font&gt;
#else
&lt;font color=&quot;$blu&quot;&gt;&lt;b&gt;$yapper.getName()&lt;/b&gt;&lt;/font&gt;
#end
$event.getStoredData() &lt;br&gt;
#end
#end
&lt;hr&gt;
&lt;br&gt;$meeting.getMeetingId():$repId&lt;br&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
----------------8&lt;---------------
I was subsequently able to define that largish foreach loop into a
macro and shrink it even more, using Velocity's #macro function, so
I could do this:
#drawStandardHtmlTranscript ( $meeting )
removing 20 lines of code from each template whilst only adding 2
lines (one for #parse and the other for the
#drawStandardHtmlTranscript.
The call to the Velocity runtime to finally merge the template
consumes about 20-50 milleseconds (on a 400 mHz PII Linux system)
when I pool the contexts (time doubles when I do not). This is great
performance, too!
Last but not least, teaching the web design team to write a template
took literally 10 minutes from start to finish. They haven't asked
me a single question since.
--
Nick Bauman
Software Engineer
3600 Dupont
Minneapolis, MN
55412
Mobile Phone: (612) 810-7406
Home Phone: (612) 522-0165
</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>
</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 -->