|
Velocityについて
コミュニティ
ドキュメント
ツール
比較
日本語訳について
|
|
What is Texen? − Texen とは?
|
Texen is a general purpose text generating utility. It is capable of
producing almost any sort of text output. Driven by Ant, essentially
an Ant 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.
Texen は、汎用テキスト生成ユーティリティです。
ほぼどんな種類のテキストでも生成できます。
Texen の実体は、Ant タスクで、Ant によって実行されます。
Taxen は、制御テンプレート、場合によってはワーカテンプレート群と、生成された出力を管理するための
制御コンテキストを使用します。
TexenTask は直接使用することもできますが、通常はサブクラス化します。
何らかの出力を生成する前に制御コンテキストを初期化するためです。
Texen was created to deal with the source generating requirements of
the Turbine web application framework. The Torque utility
in Turbine, 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!
Texen は、Turbine Web アプリケーションフレームワークで必要とされるソース生成を行うために作成されました。
Turbine にある
Torque ユーティリティ
(これは TexenTask のサブクラスです)では、Turbine プロジェクトのために SQLの生成と、
OR (オブジェクト-リレーショナル) マッピングのソース生成を担っています。
これは、1つの例にすぎません。
Texenは、テキストの生成ならほぼ何にでも使えるのです!
|
|
|
The TexenTask − TexenTask
|
This trivial example, which shows how to use Texen from an Ant
build.xml, is intended to illustrate how the Texen mechanism works.
このちょっとした例は Ant の build.xml から Texen を使う方法を示しているわけですが、
Texen の仕組みがどうやって働くのかも示しています。
Ant Build File
Ant ビルドファイル
 |
 |
 |
 |
<project name="HtmlGenerator" default="main" basedir=".">
<taskdef name="texen" classname="org.apache.velocity.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>
|
 |
 |
 |
 |
 |
 |
 |
 |
<project name="HtmlGenerator" default="main" basedir=".">
<taskdef name="texen" classname="org.apache.velocity.texen.ant.TexenTask"/>
<!-- ================================================================ -->
<!-- G E N E R A T E H T M L P A G E S -->
<!-- ================================================================ -->
<!-- このターゲット(main)は、制御コンテキストの情報に基づいて -->
<!-- HTMLページ群を生成します。 -->
<!-- ================================================================ -->
<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>
|
 |
 |
 |
 |
Control Template
制御テンプレート
 |
 |
 |
 |
#*
file: Control.vm
This is the control template for our HTML
page generator!
*#
#set ($Planets = ["Earth", "Mars", "Venus"])
#foreach ($planet in $Planets)
#set ($outputFile = $stringutils.concat([$planet, ".html"]))
$generator.parse("HtmlTemplate.vm", $outputFile, "planet", $planet)
#end
|
 |
 |
 |
 |
 |
 |
 |
 |
#*
file: Control.vm
これは HTML ページジェネレータのための制御テンプレートです!
*#
#set ($Planets = ["Earth", "Mars", "Venus"])
#foreach ($planet in $Planets)
#set ($outputFile = $stringutils.concat([$planet, ".html"]))
$generator.parse("HtmlTemplate.vm", $outputFile, "planet", $planet)
#end
|
 |
 |
 |
 |
Worker Template
ワーカテンプレート
 |
 |
 |
 |
#*
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>
|
 |
 |
 |
 |
 |
 |
 |
 |
#*
file: HtmlTemplate.vm
これはワーカテンプレートです。
制御テンプレートから呼ばれて、実用的な出力を生成します
(この例はあまり実用的ではありませんが)。 :-)
*#
#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>
|
 |
 |
 |
 |
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.
Texen は、Earth.html、Mars.html、 Venus.html の 3 つの html ページを生成します。
もっと実用的にするためには、TexenTask をサブクラス化したり、
制御コンテキストに何かオブジェクトを設定したり、
有効な出力を生成するために制御コンテキストに情報を設定したりします。
See the Torque utility in Turbine for a full working example of
Texen. A standalone version of Torque is available here.
Texen の全機能の実例は、Turbine の Torque ユーティリティを参照してください。
Torque のスタンドアローン版は、
こちら
にあります。
|
|
|