<?xml version="1.0" encoding="Shift_JIS"?>

<document>

 <properties>
  <title>開発者ガイド</title>
  <author email="geirm@apache.org">Velocity Documentation Team</author>
  <translator>熊坂祐二</translator>
  <translator>高橋達男</translator>
  <translator>野瀬直樹</translator>
  <original>developer-guide</original>
 </properties>

<body>

<section name="Contents" alias="目次">

<primary>
<p>
<ol>

<li>
<a href="developer-guide.html#Introduction">Introduction and Getting Started</a>
</li>

<li>
<a href="developer-guide.html#Resources">Resources</a>
</li>

<li>
<a href="developer-guide.html#How Velocity Works">How Velocity Works</a>
<ul>
 <li><a href="developer-guide.html#The Fundamental Pattern">The Fundamental Pattern</a></li>
</ul>
</li>

<li>
<a href="developer-guide.html#To Singleton Or Not To Singleton...">To Singleton Or Not To Singleton...</a>
<ul>
  <li><a href="developer-guide.html#Singleton">Singleton Model</a></li>
  <li><a href="developer-guide.html#Separate">Separate Instance</a></li>
</ul>
</li>

<li>
<a href="developer-guide.html#The Context">The Context</a>
<ul>
<li><a href="developer-guide.html#The Basics">The Basics</a></li>
<li><a href="developer-guide.html#Support for Iterative Objects for #foreach()">Support for Iterative Objects for #foreach()</a></li>
<li><a href="developer-guide.html#Context Chaining">Context Chaining</a></li>
<li><a href="developer-guide.html#Objects Created in the Template">Objects Created by the Template</a></li>
<li><a href="developer-guide.html#Other Context Issues">Other Context Issues</a></li>
</ul>
</li>

<li>
<a href="developer-guide.html#Using Velocity In Servlets">Using Velocity in Servlets</a>
<ul>
<li><a href="developer-guide.html#Servlet Programming">Servlet Programming</a></li>
<li><a href="developer-guide.html#Deployment">Deployment</a></li>
</ul>
</li>

<li>
<a href="developer-guide.html#Using Velocity In General Applications">Using Velocity in General Applications</a>
<ul>
<li><a href="developer-guide.html#The Velocity Helper Class">The Velocity Helper Class</a></li>
<li><a href="developer-guide.html#Exceptions">Exceptions</a></li>
<li><a href="developer-guide.html#Miscellaneous Details">Miscellaneous Details</a></li>
</ul>
</li>

<li>
  <a href="developer-guide.html#Application Attributes">Application Attributes</a>
</li>

<li>
<a href="developer-guide.html#EventCartridge and Event Handlers">EventCartridge and Event Handlers</a>
</li>

<li>
<a href="developer-guide.html#Velocity Configuration Keys and Values">Velocity Configuration Keys and Values</a>
</li>

<li>
<a href="developer-guide.html#Configuring the Log System">Configuring the Log System</a>
 <ul>
  <li>
    <a href="developer-guide.html#Using Log4j With Existing Category">Using Log4j With Existing Category</a>
  </li>
  <li>
    <a href="developer-guide.html#Simple Example of a Custom Logger">Simple Example of a Custom Logger</a>
  </li>
 </ul>
</li>

<li>
<a href="developer-guide.html#Configuring Resource Loaders">Configuring the Resource Loaders (template loaders)</a>
<ul>
  <li>
    <a href="developer-guide.html#Resource Loaders">Resource Loaders</a>
  </li>
  <li>
    <a href="developer-guide.html#Configuration Examples">Configuration Examples</a>
  </li>
  <li>
    <a href="developer-guide.html#Resource Manager and Cache">Pluggable Resource Manager and Resource Cache</a>
  </li>
 </ul>
</li>

<li>
<a href="developer-guide.html#Template Encoding for Internationalization">Template Encoding for Internationalization</a>
</li>

<li>
<a href="developer-guide.html#Velocity and XML">Velocity and XML</a>
</li>

<li>
<a href="developer-guide.html#FAQ (Frequently Asked Questions)">FAQ (Frequently Asked Questions)</a>
</li>

<li>
<a href="developer-guide.html#Summary">Summary</a>
</li>

<li>
<a href="developer-guide.html#Appendix 1 : Deploying the Example Servlet">Appendix 1 : Deploying the Example Servlet</a>
<ul>
  <li>
    <a href="developer-guide.html#TomcatExample">Jakarta Tomcat</a>
  </li>
  <li>
    <a href="developer-guide.html#ResinExample">Caucho Technology's Resin</a>
  </li>
  <li>
    <a href="developer-guide.html#WebLogic">BEA WebLogic</a>
  </li>
 </ul>
</li>

</ol>
</p>
</primary>
<p>
<ol>

<li>
<a href="developer-guide.html#Introduction">はじめに</a>
</li>

<li>
<a href="developer-guide.html#Resources">リソース</a>
</li>

<li>
<a href="developer-guide.html#How Velocity Works">Velocity の動作原理</a>
<ul>
 <li><a href="developer-guide.html#The Fundamental Pattern">基本パターン</a></li>
</ul>
</li>

<li>
  <a href="developer-guide.html#To Singleton Or Not To Singleton...">Singletonにすべきか否か…</a> 
   <ul> 
     <li><a href="developer-guide.html#Singleton">Singleton モデル</a></li> 
     <li><a href="developer-guide.html#Separate">分離インスタンス</a></li> 
   </ul> 
   </li> 
<li>
<a href="developer-guide.html#The Context">コンテキスト</a>
<ul>
<li><a href="developer-guide.html#The Basics">基本</a></li>
<li><a href="developer-guide.html#Support for Iterative Objects for #foreach()">#foreach() での繰り返しオブジェクトのサポート</a></li>
<li><a href="developer-guide.html#Context Chaining">コンテキストの連鎖</a></li>
<li><a href="developer-guide.html#Objects Created in the Template">テンプレートが生成したオブジェクト</a></li>
<li><a href="developer-guide.html#Other Context Issues">その他のコンテキストの課題</a></li>
</ul>
</li>

<li>
<a href="developer-guide.html#Using Velocity In Servlets"> サーブレットで Velocity を使う</a>
<ul>
<li><a href="developer-guide.html#Servlet Programming"> サーブレットのプログラミング</a></li>
<li><a href="developer-guide.html#Deployment">配備</a></li>
</ul>
</li>

<li>
<a href="developer-guide.html#Using Velocity In General Applications">一般的なアプリケーションで Velocity を使う</a>
<ul>
<li><a href="developer-guide.html#The Velocity Helper Class">Velocity ヘルパクラス</a></li>
<li><a href="developer-guide.html#Exceptions">例外</a></li>
<li><a href="developer-guide.html#Miscellaneous Details">その他雑記</a></li>
</ul>
</li>

<li>
  <a href="developer-guide.html#Application Attributes">アプリケーション属性</a>
</li>

<li>
<a href="developer-guide.html#EventCartridge and Event Handlers">EventCartridge とイベントハンドラ</a>
</li>

<li>
<a href="developer-guide.html#Velocity Configuration Keys and Values">Velocity 設定キーと値</a>
</li>

<li>
<a href="developer-guide.html#Configuring the Log System">ログシステム設定</a>
 <ul>
  <li>
    <a href="developer-guide.html#Simple Example of a Custom Logger">カスタムロガーの簡単な例</a>
  </li>
 </ul>
</li>

<li>
<a href="developer-guide.html#Configuring Resource Loaders">リソースローダの設定</a>
<ul>
  <li>
    <a href="developer-guide.html#Configuration Examples">設定例</a>
  </li>
 </ul>
</li>

<li>
<a href="developer-guide.html#Template Encoding for Internationalization">国際化のためのテンプレートエンコーディング</a>
</li>

<li>
<a href="developer-guide.html#Velocity and XML">Velocity と XML</a>
</li>

<li>
<a href="developer-guide.html#FAQ (Frequently Asked Questions)">FAQ (よく聞かれる質問)</a>
</li>

<li>
<a href="developer-guide.html#Summary">まとめ</a>
</li>

<li>
<a href="developer-guide.html#Appendix 1 : Deploying the Example Servlet">追記 1：サンプルサーブレットの配備</a>
<ul>
  <li>
    <a href="developer-guide.html#TomcatExample">Jakarta Tomcat</a>
  </li>
  <li>
    <a href="developer-guide.html#ResinExample">Caucho Technology の Resin</a>
  </li>
 </ul>
</li>

</ol>
</p>

</section>

<section name="Introduction" alias="はじめに">
<primary>
<p>
Velocity is a Java-based template engine, a simple and powerful development tool
that allows you to easily create and render documents that format and present
your data. In this guide, we hope to give an overview of the basics of
development using Velocity, focusing on the two main areas for Velocity usage :
</p>
</primary>
<p>
Velocity は、Java ベースのテンプレートエンジンであり、
データをフォーマット・表示する文書を簡単に作成・提供するための単純で強力な開発ツールです。
このガイドでは、 Velocity の主な用途である以下の2つの領域に焦点を当てながら、
Velocity を使用した開発の基本概要について説明したいと思います。
</p>

<primary>
<ul>
<li>servlet-based WWW development</li>
<li>general application use</li>
</ul>
</primary>
<ul>
<li>サーブレットベースの WWW 開発</li>
<li>一般的なアプリケーションでの使用</li>
</ul>

<primary>
<p>
You will see that there is no real difference between these, other than we make
servlet development with Velocity very easy if you use our provided class
VelocityServlet as a base class for your servlet, and offer a utility class to
help with application development.
</p>
</primary>
<p>
両者は本質的には違いはないことが分かると思います。あえて違いがあるとすれば、
サーブレット開発では基本クラスとして我々の提供する VelocityServlet を使うと簡単になるのと、
アプリケーション開発で役立つユーティリティクラスを提供していることぐらいでしょう。
</p>

<primary>
<p>
<strong>Getting Started</strong>
</p>
</primary>
<p>
<strong>導入</strong>
</p>

<primary>
<p>
While this information is found elsewhere on the Velocity site and in the
documentation, it is included here for completeness. Getting Velocity running on
your computer is very easy.  Note that all directory references are relative the
root of the Velocity distribution tree.
<ol>
  <li>
    Get the Velocity distribution. This is available as a release, nightly snapshot or
    directly from the CVS code repository. Any are fine, although for the latest
    features, the nightly snapshot is most likely the best way. For more
    information, go <a href="index.html">here</a>.
  </li>
  <li>
    If you don't have <a href="http://jakarta.apache.org/ant/">Jakarta Ant</a>,
    the Java build tool already installed, please do so.  It is required for
    building Velocity, although not required for <i>using</i> Velocity.
  </li>
  <li>
    Go to the <code>build</code> directory in the distribution.
  </li>
  <li>
    Type <code>ant &lt;build target&gt;</code> where &lt;build target&gt;
    is one of:
    <ul>
      <li>
        <b><code>jar</code></b> builds the complete Velocity jar in the
        <code>bin</code> directory.  This jar will be called 'velocity-X.jar',
        where 'X' is the current version number. This jar does not include
        necessary dependencies for Velocity.  If you use this
        target, you must get the Collections component jar from Jakarta Commons and add
        to your CLASSPATH (or WEB-INF/lib).
        If you wish to use the built-in logging or template conversion,
        you must include the appropriate jars in your CLASSPATH or
        webapp's WEB-INF/lib.
        For convenience, you can use the <code>jar-dep</code> target to build
        a jar with ORO, Logkit and Commons Collections included.
      </li>
      <li>
        <b><code>jar-dep</code></b> builds the complete Velocity jar in
        the <code>bin</code> directory, including necessary
        support for logging from the
        <a href="http://jakarta.apache.org/avalon/logkit/index.html">Jakarta
        Avalon Logkit</a> package, critical configuration support from the
        <a href="http://jakarta.apache.org/commons/">Jakarta Commons</a>
        and the necesary support for WebMacro
        template conversion using the
        <a href="http://jakarta.apache.org/oro/index.html">Jakarta ORO</a>
        package.
       </li>
       <li>
        <b><code>jar-core</code></b> builds a slimmer Velocity jar in the
        <code>bin</code> directory, called 'velocity-core-X.jar'. This jar
        contains the core Velocity functionality, and doesn't include example
        and utility things like Anakia, Texen or the VelocityServlet support
        baseclass.  It has the same external dependency requirements as the
        regular <code>jar</code> target.
      </li>
      <li>
        <b><code>jar-util</code></b> builds a utility Velocity jar in the
        <code>bin</code> directory, called 'velocity-util-X.jar'. This jar
        contains utility code, specifically Anakia, Texen, and the WebMacro
        template conversion utility. It has the same external dependency requirements as the
        regular <code>jar</code> target.
      </li>
      <li>
        <b><code>jar-servlet</code></b> builds a utility Velocity jar in the
        <code>bin</code> directory, called 'velocity-servlet-X.jar'. This jar
        contains utility code for servlet programmers. It has the same external dependency requirements as the
        regular <code>jar</code> target.
      </li>
      <li>
        <b><code>jar-J2EE</code></b> builds a complete jar, like the 'jar' target,
        that includes any components that require J2EE support. Currently, this
        includes only org.apache.velocity.runtime.resource.loader.DataSourceResourceLoader.
        As usual, it is placed in the  <code>bin</code> directory, called
        'velocity-j2ee-X.jar'. NOTE : if you wish to use this build target, you
        must place (or link) a copy of j2ee.jar into the build/lib directory.
        We do not provide it as part of the distribution. A good source is
        http://java.sun.com/.  It has the same external dependency requirements as the
        regular <code>jar</code> target.
      </li>
      <li>
        <b><code>jar-J2EE-dep</code></b> build a complete jar with J2EE support
        and includes logging support from the Jakarta Avalon Logkit and
        regexp support fromt the Jakarta ORO package. See the notes on the
        <code>jar-dep</code> target, above.
      </li>
      <li>
        <b><code>examples</code></b> builds the example code in the example programs
        found in the <code>examples</code> directory. This build target will
        also build the forumdemo example project.
      </li>
      <li>
        <b><code>forumdemo</code></b> builds the example webapplication in the
        <code>examples/forumdemo</code> directory.
      </li>
      <li>
        <b><code>docs</code></b> builds these docs in the <code>docs</code> directory
        using Velocity's <a href="anakia.html">Anakia</a> XML transformation tool.
        Allowing you to use
        Velocity templates in place of stylesheets
        - give it a try!  <i>Note: This target requires that the jakarta-site2 project
        is located as a peer directory to the jakarta-velocity distribution directory.
        Please see the note in the build.xml file for this target for further information.</i>
      </li>
      <li>
        <b><code>jar-src</code></b> bundles all the Velocity source code into a single
        jar, placed in the <code>bin</code> directory.
      </li>
      <li>
        <b><code>javadocs</code></b> builds the Javadoc class documentation in the
        <code>docs/api</code> directory
      </li>
      <li>
        <b><code>test</code></b> (after jar) will test Velocity against it's testbed
        suite of test routines
      </li>
      <li>
        <b><code>help</code></b> lists the build targets that are available.
      </li>
    </ul>
  </li>
  <li>
    While not required, testing the build is a good idea. Use the
    <code>test</code> target mentioned above.
  </li>
  <li>
    That's it! Velocity is ready to be used. Put the jar into your classpath, or
    into other appropriate places (such as the lib directory of your webapp if
    using with servlets)
  </li>
  <li>
    If you want to play with the examples, which is highly recommended when
    getting started, use build the examples via
    <code>ant examples</code>.
  </li>
</ol>
</p>
</primary>
<p>
この情報は Velocity サイト上や文書内の他の場所にもありますが、
念のために、ここでも記述しています。
Velocity をあなたのコンピュータで動かすのは、非常に簡単です。
なお、全てのディレクトリの参照は、
Velocity 配布のルートディレクトリを基準にしていますのでご注意ください。

<primary>
</primary>
<ol>
  <li>
Velocity 配布を入手します。
リリース版や、夜間スナップショットとしても入手できますし、直接
CVS コードリポジトリからも入手可能です。
どれでも構いませんが、最新の機能なら、夜間スナップショットがおそらく一番良いでしょう。
詳細情報は、<a href="index.html">こちら</a>を参照してください。
  </li>
  <li>
    Java 構築ツールの
    <a href="http://ant.apache.org/">Jakarta Ant</a> を
まだインストールしていない場合には、まずそれをインストールしてください。
Velocity を<i>使用する</i>には必要ありませんが、Velocity を構築するのに必要です。
  </li>
  <li>
    配布の <code>build</code> ディレクトリに移動します。
  </li>
  <li>
    <code>ant &lt;build target&gt;</code> とタイプします。&lt;build target&gt; は以下のうちのどれかです。
    <ul>
      <li>
        <b><code>jar</code></b> <code>bin</code> ディレクトリに Velocity
        の完全版の jar ファイルを構築します。jar ファイルは、'velocity-X.jar' という名前で、
        「X」は、現在のバージョン番号です。このjarファイルにはVelocity
        で必要なコンポーネントは含まれていません。このターゲットを使う場合は、
        Jakarta Commons から Collections コンポーネントを入手し、クラスパス
        (あるいは WEB-INF/lib)に追加する必要があります。
        ビルドインされたログ機能やテンプレート変換機能を使いたい場合は、
        クラスパスか Web アプリケーションの WEB-INF/lib に jar 
        ファイルを適宜含めなければなりません。
        便宜上、ORO、Logkit、Commons Collections を含めた jar ファイルを構築できる
        jar-dep タスクを使うこともできます。
      </li>
      <li>
        <b><code>jar-dep</code></b> <code>bin</code> ディレクトリに Velocity
        の完全版の jar ファイルを構築します。この jar ファイルには、
        <a href="http://avalon.apache.org/logkit/index.html">Jakarta
        Avalon Logkit</a> パッケージによるロギングに必要なサポートや、
        <a href="http://jakarta.apache.org/commons/">Jakarta Commons</a>
        による重要な設定のサポートや、
        <a href="http://www.jajakarta.org/oro/">Jakarta ORO</a>
        パッケージを使った WebMacro テンプレート変換に必要なサポートが含まれています。
      </li>
      <li> 
        <b><code>jar-core</code></b>
        <code>bin</code> ディレクトリにサイズの小さな「velocity-core-X.jar」という
        名前のVelocity JAR ファイルを構築します。この JAR ファイルには、Velocity
        機能のコアが含まれていますが、サンプルや、Anakia、Texen、VelocityServlet
        をサポートする基本クラスといったユーティリティは含まれていません。
      </li>
      <li>
        <b><code>jar-util</code></b> 
        <code>bin</code> ディレクトリに「velocity-util X.jar」という名前の
        ユーティリティ Velocity JAR ファイルを 構築します。この JAR ファイルには、
        Anakia、Texen 、 WebMacro テンプレート変換ユーティリティといった、
        ユーティリティのコードが入っています。通常の <code>jar</code>
        ターゲットと同様の外部依存が必要です。
      </li>
      <li>
        <b><code>jar-servlet</code></b> 
        <code>bin</code> ディレクトリに「velocity-servlet X.jar」という名前の
        ユーティリティ Velocity jar ファイルを構築します。この jar ファイルには、
        サーブレットプログラマ向けのユーティリティのコードがあります。
        通常の <code>jar</code> ターゲットと同様の外部依存が必要です。
      </li>
      <li>
        <b><code>jar-j2ee</code></b> 
        「jar」ターゲットと同様に、
        J2EE サポートを必要とするすべてのコンポーネントが含まれている、
        完全な jar を構築します。現在のところ、
        org.apache.velocity.runtime.resource.loader.DataSourceResourceLoader
        だけしか含まれません。他のものと同様に、「velocity-j2ee-X.jar」という名前で、
        <code>bin</code> ディレクトリに置かれます。注意：
        この構築ターゲットを使用したいときには、build/lib ディレクトリに j2ee.jar
        のコピー(またはリンク)を置かなければなりません。我々は、
        配布の一部としてそれを提供していません。取得元としては、
        http://java.sun.com/ が良いしょう。通常の <code>jar</code>
        ターゲットと同様の外部依存が必要です。
      </li> 
      <li>
        <b><code>jar-J2EE-dep</code></b>
        J2EE をサポートする完全な jar ファイルを構築し、Jakarta Avalon Logkit
        によるロギングサポートや、Jakarta ORO
        パッケージによる正規表現サポートが含まれています。上記の
        <code>jar-dep</code> ターゲットでの注意もご覧下さい。
      </li>
      <li>
        <b><code>examples</code></b>
        <code>examples</code> ディレクトリにあるプログラムサンプルのコードを構築します。
        このターゲットは forumdemo プロジェクトも構築します。
      </li>
      <li>
        <b><code>forumdemo</code></b> 
        <code>examples/forumdemo</code> ディレクトリにサンプル Web 
        アプリケーションを 構築します。
      </li>
      <li>
        <b><code>docs</code></b> 
        Velocity の <a href="anakia.html">Anakia</a> XML 変換ツールを使用して
        今ご覧のドキュメントを <code>docs</code> ディレクトリに構築します。
        スタイルシートの代わりに Velocity テンプレートを使うことができます。
        ── 一度お試しください！ <i>注意：このターゲットでは、
        jakarta-site2 プロジェクトのディレクトリが jakarta-velocity
        配布ディレクトリと同じディレクトリの下にある必要があります。
        このターゲットについての詳細は build.xml ファイルをご覧ください。</i>
      </li>
      <li>  
        <b><code>jar-src</code></b> 
        全ての Velocity ソースコードを一つの jar にまとめ、
        <code>bin</code> ディレクトリに置きます。
      </li>
      <li>
        <b><code>javadocs</code></b>
        <code>docs/api</code> ディレクトリに Javadoc クラスドキュメントを構築します。
      </li>
      <li>
        <b><code>test</code></b> (jar タスクのあとで)
        テストルーチンの testbed スイートに対して Velocity のテストを行ないます。
      </li>
      <li>  
        <b><code>help</code></b> 利用できる構築ターゲットの一覧を表示します。
      </li>
    </ul>
  </li>
  <li>
    ビルドのテストは必要ではありませんが、するに越したことはないでしょう。
    上記の <code>test</code> ターゲットを使ってください。
  </li>
  <li>
    これで、 Velocity を、使用する準備ができました。JAR ファイルを、
    クラスパスなどの適切な場所（サーブレットで使うのなら、
    Webアプリケーションの lib ディレクトリとか）に置きます
  </li>
  <li>
    サンプルを試してみたいという場合(はじめての場合には特に推奨します)には、
    <code>ant examples</code> でサンプルを構築してください。
  </li>
</ol>
</p>

<primary>
<strong>Dependencies</strong>
</primary>
<a name="Dependencies"></a><strong>依存関係</strong>

<primary>
<p>
Velocity uses elements of the Java 2 API such as collections, and therefore
building requires the Java 2 Standard Edition SDK (Software Development Kit).
To run Velocity, the Java 2 Standard Edition RTE (Run Time Environment)
is required (or you can use the SDK, of course).
</p>
</primary>
<p>
Velocity ではコレクションなど Java 2 API を使っているので、ビルドには
Java 2 Standard Edition SDK (Software Development Kit) が必要です。
Velocity を実行するには、Java 2 Standard Edition RTE (Run Time Environment)
(もちろん SDK でも可) が必要です。
</p>

<primary>
<p>
Velocity also is dependent upon a few packages for general functionality.  They
are included in the <code>build/lib</code> directory for convenience, but
the default build target (see above) does not include them.  If you use the
default build target, you must add the dependencies to your classpath.
</p>
</primary>
<p>
Velocity はまた、汎用的な機能に関していくつかのパッケージに依存しています。
これらのパッケージは便宜上、<code>build/lib</code> に入っています。
しかし、デフォルトのビルドターゲット(上述)には入っていません。
デフォルトのビルドターゲットを使う場合は、
クラスパスにこの依存関係を加えなければなりません。
</p>

<primary>
<ul>
<li>
  <a href="http://jakarta.apache.org/commons/">
  <b>Jakarta Commons Collections</b></a> - required.
</li>
<li>
  <a href="http://jakarta.apache.org/avalon/logkit/index.html">
  <b>Jakarta Avalon Logkit</b></a> - optional, but very common.
  Needed if using the default file-based logging in Velocity.
</li>
<li>
  <a href="http://jakarta.apache.org/oro/index.html"><b>Jakarta ORO</b></a>
   - optional.  Needed when using the
   <code>org.apache.velocity.convert.WebMacro</code> template conversion
   utility.
 </li>
</ul>
</primary>
<ul>
<li>
  <a href="http://jakarta.apache.org/commons/">
  <b>Jakarta Commons Collections</b></a> ─ 必須です。
</li>
<li>
  <a href="http://avalon.apache.org/logkit/index.html">
  <b>Jakarta Avalon Logkit</b></a> ─ オプションですが、非常に一般的です。
  Velocityで、デフォルトのファイルベースのロギングを使う場合に必要です。
</li>
<li>
  <a href="http://jakarta.apache.org/oro/index.html"><b>Jakarta ORO</b></a>
   ─ オプションです。<code>org.apache.velocity.convert.WebMacro</code>
   テンプレート変換ユーティリティを使う場合に必要です。
 </li>
</ul>

</section>

<section name="Resources" alias="リソース">
<primary>
<p>
There are quite a few resources and examples available to the programmer, and we
recommend that you look at our examples, documentation and even the source code.
Some great sources are :
</p>
</primary>
<p>
かなりの数のリソースやサンプルをプログラマは利用できます。
サンプルやドキュメント、できればソースコードもチェックすることをお勧めします。
素晴らしいソースをいくつか紹介しましょう。
</p>

<primary>
<ul>
  <li>
     The user and developer community : join us via the
     <a href="http://jakarta.apache.org/getinvolved/mail.html">mail-lists</a>.
  </li>
  <li>
     Mail-list archives : <a href="http://www.mail-archive.com">
    http://www.mail-archive.com</a> is a good one.  Type 'velocity' into the search
    box to see both our -user and -dev archives.
  </li>
  <li>
    source code : <code>src/java/...</code> : all the source code to the
    Velocity project
  </li>
  <li>
    application example 1 : <code>examples/app_example1</code> : a simple
    example showing how to use Velocity in an application program.
  </li>
  <li>
    application example 2 : <code>examples/app_example2</code> : a simple
    example showing how to use Velocity in an application program using the
    Velocity application utility class.
  </li>
  <li>
    servlet example : <code>examples/servlet_example1</code> : a simple example
    showing how to use Velocity in a servlet.
  </li>
  <li>
    logger example : <code>examples/logger_example</code> : a simple example
    showing how to create a custom logging class and register it with
    Velocity to receive all log messages.
  </li>
  <li>
    XML example : <code>examples/xmlapp_example</code> : a simple example
    showing how to use JDOM to read and access XML document data from
    within a Velocity template.  It also includes a demonstration of
    a recursive Velocimacro that walks the document tree.
  </li>
 <li>
    event example : <code>examples/event_example</code> : An example that
    demonstrates the use of the event handling API in Velocity 1.1
  </li>
  <li>
    Anakia application : <code>examples/anakia</code> : example application
    showing how to use Velocity for creating stylesheet renderings of xml data
  </li>
  <li>
    Forumdemo web app : <code>examples/forumdemo</code> : working example of a
    simple servlet-based forum application
  </li>
  <li>
    documentation : <code>docs</code> : all the generated documentation for the
    Velocity project in html
  </li>
  <li>
    API documentation : <code>docs/api</code> : the generated Javadoc
    documentation for the Velocity project
  </li>
  <li>
    templates : <code>test/templates</code> : a large collection of template
    examples in our testbed directory, these are a great source of useage
    examples of VTL, the Velocity Template Language
  </li>
  <li>
    context example : <code>examples/context_example</code> : two examples
    showing how the Velocity context can be extended. For advanced users.
  </li>
</ul>
</primary>
<ul>
  <li>
     ユーザコミュニティと開発者コミュニティ : 
     <a href="http://jakarta.apache.org/getinvolved/mail.html">メーリングリスト</a>
     から参加してください。
  </li>
  <li>
     メーリングリスト・アーカイブ : <a href="http://www.mail-archive.com">
    http://www.mail-archive.com</a> は、そのひとつです。 velocity-user、
    velocity-devの両方のアーカイブを見るには、検索フィールドに
    'velocity' と入力してください。
  </li>
  <li>
    ソースコード : <code>src/java/…</code> : Velocity
    プロジェクトのすべてのソースコードがあります。
  </li>
  <li>
    アプリケーションサンプル 1 : <code>examples/app_example1</code> : 
    アプリケーションプログラムでの Velocity の使い方を示した簡単なサンプル。
  </li>
  <li>
    アプリケーションサンプル 2 : <code>examples/app_example2</code> : 
    Velocity アプリケーション ユーティリティクラスを使用したアプリケーション
    プログラムの簡単なサンプル。
  </li>
  <li>
    サーブレットサンプル : <code>examples/servlet_example1</code> : 
    サーブレットでの Velocity の使い方を示した簡単なサンプル。
  </li>
  <li>
    ロガーサンプル : <code>examples/logger_example</code> : 
    カスタムロギングクラスを作成し、全てのログメッセージを受信できるように Velocity
    に登録する方法を示す簡単なサンプル。
  </li>
  <li>
    XML サンプル : <code>examples/xmlapp_example</code> : 
    JDOM を使って、Velocity テンプレート内から XML
    ドキュメントデータを読み込んでアクセスする方法を示す簡単なサンプル。
    ドキュメントツリーを探索するための再帰的な Velocimacro
    デモも含まれています。
  </li>
 <li>
    イベントサンプル : <code>examples/event_example</code> : 
    Velocity 1.1 の イベントハンドリングAPIを使い方をデモするサンプル。
  </li>
  <li>
    Anakia アプリケーション : <code>examples/anakia</code> : 
    Velocityを使って、XML データを処理するスタイルシートを作る方法
    を示すサンプルアプリケーション。
  </li>
  <li>
    フォーラムデモ Web アプリ : <code>examples/forumdemo</code> :
    単純なサーブレットベースのフォーラムアプリケーションの動作サンプル。
  </li>
  <li>
    ドキュメンテーション : <code>docs</code> : 
    html で生成されたVelocityプロジェクトの全てのドキュメント。
  </li>
  <li>
    API ドキュメント : <code>docs/api</code> : 
    生成された、Velocity プロジェクトの Javadoc ドキュメント
  </li>
  <li>
    各種テンプレート : <code>test/templates</code> : 
    testbed ディレクトリ内には、テンプレートサンプルがたくさん入っています。
    VTL (Velocity Template Language) の使い方についてのすばらしい情報源となるでしょう。
  </li>
  <li>
    コンテキストサンプル : <code>examples/context_example</code> : 
    Velocity コンテキストの拡張方法を示した2つのサンプルがあります。
    上級者向け。
  </li>
</ul>

<primary>
<p>
All directory references above are relative to the distribution root directory.
</p>
</primary>
<p>
上記の全てのディレクトリは、配布ルートディレクトリからの相対パスとなっています。
</p>

</section>

<section name="How Velocity Works" alias="Velocity の動作原理">

<primary>
<p>
<a name="The Fundamental Pattern"><strong>'The Fundamental Pattern'</strong></a>
</p>
</primary>
<p>
<a name="The Fundamental Pattern"><strong>「基本パターン」</strong></a>
</p>

<primary>
<p>
When using Velocity in an application program or in a servlet
(or anywhere, actually), you will generally do the following :
</p>
</primary>
<p>
アプリケーションプログラムやサーブレットで Velocity を使う場合
(実際のところ、どこで使う場合も)、通常は以下のことを行なう必要があります。
</p>

<primary>
<ol>
<li>Initialize Velocity. This applies to both usage patterns for Velocity,
    the Singleton as well as the 'separate runtime instance' (see more on this
    below), and you only do this once.</li>
<li>Create a Context object (more on what that is later).</li>
<li>Add your data objects to the Context.</li>
<li>Choose a template.</li>
<li>'Merge' the template and your data to produce the ouput.</li>
</ol>
</primary>
<ol>
<li>Velocity を初期化します。
これは、Singleton と、「分離実行時インスタンス」(詳細については下記参照)
という Velocity の利用パターンの両方に適用され、一度だけ行なう必要があります。</li>
<li>Context オブジェクトを生成します (詳細は後述)。</li>
<li>データオブジェクトを Context に追加します。</li>
<li>テンプレートを選択します。</li>
<li>出力を生成するためにデータとテンプレートを「マージ」します。</li>
</ol>

<primary>
<p>
In code, using the singleton pattern via the
<code>org.apache.velocity.app.Velocity</code> class,
this looks like
</p>
</primary>
<p>
<code>org.apache.velocity.app.Velocity</code>
クラスから Singleton パターンを使用する場合、
コードではこんな風になります。
</p>

<primary>
<source><![CDATA[
import java.io.StringWriter;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.Template;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.MethodInvocationException;

Velocity.init();

VelocityContext context = new VelocityContext();

context.put( "name", new String("Velocity") );

Template template = null;

try
{
   template = Velocity.getTemplate("mytemplate.vm");
}
catch( ResourceNotFoundException rnfe )
{
   // couldn't find the template
}
catch( ParseErrorException pee )
{
  // syntax error : problem parsing the template
}
catch( MethodInvocationException mie )
{
  // something invoked in the template
  // threw an exception
}
catch( Exception e )
{}

StringWriter sw = new StringWriter();

template.merge( context, sw );

]]></source>
</primary>
<source><![CDATA[
import java.io.StringWriter;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.Template;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.exception.ResourceNotFoundException; 
import org.apache.velocity.exception.ParseErrorException; 
import org.apache.velocity.exception.MethodInvocationException; 

Velocity.init();

VelocityContext context = new VelocityContext();

context.put( "name", new String("Velocity") );

Template template = null;

try
{
   template = Velocity.getTemplate("mytemplate.vm");
}
catch( ResourceNotFoundException rnfe )
{
   // テンプレートが見つからない
}
catch( ParseErrorException pee )
{
  // 構文エラー : テンプレートの解析時に問題発生
}
catch( MethodInvocationException mie ) 
{ 
  // テンプレートのどこかで例外が投げられた
} 
catch( Exception e )
{}

StringWriter sw = new StringWriter();

template.merge( context, sw );

]]></source>

<primary>
<p>
That's the basic pattern. It is very simple, isn't it?  This is generally what
happens when you use Velocity to render a template. You probably won't be
writing code exactly like this - we provide a few tools to help make it even
easier than this for both servlet and application programmers.
Later on in this guide, we will talk about using Velocity in both servlets
as well as general applications, and we discuss the tools we provide to make
things easier. In each case, though, the above sequence is what is happening
either explicitly, or behind the scenes.
</p>
</primary>
<p>
これが、基本的なパターンです。とっても単純ですよね？ これが、
テンプレート処理で Velocity を使うときに通常行なうことです。
たぶん、ここまで厳密にコードを書くことにはならないでしょう
── サーブレットプログラマとアプリケーションプログラマの両方に対して、
より簡単にするためのいくつかのツールを用意しています。
このガイドの後の方で、サーブレットと一般的なアプリケーションの両方での
Velocity の使い方について説明し、
より簡単にするために我々が提供するツールについて説明します。
しかし、どちらの場合でも上記のような処理が、
表立って、あるいは舞台裏で行われているのです。
</p>

</section> 
    
<section name="To Singleton Or Not To Singleton..."
    alias="Singletonにすべきか否か…"> 
    
<primary>
<p>
As of Velocity 1.2 and later, developers now have two options
for using the Velocity engine, the singleton model and the separate instance
model.  The same core Velocity code is used for both approaches, which are
provided to make Velocity easier to integrate into your Java application.
</p>
</primary>
   <p> 
   Velocity 1.2 からは、Velocity エンジンを使うにあたって、開発者には
   Singleton モデルと分離インスタンスモデルの 2 つの選択肢があります。
   どちらの方法でも同じコアの Velocity コードを使用し、どちらの方法でも
   Velocity を簡単に Java アプリケーションに統合できます。
   </p> 
    
    
<primary>
<p>
<a name="Singleton"><strong>Singleton Model</strong></a>
</p>
</primary>
   <p> 
   <a name="Singleton"><strong> Singleton モデル</strong></a> 
   </p> 
    
<primary>
<p>
   This is the legacy pattern, where there is only one instance of the Velocity
   engine in the JVM (or web application, depending) that is shared by all.
   This is very convenient as it
   allows localized configuration and sharing of resources.  For example, this
   is a very appropriate model for use in a Servlet 2.2+ compliant web application
   as each web application can have it's own instance of Velocity, allowing
   that web application's servlet to share resources like templates, a logger, etc.
   The singleton is accessable via the <code>org.apache.velocity.app.Velocity</code>
   class, and and example of use :
</p>
</primary>
   <p> 
これは従来のパターンで、JVM (場合によっては Webアプリケーション) 内にただ一つの
Velocity エンジンのインスタンスがあり、これを全体で共有します。
設定をローカライズしたり、リソースを共有することができるので、とても便利です。
例えば、このパターンはサーブレット2.2 以降に準拠した Web
アプリケーションで使用するのに適切なモデルです。なぜなら、
各 Web アプリケーションが独自の Velocity のインスタンスを持つため、
Web アプリケーションのサーブレットは、テンプレート、ロガーといったリソースを共有できるからです。
Singleton は、<code>org.apache.velocity.app.Velocity</code> クラスからアクセス
でき、以下の例のように使用します。
   </p> 

<primary>
<source><![CDATA[

import org.apache.velocity.app.Velocity;
import org.apache.velocity.Template;

...

/*
 *  Configure the engine - as an example, we are using
 *  ourselves as the logger - see logging examples
 */

Velocity.setProperty( Velocity.RUNTIME_LOG_LOGSYSTEM, this);

/*
 *  now initialize the engine
 */

Velocity.init();

...

Template t = Velocity.getTemplate("foo.vm");
]]></source>
</primary>
<source><![CDATA[ 

import org.apache.velocity.app.Velocity; 
import org.apache.velocity.Template; 

(中略) 
/* 
 *  エンジンの設定 ─ サンプルとして、このクラスそのものを
 *  ロガーとして使っています ─ ロギングサンプルを参照
 */ 
Velocity.setProperty( Velocity.RUNTIME_LOG_LOGSYSTEM, this); 
/* 
 *  ここで、エンジンを初期化します
 */ 
Velocity.init(); 

(中略) 

Template t = Velocity.getTemplate("foo.vm"); 
]]></source> 
   
<primary>
<p>
Please note that the Singleton model is used in the
<code>org.apache.velocity.servlet.VelocityServlet</code> base class,
a utility class provided with the distribution to make writing servlets
easier.  While extending this class is the most common and convenient
way to write servlets using Velocity, you are free to not use this
class if you needs require something different.
</p>
</primary>
   <p> 
    Singleton モデルは、
   <code>org.apache.velocity.servlet.VelocityServlet</code> 
   という基本クラスでも使われていることに注意してください。
   このクラスはサーブレットを簡単に作成するためにこの配布で提供されている
   ユーティリティクラスです。
   このクラスを拡張するのが、Velocity 
   を使ったサーブレットを開発する際に最も一般的で便利な方法ですが、
   何か別のものが必要ならばこのクラスを使わないことも可能です。
   </p> 
    
<primary>
<p>
<a name="Separate"><strong>Separate Instance</strong></a>
</p>
</primary>
   <p> 
   <a name="Separate"><strong>分離インスタンス</strong></a> 
   </p> 
    
<primary>
<p>
   New in version 1.2, the separate instance allows you to create, configure
   and use as many instances of Velocity as you wish in the same JVM
   (or web application.)  This
   is useful when you wish to support separate configurations, such as template
   directories, loggers, etc in the same application.  To use separate
   instances, use the <code>org.apache.velocity.app.VelocityEngine</code>
   class.  An example, which parallels the above singleton example, looks
   like :
</p>
</primary>
   <p> 
      バージョン 1.2 から、分離インスタンスによって、同一のJVM (または Web
      アプリケーション)
      内で Velocity インスタンスを欲しいだけ生成・設定・使用できます。
      テンプレートディレクトリやロガーなどのように、同じアプリケーションで
      別々の構成をサポートしたいときに役に立ちます。分離インスタンスを使用するには、
      <code>org.apache.velocity.app.VelocityEngine</code> クラスを使用します。
      上記の Singleton の例と似たような例があります。
   </p> 
    
<primary>
<source><![CDATA[

import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.Template;

...

/*
 *  create a new instance of the engine
 */

VelocityEngine ve = new VelocityEngine();

/*
 *  configure the engine.  In this case, we are using
 *  ourselves as a logger (see logging examples..)
 */

ve.setProperty( VelocityEngine.RUNTIME_LOG_LOGSYSTEM, this);

/*
 *  initialize the engine
 */

ve.init();

...

Template t = ve.getTemplate("foo.vm");
]]></source>
</primary>
<source><![CDATA[ 
    
import org.apache.velocity.app.VelocityEngine; 
import org.apache.velocity.Template; 

(中略) 

/*
 * 新たなエンジンのインスタンスを生成
 */

VelocityEngine ve = new VelocityEngine(); 

/*
 * エンジンの設定。この場合、このクラスそのものを、
 * ロガーとして使用しています(ロギングサンプルを参照)。
 */

ve.setProperty( VelocityEngine.RUNTIME_LOG_LOGSYSTEM, this); 

/*
 * エンジンを初期化
 */

ve.init(); 
 
(中略) 

Template t = ve.getTemplate("foo.vm"); 
]]></source> 
    
<primary>
<p>
As you can see, this is very simple and straightforward.  Except for some simple
syntax changes, using Velocity as a singleton or as separate instances requires
no changes to the high-level structure of your application or templates.
</p>
</primary>
   <p> 
ごらんのように、これはとても単純でストレートです。
幾つかの単純な構文の変更を除いて、 Singleton にせよ分離インスタンスにせよ、
Velocity を使う時にアプリケーションやテンプレートの高レベルの構造を
変更する必要はありません
   </p> 

<primary>
<p>
As a programmer, the classes you should use to interact with the Velocity
internals are the <code>org.apache.velocity.app.Velocity</code> class if
using the singleton model, or <code>org.apache.velocity.app.VelocityEngine</code>
if using the non-singleton model ('separate instance').
</p>
</primary>
  <p> 
プログラミングの際に Velocity 内部と情報をやり取りするのに使うクラスは、
Singleton モデルを使用するなら
<code>org.apache.velocity.app.Velocity</code> で、
Singleton でないモデル(「分離インスタンス」)を使用するなら
<code>org.apache.velocity.app.VelocityEngine</code> です。
   </p> 

<primary>
<p>
At no time should an application use the internal <code>Runtime, RuntimeConstants,
RuntimeSingleton or RuntimeInstance</code> classes in the
<code>org.apache.velocity.runtime</code> package, as these are intended for
internal use only and may change over time.  As mentioned above,
the classes you should use
are located in the <code>org.apache.velocity.app</code> package, and are the
<code>Velocity</code> and <code>VelocityEngine</code> classes.  If anything is
missing or needed from those classes, do not hesitate to suggest changes - these
classes are intended for the application developer.
</p>
</primary>
   <p> 
アプリケーションでは、<code>org.apache.velocity.runtime</code> パッケージの
<code>Runtime</code>、<code>RuntimeConstants</code>、<code>RuntimeSingleton</code>、
<code>RuntimeInstance</code> の各クラスは絶対に使わないでください。
これらは内部使用のみを想定しており、いつか変更される可能性があります。
上で説明したとおり、使うべきクラスは <code>org.apache.velocity.app</code>
パッケージにある、<code>Velocity</code> クラスと <code>VelocityEngine</code>
クラスです。これらのクラスに何かが抜けていたり何かが必要ならば、
ためらわずに変更点を提案して下さい
─ これらのクラスはアプリケーション開発者向けのものです。
   </p> 

</section>

<section name="The Context" alias="コンテキスト">

<primary>
<a name="The Basics"><strong>The Basics</strong></a>
</primary>
<a name="The Basics"><strong>基本</strong></a>

<primary>
<p>
The concept of the 'context' is central to Velocity, and is a common technique
for moving a container of data around between parts of a system. The idea is
that the context is a 'carrier' of data between the Java layer (or you the
programmer) and the template layer ( or the designer ). You as the programmer
will gather objects of various types, whatever your application calls for, and
place them in the context.  To the designer, these objects, and their methods
and properties, will become accessable via template elements called
<a href="vtl-reference-guide.html"> references</a>. Generally, you will work
with the designer to determine the data needs for the application. In a sense,
this will become an 'API'  as you produce a data set for the designer to access
in the template.  Therefore, in this phase of  the development process it is
worth devoting some time and careful analysis.
</p>
</primary>
<p>
「コンテキスト」という概念は、Velocity の核となるもので、システムの各部分の間で、
データのコンテナ(入れ物)をやり取りするのに一般的なテクニックです。
つまり、コンテキストは、 Java 層 (またはプログラマ) とテンプレート層
 (またはデザイナ) の間でのデータの「運び屋」だということです。
プログラマは、アプリケーションで必要な色々なタイプのオブジェクトを集めて、
コンテキストに設定します。デザイナの方では、これらのオブジェクト、
あるいはそのメソッドやプロパティは、<a href="vtl-reference-guide.html">リファレンス</a>
と呼ばれるテンプレート要素でアクセスできます。
一般的に、プログラマはデザイナと一緒にアプリケーションでのデータ要件を決めます。
ある意味ではこの要件が、デザイナがテンプレートでアクセスできるデータセットを生成する
「API」となります。ですから、開発プロセスのこのフェーズではある程度時間を割いて
慎重な分析を行なうだけの意味があります。
</p>

<primary>
<p>
While Velocity allows you to create your own context classes to support special
needs and techniques (like a context that accesses an LDAP server directly, for
example), a good basic implementation class called VelocityContext is provided
for you as part of the distribution.
</p>
</primary>
<p>
Velocityを使うと、特別な要件やテクニック (例えばLDAPサーバに直接アクセスする
コンテキストとか) をサポートする自分用のコンテキストクラスを作ることもできますが、
配布の一部として、VelocityContext という良く出来た基本的な実装クラスが用意されています。
</p>

<primary>
<p>
VelocityContext is suitable for all general purpose needs, and we strongly
recommended that you use it. Only in exceptional and advanced cases will you
need to extend or create your own context implementation.
</p>
</primary>
<p>
VelocityContext はあらゆる汎用的な用途に適しており、使用を強く推奨します。
自分用のコンテキスト実装を拡張または作成する必要があるのは例外的で高度な場合のみです。
</p>

<primary>
<p>
Using VelocityContext is as simple as using a normal Java Hashtable class.
While the interface contains other useful methods, the two main methods you
will use are
</p>
</primary>
<p>
VelocityContext の使い方は、通常の Java の Hashtable クラスを使用するのと
同じくらい単純です。このインタフェースには便利なメソッドがいろいろありますが、
主に使うメソッドは以下の2つです。
</p>

<source><![CDATA[
public Object put(String key, Object value);
public Object get(String key);
]]></source>

<primary>
<p>
Please note that like a Hashtable, the value must be derived from
java.lang.Object, and must not be null. Fundamental types like int or float must
be wrapped in the appropriate wrapper classes.
</p>
</primary>
<p>
HashTable と同様に、値は java.lang.Object から派生しており、null 
は禁止されていることに注意して下さい。
int や float といった基本タイプは適宜ラッパクラスでラップしなければなりません。
</p>

<primary>
<p>
That's really all there is to basic context operations. For more information,
see the API documentation included in the distribution.
</p>
</primary>
<p>
基本的なコンテキストの操作方法は本当にこれで全てです。詳細については配布に含まれている
APIドキュメントをご覧下さい。
</p>


<primary>
<p>
<a name="Support for Iterative Objects for #foreach()"><strong>Support for Iterative Objects for
#foreach()</strong></a>
</p>
</primary>
<p>
<a name="Support for Iterative Objects for #foreach()"><strong>#foreach()
での繰り返しオブジェクトのサポート</strong></a>
</p>

<primary>
<p>
As a programmer, you have great freedom in the objects that you put into the
context.  But as with most freedoms, this one comes with a little bit of
responsibility, so understand what Velocity supports, and any issues that may
arise.  Velocity supports serveral types of collection types  suitable for use
in the VTL <code>#foreach()</code> directive.
</p>
</primary>
<p>
プログラマであれば、コンテキストへのオブジェクトの設定を極めて自由に行なえます。
しかし、他の大部分の自由と同様に、この自由にも少しですが責任がついてきます。
そのためには、 Velocity のサポート対象とそれによって起こる問題を理解する必要があります。
Velocity は VTL の <code>#foreach()</code> 指示子で使うのに適した、
何種類かのコレクション型をサポートしています。
</p>

<primary>
<ul>

<li> <code>Object [] </code>  Regular object array, not much needs to be said
here. Velocity will internally wrap your array in a class that provides an
Iterator interface,  but that shouldn't concern you as the programmer, or the
template author.
</li>

<li> <code>java.util.Collection</code>  Velocity will use the
<code>iterator()</code> method to get an Iterator to use in the loop,
so if you are implementing a Collection interface on your object, please
ensure that <code>iterator()</code> returns a working  Iterator.
</li>

<li> <code>java.util.Map </code> Here, Velocity depends upon the
<code>values()</code> method of the interface to get a <code>Collection</code>
interface, on which <code>iterator()</code> is called to retrieve an Iterator
for the loop.
</li>

<li> <code>java.util.Iterator</code> USE WITH CAUTION : This is currently
supported only provisionally - the issue of concern is the
'non-resettablity' of the Iterator.  If a 'naked' Iterator is placed into
the context, and used in more than one #foreach(), subsequent #foreach()
blocks after the first will fail, as the Iterator doesn't reset.
</li>

<li> <code>java.util.Enumeration</code> USE WITH CAUTION : Like
<code>java.util.Iterator</code>, this is currently
supported only provisionally - the issue of concern is the
'non-resettablity' of the Enumeration.  If a 'naked' Enumeration
is placed into the context, and used in more than one #foreach(),
subsequent #foreach() blocks after the first will fail,
as the Enumeration doesn't reset.
</li>

</ul>
</primary>
<ul>

<li> <code>Object[] </code> 通常のオブジェクト配列。特に説明の必要はないでしょう。
Velocity 内部では、Iterator インタフェースを備えたクラスで配列をラップしますが、
プログラマやテンプレート作者としてそれを気にする必要はありません。
</li>

<li> <code>java.util.Collection</code> Velocity ではループで使う Iterator を
取得するのに <code>iterator()</code> メソッドを使用します。
したがってオブジェクトで Collection インタフェースを実装する場合は
正しく動作する Iterator を <code>iterator()</code> が返すことを確認してください。
</li>

<li> <code>java.util.Map </code> この場合、Velocity は、インタフェースメソッドの
<code>values()</code> を使います。これは、ループで Iterator 
を取り出すために呼ばれる <code>iterator()</code> メソッドを持つ 
<code>Collection</code> インタフェースを取得するためです。
</li>

<li> <code>java.util.Iterator</code> 使用上の注意：
今のところ条件つきでのみサポートされています ─ 懸念されるのは Iterator が
「リセット不可」であることです。もし Iterator が「何も着けずに」
[訳注：他の型を経由せずに] コンテキストに設定されて #foreach()
で2回以上使われる場合、 Iterator はリセットされないので、2回目以降の #foreach()
ブロックでは失敗します。
</li>

<li> <code>java.util.Enumeration</code> 使用上の注意：
<code>java.util.Iterator</code> と同様に、今のところ条件つきでサポートされています ─
懸念されるのは Enumeration が「リセット不可」であることです。もし Enumeration
が「何も着けずに」コンテキストに設定されて #foreach() で2回以上使われる場合、
Enumerationはリセットされないので、2回目以降の #foreach() ブロックでは失敗します。
</li>

</ul>

<primary>
<p>
In the case of the <code>Iterator</code> and <code>Enumeration</code>, it is
recommended that they are placed in the context only when it cannot be avoided,
and you should let Velocity find the appropriate reusable iterative interface when
that is sufficient and possible.
</p>
</primary>
<p>
<code>Iterator</code> と <code>Enumeration</code> については、
どうしても必要な時のみコンテキストに設定することをお勧めします。
それが可能で問題がないのなら、再利用可能な繰り返しインタフェースを
Velocity が見つけるという形にすべきです。
</p>

<primary>
<p>
There are good reasons to use the <code>java.util.Iterator</code> interface
directly (large data sets via JDBC, for example), but if it can be
avoided, it might be better to use something else. By 'directly' , we meant
doing something like:
</p>
</primary>
<p>
直接 <code>java.util.Iterator</code> インタフェースを使用するのが適切な場合もあります
(例えば、JDBC 経由の大きなデータセット)。しかし、もし避けられるのであれば、
他のものを使う方がよいでしょう。「直接」とは以下のようなやり方のことです。
</p>

<source><![CDATA[
Vector v = new Vector();
v.addElement("Hello");
v.addElement("There");

context.put("words", v.iterator() );
]]></source>

<primary>
<p>
where the Iterator itself is placed into the context. Instead, if you
simply did:
</p>
</primary>
<p>
この場合、Iterator そのものがコンテキストに設定されます。
代わりに単純に以下のようにしたとしましょう。
</p>

<source><![CDATA[
context.put("words", v );
]]></source>

<primary>
<p>
then all would be fine: Velocity would figure out that Vector implement
Collection (via List), and therefore will find the <code>iterator()</code>
method, and use that to get a 'fresh' Iterator for its use each time
it needs to.  With just a plain Iterator (the first snippet above...),
once velocity has used it in a <code>#foreach()</code>, Velocity has
no way of getting a new one to use for the next <code>#foreach()</code>
it is used in.  The result is no output from any subsequent
<code>#foreach()</code> blocks using that reference.
</p>
</primary>
<p>
これですべて丸く収まります。Velocity は Vector が (List 経由で) Collection
を実装していることを理解するので、<code>iterator()</code>
メソッドを見つけられますし、このメソッドを使って、必要に応じて毎回「新鮮な」
Iterator を取得します。Iterator をそのまま使った場合(二つのコード例の最初の方)、
Velocityが <code>#foreach()</code> で一度使うと、次の <code>#foreach()</code>
で使う場合に、新しいオブジェクトを取得できません。その結果、
このリファレンスを使った2回目以降の <code>#foreach()</code> ブロックは何も出力できません。
</p>

<primary>
<p>
This above isn't meant to give the impression that iterating over
collections in Velocity is something that requires great care and
thought.  Rather, the opposite is true, in general.  Just be
careful when you place an Iterator into the context.
</p>
</primary>
<p>
以上の説明で、Velocity ではコレクションを使った繰り返し処理は、
慎重によく考えて行なう必要があると言いたいわけではありません。
むしろ通常は逆なのです。コンテキストに
Iterator [訳注：Enumerationも同様です] を設定する時だけ気をつければいいのです。
</p>

<primary>
<a name="Context Chaining"><strong>Context Chaining</strong></a>
</primary>
<a name="Context Chaining"><strong>コンテキスト連鎖</strong></a>

<primary>
<p>
An innovative feature of Velocity's context design is the concept
of <i>context chaining</i>. Also sometimes referred to as
<i>context wrapping</i>, this advanced feature allows you to connect
separate contexts together in a manner that makes it appear as one
'contiguous' context to the template.
</p>
</primary>
<p>
Velocity のコンテキスト設計の画期的な機能として、<i>コンテキスト連鎖</i>
という概念があります。時には <i>コンテキストラッピング</i> と呼ばれることもある、
この先進的な機能を使うと、別々のコンテキストをくっつけて、テンプレートからは、
「連続した」コンテキストであるように見えるようにできます。
</p>

<primary>
<p>
This is best illustrated by an example :
</p>
</primary>
<p>
具体的に例を示すのが一番でしょう。
</p>

<source><![CDATA[
VelocityContext context1 = new VelocityContext();

context1.put("name","Velocity");
context1.put("project", "Jakarta");
context1.put("duplicate", "I am in context1");

VelocityContext context2 = new VelocityContext( context1 );

context2.put("lang", "Java" );
context2.put("duplicate", "I am in context2");

template.merge( context2, writer );
]]></source>

<primary>
<p>
In the code above, we have set up context2 such that it <i>chains</i>
context1.  This means that in the template, you can access any of
the items that were put into either of the two VelocityContext objects,
as long as there is no duplication of the keys used to add objects.
If that is the case, as it is above for the key 'duplicate', the object
stored in the nearest context in the chain will be available.  In this
example above, the object returned would
be the string "I am in context2".
</p>
</primary>
<p>
上記のコードでは、 context2 が context1 に連鎖するように context2 を設定しました。
つまり、テンプレートでは二つの VelocityContext オブジェクトのどちらに設定した項目でも、
オブジェクト追加時に使ったキーが重複しない限りはアクセスできるということです。
上記の「duplicate」というキーのように、重複している場合は、
連鎖の後方のコンテキストに格納されたオブジェクトが利用できます。
上記の例でいえば、オブジェクトとして返されるのは、
「I am in context2」という文字列となります。
</p>

<primary>
<p>
Note that this duplication, or 'covering', of a context item does not in
any way harm or alter the covered object.  So in the example above, the
string "I am in context1" is alive and well, still accessable via
context1.get("duplicate").  But in the example above, the value of the
reference '$duplicate' in the template would be 'I am in context2',
and the template has no access to the covered string 'I am in context1'.
</p>
</primary>
<p>
このような、コンテキストの項目の重複または「被覆」 (covering) によって、
覆われたオブジェクトに害が及んだり変更されたりはしないことに注意して下さい。
したがって上記の例では、「I am in context1」は無事ですし、context1.get("duplicate")
でアクセスできます。しかし、テンプレート内では「$duplicate」というリファレンスの値は
「I am in context2」となり、覆われた「I am in context1」という文字列に、
テンプレートはアクセスできません。
</p>

<primary>
<p>
Note also that you have to be careful when you are relying on the template
to add information to a context that you will examine later after the
rendering.  The changes to the context via <code>#set()</code> statements
in a template will affect only the outer context.  So make sure that you
don't discard the outer context, expecting the data from the template to
have been placed onto the inner one.
</p>
</primary>
<p>
同様に、テンプレート処理をした後で検証するコンテキストに、
情報を追加するテンプレートを使っている場合は注意が必要です。テンプレート内の
<code>#set()</code> ステートメント経由でコンテキストに変更を加えても、
外側の [訳注：連鎖の後方の] コンテキストにしか影響しません。したがって、
テンプレートからのデータが内部のコンテキストに設定されていると思って、
外側のコンテキストを廃棄したりしないように気をつけてください。
</p>

<primary>
<p>
This feature has many uses, the most common so far is providing layered
data access and toolsets.
</p>
</primary>
<p>
この機能はいろんな使い方ができますが、その中でも特に一般的なのは、
階層化したデータアクセスやツールセットの提供でしょう。
</p>

<primary>
<p>
As mentioned before, the Velocity context mechanism is also extendable,
but beyond the current scope of this guide. If you are interested,
please see the classes in the package <code>org.apache.velocity.context</code>
to see how the provided contexts are put together.  Futher, there are a few
examples in the <code>examples/context_example</code> directory in the
distribution which show alternate implementations, including [a goofy] one
that uses a database as the backing storage.
</p>
</primary>
<p>
先に述べたとおり、Velocity コンテキストの仕組も拡張できるのですが、それについては、
今のところ、このガイドの範囲外です。もし興味があるのでしたら、コンテキストがどのように
まとめられるかを理解するために <code>org.apache.velocity.context</code>
パッケージの各クラスのソースコードをご覧下さい。さらに、配布の
<code>examples/context_example</code> ディレクトリにあるいくつかのサンプルでは、
代替的な実装を示しており、その中にはバックアップ先としてデータベースを使う
「あまり賢くない」 サンプルもあります。 [訳注：context_exampleのことだと思われます。]
</p>

<primary>
<p>
Please note that these examples are unsupported and are there for
demonstration/educational purposes only.
</p>
</primary>
<p>
これらのサンプルはあくまでデモや教育のためのものであり、サポートはされませんので、
ご注意ください。
</p>


<primary>
<a name="Objects Created in the Template"><strong>Objects Created in the
Template</strong></a>
</primary>
<a name="Objects Created in the Template">
<strong>テンプレートで生成されたオブジェクト</strong></a>

<primary>
<p>
 There are two common situations where the Java code must deal with objects
 created at runtime in the template :
</p>
</primary>
<p>
テンプレート内で実行時に生成されたオブジェクトを Java コードが扱わざるを得ない
状況としてよくあるのは次の2種類でしょう。
</p>

<primary>
<p>
When a template author calls a method of an object placed into
the context by Java code.
</p>
</primary>
<p>
テンプレート作者が Java コードがコンテキストに設定したオブジェクトのメソッドを
呼び出すとき。
</p>

<source><![CDATA[
#set($myarr = ["a","b","c"] )
$foo.bar( $myarr )
]]></source>

<primary>
<p>
When a template adds objects to the context, the Java code can access
those objects after the merge process is complete.
</p>
</primary>
<p>
テンプレートでオブジェクトをコンテキストに加えるとき。この場合、
マージ処理が完了した後で、Java コードはこれらのオブジェクトにアクセスできます。
</p>

<source><![CDATA[
#set($myarr = ["a","b","c"] )
#set( $foo = 1 )
#set( $bar = "bar")
]]></source>

<primary>
<p>
Dealing with these cases if very straighforward, as there are just a few
things to know:
</p>
</primary>
<p>
こういうケースを扱う場合、とても単純な場合でも、以下の事柄だけは知っておくべきです。
</p>

<primary>
  <ul>
    <li>
    The VTL RangeOperator  [ 1..10 ]  and  ObjectArray ["a","b"] are
    <code>java.util.ArrayList</code> objects when placed in the context
    or passed to methods.   Therefore, your methods that are designed to
    accept arrays created in the template should be written with this
    in mind.
    </li>
    <li>
    Numbers will be Integers in the context, and strings will be, of course, Strings.
    </li>
    <li>
    Velocity will properly 'narrow' args to method calls, so calling
    <code>setFoo( int i )</code> with an int placed into the
    context via <code>#set()</code> will work fine.
    </li>
  </ul>
</primary>
  <ul>
    <li>
VTLのRangeOperator [ 1..10 ] や ObjectArray ["a","b"] は、
コンテキストに設定される場合や、メソッドに渡される場合は、
<code>java.util.ArrayList</code> オブジェクトとなります。したがって、
テンプレート内で生成された配列を受け取るメソッドを作成する時は、
このことを考慮する必要があります。
    </li>

    <li>
コンテキスト内では数字は Integer になり、文字列はもちろん String になります。
    </li>
    <li>
Velocityはメソッド呼び出しにおいて引数を適切に「狭く」[キャスト]します。
したがって、
<code>#set()</code> を通してコンテキストに設定された int データを引数に
<code>setFoo( int i )</code> を呼び出しても正しく動作します。
    </li>

  </ul>

<primary>
<a name="Other Context Issues"><strong>Other Context Issues</strong></a>
</primary>
<a name="Other Context Issues"><strong>その他のコンテキストの課題</strong></a>

<primary>
<p>
One of the features provided by the VelocityContext
(or any Context derived from AbstractContext) is
node specific introspection caching.  Generally, you as a the developer
don't need to worry about this when using the VelocityContext
as your context.  However, there is currently one
known usage pattern where you must be aware of this feature.
</p>
</primary>
<p>
VelocityContext（および AbstractContext から派生するすべてのコンテキスト）で提供される
機能の1つに、ノード単位イントロスペクションキャッシングがあります。通常の場合、
開発者であっても、 VelocityContext をコンテキストとして使う限りは、
この機能を気にする必要はありません。しかし、この機能を意識しなければならない
既知の使い方のパターンが現在一つだけあります。
</p>

<primary>
<p>
The VelocityContext will accumulate intropection information about the
syntax nodes in a template as it visits those nodes.  So, in the following
situation:
</p>
</primary>
<p>
VelocityContext ではテンプレート内の構文ノードに関する、
イントロスペクション情報を、ノードを処理する(訪れる)ごとに蓄積していきます。
したがって、
</p>

<primary>
<ul>
<li>
  You are iterating over the same template using the same VelocityContext
  object.
</li>
<li>
Template caching is off.
</li>
<li>
You request the Template from getTemplate() on each iteration.
</li>
</ul>
</primary>
<ul>
<li>
同じ VelocityContext を使って、同じテンプレート上で繰り返し処理を行っている
</li>
<li>
Template キャッシュがオフである
</li>
<li>
繰り返しごとに getTemplate() で Template を要求している
</li>

</ul>

<primary>
<p>
It is possible that your VelocityContext will appear to 'leak' memory
(it is really just gathering more introspection information.)  What
happens is that it accumulates template node introspection information
for each template it visits, and as template caching is off, it appears
to the VelocityContext that it is visiting a new template each time.
Hence it gathers more introspection information and grows. It is highly
recommended that you do one or more of the following :
</p>
</primary>
<p>
という条件が重なると、VelocityContext が「メモリリーク」しているように見える
ことがあります（実際には、さらなるイントロスペクション情報を集めているだけです)。
この場合、処理する(訪れる)テンプレートごとに、テンプレートノードのイントロスペクション
情報が蓄積され、テンプレートのキャッシュがオフであるため、 VelocityContext は、
毎回新しいテンプレートを処理していると思ってしまいます。そのため、他の場合に比べて、
より多くのイントロスペクション情報を集めることになり、消費メモリが多くなるのです。
この場合、以下の対応のうち最低でも一つは行なうことを強く推奨します。
</p>

<primary>
<ul>
<li>Create a new VelocityContext for each excursion
down through the template render process.   This will prevent the accumulation
of introspection cache data.  For the case where you want to reuse the
VelocityContext because it's populated with data or objects,
 you can simply wrap the populated
VelocityContext in another, and the 'outer' one will accumulate the
introspection information, which you will just discard.  Ex.
<code>VelocityContext useThis = new VelocityContext( populatedVC );</code>
This works because the outer context will store the introspection
cache data, and get any requested data from the inner context (as it is empty.)
Be careful though - if your template places data into the context and it's
expected that it will be used in the subsequent iterations, you will need to do
one of the other fixes, as any template #set() statements will be stored in
the outermost context. See the discussion in
<a href="developer-guide.html#Context Chaining">Context chaining</a> for more
information.
</li>

<li>
Turn on template caching.  This will prevent the template from being re-parsed
on each iteration, resulting the the VelocityContext being able to not only
avoid adding to the introspection cache information, but be able to use it
resulting in a performance improvement.
</li>

<li>
Reuse the Template object for the duration of the loop iterations.
Then you won't be forcing Velocity, if the cache is turned off, to
reread and reparse the same template over and over, so the VelocityContext
won't gather new introspection information each time.
</li>
</ul>
</primary>
<ul>
<li>
テンプレート処理プロセスによる解析毎に新しい VelocityContext を生成します。
これにより、イントロスペクションキャッシュデータの蓄積を防ぐことができます。
データやオブジェクトをロードしているという理由で VelocityContext 
を再利用したいのなら、単にロードした VelocityContext 
をラップ[連鎖]すればいいのです。そうすれば「外側の」コンテキストが
イントロスペクション情報を蓄積するので、あとはそれを廃棄するだけです。
例) <code>VelocityContext useThis = new VelocityContext( populatedVC );</code>
これで問題ないのは、
外側のコンテキストはイントロスペクションのキャッシュデータを保存しつつ、
要求されたデータは全て、(キャッシュされない) 
内側のコンテキストから取得するからです。
ただし気をつけるべきことがあります ─ テンプレートでコンテキストにデータを設定し、
次の繰り返しでそれが使われることがわかっている場合は、
他の対応策を取る必要があります。
なぜなら、テンプレートで #set() メソッドを使う場合、
一番外側のコンテキストに保存されてしまうからです。詳しくは、
<a href="developer-guide.html#Context Chaining">コンテキスト連鎖</a>
の説明をご覧下さい。
</li>

 <li>
テンプレートキャッシュをオンにします。これにより、繰り返しのたびにテンプレートが
解析されることが防げるため、イントロスペクションのキャッシュ情報の追加が避けられる
のみならず、キャッシュ情報を使うことで性能向上につながります。
</li>

<li>
ループによる繰り返しの間はテンプレートオブジェクトを再利用します。そうすれば、
キャッシュがオフであっても、 Velocity は同じテンプレートを何度も読み込んだり、
何度も解析したりしなくなるので、 VelocityContext は毎回新しいイントロスペクション
情報を集めなくなります。
</li>

</ul>

</section>

<section name="Using Velocity In Servlets" alias="サーブレットでVelocityを使う">

<primary>
<a name="Servlet Programming"><strong>Servlet Programming</strong></a>
</primary>
<a name="Servlet Programming"><strong>サーブレットのプログラミング</strong></a>

<primary>
<p>
The most common use of Velocity is in the area of Java Servlet programming
for the WWW.   There are many reasons why Velocity is well suited for this
task, one of the primary ones is Velocity's enforcement of the
separation of the presentation (or view) layer from the
code layer.  There are many resources on this subject, including
<a href="http://www.javaworld.com/javaworld/jw-12-1999/jw-12-ssj-jspmvc.html">
this</a>.
</p>
</primary>
<p>
Velocity の最も代表的な利用領域は WWW 向けの Java サーブレットプログラミングの領域です。
Velocity がこの領域で最適な理由はたくさんありますが、主要な理由のひとつに、
Velocity ではコード層からプレゼンテーション層(またはビュー)
を強制的に分離できることが挙げられます。
このことに関しては多くのリソースがありますが、例えば
<a href="http://www.javaworld.com/javaworld/jw-12-1999/jw-12-ssj-jspmvc.html">こういうもの</a>があります。
</p>

<primary>
<p>
The basic technique of using Velocity in a servlet environment is very simple.
In a nutshell, all you must do is extend the provided VelocityServlet base class
and implement a single method, <code>handleRequest()</code>.  That's really all that is
required to use Velocity in your servlet development.
</p>
</primary>
<p>
サーブレット環境で Velocity を使う基本テクニックは、非常に単純なものです。
念のために説明すると、やるべきことは提供されている VelocityServlet 基本クラスを
拡張して、ひとつのメソッド（<code>handleRequest()</code>）を実装するだけです。
サーブレット開発で Velocity を使うのに必要なのは本当にこれだけなのです。
</p>

<primary>
<p>
As of Velocity 1.1, there are two <code>handleRequest()</code> methods :

<br/>
<br/>

<i><code>public Template handleRequest( Context )</code></i>

<blockquote>
  This is the older of the two methods.  This method requires that you
  return a valid Template object.  If not valid, or <code>null</code>,
  this is considered an error condition, and will result in the <a
  href="developer-guide.html#error()"><code>error()</code></a> error
  handling method being called.  You may override the
  <code>error()</code> if you wish.  If returning a <code>null</code> is
  something you expect to do (for example, you will want to redirect
  requests) it is recommended that you use the newer method, listed
  next.
</blockquote>
  <br/>

<i><code>public Template handleRequest( HttpServletRequest, HttpServletResponse, Context )</code></i>

<blockquote>
   This is the newer of the two <code>handleRequest()</code> methods,
   implemented in version 1.1. The difference with this method is that
   the <code>HttpServletRequest</code> and
   <code>HttpServletResponse</code> objects are passed to you as
   arguments to the method, as well as in the <code>Context</code>.  The
   other difference is that this method can return <code>null</code> to
   indicate that all processing has been handled by the method, and that
   Velocity should do nothing further than call
   <a href="developer-guide.html#requestCleanup()"><code>requestCleanup()</code></a>.
   This is extremely useful is you wish to redirect the request, for
   example.
</blockquote>

As always, please refer to the Javadoc API documentation for the definitive and
latest notes.
</p>
</primary>
<p>
Velocity 1.1 では、以下の2つの <code>handleRequest()</code> メソッドがあります。

<br/>
<br/>

<i><code>public Template handleRequest( Context )</code></i>
  
 <blockquote>
これは、2つのメソッドの古い方です。このメソッドでは有効なテンプレートオブジェクトを
返す必要があります。有効でなかったり、<code>null</code> だったりすると、
エラーと見なされ、その結果、
<a href="developer-guide.html#error()"><code>error()</code></a>
エラーハンドリングメソッドが呼び出されます。必要なら <code>error()</code>
をオーバーライドできます。<code>null</code> を返す可能性がある場合
(例えば、リクエストをリダイレクトさせたい場合)は、
次に説明する新しいメソッドを使用することが推奨されます。
</blockquote>

<i><code>public Template handleRequest( HttpServletRequest, HttpServletResponse, Context )</code></i>

<blockquote>
これは2つの <code>handleRequest()</code> メソッドの新しい方で、バージョン 1.1
において実装されました。上のメソッドとの違いは、このメソッドでは、<code>Context</code>
に加えて、 <code>HttpServletRequest</code> と <code>HttpServletResponse</code>
オブジェクトがメソッドに対する引数として渡されるということです。もう一つの違いは、
このメソッドでは全ての処理をメソッドが行ったことを明示するために 
<code>null</code> を返すことができることです。この場合 Velocity は
<a href="developer-guide.html#requestCleanup()"><code>requestCleanup()</code></a>
以外は何もしません。これは、例えば要求をリダイレクトしたい場合に極めて便利です。
</blockquote>

当然のことながら、最も確実で最新の注意事項については、Javadoc API
ドキュメンテーションを参照してください。
</p>

<primary>
<p>
The following code is similar to the SampleServlet.java class included
in the distribution in the examples directory.
</p>
</primary>
<p>
以下のコードは、配布のサンプルディレクトリに入っている SampleServlet.java クラスと
同じ物です。
</p>

<primary>
<source><![CDATA[
public class SampleServlet extends VelocityServlet
{
    public Template handleRequest( HttpServletRequest request,
                                   HttpServletResponse response,
                                   Context context )
    {

        String p1 = "Jakarta";
        String p2 = "Velocity";

        Vector vec = new Vector();
        vec.addElement( p1 );
        vec.addElement( p2 );

        context.put("list", vec );

        Template template = null;

        try
        {
            template =  getTemplate("sample.vm");
        }
        catch( ResourceNotFoundException rnfe )
        {
          // couldn't find the template
        }
        catch( ParseErrorException pee )
        {
          // syntax error : problem parsing the template
        }
        catch( Exception e )
        {}

        return template;
    }
}
]]></source>
</primary>
<source><![CDATA[
public class SampleServlet extends VelocityServlet
{
    public Template handleRequest( HttpServletRequest request, 
                                   HttpServletResponse response, 
                                   Context context )
    {

        String p1 = "Jakarta";
        String p2 = "Velocity";

        Vector vec = new Vector();
        vec.addElement( p1 );
        vec.addElement( p2 );

        context.put("list", vec );

        Template template = null;

        try
        {
            template =  getTemplate("sample.vm");
        }
        catch( ResourceNotFoundException rnfe )
        {
          // テンプレートを見つけられなかった
        } 
        catch( ParseErrorException pee )
        {
          // 構文エラー：テンプレート解析で問題あり
        }
        catch( Exception e )
        {}

        return template;
    }
}
]]></source>

<primary>
<p>
Look familiar?  With the exception of creating the context object, which is
done for you by the VelocityServlet base class, and  the  merge() step
which is also done for you by the VelocityServlet base class, it's identical
to the basic code pattern we mentioned at the beginning of this guide.
We take the context, add our application data, and return a template.
</p>
</primary>
<p>
見覚えがありませんか？ VelocityServlet 基本クラスが代わりに行なう、
コンテキストオブジェクトの生成と merge() ステップを除いて、
このガイドの初めの方に説明した基本的なコードパターンと同じです。
この場合は、コンテキストを取得し、アプリケーションデータを追加し、
テンプレートを返します。
</p>

<primary>
<p>
The default <code>Context</code> object that is passed into the
<code>handleRequest()</code> methods contains both the current
<code>HttpServletRequest</code> and <code>HttpServletResponse</code>
objects.  They are placed in the context using the the constants
<code>VelocityServlet.REQUEST</code> (value = 'req') and
<code>VelocityServlet.RESPONSE</code> (value = 'res')
respectively.  To access and use these objects in your Java code :
</p>
</primary>
<p>
<code>handleRequest()</code>メソッドに渡されるデフォルトの <code>Context</code>
オブジェクトには、現在の<code>HttpServletRequest</code> と
<code>HttpServletResponse</code>オブジェクトの両方が含まれています。
これらは、定数 <code>VelocityServlet.REQUEST</code>
 (値は「req」)  と <code>VelocityServlet.RESPONSE</code> (値は「res」) を使って、
コンテキストに設定されます。Java コードでこれらのオブジェクトにアクセスするには、
以下のようにします。
</p>

<source><![CDATA[
public Template handleRequest(  Context context )
{
    HttpServletRequest request =  (HttpServletRequest) context.get( REQUEST );
    HttpServletResponse response =  (HttpServletResponse) context.get( RESPONSE );

   ...
]]></source>

<primary>
<p>
and in your templates:
</p>
</primary>
<p>
そしてテンプレートでは以下のようにアクセスします。
</p>

<source><![CDATA[
#set($name = $req.getParameter('name') )
]]></source>

<primary>
<p>
For more advanced uses,  the VelocityServlet base class allows you to override
parts of the handling of the request processing.  The following methods may
be overridden :
<br/>
<br/>

<i><code> Properties loadConfiguration( ServletConfig )</code></i>
<blockquote>
  Allows you to override the normal configuration mechanism and add or
  alter the configuation properties.  This is useful for overriding or
  augmenting template and log paths, to set the absolute path into the
  webapp root at runtime.
</blockquote>

<i><a name="createContext()">
<code>Context createContext(HttpServletRequest, HttpServletResponse )</code></a></i>
<blockquote>
  Allows you to create the Context object yourself. This allows more advanced
  techniques, such as chaining or pre-loading with tools or data.  The default
  implementation simply returns a VelocityContext object with the request
  and response objects placed inside.  The request and response objects are
  wrapped in simple wrapper classes to avoid introspection problems that may
  occurr in some servlet container implementations.  You can use the request
  and repsponse objects normally, accessing methods of either from the
  template.  Just note that they aren't specifically javax.servlet.XXXX
  classes, if that is important to you.
</blockquote>

<i><code>void setContentType( HttpServletRequest,HttpServletResponse )</code></i>
<blockquote>
  Allows you to examine the request and set the content type yourself,
  depending on the request or client.  The default implementation sets
  the content type to be that either specified in the
  velocity.properties, if any, or the default, "text/html" if not
  specified in the properties.
</blockquote>

<i><code>void mergeTemplate( Template, Context, HttpServletResponse )</code></i>
<blockquote>
  Allows you to produce the output stream.  The VelocityServlet uses a
  pool of very efficient Writer classes, so this would usually be
  overridden in special situations.
</blockquote>

<i><a name="requestCleanup()"><code>void requestCleanup( HttpServletRequest,
  HttpServletResponse , Context )</code></a></i>
<blockquote>
  Allows you to do any cleanup or resource reclamation at the end of the
  request processing.  The default does nothing.
</blockquote>

<i><a name="error()"><code>protected void error( HttpServletRequest,
  HttpServletResponse, Exception )</code></a></i>
<blockquote>
  Error handler that is called an exception occurrs in request
  processing. Default implementation will send a simple HTML message
  with stacktrace and exception information back to the user.  Override
  for custom client messages and more advanced problem handling.
</blockquote>

For further information, please see the Javadoc
<a href="apidocs/index.html">API documentation</a>.
</p>
</primary>
<p>
より高度な使い方として、 VelocityServlet 基本クラスは、
リクエスト処理のハンドリングの一部をオーバーライドできます。
オーバーライドできるのは以下の各メソッドです。

<br/>
<br/>

<i><code> Properties loadConfiguration( ServletConfig )</code></i>
<blockquote>
通常の設定メカニズムをオーバーライドし、設定プロパティの追加や変更ができます。
実行時に Webアプリケーションのルートに絶対パスを設定するために、
テンプレートやログのパスをオーバーライドしたり増やしたりするのに役立ちます。
</blockquote>

<i><a name="createContext()">
<code>Context createContext(HttpServletRequest, HttpServletResponse )</code></a></i>
<blockquote>
自分でコンテキストオブジェクトを生成できます。これによってより高度なテクニック、
例えば、例えばコンテキストの連鎖や、ツールやデータでの事前ロードを行なえます。
デフォルトの実装では、内部で設定されたリクエストおよびレスポンスオブジェクトを
含む VelocityContext オブジェクトを返します。
リクエストおよびレスポンスオブジェクトは、サーブレットコンテナの実装によっては発生する
かもしれない、イントロスペクションでの問題を回避するために単純なラッパクラスで
ラップされています。リクエストおよびレスポンスオブジェクトは通常どおり使用できますし、
テンプレートからもどちらのメソッドにもアクセスできます。
人によっては重要かも知れないので、念のため注記しておくと、これらのクラスは、
厳密には javax.servlet.XXXX クラスではありません。
</blockquote>

<i><code>void setContentType( HttpServletRequest,HttpServletResponse )</code></i>
<blockquote>
リクエストをチェックして、リクエストやクライアントに応じて独自のコンテントタイプを
設定できます。デフォルトの実装ではコンテントタイプは velocity.properties
に指定した値か、指定されていなければデフォルトで「text/html」が設定されます。
</blockquote>

<i><code>void mergeTemplate( Template, Context, HttpServletResponse )</code></i>
<blockquote>
出力ストリームを生成できます。 VelocityServlet は非常に効率的な Writer
クラスのプールを使いますので、通常は特別な状況においてのみオーバーライドされます。
</blockquote>

<i><a name="requestCleanup()"><code>void requestCleanup( HttpServletRequest, 
  HttpServletResponse , Context )</code></a></i>
<blockquote>
リクエスト処理の最後に、クリーンアップやリソース再利用といった処理ができます。
デフォルトでは、何もしません。
</blockquote>

<i><a name="error()"><code>protected void error( HttpServletRequest, 
  HttpServletResponse, Exception )</code></a></i>
<blockquote>
リクエスト処理での例外発生時に呼ばれるエラーハンドラ。
デフォルトの実装では、スタックトレースと例外情報とともに単純な
HTML メッセージをユーザに送ります。クライアントメッセージをカスタマイズしたり、
より高度にエラーを扱うためにオーバーライドします。
</blockquote>

詳細情報は、Javadoc の
<a href="apidocs/index.html">API ドキュメント</a>
をご覧下さい。
</p>

<primary>
<a name="Deployment"><strong>Deployment</strong></a>
</primary>
<a name="Deployment"><strong>配備</strong></a>

<primary>
<p>
When you deploy your Velocity-based servlets, you will certainly want to
ensure that your properties file is used to configure the Velocity runtime.
Under Tomcat, one way to accomplish this is by placing your velocity.properties
file into the root directory of your web app (webapps/appname ) and then
add the following to your WEB-INF/web.xml file :
</p>
</primary>
<p>
Velocity ベースのサーブレットを配備する場合、プロパティファイルが Velocity
ランタイムを設定するのに使われているかどうか確認したいことがあるかと思います。
Tomcat でこの目的を達成するためには、Web アプリケーションのルートディレクトリ（webapps/appname）
に velocity.properties ファイルを置き、以下の内容を WEB-INF/web.xml
ファイルに追加するという方法があります。
</p>

<source><![CDATA[
<servlet>
  <servlet-name>MyServlet</servlet-name>
  <servlet-class>com.foo.bar.MyServlet</servlet-class>
  <init-param>
      <param-name>properties</param-name>
      <param-value>/velocity.properties</param-value>
  </init-param>
</servlet>
]]></source>

<primary>
<p>
Assuming all is right, this will ensure that when MyServlet is loaded,
it will use the velocity.properties file to initialize itself
rather than relying on it's internal defaults.
</p>
</primary>
<p>
記述が全て正しければ、MyServlet がロードされるとき、内部のデフォルトに依存せずに、
MyServlet自身を初期化するために velocity.properties ファイルを確実に使用します。
</p>

<primary>
<p>
Note that Velocity uses a singleton model for it's central core Runtime
class, so it is a very good idea to put the velocity-XX.jar
into the WEB-INF/lib directory in all web applications that use
Velocity to ensure that the web app classloader is
managing your Runtime instance, rather than putting it in the CLASSPATH
or the top level lib directory of the servlet runner.
</p>
</primary>
<p>
注意: Velocity は中心となるコアの Runtime クラスで Singleton モデルを使うので、
確実に Web アプリのクラスローダが自分の Runtime インスタンスを管理できるように、
velocity-XX.jar は CLASSPATH やサーブレットコンテナのトップレベルの lib
ディレクトリに置くのではなく、Velocity を使用するすべての Web アプリケーションの
WEB-INF/lib ディレクトリに置くのがよいでしょう。
</p>

<primary>
<p>
This deployment method will ensure that different web applications will
not be subject to Velocity configuration conflicts.
</p>
</primary>
<p>
この配備方法なら、異なる Web アプリケーションでの Velocity 
設定での衝突を確実に防げます。
</p>

</section>

<section name="Using Velocity In General Applications"
alias="一般的なアプリケーションで Velocity を使う">

<primary>
<p>
As Velocity was designed to be a general-use tool, it is just as useful in
general application programs as it is servlets. In general, you can use the
same programming pattern discussed at the beginning of this guide, but there
are a few utility methods provided for application use, just like we provide
the VelocityServlet base class for ease of use in servlet programming.
The only new responsibility you have as the application programmer is to
initialize the Velocity runtime engine, but that is easy.
</p>
</primary>
<p>
Velocity は汎用ツールとして設計されたので、一般的なアプリケーションプログラムでも、
サーブレットで使う場合と同様に役に立ちます。
通常はこのガイドの初めに説明したのと同じプログラミングパターンを使うことができますが、
サーブレットプログラミングで簡単に使える VelocityServlet 基本クラスを提供したのと同様に、アプリケーション用に、いくつかのユーティリティメソッドが用意されています。
アプリケーションプログラマとして追加で行なう必要があるのは Velocity
ランタイムエンジンを初期化することだけで、しかもそれは簡単です。
</p>

<primary>
<a name="The Velocity Helper Class"><strong>The Velocity Helper Class</strong></a>
</primary>
<a name="The Velocity Helper Class"><strong>Velocity ヘルパクラス</strong></a>

<primary>
<p>
Velocity contains an application utility class called Velocity
( <code>org.apache.velocity.app.Velocity</code> ).  The purpose of this class
is to provide the necessary methods required to initialize Velocity, as well as
useful utility routines to make life easier in using Velocity. This class is
documented  in the project's javadoc, so please look there for definitive
details. This documentation is intended to be of a tutorial nature; therefore
for compete API information, the Javadoc is the definitive source.
</p>
</primary>
<p>
Velocity には、Velocity（<code>org.apache.velocity.app.Velocity</code>)
と呼ばれるアプリケーションユーティリティクラスがあります。
このクラスの目的は、Velocity の初期化で必要なメソッドや Velocity
を使いやすくするのに役に立つユーティリティルーチンを提供することです。
このクラスはプロジェクトの Javadoc で文書化されていますので、より確実な詳細については、
そちらを参照してください。このドキュメンテーションは、本来チュートリアルであるため、
完璧な API 情報については、Javadoc が最も信頼できる情報源です。
</p>

<primary>
<p>
The Velocity runtime engine is a singleton instance that provides resource,
logging and other services to all Velocity users running in the same JVM.
Therefore, the runtime engine is initialized only once.  You can attempt to
initialize Velocity more than once, but only the first initialization will
apply.  The rest of the attempts will be ignored.  The Velocity utility
class currently provides five methods used in configuration of the runtime engine.
</p>
</primary>
<p>
Velocity ランタイムエンジンは、同じ JVM で実行される全ての Velocity
ユーザに対してリソース、ロギングなどのサービスを提供する Singleton インスタンスです。
したがって、ランタイムエンジンは一度だけ初期化されます。Velocity
の初期化は何度でも試せますが、適用されるのは最初の初期化のみで、他のものは無視されます。
Velocity ユーティリティクラスは、現在ランタイムエンジンの設定で使用される
5つのメソッドを提供します。
</p>

<primary>
<p>
The five configuration methods are :
</p>
</primary>
<p>
設定メソッドは以下の通りです。
</p>

<primary>
<ul>

<li><code>setProperty( String key, Object o )</code><br/>
Sets the property <code>key</code> with the value <code>o</code>. The value
is typically a String, but in special cases can also be a comma-separated
list of values (in a single String, ex."foo, bar, woogie") as well as other
things that will arise.
</li>

<li><code>Object getProperty( String key )</code><br/>
Returns the value of the property key.  Note that you must be aware of the
type of the return value, as they can be things other than Strings.
</li>

<li><code>init()</code><br/>
Initializes the runtime with the default properties provided in the
distribution.(These are listed below in the section pertaining to
properties.)
</li>

<li><code>init( Properties p )</code><br/> Initialize the runtime with the
properties contained in the <code>java.util.Properties</code> object passed
as an argument.
</li>

<li><code>init( String filename )</code><br/> initilizes the runtime
using the properties found in the properties file filename
</li>

</ul>
</primary>
<ul>

<li><code>setProperty( String key, Object o )</code><br />  
プロパティ <code>key</code> に値 <code>o</code> を設定します。
値は通常は String ですが、特殊なケースとして、
値のコンマ区切りのリスト ("foo, bar, woogie" といった
String) の可能性もありますし、他のケースも将来出てくるかもしれません。
</li>

<li><code>Object getProperty( String key )</code><br /> 
プロパティキーの値を返します。
注意: String 以外もありうるので、あなたは戻り値のタイプを
把握していなければなりません。
</li>

<li><code>init()</code><br /> 
配布で提供されるデフォルトの各プロパティでランタイムを初期化します。
(<a href="developer-guide.html#Velocity Configuration Keys and Values">プロパティに関するセクション (後述)</a>
にデフォルト値の一覧があります。）
</li>

<li><code>init( Properties p )</code><br />
引数として渡される <code>java.util.Properties</code>
オブジェクトに含まれる各プロパティでランタイムを初期化します。</li>

<li><code>init( String filename )</code><br /> 
filename で示されるプロパティファイルにある各プロパティでランタイムを初期化します。
</li>
</ul>

<primary>
<p>
Note that in each case, the default properties will be used as a base
configuration, and any additional properties specified by the application
will replace individual defaults.  Any default properties not overwritten
will remain in effect.  This has the benefit that only the properties
you are interested in changing need to be specified, rather
than a complete set.
</p>
</primary>
<p>
注意: それぞれの場合、デフォルトプロパティは、基本設定として使用され、
アプリケーションで指定された追加のプロパティはデフォルトのプロパティを上書きします。
オーバーライトされないデフォルトプロパティは全て有効となります。この方法には、
プロパティ全てでなく変更したい部分だけ指定できるという利点があります。
</p>

<primary>
<p>
Another thing to note is that the <code>init()</code> calls may be called
more than once without harm in an application.  However, the first call to any
of the <code>init()</code> functions will configure the engine with the
configuration properties set at that point, and any further configuration
changes or <code>init()</code> calls will be ignored.
</p>
</primary>
<p>
もう一点、注意事項として、 <code>init()</code> の呼び出しは、
アプリケーションに悪影響を与えずに複数回行われるかもしれません。
しかし、エンジンの設定は、最初の<code>init()</code> メソッドの呼び出しで
セットされた設定プロパティによって行われ、
それ以降の設定変更や <code>init()</code> 呼び出しは無視されます。
</p>

<primary>
<p>
The most common approaches to initializing Velocity will be something like :
</p>
</primary>
<p>
最も一般的な Velocity の初期化の方法は以下の通りです。
</p>

<primary>
<ol>
<li> Setup the configuration values you wish to set in a file in the same
format as org/apache/velocity/runtime/defaults/velocity.properties
(the default set),  or in a <code>java.util.Properties</code>, and then
call either <code>init( filename )</code> or <code>init( Properties )</code>
</li>

<li> Set the configuration values individually using <code>setProperty()</code>
and then call <code>init()</code>.  This method is generally used by more advanced
applications that already have their own configuration management system -
this allows the application so configure Velocity based upon values it generates
at runtime, for example.
</li>
</ol>
</primary>
<ol>
<li>
設定したい値を org/apache/velocity/runtime/defaults/velocity.properties（デフォルトのセット）と同じフォーマットのファイル、または <code>java.util.Properties</code>
で設定し、その上で <code>init( filename )</code> または
<code>init( Properties )</code> を呼び出します。
</li>

<li>
<code>setProperty()</code> を使って設定値を別々にセットし、それから<code>init()</code>
を呼びます。この方法は通常、すでに設定管理システムを持つ、
より高度なアプリケーションで使われます ─ この方法を使えば、
例えば実行時に生成する値に基づいてアプリケーションで Velocity
を設定できます。
</li>

</ol>

<primary>
<p>
Once the runtime is initialized, you can do with it what you wish.. This mostly
revolves around rendering templates into an output stream, and the Velocity
utility class allows you to do this easily.  Currently, here are the methods
and a brief description of what they do :
</p>
</primary>
<p>
一度ランタイムが初期化されたら、ランタイムでやりたいことができます。
その際に行なうことのほとんどは、テンプレートを処理して出力ストリームに送ることであり、
Velocity ユーティリティクラスで簡単に行なうことができます。
現状でのメソッドと処理概要の一覧は以下の通りです。
</p>

<primary>
<ul>
  <li>
     <code> evaluate( Context context,  Writer out, String logTag,
     String instring )</code><br/>
     <code>evaluate( Context context, Writer writer, String logTag,
     InputStream instream )</code><br/>
     These methods will render the input, in either the form of String or
     InputStream to an output Writer, using a Context that you provide.
     This is a very convenienient method to use for token replacement of
     strings, or if you keep 'templates' of VTL-containing content in a
     place like a database or other non-file storage, or simply generate such
     dynamically.
  </li>

  <li>
    <code>invokeVelocimacro( String vmName, String namespace, String params[],
    Context context, Writer writer )</code><br/>
    Allows direct access to Velocimacros.  This can also be accomplished
    via the <code>evaluate()</code> method above  if you wish.  Here you
    simply name the vm you wish to be called, create an array of args to the VM,
    a Context of data, and Writer for the output.  Note that the VM args
    must be the 'keys' of the data objects in the Context, rather than
    literal data to be used as the arg.  This will probably change.
  </li>

  <li>
    <code>mergeTemplate( String templateName, Context context, Writer writer )
    </code><br/>
    Convenient access to the normal template handling and rendering services
    of Velocity.  This method will take care of getting and rendering the
    template.  It will take advantage of loading the template according
    to the properties setting for the file resource loader, and therefore
    provides the advantage of file and parsed template caching that Velocity
    offers.  This is the most efficient way to access templates,
    and is recommended unless you have special needs.
  </li>

  <li>
    <code> boolean templateExists( String name ) </code><br/>
    Determines if a template <code>name</code> is able to be found by
    the currently configured resource loaders.
  </li>
</ul>
</primary>
<ul>
  <li>
     <code> evaluate( Context context,  Writer out, String logTag, 
     String instring )</code><br/>
     <code>evaluate( Context context, Writer writer, String logTag, 
     InputStream instream )</code><br/>
この2つのメソッドは、String あるいは InputStream 形式の入力を、
指定した Context を使って処理し、出力 Writer に送ります。
文字列のトークンの置換に使うとか、データベースなどファイルでないストレージに VTL
を含んだ内容の「テンプレート」を保持したり同様のデータを動的に作成したりする場合に、
非常に便利なメソッドです。
  </li>

  <li>
    <code>invokeVelocimacro( String vmName, String namespace, String params[], 
    Context context, Writer writer )</code><br />
Velocimacro (VM) に直接アクセスできます。やろうと思えば、上記の
<code>evaluate()</code> メソッドでも行なえます。このメソッドの場合は、
VMに好きな名前をつけ、VMへの引数となる配列やデータのコンテキスト、
それに出力先のWriterを生成します。注意: VM の引数は、
引数として使う文字列データではなく、Context 内のデータオブジェクトの「キー」
でなければなりません。これは将来変更される可能性があります。
  </li>

  <li>
    <code>mergeTemplate( String templateName, Context context, Writer writer )
    </code><br />
Velocity の通常のテンプレート処理サービスに簡単にアクセスできます。このメソッドは、
テンプレートの取得と処理を担当します。このメソッドには、ファイルリソースローダ向けの
プロパティ設定にしたがってテンプレートをロードできるという利点があり、それによって
Velocity が提供するファイルテンプレートおよび解析済みテンプレートのキャッシュ化という
利点が得られます。この方法はテンプレートにアクセスするのに最も効率的な方法であり、
特に必要がない限りはこの方法をお勧めします。
  </li>

  <li>
    <code> boolean templateExists( String name ) </code><br />
<code>name</code> で指定されたテンプレートが現在設定されているリソースローダで
見つけられるかどうか判定します。
  </li>

</ul>

<primary>
<p>
Once we know about these basic helpers, it is easy to write Java program
that uses Velocity.  Here it is:
</p>
</primary>
<p>
一度これらの基本ヘルパを理解すれば、Velocity を使った Java
プログラムを書くのは簡単です。
こんな感じです。
</p>

<primary>
<source><![CDATA[
import java.io.StringWriter;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.VelocityContext;

public class Example2
{
    public static void main( String args[] )
    {
        /* first, we init the runtime engine.  Defaults are fine. */

        Velocity.init();

        /* lets make a Context and put data into it */

        VelocityContext context = new VelocityContext();

        context.put("name", "Velocity");
        context.put("project", "Jakarta");

        /* lets render a template */

        StringWriter w = new StringWriter();

        Velocity.mergeTemplate("testtemplate.vm", context, w );
        System.out.println(" template : " + w );

        /* lets make our own string to render */

        String s = "We are using $project $name to render this.";
        w = new StringWriter();
        Velocity.evaluate( context, w, "mystring", s );
        System.out.println(" string : " + w );
    }
}
]]></source>
</primary>
<source><![CDATA[
import java.io.StringWriter;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.VelocityContext;

public class Example2
{
    public static void main( String args[] )
    {
        /* まず実行時エンジンを初期化する。デフォルトでよい。 */

        Velocity.init();

        /* Context を作成して、データを入れる */

        VelocityContext context = new VelocityContext();

        context.put("name", "Velocity");
        context.put("project", "Jakarta");

        /* テンプレートを処理する */

        StringWriter w = new StringWriter();

        Velocity.mergeTemplate("testtemplate.vm", context, w );
        System.out.println(" template : " + w );

        /* 処理する文字列を作成する */

        String s = "We are using $project $name to render this.";
        w = new StringWriter();
        Velocity.evaluate( context, w, "mystring", s );
        System.out.println(" string : " + w );
    }
}
]]></source>

<primary>
<p>
When we run this program, and have the template <code> testtemplate.vm</code>
in the same directory as our program (because we used the default
configuration properties, and the defaul place to load templates
from is the current directory...), our output should be :
</p>
</primary>
<p>
このプログラムを実行し、プログラムと同じディレクトリに<code>testtemplate.vm</code>
というテンプレートを置きます (デフォルトの設定プロパティを使ったため、
テンプレートをロードするデフォルトの場所は現在のディレクトリになります）。
その結果、出力は以下のようになります。
</p>

<source><![CDATA[
template : Hi!  This Velocity from the Jakarta project.

string : We are using Jakarta Velocity to render this.
]]></source>

<primary>
<p>
where the template we used, testtemplate.vm, is
</p>
</primary>
<p>
この際に使用したテンプレート（testtemplate.vm）は以下のとおりです。
</p>

<source><![CDATA[
Hi!  This $name from the $project project.
]]></source>

<primary>
<p>
That's all there is to it!  Note that we didn't have to use both
<code>mergeTemplate()</code> and <code>evaluate()</code> in our
program.  They are both included there for demonstration purposes.
You will probably use only one of the methods, but depending
on you application requirements,  you are free to do what you wish.
</p>
</primary>
 <p>
これで完了です！ プログラムで <code>mergeTemplate()</code> と <code>evaluate()</code>
の両方を使う必要はなかったことにご注意ください。両方入れたのはデモのためです。
恐らくどちらか1つだけを使うことになりますが、
アプリケーションの要件に応じて好きな処理を行なえます。
</p>

<primary>
<p>
This appears to be a little different from the 'fundamental pattern'
that was mentioned at the beginning of this guide, but it really is the
same thing.  First, you are making a context and filling it with
the data needed.  Where this examples differs is that in the part of
the above example where <code>mergeTemplate()</code> is used,
<code>mergeTemplate()</code> is doing the work of getting the template
and merging it for you, using the lower-level calls in the Runtime class.
In the second example, you are making your template dynamically via the
String, so that is analgous to the 'choose template' part of the process,
and the <code>evaluate()</code> method does the merging for you using
lower level calls.
</p>
</primary>
<p>
これはこのガイドの最初の方で説明した「基本パターン」と少し違うように見えますが、
実は同じパターンなのです。まず、コンテキストを作り、必要なデータで埋めています。
この例との違いですが、最初の例では、<code>mergeTemplate()</code> を使っている箇所で、
<code>mergeTemplate()</code> が Runtime クラスの低レベルの呼び出しを利用して、
テンプレートの取得とマージを行っています。第二の例では、
処理の「テンプレート選択」の部分に対応させるように、
String 経由で動的にテンプレートを生成し、低レベル呼び出しを行なう代わりに
<code>evaluate()</code> メソッドでマージを行っています。
</p>

<primary>
<p>
So the example above sticks to the same simply pattern of using the Velocity
template engine, but the utility functions do some of
the repeated drudge work, or allow you other options for your
template content other than template files.
</p>
</primary>
<p>
このように、上記の例では Velocity テンプレートエンジンを使用する際の
単純なパターンに合わせたわけですが、この他にも各ユーティリティメソッドは、
退屈な繰り返し作業を行ったり、
テンプレートファイル以外のテンプレート生成手段を提供したりします。
</p>

<primary>
<a name="Exceptions"><strong>Exceptions</strong></a>
</primary>
<a name="Exceptions"><strong>例外</strong></a>

<primary>
<p>
There are three exceptions that Velocity will throw during the parse / merge cycle.
This are additional to the exceptions that will come from IO problems, etc.
They are found in the package <code>org.apache.velocity.exception</code> and are:
</p>
</primary>
<p>
Velocity が、解析/マージのサイクルで投げる例外は3種類あります。これらの例外は、
I/O の問題などによる例外に追加するものです。<code>org.apache.velocity.exception</code>
パッケージにあるこれらの例外を以下に示します。
</p>

<primary>
<ol>
<li>
<code>ResourceNotFoundException</code><br/>
Thrown when the resource managment system cannot find a resource (template) that
was requested.
</li>

<li>
<code>ParseErrorException</code><br/>
Thrown when a VTL syntax error is found when parsing a resource (template).
</li>

<li>
<code>MethodInvocationException</code><br/>
Thrown when a method of object in the context thrown an exception during
render time.  This exception wraps the thrown exception and propogates it
to the application.  This allows you to handle problems in your own objects
at runtime.
</li>
</ol>
</primary>
<ol>
<li>
<code>ResourceNotFoundException</code><br />
リソース管理システムが要求されたリソース (テンプレート)
を見つけられない時に投げられます。
</li>

<li>
<code>ParseErrorException</code><br />
リソース (テンプレート) を解析するとき、VTL 構文エラーが見つかった時に投げられます。
</li>

<li>
<code>MethodInvocationException</code><br />
処理時にコンテキスト内のオブジェクトのメソッドで例外が投げられた場合に投げられます。
この例外は投げられた例外をラップしてアプリケーションに伝搬するためのものです。
これを使えば固有のオブジェクトで実行時に起こった問題を扱うことができます。
</li>

</ol>

<primary>
<p>
In each case, a message is put into the runtime log.  For more information,
see the Javadoc API documentation.
</p>
</primary>
<p>
どの場合でもメッセージはランタイムログに入ります。
詳細は、Javadoc API ドキュメンテーションをご覧下さい。
</p>

<primary>
<a name="Miscellaneous Details"><strong>Miscellaneous Details</strong></a>
</primary>
<a name="Miscellaneous Details"><strong>その他雑記</strong></a>

<primary>
<p>
While the above example used the default properties, setting your own
properties is very simple. All you have to do is make a properties file
somewhere and pass the name of that file to the <code>init(String)</code>
method of the Velocity utility class, or make a
<code>java.util.Properties</code> object, add the desired properties and
values, and pass that to the <code>init(Properties)</code> method.
The latter method is convenient, because you can either fill it directly
from a separate properties file via the <code>load()</code>  method, or even
better, you can fill it dynamically from your own application / framework's
property set at runtime.  This gives you the freedom to combine all of the
properties for your app into one properties file.
</p>
</primary>
<p>
上記の例ではデフォルトのプロパティが使われていましたが、
固有のプロパティ設定はとても簡単です。どこかにプロパティファイルを作り、
そのファイル名を Velocity ユーティリティクラスの <code>init(String)</code>
メソッドに渡す方法と、<code>java.util.Properties</code> オブジェクトを作り、
好きなプロパティと値を加え、それを <code>init(Properties)</code>
メソッドに渡す方法があります。後者の方法の方が便利です。
というのは、<code>load()</code> メソッドを使って、
別々のプロパティファイルから直接設定したり、
もっといい方法として、実行時にアプリケーション/フレームワークの
プロパティセットから動的に設定することができるからです。
これによって、自分のアプリのプロパティ全てを、
1つのプロパティファイルにまとめることができるのです。
</p>

<primary>
<p>
If we wanted to use a different directory than the current directory to
load our template from, we could do something like this :
</p>
</primary>
<p>
テンプレートをロードするのにカレントディレクトリ以外のディレクトリを使いたい場合には、
以下のようにもできます。
</p>

<primary>
<source><![CDATA[
 ...

import java.util.Properties;
 ...

public static void main( String args[] )
{
    /* first, we init the runtime engine.  */

    Properties p = new Properties();
    p.setProperty("file.resource.loader.path", "/opt/templates");
    Velocity.init( p );

    /* lets make a Context and put data into it */

 ...
]]></source>
</primary>
<source><![CDATA[
 ...

import java.util.Properties;
 ...

public static void main( String args[] )
{
    /* まずは、実行エンジンを初期化する  */

    Properties p = new Properties();
    p.setProperty("file.resource.loader.path", "/opt/templates");
    Velocity.init( p );

    /* Contextを作ってデータを入れる */

 ...
]]></source>

<primary>
<p>
And, assuming you have a directory <code>/opt/templates</code> and the template
<code>testtemplate.vm</code> is in there, then things would work just fine.
If you try this and have a problem, be sure to look at the velocity.log for
information - the error messages are pretty good for figuring out what is wrong.
</p>
</primary>
<p>
ディレクトリ <code>/opt/templates</code> があり、そこにテンプレート
<code>testtemplate.vm</code> がある場合に、これはうまく動きます。
これを試して問題があるなら、情報を得るために velocity.log をチェックして下さい ─
エラーメッセージは何がおかしいか理解するためにかなり役立ちます。
</p>

</section>

<section name="Application Attributes" alias="アプリケーション属性">
<primary>
<p>
<i>Application Attributes</i> are name-value pairs that can be associated with
a RuntimeInstance (either via the <code>VelocityEngine</code> or
the <code>Velocity</code> singleton) and accessed from any part of the Velocity
engine that has access to the RuntimeInstance.
</p>
</primary>
<p>
<i>アプリケーション属性</i> は、(<code>VelocityEngine</code>、
<code>Velocity</code> Singleton のどちらかを経由して) RuntimeInstance 
に関連付けられる名前と値のペアです。RuntimeInstance にアクセスできる VeclocityEngine
のどの部分からでもアクセスできます。
</p>

<primary>
<p>
This feature was designed for applications that need to communicate between
the application layer and custom parts of the Velocity engine, such as
loggers, resource loaders, resource managers, etc.
</p>
</primary>
<p>
この機能は、アプリケーションレイヤと Velocity エンジンのカスタムの部分
(ロガー、リソースローダ、リソースマネージャなど)
の間でのデータの受け渡しが必要なアプリケーションのために用意しました。
</p>

<primary>
<p>
The Application Attribute API is very simple.  From the application layer, there
is a method of the <code>VelocityEngine</code> and the <code>Velocity</code>
classes :
</p>
</primary>
<p>
アプリケーション属性 API は非常に単純です。
アプリケーションからアクセスするメソッドとしては、<code>VelocityEngine</code> と
<code>Velocity</code> クラスに以下のメソッドがあります。
</p>

<source>
<![CDATA[
    public void setApplicationAttribute( Object key, Object value );
]]>
</source>

<primary>
<p>
through which an application can store on Object under an application (or
internal component) specified key.  There are no restrictions on the key
or the value.  The value for a key may be set at any time - it is not required
that this be set before init() is called.
</p>
</primary>
<p>
このメソッドを使うと、アプリケーション (または内部コンポーネント)
固有のキーで Object を保存できます。キーや値に制限はありません。
キーの値はいつでも設定できます ─ init() が呼ばれる前に設定する必要はありません。
</p>

<primary>
<p>
Internal components can access the key-value pairs if they have access to the
object via the <code>RuntimeServices</code> interface, using the method
</p>
</primary>
<p>
内部コンポーネントが <code>RuntimeServices</code>
インタフェース経由でオブジェクトにアクセスする場合は、以下のメソッドを使って、
キーと値のペアにアクセスできます。
</p>

<source>
<![CDATA[
    public Object getApplicationAttribute( Object key );
]]>
</source>

<primary>
<p>
Note that internal components cannot set the value of the key, just get it.
if the internal component must communicate information to the application layer,
it must do so via the Object passed as the value.
</p>
</primary>
<p>
内部コンポーネントではキーの値の取得はできても、設定はできないことに注意して下さい。
内部コンポーネントがアプリケーションと情報の受け渡しをしなければならない場合は、
値として渡される Object 経由でなければなりません。
</p>
</section>

<section name="EventCartridge and Event Handlers"
alias="EventCartridge とイベントハンドラ">

<primary>
<p>
Starting in version 1.1, a fine-grain event handling system was added to Velocity.
The EventCartridge is a class in which you register your event handlers, and then the
EventCartridge acts as the delivery agent from which the Velocity engine will
access the event handlers at merge time if needed.
Currently, there are 3 events that can be handled, and all are found in the
<code>org.apache.velocity.app.event</code> package.
</p>
</primary>
<p>
バージョン 1.1 から、Velocity にきめの細かいイベントハンドリングシステムが追加されました。
EventCartridge はイベントハンドラを登録するためのクラスで、さらに、
必要ならば、マージ時に登録したイベントハンドラにアクセスするための
デリバリエージェントとしても動作します。
現在、ハンドルできるイベントは3つで、すべて <code>org.apache.velocity.app.event</code>
パッケージにあります。
</p>

<primary>
<p>
<i><code>org.apache.velocity.app.event.NullSetEventHandler</code></i>

<blockquote>
When a #set() results in a null assignment, this is normally
logged.  The <code>NullSetEventHandler</code> allows you to 'veto' the
logging of this condition.
<br/>
<pre>
public interface NullSetEventHandler extends EventHandler
{
    public boolean shouldLogOnNullSet( String lhs, String rhs );
}
</pre>
</blockquote>

<i><code>org.apache.velocity.app.event.ReferenceInsertionEventHandler</code></i>
<blockquote>
A <code>ReferenceInsertionEventHandler</code> allows the
developer to intercept each write of a reference ($foo) value to the output
stream and modify that output.
<pre>
public interface  ReferenceInsertionEventHandler extends EventHandler
{
    public Object referenceInsert( String reference, Object value  );
}
</pre>
</blockquote>

<i><code>org.apache.velocity.app.event.MethodExceptionEventHandler</code></i>
<blockquote>
When a user-supplied method throws an exception, the
<code>MethodExceptionEventHandler</code> is invoked with the Class, method name
and thrown Exception.  The handler can either return a valid Object to be used
as the return value of the method call, or throw the passed-in or new Exception,
which will be wrapped and propogated to the user as a
<code>MethodInvocationException</code>
<pre>
public interface MethodExceptionEventHandler extends EventHandler
{
    public Object methodException( Class claz, String method, Exception e )
         throws Exception;
}
</pre>
</blockquote>
</p>
</primary>
<p>
<i><code>org.apache.velocity.app.event.NullSetEventHandler</code></i>

<blockquote>
#set() で null が代入された場合、通常はログに記録されます。
<code>NullSetEventHandler</code> を使うと、こうした場合にロギングを「拒否」できます。
<br/>
<pre>
public interface NullSetEventHandler extends EventHandler
{
    public boolean shouldLogOnNullSet( String lhs, String rhs );
}   
</pre>
</blockquote>

<i><code>org.apache.velocity.app.event.ReferenceInsertionEventHandler</code></i>
<blockquote>

<code>ReferenceInsertionEventHandler</code> を使うと、リファレンス ($foo) の値の
出力ストリームへの書き出しに割り込んで、出力内容を変更できます。

<pre>
public interface  ReferenceInsertionEventHandler extends EventHandler
{
    public Object referenceInsert( String reference, Object value  );
}
</pre>
</blockquote>

<i><code>org.apache.velocity.app.event.MethodExceptionEventHandler</code></i>
<blockquote>
ユーザが作成したメソッドから例外が投げられた時に、
<code>MethodExceptionEventHandler</code> が、関連する Class やメソッド名、
投げられた例外とともに起動します。このハンドラは、メソッド呼び出しの返り値
として使われる使われる有効なオブジェクトを返すか、
引数として渡された例外、あるいは新しい例外を投げます。新しい例外の場合は、
<code>MethodInvocationException</code> としてラップされてユーザに伝搬されます。

<pre>
public interface MethodExceptionEventHandler extends EventHandler
{
    public Object methodException( Class claz, String method, Exception e )
         throws Exception;
}
</pre>
</blockquote>
</p>

<primary>
<p>
<strong>Using the EventCartridge</strong>
</p>
</primary>
<p>
<strong>EventCartridge の使い方</strong>
</p>

<primary>
<p>
Using the EventCartridge is fairly straightforward.  The following abbreviated
example was taken from <code>org.apache.velocity.test.misc.Test</code>.
</p>
</primary>
<p>
EventCartridge の使い方はとても簡単です。
以下の例は、<code>org.apache.velocity.test.misc.Test</code> から抜粋したものです。
</p>

<primary>
<source><![CDATA[
 ...

import org.apache.velocity.app.event.EventCartridge;
import org.apache.velocity.app.event.ReferenceInsertionEventHandler;
import org.apache.velocity.app.event.MethodExceptionEventHandler;
import org.apache.velocity.app.event.NullSetEventHandler;

 ...

public class Test implements ReferenceInsertionEventHandler,
                             NullSetEventHandler,
                             MethodExceptionEventHandler
{
    public void myTest()
    {
        ....

        /*
         *  now, it's assumed that Test implements the correct methods to
         *  support the event handler interfaces.  So to use them, first
         *  make a new cartridge
         */
        EventCartridge ec = new EventCartridge();

        /*
         * then register this class as it contains the handlers
         */
        ec.addEventHandler(this);

        /*
         * and then finally let it attach itself to the context
         */
        ec.attachToContext( context );

        /*
         * now merge your template with the context as you normally
         * do
         */

        ....
    }

    /*
     *  and now the implementations of the event handlers
     */
    public Object referenceInsert( String reference, Object value  )
    {
        /*  do something with it */
        return value;
    }

    public boolean shouldLogOnNullSet( String lhs, String rhs )
    {
        if ( /* whatever rule */ )
            return false;

        return true;
    }

    public Object methodException( Class claz, String method, Exception e )
         throws Exception
    {
        if ( /* whatever rule */ )
           return "I should have thrown";

        throw e;
    }
}
]]></source>
</primary>
<source><![CDATA[
 ...

import org.apache.velocity.app.event.EventCartridge;
import org.apache.velocity.app.event.ReferenceInsertionEventHandler;
import org.apache.velocity.app.event.MethodExceptionEventHandler;
import org.apache.velocity.app.event.NullSetEventHandler;

 ...

public class Test implements ReferenceInsertionEventHandler, 
                             NullSetEventHandler,
                             MethodExceptionEventHandler
{
    public void myTest()
    {
        ....

        /*
         * ここでは、Test クラスは、イベントハンドラインタフェースを
         * サポートするように正しいメソッドを実装していると仮定します。
         * これらを使うにはまず、カートリッジを新しく作ります。
         */
        EventCartridge ec = new EventCartridge();
         
        /*
         * そして、このクラスをハンドラに収容するように登録します
         */
        ec.addEventHandler(this);
           
        /*
         * 最後に カートリッジそのものをコンテキストに取り付けます。
         */
        ec.attachToContext( context );

        /*
         * あとは、いつものようにコンテキストをテンプレートにマージします。
         */

        ....
    }
      
    /*
     *  ここで、イベントハンドラの実装を行ないます。
     */
    public Object referenceInsert( String reference, Object value  )
    {
        /*  リファレンスを使って何かします */
        return value;
    }

    public boolean shouldLogOnNullSet( String lhs, String rhs )
    {
        if ( /* 何らかのルール */ )
            return false;
        
        return true;
    }

    public Object methodException( Class claz, String method, Exception e )
         throws Exception
    {
        if ( /* 何らかのルール */ )
           return "I should have thrown";

        throw e;
    }
}
]]></source>

</section>

<section name="Velocity Configuration Keys and Values"
alias="Velocity 設定キーと値">

<primary>
<p>
Velocity's runtime configuration is controlled by a set of configuration keys
listed below.  Generally, these keys will have values that consist of either a
String, or a comma-separated list of Strings, referred to as a CSV for
comma-separated values.
</p>
</primary>
<p>
Velocity の実行時構成は、以下の一覧にある各設定キーで制御します。
通常、これらのキーは String の値、あるいは CSV (Comma Separated Values)
と呼ばれるコンマ区切りの String のリストの値を持ちます。
</p>

<primary>
<p>
There is a set of default values contained in Velocity's jar, found in
/src/java/org/apache/velocity/runtime/defaults/velocity.defaults, that
Velocity uses as it's configuration baseline.
This ensures that Velocity will always have a 'correct' value
for it's configuration keys at startup, although it may not be what you want.
</p>
</primary>
<p>
各デフォルト値は Velocity の JAR ファイルに含まれており、ソースとしては
/src/Java/org/apache/velocity/runtime/defaults/velocity.defaults にあり、
Velocity はこれらを設定のベースラインとして使います。
これにより、 Velocity の起動時に設定キーに常に「正しい」値が入っていることが
保証されますが、それはあなたが求めている値だとは限りません。
</p>

<primary>
<p>
Any values specified before init() time will replace the  default values.
Therefore, you only have toconfigure velocity with the values for the keys
that you need to change, and not worry about the rest.  Further, as we add more
features and configuration capability, you don't have to change your
configuration files to suit - the Velocity engine will always have default
values.
</p>
</primary>
<p>
init() の実行前に値を指定すると、デフォルトの値を置き換えられます。
したがって、Velocity では変更が必要なキーの値だけを設定すればよく、それ以外は
気にする必要はありません。さらに、設定関連を含めて多くの機能が追加されても、
それに合わせて設定ファイルを変更する必要はありません ─ Velocity エンジンは、
常にデフォルト値を持っているからです。
</p>

<primary>
<p>
Please sees the section above <a href="developer-guide.html#Using
Velocity In General Applications"><b>Using Velocity In General
Applications</b></a> for discussion on the configuration API.
</p>
</primary>
<p>
設定 API についての詳細は上のセクション
<a href="developer-guide.html#Using Velocity In General Applications"><b>一般的なアプリケーションで Velocity を使う </b></a> を参照してください。
</p>

<primary>
<p>
Below are listed the configuration keys that control Velocity's behavior.
Organized by category, each key is listed with it's current default value
to the right of the '=' sign.
</p>
</primary>
<p>
Velocity の動作を制御する設定キーの一覧は以下の通りです。
各キーはカテゴリ別に分類され、「=」記号の後に現在のデフォルト値を示しています。
</p>

<primary>
<p>
<strong>Runtime Log</strong>
</p>
</primary>
<p>
<strong>Runtime Log</strong>
</p>

<primary>
<p>
<code>runtime.log = velocity.log</code><br/>
Full path and name of log file for error, warning,
and informational messages.  The location, if not absolute, is
relative to the 'current directory'.
</p>
</primary>
<p>
<code>runtime.log = velocity.log</code><br />
エラー、警告、情報に関するメッセージのためのログファイルのフルパスと名前。
格納場所は、絶対パスでなければ、「カレントディレクトリ」の相対パスとなります。
</p>

<primary>
<p>
<code>runtime.log.logsystem</code><br/>
This property has no default value.  It is used to give Velocity an
instantiated instance of a logging class that supports the interface
<code>org.apache.velocity.runtime.log.LogSystem.</code>, which allows
the combination of Velocity log messages with your other application
log messages.  Please see the section
<a href="developer-guide.html#Configuring the Log System">Configuring the Log System</a>
for more information.
</p>
</primary>
<p>
<code>runtime.log.logsystem</code><br />
このプロパティには、デフォルトの値がありません。このキーは Velocity でロギングクラス
のインスタンスを使うのに使用します。ロギングクラスは 
<code>org.apache.velocity.runtime.log.LogSystem</code> インタフェースをサポートします。
このインタフェースを使えば、 Velocity のログメッセージと
アプリケーションのログメッセージを同じログに入れることができます。詳細は、
<a href="developer-guide.html#Configuring the Log System">一般的なアプリケーションで
Velocity を使う</a> のセクションをご覧ください。
</p>

<primary>
<p>
<code>runtime.log.logsystem.class =
org.apache.velocity.runtime.log.AvalonLogSystem</code><br/>
Class to be used for the Velocity-instantiated log system.
</p>
</primary>
<p>
<code>runtime.log.logsystem.class = 
org.apache.velocity.runtime.log.AvalonLogSystem</code><br/>
Velocity がインスタンス化したログシステムで使用されるクラスです。
</p>

<primary>
<p>
<code>runtime.log.error.stacktrace = false</code><br/>
<code>runtime.log.warn.stacktrace = false</code><br/>
<code>runtime.log.info.stacktrace = false</code><br/>
Turns on stacktracing for the three error categories.
These produce a large amount of log output.
</p>
</primary>
<p>
<code>runtime.log.error.stacktrace = false</code><br/>
<code>runtime.log.warn.stacktrace = false</code><br/>
<code>runtime.log.info.stacktrace = false</code><br/>
true にすると、これらのエラーカテゴリーのスタックトレースを有効にします。
これは大量のログを生成します。
</p>

<primary>
<p>
<code>runtime.log.invalid.references = true </code><br/>
Property to turn off the log output when a reference isn't valid.
Good thing to turn of in production, but very valuable
for debugging.
</p>
</primary>
<p>
<code>runtime.log.invalid.references = true </code><br/>
false にすると、リファレンスが無効な場合もログ出力されません。
本番環境では false にすると良いのですが、
デバッグ時には [trueにしておくと] とても役立ちます。
</p>
 
<primary>
<p>
<code>runtime.log.logsystem.avalon.logger = <i>name</i> </code><br/>
Allows user to specify an existing logger <i>name</i>
in the Avalon hierarchy
without having to wrap with a LogSystem interface.  <b>Note:</b>
You must also specify
<code>runtime.log.logsystem.class =
org.apache.velocity.runtime.log.AvalonLogSystem</code> as the default
logsystem may change.  There is <b>no</b> guarantee that the Avalon
log system will remain the default log system.
</p>
</primary>
<p> 
<code>runtime.log.logsystem.avalon.logger = <i>name</i> </code><br/> 
これを使うと、ユーザは Avalon 階層内の既存のロガーを LogSystem インタフェースで
ラップしなくても <i>name</i> で指定できます。
<b>注意:</b> デフォルトのログシステムは変更される可能性があるため、この設定とともに
<code>runtime.log.logsystem.class = 
org.apache.velocity.runtime.log.AvalonLogSystem</code> と指定しなければ
なりません。また Avalon ログシステムが将来もデフォルトのログシステムであることは
<b>保証されていません</b>。
</p>

<primary>
<p>
<strong>Character Encoding</strong>
</p>
</primary>
<p>
<strong>文字エンコーディング</strong>
</p>

<primary>
<p>
<code>input.encoding = ISO-8859-1</code><br/>
Character encoding for input (templates).  Using this, you can use
alternative encoding for your templates, such as UTF-8.
</p>
</primary>
<p>
<code>input.encoding = ISO-8859-1</code><br/>
入力 (テンプレート) の文字エンコーディングを指定します。
これを使うと、テンプレートで UTF-8 といった別のエンコーディングを使用できます。
</p>

<primary>
<p>
<code>output.encoding = ISO-8859-1</code><br/>
Character encoding for output streams from the VelocityServlet and Anakia.
</p>
</primary>
<p>
<code>output.encoding = ISO-8859-1</code><br/>
VelocityServlet と Anakia からの出力ストリームのための文字エンコーディング
</p>

<primary>
<p>
<strong>#foreach() Directive</strong>
</p>
</primary>
<p>
<strong>#foreach() 指示子</strong>
</p>

<primary>
<p>
<code>directive.foreach.counter.name = velocityCount</code><br/>
Used in the #foreach() directive, defines the string to be used as the
context key for the loop count. A template would access
the loop count as $velocityCount.
</p>
</primary>
<p>
<code>directive.foreach.counter.name = velocityCount</code><br/>
#foreach() 指示子で使用され、ループカウントのためのコンテキストキー
として使用される文字列を定義します。テンプレートでは、このループカウントに
$velocityCount でアクセスできます。
</p>

<primary>
<p>
<code>directive.foreach.counter.initial.value = 1</code><br/>
Default starting value for the loop counter reference in a #foreach() loop.
</p>
</primary>
<p>
<code>directive.foreach.initial.value = 1</code><br/>
#foreach() ループでのループカウンタリファレンスのためのデフォルトの開始値
</p>

<primary>
<p>
<strong>#include() and #parse() Directive</strong>
</p>
</primary>
<p>
<strong>#include() と #parse() 指示子</strong>
</p>

<primary>
<p>
<code>directive.include.output.errormsg.start
= <![CDATA[ <!-- include error : ]]> </code><br/>
<code>directive.include.output.errormsg.end
=  <![CDATA[ see error log --> ]]></code><br/>
Defines the beginning and ending tags for an in-stream error message in the
case of a problem with the #include() directive. If both the .start and .end
tags are defined, an error message will be output to the stream, of the
form '.start msg .end' where .start and .end refer to the property values.
Output to the render stream will only occur if b