blob: 610e63e6be5f7cfc2b13cfd2b335435ccc602fea [file] [log] [blame]
<!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 -
Texen</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 -
Texen 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>
&gt;
<a href="../../../../">Velocity</a>
&gt;
<a href="../">Velocity Engine</a>
</div>
<div class="xright"> <a href="../../../devel/index.html">Engine</a>
|
<a href="../../../../tools/devel/index.html">Tools</a>
|
<a href="../../../../dvsl/devel/index.html">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">
<a href="../overview.html">Overview</a>
</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="../docs/user-guide.html">User Guide</a>
</li>
<li class="none">
<a href="../docs/developer-guide.html">Developer Guide</a>
</li>
<li class="none">
<a href="../docs/vtl-reference-guide.html">VTL Reference</a>
</li>
<li class="none">
<a href="../docs/anakia.html">Anakia: XML->doc tool</a>
</li>
<li class="none">
<strong>Texen: text generation</strong>
</li>
<li class="none">
<a href="../docs/veltag.html">Veltag: JSP taglib</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 in 1.5</a>
</li>
<li class="none">
<a href="../jira-report.html">Resolved Issues in 1.5</a>
</li>
<li class="none">
<a href="../jar-dependencies.html">Dependencies</a>
</li>
<li class="none">
<a href="../../../../download.cgi">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>
</div>
</div>
<div id="bodyColumn">
<div id="contentBox">
<a name="what_is_texen"></a><div class="section"><h2>What is Texen?</h2>
<p>
Texen is a general purpose text generating utility. It is capable of
producing almost any sort of text output. Driven by Ant, essentially
an <a href="http://jakarta.apache.org/ant/" class="externalLink">Ant</a> Task, Texen uses
a control template, an optional set of worker templates, and control
context to govern the generated output. Although TexenTask can be
used directly, it is usually subclassed to initialize your control
context before generating any output.
</p>
<p>
Texen was created to deal with the source generating requirements of
the Turbine web application framework. The <a href="http://jakarta.apache.org/turbine/torque.html" class="externalLink">Torque</a> utility
in <a href="http://jakarta.apache.org/turbine/" class="externalLink">Turbine</a>, which is a
subclass of the TexenTask, is responsible for generating the SQL,
and the Object-Relational mapping sources for a Turbine project.
This is only one example; you can use Texen to generate almost any
sort of text output!
</p>
</div>
<a name="the_texentask"></a><div class="section"><h2>The TexenTask</h2>
<p>
This trivial example, which shows how to use Texen from an Ant
build.xml, is intended to illustrate how the Texen mechanism works.
</p>
<p>
<strong>Ant Build File</strong>
</p>
<div class="source"><pre>
&lt;project name=&quot;HtmlGenerator&quot; default=&quot;main&quot; basedir=&quot;.&quot;&gt;
&lt;taskdef name=&quot;texen&quot; classname=&quot;org.apache.velocity.texen.ant.TexenTask&quot;/&gt;
&lt;!-- ============================================================= --&gt;
&lt;!-- G E N E R A T E H T M L P A G E S --&gt;
&lt;!-- ============================================================= --&gt;
&lt;!-- This target will generate a set of HTML pages based on --&gt;
&lt;!-- the information in our control context. --&gt;
&lt;!-- ============================================================= --&gt;
&lt;target name=&quot;main&quot;&gt;
&lt;echo message=&quot;+------------------------------------------+&quot;/&gt;
&lt;echo message=&quot;| |&quot;/&gt;
&lt;echo message=&quot;| Generating HTML pages! |&quot;/&gt;
&lt;echo message=&quot;| |&quot;/&gt;
&lt;echo message=&quot;+------------------------------------------+&quot;/&gt;
&lt;texen
controlTemplate=&quot;Control.vm&quot;
outputDirectory=&quot;.&quot;
templatePath=&quot;.&quot;
outputFile=&quot;generation.report&quot;
/&gt;
&lt;/target&gt;
&lt;/project&gt;
</pre></div>
<p>
<strong>Control Template</strong>
</p>
<div class="source"><pre>
#*
file: Control.vm
This is the control template for our HTML
page generator!
*#
#set ($Planets = [&quot;Earth&quot;, &quot;Mars&quot;, &quot;Venus&quot;])
#foreach ($planet in $Planets)
#set ($outputFile = $strings.concat([$planet, &quot;.html&quot;]))
$generator.parse(&quot;HtmlTemplate.vm&quot;, $outputFile, &quot;planet&quot;, $planet)
#end
</pre></div>
<p>
<strong>Worker Template</strong>
</p>
<div class="source"><pre>
#*
file: HtmlTemplate.vm
This is worker template. It is called by the
control template to produce useful output (or
not so useful in this case). :-)
*#
#set ($bgcolor = &quot;#ffffff&quot;)
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;
Everything you wanted to know about $planet!
&lt;/title&gt;
&lt;/head&gt;
&lt;body bgcolor=&quot;$bgcolor&quot;&gt;
$planet is a great place to live!
&lt;/body&gt;
&lt;/html&gt;
</pre></div>
<p>
Texen produces three html pages: Earth.html, Mars.html, and
Venus.html. To do something more useful, you would subclass the
TexenTask, place some objects in the control context, and use the
information placed in the control context to generate useful output.
</p>
<p>
See the Torque utility in Turbine for a full working example of
Texen. A standalone version of Torque is available <a href="http://jakarta.apache.org/builds/jakarta-turbine/release/" class="externalLink">here</a>.
</p>
<table class="bodyTable">
<tr class="a">
<th >Name</th>
<th >Description</th>
</tr>
<tr class="b">
<td >templatePath</td>
<td ><b>[REQUIRED]</b>
Set the path where Velocity will look
for templates using the file template
loader.
<b>This is only required if useClasspath is not turned on.</b></td>
</tr>
<tr class="a">
<td >useClasspath</td>
<td ><b>[REQUIRED]</b>
Set the use of the classpath in locating templates.
true means the classpath will be used.
<b>This is only required if templatePath is not set.</b></td>
</tr>
<tr class="b">
<td >useResourceLoaderCache</td>
<td >Optional argument used when useClasspath is turned on.
See the <a href="developer-guide.html#ConfiguringResourceLoaders">Developer's Guide</a>
for details on resource caching.</td>
</tr>
<tr class="a">
<td >resourceLoaderModificationCheckInterval</td>
<td >Optional argument used when useClasspath is turned on.
See the <a href="developer-guide.html#ConfiguringResourceLoaders">Developer's Guide</a>
for details on resource caching.</td>
</tr>
<tr class="b">
<td >controlTemplate</td>
<td ><b>[REQUIRED]</b>
Set the control template for the
generating process.</td>
</tr>
<tr class="a">
<td >outputDirectory</td>
<td ><b>[REQUIRED]</b>
Set the output directory. It will be
created if it doesn't exist.</td>
</tr>
<tr class="b">
<td >outputFile</td>
<td ><b>[REQUIRED]</b>
Set the output file for the
generation process.</td>
</tr>
<tr class="a">
<td >outputEncoding</td>
<td >Set the output encoding.</td>
</tr>
<tr class="b">
<td >inputEncoding</td>
<td >Set the input (template) encoding.</td>
</tr>
<tr class="a">
<td >contextProperties</td>
<td >Set the context properties that will be
fed into the initial context be the
generating process starts.
<p>
We are going to do something special
for properties that have a &quot;file.contents&quot;
suffix: for these properties will pull
in the contents of the file and make
them available in the context. So for
a line like the following in a properties file:
<pre>license.file.contents = license.txt</pre>
We will pull in the contents of license.txt
and make it available in the context as
$license. This should make texen a little
more flexible.
</p></td>
</tr>
</table>
</div>
<a name="predefined_context_objects"></a><div class="section"><h2>Predefined Context Objects</h2>
<p>
The Texen Ant task places several objects into the Context for you.
</p>
<table class="bodyTable">
<tr class="b">
<th >Name</th>
<th >Value</th>
</tr>
<tr class="a">
<td >$generator</td>
<td >
This contains the the <a href="api/org/apache/velocity/texen/Generator.html">Generator</a>
instance used to output the text files.
</td>
</tr>
<tr class="b">
<td >$outputDirectory</td>
<td >
This contains the the value of the outputDirectory property given to the Texen Ant Task.
</td>
</tr>
<tr class="a">
<td >$strings</td>
<td >
This contains the an instance of a <a href="http://jakarta.apache.org/commons/lang/apidocs/org/apache/commons/lang/StringUtils.html" class="externalLink">StringUtils</a>
object.
</td>
</tr>
<tr class="b">
<td >$files</td>
<td >
This contains the an instance of a <a href="api/org/apache/velocity/texen/util/FileUtil.html">FileUtil</a>
object.
</td>
</tr>
<tr class="a">
<td >$properties</td>
<td >
This contains the an instance of a <a href="api/org/apache/velocity/texen/util/PropertiesUtil.html">PropertiesUtil</a>
object.
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="clear">
<hr/>
</div>
<div id="footer">
<div class="xright">&#169;
2000-2007
The Apache Software Foundation
Last Published: 2007-01-28 17:40:21
</div>
<div class="clear">
<hr/>
</div>
</div>
</body>
</html>