| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <html> |
| <head> |
| <title>Apache Texen - |
| 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 Texen - |
| 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"> |
| |
| <p>Apache Texen</p> |
| |
| </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> |
| > |
| |
| Texen |
| </div> |
| <div class="xright"> <a href="../../../engine/devel/">Engine</a> |
| | |
| <a href="../../../tools/devel/">Tools</a> |
| | |
| <a href="../../../anakia/devel/">Anakia</a> |
| | |
| <a href="../../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>Texen</h5> |
| <ul> |
| |
| <li class="none"> |
| <strong>General</strong> |
| </li> |
| |
| <li class="none"> |
| <a href="../../../download.cgi">Download</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="http://svn.apache.org/viewvc/velocity/texen/trunk/">Source Code Repository</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="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/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/TEXEN">Issues</a> |
| </li> |
| |
| <li class="none"> |
| <a href="../../../who-we-are.html">Who we are</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://ant.apache.org/" 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://db.apache.org/torque/" class="externalLink">Torque</a> uses a subclass of |
| the TexenTask to generate SQL and the Object-Relational mapping |
| sources for its O/R layer. 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> |
| <project name="HtmlGenerator" default="main" basedir="."> |
| |
| <taskdef name="texen" classname="org.apache.texen.ant.TexenTask"/> |
| |
| <!-- ============================================================= --> |
| <!-- G E N E R A T E H T M L P A G E S --> |
| <!-- ============================================================= --> |
| <!-- This target will generate a set of HTML pages based on --> |
| <!-- the information in our control context. --> |
| <!-- ============================================================= --> |
| |
| <target name="main"> |
| |
| <echo message="+------------------------------------------+"/> |
| <echo message="| |"/> |
| <echo message="| Generating HTML pages! |"/> |
| <echo message="| |"/> |
| <echo message="+------------------------------------------+"/> |
| |
| <texen |
| controlTemplate="Control.vm" |
| outputDirectory="." |
| templatePath="." |
| outputFile="generation.report" |
| /> |
| |
| </target> |
| |
| </project> |
| </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 = ["Earth", "Mars", "Venus"]) |
| |
| #foreach ($planet in $Planets) |
| |
| #set ($outputFile = $strings.concat([$planet, ".html"])) |
| $generator.parse("HtmlTemplate.vm", $outputFile, "planet", $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 = "#ffffff") |
| |
| <html> |
| <head> |
| <title> |
| Everything you wanted to know about $planet! |
| </title> |
| </head> |
| <body bgcolor="$bgcolor"> |
| |
| $planet is a great place to live! |
| |
| </body> |
| </html> |
| </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://db.apache.org/torque/" 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="/engine/devel/developer-guide.html#configuring_resource_loaders">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="/engine/devel/developer-guide.html#configuring_resource_loaders">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 "file.contents" |
| 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="apidocs/org/apache/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="apidocs/org/apache/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="apidocs/org/apache/texen/util/PropertiesUtil.html">PropertiesUtil</a> |
| object. |
| </td> |
| </tr> |
| </table> |
| |
| </div> |
| |
| |
| |
| </div> |
| </div> |
| <div class="clear"> |
| <hr/> |
| </div> |
| <div id="footer"> |
| <div class="xright">© |
| 2007 |
| |
| The Apache Software Foundation |
| |
| |
| |
| |
| |
| |
| |
| |
| Last Published: 2007-06-24 14:11:21 |
| </div> |
| <div class="clear"> |
| <hr/> |
| </div> |
| </div> |
| </body> |
| </html> |