Velocity

Velocityについて

コミュニティ

ドキュメント

ツール

比較

日本語訳について

Embedded Usage − 組み込みでの使用

This is an example of using Velocity within an application.

これは、アプリケーション内で Velocity を使用する例です。

    OutputStreamWriter writer = new OutputStreamWriter(output, encoding);
    Template template = RunTime.getTemplate(filename);
    template.merge( context, writer );

In other words, the above is translated into:

上記のコードは以下のように翻訳できます。

  1. Create a Writer.
  2. Ask the Velocity RunTime to retrieve the Template.
  3. Merge the Context with the Template.
  1. Writer を作成する
  2. Velocity ランタイムにテンプレートを取り出させる
  3. テンプレートとコンテキストをマージする

Velocity templates can contain *any* type of data. It can be XML, SQL, HTML, plain text, internationalized text, anything. The parser is very robust in terms of only parsing out what it cares about and ignoring the rest. As demonstrated above, it is possible to embed Velocity's template engine into any other Java code. The advantage of this is that it provides users with a single template system for all sorts of uses.

Velocity テンプレートは、どんなタイプのデータでも含むことができます。 XML、SQL、HTML、普通のテキスト、国際化されたテキスト…何でも可能です。 パーサは、必要なものだけを解析して、それ以外は無視するという点で非常に頑強です。 上で示したように、どんな Java コードにでも Velocity のテンプレートエンジンを 組み込むことができます。 この利点は、どんな用途でもユーザに単独のテンプレートシステムを提供できるということです。

For example, in the PetStore example on the J2EE website, there is a JavaBean which sends an email confirmation when an order is complete. The unfortunate part about this example is that in order to change the contents of the email, one needs to edit Java code. Of course this example could have been done differently to use a JSP based template as the base format. However, the implementation of this is more difficult than simply creating a Java object which resides in the Context that can take as arguments the template to render.

例えば、J2EE Web サイトのペットショップサンプルには、注文が完了すると確認メールを送る JavaBean があります。 このサンプルで残念なのは、メールの内容を変更するためには、 Java コードを編集する必要があるという点です。 もちろんこのサンプルでは、基本フォーマットとして JSP ベースのテンプレートを使うという別のやり方も可能だったでしょう。 しかしそうした実装でも、引数として処理対象のテンプレートをとることができるコンテキスト内に Javaオブジェクトをただ作成するのに比べると簡単ではありません。

Another example of this is the Texen and Anakia tools that come with Velocity. The advantage again is the ability to use Velocity as an embedded tool to produce other useful applications that are not bound strictly to a web application. While it is most likely possible to do this with the JSP engine, it is significantly more difficult to do so.

もう一つの例としてあげるのは、Velocity が組み込まれている TexenAnakia というツールです。 その利点はやはり、Web アプリケーションに限定されることなく、 他の便利なアプリケーションを生み出すための埋め込みツールとして Velocity を使えることです。同じことは JSP エンジンでもたぶん可能ですが、 ずっと難しいでしょう。

You make the decision.

[どちらを選ぶかは] あなたが判断してください。

[ Taglibs <- Previous | Next -> Implementation ]

[ Taglibs <- 前 | 次 -> 実装 ]



このドキュメントは、 熊坂祐二 、 高橋達男 、 野瀬直樹 が訳しました。
コメントがある場合は、 report@jajakarta.org までお願いします。
オリジナル英文 Copyright © 1999-2005, The Apache Software Foundation