You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by he...@apache.org on 2006/05/26 11:19:13 UTC
svn commit: r409603 [3/4] - in /jakarta/velocity/docbook/trunk: ./ lib/ src/
src/css/ src/css/html/ src/docbook/ src/docbook/userguide/ src/images/
src/styles/ src/styles/html/ src/styles/pdf/ src/zip/
Added: jakarta/velocity/docbook/trunk/src/docbook/userguide/VelocityUsersGuide.xml
URL: http://svn.apache.org/viewvc/jakarta/velocity/docbook/trunk/src/docbook/userguide/VelocityUsersGuide.xml?rev=409603&view=auto
==============================================================================
--- jakarta/velocity/docbook/trunk/src/docbook/userguide/VelocityUsersGuide.xml (added)
+++ jakarta/velocity/docbook/trunk/src/docbook/userguide/VelocityUsersGuide.xml Fri May 26 02:19:10 2006
@@ -0,0 +1,2070 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
+"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
+
+<!--
+ Copyright 2006 The Apache Software Foundation.
+
+ Licensed under the Apache License, Version 2.0 (the "License")
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<book lang="en">
+ <title>Velocity User Guide</title>
+
+ <bookinfo>
+ <copyright>
+ <year>2006</year>
+
+ <holder>The Apache Software Foundation</holder>
+ </copyright>
+
+ <releaseinfo>Version 1.5</releaseinfo>
+
+ <productname>Velocity</productname>
+
+ <authorgroup>
+ <corpauthor>The Jakarta Velocity Developers</corpauthor>
+ </authorgroup>
+
+ <mediaobject>
+ <imageobject>
+ <imagedata fileref="images/logo.png"/>
+ </imageobject>
+ </mediaobject>
+ </bookinfo>
+
+ <toc/>
+
+ <chapter id="chapter-preface">
+ <title>Preface</title>
+
+ <section id="section-about-this-guide">
+ <title>About this Guide</title>
+
+ <para>The Velocity User Guide is intended to help page designers and
+ content providers get acquainted with Velocity and the syntax of its
+ simple yet powerful scripting language, the Velocity Template Language
+ (VTL). Many of the examples in this guide deal with using Velocity to
+ embed dynamic content in web sites, but all VTL examples are equally
+ applicable to other pages and templates.</para>
+
+ <para>Thanks for choosing Velocity!</para>
+ </section>
+
+ <section id="section-acknowledgements">
+ <title>Acknowledgements</title>
+
+ <para>This guide has been compiled from the xdoc Version which was
+ included with Velocity up to version 1.4. We explicitly acknowledge the
+ efforts of Jason Van Zyl and John Castura in preparing this first
+ version.</para>
+ </section>
+
+ <section id="section-feedback">
+ <title>Feedback</title>
+
+ <para>If you encounter any mistakes in this manual or have other
+ feedback related to the Velocity User Guide, please email the Velocity
+ user list. Thanks!</para>
+ </section>
+ </chapter>
+
+ <chapter id="chapter-what-is-velocity">
+ <title>What is Velocity?</title>
+
+ <para>Velocity is a Java-based template engine. It permits web page
+ designers to reference methods defined in Java code. Web designers can
+ work in parallel with Java programmers to develop web sites according to
+ the Model-View-Controller (MVC) model, meaning that web page designers can
+ focus solely on creating a well-designed site, and programmers can focus
+ solely on writing top-notch code. Velocity separates Java code from the
+ web pages, making the web site more maintainable over the long run and
+ providing a viable alternative to Java Server Pages (JSPs) or PHP.</para>
+
+ <para>Velocity can be used to generate web pages, SQL, PostScript and
+ other output from templates. It can be used either as a standalone utility
+ for generating source code and reports, or as an integrated component of
+ other systems. When complete, Velocity will provide template services for
+ the Turbine web application framework. Velocity+Turbine will provide a
+ template service that will allow web applications to be developed
+ according to a true MVC model.</para>
+ </chapter>
+
+ <chapter id="chapter-what-can-velocity-do-for-me">
+ <title>What can Velocity do for me?</title>
+
+ <section id="section-the-fruit-store-example">
+ <title>The Fruit Store Example</title>
+
+ <para>Suppose you are a page designer for an online store that
+ specializes in selling fruits. Let's call it <emphasis>The Online Fruit
+ Store</emphasis>. Customers place orders for various types and
+ quantities of fruits. They login to your site using their username and
+ password, which allows them to view their orders and buy more fruits.
+ Right now, apples on sale, which are very popular. A minority of your
+ customers regularly buy mangos, which are also on sale, though not as
+ popular and usually relegated to the margin of your web page.
+ Information about each customer is tracked in your database, so one day
+ the question arises, Why not use Velocity to target special deals on
+ fruit to the customers who are most interested in those types of
+ fruits?</para>
+
+ <para>Velocity makes it easy to customize web pages to your online
+ visitors. As a web site designer at <emphasis>The Online Fruit
+ Store</emphasis>, you want to make the web page that the customer will
+ see after logging into your site.</para>
+
+ <para>You meet with software engineers at your company, and everyone has
+ agreed that <literal>$customer</literal> will hold information
+ pertaining to the customer currently logged in, that
+ <literal>$fruitSpecial</literal> will be all the types of fruit on sale
+ at present. The <literal>$promoTool</literal> object contains methods
+ that help with promotion. For the task at hand, let's concern ourselves
+ only with these three references. Remember, you don't need to worry
+ about how the software engineers extract the necessary information from
+ the database, you just need to know that it works. This lets you get on
+ with your job, and lets the software engineers get on with
+ theirs.</para>
+
+ <para>You could embed the following VTL statement in the web
+ page:</para>
+
+ <programlisting><html><body>
+Hello $customer.Name!
+<table>
+ #foreach( $fruit in $fruitSpecial )
+ #if ( $customer.hasPurchased($fruit) )
+ <tr>
+ <td>
+ $promoTool.getPromo($fruit)
+ </td>
+ </tr>
+ #end
+ #end
+</table>
+</body></html></programlisting>
+
+ <para>The exact details of the <literal>#foreach</literal> and
+ <literal>#if</literal> statement will be described in greater depth
+ shortly; what's important is the impact this short script may have on
+ your web site. When a customer with a penchant for mangos logs in, and
+ mangos are on sale, that is what this customer will see, prominently
+ displayed. If another customer with a long history of apple purchases
+ logs in, the notice of an apple sale will be front and center. The
+ flexibility of Velocity is enormous and limited only by your
+ creativity.</para>
+
+ <para>Documented in the VTL Reference Manual are the many other Velocity
+ elements, which collectively give you the power and flexibility you need
+ to make your web site a web <emphasis>presence</emphasis>. As you get
+ more familiar with these elements, you will begin to unleash the power
+ of Velocity.</para>
+ </section>
+ </chapter>
+
+ <chapter id="chapter-velocity-template-language-introduction">
+ <title>Velocity Template Language (VTL): An Introduction</title>
+
+ <para>The <firstterm>Velocity Template Language</firstterm>
+ (<firstterm>VTL</firstterm>) is meant to provide an easy, simple and clean
+ way to incorporate dynamic content in a web page. Even a web page
+ developer with little or no programming experience should soon be capable
+ of using VTL to incorporate dynamic content in a web site.</para>
+
+ <para>VTL uses <firstterm>references</firstterm> to embed dynamic content
+ in a web site, and a variable is one type of reference. Variables are one
+ type of reference that can refer to something defined in the Java code, or
+ it can get its value from a VTL <firstterm>statement</firstterm> in the
+ web page itself. Here is an example of a VTL statement that could be
+ embedded in an HTML document:</para>
+
+ <programlisting>#set( $a = "Velocity" )</programlisting>
+
+ <para>This VTL statement, like all VTL statements, begins with the
+ <literal>#</literal> character and contains a directive:
+ <literal>set</literal>. When an online visitor requests your web page, the
+ Velocity Templating Engine will search through your web page to find all
+ <literal>#</literal> characters, then determine which mark the beginning
+ of VTL statements, and which of the <literal>#</literal> characters that
+ have nothing to do with VTL.</para>
+
+ <para>The <literal>#</literal> character is followed by a directive,
+ <literal>set</literal>. The <literal>set</literal> directive uses an
+ expression (enclosed in brackets) -- an equation that assigns a
+ <firstterm>value</firstterm> to a <firstterm>variable</firstterm>. The
+ variable is listed on the left hand side and its value on the right hand
+ side; the two are separated by an <literal>=</literal> character.</para>
+
+ <para>In the example above, the variable is <literal>$a</literal> and the
+ value is <literal>Velocity</literal>. This variable, like all references,
+ begins with the <literal>$</literal> character. String values are always
+ enclosed in quotes, either single or double quotes. Single quotes will
+ ensure that the quoted value will be assigned to the reference as is.
+ Double quotes allow you to use velocity references and directives to
+ interpolate, such as <literal>"Hello $name"</literal>, where the
+ <literal>$name</literal> will be replaced by the current value before that
+ string literal is assigned to the left hand side of the
+ <literal>=</literal>.</para>
+
+ <para>The following rule of thumb may be useful to better understand how
+ Velocity works: References begin with <literal>$</literal> and are used to
+ get something. Directives begin with <literal>#</literal> and are used to
+ do something.</para>
+
+ <para>In the example above, <literal>#set</literal> is used to assign a
+ value to a variable. The variable, <literal>$a</literal>, can then be used
+ in the template to output <literal>Velocity</literal>.</para>
+ </chapter>
+
+ <chapter id="chapter-hello-velocity-world">
+ <title>Hello Velocity World!</title>
+
+ <para>Once a value has been assigned to a variable, you can reference the
+ variable anywhere in your HTML document. In the following example, a value
+ is assigned to <literal>$foo</literal> and later referenced.</para>
+
+ <programlisting><html><body>
+#set( $foo = "Velocity" )
+Hello $foo World!
+</body></html></programlisting>
+
+ <para>The result is a web page that reads</para>
+
+ <programlisting>Hello Velocity World!</programlisting>
+
+ <para>To make statements containing VTL directives more readable, we
+ encourage you to start each VTL statement on a new line, although you are
+ not required to do so. The <literal>set</literal> directive will be
+ revisited in greater detail later on.</para>
+ </chapter>
+
+ <chapter id="chapter-comments">
+ <title>Comments</title>
+
+ <para>Comments allows descriptive text to be included that is not placed
+ into the output of the template engine. Comments are a useful way of
+ reminding yourself and explaining to others what your VTL statements are
+ doing, or any other purpose you find useful. Below is an example of a
+ comment in VTL.</para>
+
+ <programlisting>## This is a single line comment.</programlisting>
+
+ <para>A single line comment begins with <literal>##</literal> and finishes
+ at the end of the line. If you're going to write a few lines of
+ commentary, there's no need to have numerous single line comments.
+ Multi-line comments, which begin with <literal>#*</literal> and end with
+ <literal>*#</literal>, are available to handle this scenario.</para>
+
+ <programlisting>This is text that is outside the multi-line comment.
+Online visitors can see it.
+
+#*
+ Thus begins a multi-line comment. Online visitors won't
+ see this text because the Velocity Templating Engine will
+ ignore it.
+*#
+
+Here is text outside the multi-line comment; it is visible.</programlisting>
+
+ <para>Here are a few examples to clarify how single line and multi-line
+ comments work:</para>
+
+ <programlisting>This text is visible. ## This text is not.
+This text is visible.
+This text is visible. #* This text, as part of a multi-line
+comment, is not visible. This text is not visible; it is also
+part of the multi-line comment. This text still not
+visible. *# This text is outside the comment, so it is visible.
+## This text is not visible.</programlisting>
+
+ <para>There is a third type of comment, the VTL comment block, which may
+ be used to store such information as the document author and versioning
+ information:</para>
+
+ <programlisting>#**
+This is a VTL comment block and
+may be used to store such information
+as the document author and versioning
+information:
+@author
+@version 5
+*#</programlisting>
+ </chapter>
+
+ <chapter id="chapter-references">
+ <title>References</title>
+
+ <para>There are three types of references in the VTL:
+ <firstterm>variables</firstterm>, <firstterm>properties</firstterm> and
+ <firstterm>methods</firstterm>. As a designer using the VTL, you and your
+ engineers must come to an agreement on the specific names of references so
+ you can use them in your templates.</para>
+
+ <para>Everything coming to and from a reference is treated as a String
+ object. If there is an object that represents <literal>$foo</literal>
+ (such as an Integer object), then Velocity will call its
+ <literal>.toString()</literal> method to resolve the object into a
+ String.</para>
+
+ <section id="section-variables">
+ <title>Variables</title>
+
+ <para>The shorthand notation of a variable consists of a leading "$"
+ character followed by a VTL <firstterm>Identifier</firstterm>. A VTL
+ Identifier must start with an alphabetic character (a .. z or A .. Z).
+ The rest of the characters are limited to the following types of
+ characters:</para>
+
+ <para><itemizedlist spacing="compact">
+ <listitem>
+ <para>alphabetic (a .. z, A .. Z)</para>
+ </listitem>
+
+ <listitem>
+ <para>numeric (0 .. 9)</para>
+ </listitem>
+
+ <listitem>
+ <para>hyphen ("-")</para>
+ </listitem>
+
+ <listitem>
+ <para>underscore ("_")</para>
+ </listitem>
+ </itemizedlist></para>
+
+ <para>Here are some examples of valid variable references in the
+ VTL:</para>
+
+ <programlisting>$foo
+$bar
+$foo-bar
+$foo_bar
+$fooBar1</programlisting>
+
+ <para>When VTL references a variable, such as <literal>$foo</literal>,
+ the variable can get its value from either a <literal>set</literal>
+ directive in the template, or from Java code. For example, if the Java
+ variable <literal>$foo</literal> has the value <literal>bar</literal> at
+ the time the template is requested, <literal>bar</literal> replaces all
+ instances of <literal>$foo</literal> on the web page. Alternatively, if
+ I include the statement</para>
+
+ <programlisting>#set( $foo = "bar" )</programlisting>
+
+ <para>The output will be the same for all instances of
+ <literal>$foo</literal> that follow this directive.</para>
+ </section>
+
+ <section id="section-properties">
+ <title>Properties</title>
+
+ <para>The second flavor of VTL references are properties, and properties
+ have a distinctive format. The shorthand notation consists of a leading
+ <literal>$</literal> character followed a VTL Identifier, followed by a
+ dot character (".") and another VTL Identifier. These are examples of
+ valid property references in the VTL:</para>
+
+ <programlisting>$customer.address
+$purchase.total</programlisting>
+
+ <para>Take the first example, <literal>$customer.address</literal>. It
+ can have two meanings. It can mean, "look in the hashtable identified as
+ <literal>customer</literal> and return the value associated with the key
+ <literal>address</literal>". But <literal>$customer.address</literal>
+ can also be referring to a method (references that refer to methods will
+ be discussed in the next chapter); <literal>$customer.address</literal>
+ could be an abbreviated way of writing
+ <literal>$customer.getAddress()</literal>. When your page is requested,
+ Velocity will determine which of these two possibilities makes sense,
+ and then return the appropriate value.<footnote id="properties1">
+ <para>This might look confusing. It gets even more confusing due to
+ the fact that you can write <literal>Address</literal> instead of
+ <literal>address</literal> and while this will request a different
+ key from the hashtable, it will still invoke
+ <literal>getAddress()</literal>. If you use
+ <literal>$customer.address</literal> to invoke a method getter, we
+ strongly recommend that you use the first-letter lowercase
+ notation.</para>
+ </footnote></para>
+ </section>
+
+ <section id="section-methods">
+ <title>Methods</title>
+
+ <para>A method is defined in the Java code and is capable of doing
+ something useful, like running a calculation or arriving at a decision.
+ Methods are references that consist of a leading <literal>$</literal>
+ character followed a VTL Identifier, followed by a VTL <firstterm>Method
+ Body</firstterm>. A VTL Method Body consists of a VTL Identifier
+ followed by an left parenthesis character ("("), followed by an optional
+ parameter list, followed by right parenthesis character (")"). These are
+ examples of valid method references in the VTL:</para>
+
+ <programlisting>$customer.getAddress()
+$purchase.getTotal()
+$page.setTitle( "My Home Page" )
+$person.setAttributes( ["Strange", "Weird", "Excited"] )</programlisting>
+
+ <para>The first two examples --
+ <literal>$customer.getAddress()</literal> and
+ <literal>$purchase.getTotal()</literal> -- may look similar to those
+ used in the Properties chapter above,
+ <literal>$customer.address</literal> and
+ <literal>$purchase.total</literal>. If you guessed that these examples
+ must be related some in some fashion, you are correct!</para>
+
+ <para>VTL Properties can be used as a shorthand notation for VTL
+ Methods. The Property <literal>$customer.address</literal> has the exact
+ same effect as using the Method
+ <literal>$customer.getAddress()</literal>. It is generally preferable to
+ use a Property when available. The main difference between Properties
+ and Methods is that you can specify a parameter list to a Method.</para>
+
+ <para>The shorthand notation can be used for the following
+ Methods</para>
+
+ <programlisting>$shop.getFruits()
+$sun.getPlanets()
+$album.getPhoto()</programlisting>
+
+ <para>We might expect these methods to return the fruits belonging to a
+ shop, the names of planets belonging to a sun, or get a photograph from
+ an album. Only the long notation works for the following Methods.</para>
+
+ <programlisting>$sun.getPlanet(3)
+## Can't pass a parameter with $sun.planet
+
+$shop.orderFruits()
+## Velocity only allows shorthand notation for get<property name>
+
+$book.setTitle( "Homage to Catalonia" )
+## Can't pass a parameter list</programlisting>
+ </section>
+
+ <section id="section-property-lookup-rules">
+ <title>Property lookup rules</title>
+
+ <para>As was mentioned earlier, properties often refer to methods of the
+ parent object. Velocity is quite clever when figuring out which method
+ corresponds to a requested property<footnote>
+ <para>Some people would say, that it is entirely too clever. For
+ this lookup, it uses a construct called the
+ <emphasis>Uberspector</emphasis>. There is more information on this
+ in the Developers Guide.</para>
+ </footnote>. It tries out different alternatives based on several
+ established naming conventions. The exact lookup sequence depends on
+ whether or not the property name starts with an upper-case letter. For
+ lower-case names, such as <literal>$customer.address</literal>, the
+ sequence is <itemizedlist spacing="compact">
+ <listitem>
+ <para><literal>getaddress()</literal></para>
+ </listitem>
+
+ <listitem>
+ <para><literal>getAddress()</literal></para>
+ </listitem>
+
+ <listitem>
+ <para><literal>get("address")</literal></para>
+ </listitem>
+
+ <listitem>
+ <para><literal>isAddress()</literal></para>
+ </listitem>
+ </itemizedlist> For upper-case property names like
+ <literal>$customer.Address</literal>, it is slightly different:
+ <itemizedlist spacing="compact">
+ <listitem>
+ <para><literal>getAddress()</literal></para>
+ </listitem>
+
+ <listitem>
+ <para><literal>getaddress()</literal></para>
+ </listitem>
+
+ <listitem>
+ <para><literal>get("Address")</literal></para>
+ </listitem>
+
+ <listitem>
+ <para><literal>isAddress()</literal></para>
+ </listitem>
+ </itemizedlist>As regular bean properties tend to be written in
+ lowercase notation, you should talk to your programmers that they don't
+ add both lower-case and upper-case methods to their objects. It would be
+ a bad idea anyway.</para>
+
+ <caution>
+ <para>There are some exotic naming cases, such as a property starting
+ with multiple upper-case letters which are treated specially according
+ to the Java Bean specification. Velocity does not conform to this
+ specification, so if you have a method called
+ <literal>getURL()</literal>, you cannot use
+ <literal>$obj.url</literal> to invoke themethod. This might change in
+ future versions of Velocity.</para>
+ </caution>
+ </section>
+
+ <section id="section-formal-reference-notation">
+ <title>Formal Reference Notation</title>
+
+ <para>Shorthand notation for references was used for the examples listed
+ above, but there is also a formal notation for references, which is
+ demonstrated below:</para>
+
+ <programlisting>${fruit}
+${customer.address}
+${purchase.getTotal()}</programlisting>
+
+ <para>In almost all cases you will use the shorthand notation for
+ references, but in some cases the formal notation is required for
+ correct processing.</para>
+
+ <para>Suppose you were building an extension to your fruit shop where
+ juices are sold. <literal>$fruit</literal> contains the name of the
+ juice which should be sold. Using the shorthand notation would be
+ inadequate for this task. Consider the following example:</para>
+
+ <programlisting>You have selected $fruitjuice.</programlisting>
+
+ <para>There is ambiguity here, and Velocity assumes that
+ <literal>$fruitjuice</literal>, not <literal>$fruit</literal>, is the
+ identifier that you want to use. Finding no value for
+ <literal>$fruitjuice</literal>, it will return
+ <literal>$fruitjuice</literal>. Using formal notation can resolve this
+ problem.</para>
+
+ <programlisting>You have selected ${fruit}juice.</programlisting>
+
+ <para>Now Velocity knows that <literal>$fruit</literal>, not
+ <literal>$fruitjuice</literal>, is the reference. Formal notation is
+ often useful when references are directly adjacent to text in a
+ template.</para>
+ </section>
+
+ <section id="section-quiet-reference-notation">
+ <title>Quiet reference notation</title>
+
+ <para>When Velocity encounters an undefined reference, its normal
+ behavior is to output the image of the reference. For example, suppose
+ the following reference appears as part of a VTL template.</para>
+
+ <programlisting><input type="text" name="email" value="$email"/></programlisting>
+
+ <para>When the form initially loads, the variable reference
+ <literal>$email</literal> has no value, but you prefer a blank text
+ field to one with a value of "$email". Using the quiet reference
+ notation circumvents Velocity's normal behavior; instead of using
+ <literal>$email</literal> in the VTL you would use
+ <literal>$!email</literal>. So the above example would look like the
+ following:</para>
+
+ <programlisting><input type="text" name="email" value="$!email"/></programlisting>
+
+ <para>Now when the form is initially loaded and
+ <literal>$email</literal> still has no value, an empty string will be
+ output instead of <literal>$email</literal>.</para>
+
+ <para>Formal and quiet reference notation can be used together, as
+ demonstrated below.</para>
+
+ <programlisting><input type="text" name="email" value="$!{email}"/></programlisting>
+
+ <caution>
+ <para>It is very easy to confuse the quiet reference notation with the
+ boolean <emphasis>not</emphasis>-Operator. Using the not-Operator, you
+ use <literal>!${foo}</literal>, while the quiet reference notation is
+ <literal>$!{foo}</literal>. And yes, you will end up sometimes with
+ <literal>!$!{foo}</literal>...</para>
+ </caution>
+ </section>
+ </chapter>
+
+ <chapter id="chapter-getting-literal">
+ <title>Getting literal</title>
+
+ <para>VTL uses special characters, such as <literal>$</literal> and
+ <literal>#</literal>, to do its work, so some added care should be taken
+ where using these characters in your templates. This chapter deals with
+ escaping the <literal>$</literal> character.</para>
+
+ <section id="section-currency">
+ <title>Currency</title>
+
+ <para>There is no problem writing "I bought a 4 lb. sack of potatoes at
+ the farmer's market for only $2.50!" As mentioned, a VTL identifier
+ always begins with an upper- or lowercase letter, so $2.50 would not be
+ mistaken for a reference.</para>
+ </section>
+
+ <section id="section-escaping-valid-vtl-references">
+ <title>Escaping Valid VTL References</title>
+
+ <para>Cases may arise where there is the potential for Velocity to get
+ confused. <emphasis>Escaping</emphasis> special characters is the best
+ way to handle VTL's special characters in your templates, and this can
+ be done using the backslash (<literal>\</literal>) character.</para>
+
+ <para>Consider the following VTL template:</para>
+
+ <programlisting>#set( $fruit = "apple" )
+$fruit</programlisting>
+
+ <para>If Velocity encounters a reference in your VTL template to
+ <literal>$fruit</literal>, it will search the Context for a
+ corresponding value. Here the output will be <literal>apple</literal>,
+ because <literal>$fruit</literal> is defined. If
+ <literal>$fruit</literal> is not defined, the output will be
+ <literal>$fruit</literal>.</para>
+
+ <para>Suppose that <literal>$fruit</literal> is defined (for example, if
+ it has the value <literal>apple</literal>), and that you want to output
+ <literal>$fruit</literal>. There are a few ways of doing this, but the
+ simplest is to use the escape character.</para>
+
+ <programlisting>## The following line defines $fruit in this template:
+#set( $fruit = "apple" )
+$fruit
+\$fruit
+\\$fruit
+\\\$fruit</programlisting>
+
+ <para>renders as</para>
+
+ <programlisting>apple $fruit \apple
+ \$fruit</programlisting>
+
+ <para>Note that the <literal>\</literal> character bind to the
+ <literal>$</literal> from the left. The bind-from-left rule causes
+ <literal>\\\$fruit</literal> to render as <literal>\\$fruit</literal>.
+ Compare these examples to those in which <literal>$fruit</literal> is
+ not defined.</para>
+
+ <programlisting>$fruit
+\$fruit
+\\$fruit
+\\\$fruit</programlisting>
+
+ <para>renders as</para>
+
+ <programlisting>$fruit \$fruit \\$fruit
+ \\\$fruit</programlisting>
+
+ <para>Notice Velocity handles references that are defined differently
+ from those that have not been defined. Here is a set directive that
+ gives <literal>$fruit</literal> the value
+ <literal>orange</literal>.</para>
+
+ <programlisting>#set( $fruit = "orange" )
+$moon = $orange</programlisting>
+
+ <para>The output will be: <literal>$moon = orange</literal> -- where
+ <literal>$moon</literal> is output as a literal because it is undefined
+ and <literal>gibbous</literal> is output in place of
+ <literal>$foo</literal>.</para>
+
+ <para>It is also possible to escape VTL directives; this is described in
+ more detail in the Directives chapter.</para>
+ </section>
+ </chapter>
+
+ <chapter id="chapter-case-substitution">
+ <title>Case Substitution</title>
+
+ <para>Now that you are familiar with references, you can begin to apply
+ them effectively in your templates. Velocity references take advantage of
+ some Java principles that template designers will find easy to use. For
+ example:</para>
+
+ <programlisting>$foo
+
+$foo.getBar()
+## is the same as $foo.bar and $foo.Bar
+
+$data.setUser("jon")
+## is the same as
+#set( $data.User = "jon" )
+
+$data.getRequest().getServerName()
+## is the same as
+$data.request.serverName and $data.Request.ServerName
+## and also
+${data.Request.ServerName}</programlisting>
+
+ <para>These examples illustrate alternative uses for the same references.
+ Velocity takes advantage of Java's introspection and bean features to
+ resolve the reference names to both objects in the Context as well as the
+ objects methods. It is possible to embed and evaluate references almost
+ anywhere in your template.</para>
+
+ <para>Velocity, which is modelled loosely after the Bean specifications
+ defined by Sun Microsystems, is case sensitive; however, its developers
+ have strove to catch and correct user errors wherever possible. When the
+ method <literal>getFoo()</literal> is referred to in a template by
+ <literal>$bar.foo</literal>, Velocity will first try
+ <literal>$getfoo</literal>. If this fails, it will then try
+ <literal>$getFoo</literal>. Similarly, when a template refers to
+ <literal>$bar.Foo</literal>, Velocity will try
+ <literal>$getFoo()</literal> first and then try
+ <literal>getfoo()</literal>.</para>
+
+ <para>Note: <emphasis>References to instance variables in a template are
+ not resolved.</emphasis> Only references to the attribute equivalents of
+ JavaBean getter/setter methods are resolved (i.e.
+ <literal>$foo.Name</literal> does resolve to the class Foo's
+ <literal>getName()</literal> instance method, but not to a public
+ <literal>Name</literal> instance variable of Foo).</para>
+ </chapter>
+
+ <chapter id="chapter-directives">
+ <title>Directives</title>
+
+ <para>References allow template designers to generate dynamic content for
+ web sites, while <emphasis>Directives</emphasis> permit web designers to
+ truly take charge of the appearance and content of the web site. A
+ directive is a script elements that can be used to manipulate the
+ rendering of the template.</para>
+
+ <para>Directives always begin with a <literal>#</literal>. Like
+ references, the name of the directive may be bracketed by a
+ <literal>{</literal> and a <literal>}</literal> symbol. This is useful
+ with directives that are immediately followed by text. For example the
+ following produces an error:</para>
+
+ <programlisting>#if($a==1)true enough#elseno way!#end</programlisting>
+
+ <para>In such a case, use the curly braces to separate
+ <literal>#else</literal> from the rest of the line.</para>
+
+ <programlisting>#if($a==1)true enough#{else}no way!#end</programlisting>
+
+ <section id="section-the-set-directive">
+ <title>The #set directive</title>
+
+ <para>The <literal>#set</literal> directive is used for setting the
+ value of a reference. A value can be assigned to either a variable
+ reference or a property reference, and this occurs in brackets, as
+ demonstrated:</para>
+
+ <programlisting>#set( $fruit = "apple" )
+#set( $customer.Favourite = $fruit )</programlisting>
+
+ <para>The left hand side (LHS) of the assignment must be a variable
+ reference or a property reference. The right hand side (RHS) can be one
+ of the following types:</para>
+
+ <para><itemizedlist spacing="compact">
+ <listitem>
+ <para>Variable reference</para>
+ </listitem>
+
+ <listitem>
+ <para>String literal</para>
+ </listitem>
+
+ <listitem>
+ <para>Property reference</para>
+ </listitem>
+
+ <listitem>
+ <para>Method reference</para>
+ </listitem>
+
+ <listitem>
+ <para>Number literal</para>
+ </listitem>
+
+ <listitem>
+ <para>List</para>
+ </listitem>
+
+ <listitem>
+ <para>Map</para>
+ </listitem>
+ </itemizedlist></para>
+
+ <para>These examples demonstrate each of the aforementioned
+ types:</para>
+
+ <programlisting>#set( $fruit = $selectedFruit ) ## variable reference
+#set( $fruit.flavor = "sweet" ) ## string literal
+#set( $fruit.amount = $cart.total ) ## property reference
+#set( $fruit.color = $colorlist.select($select) ) ## method reference
+#set( $fruit.value = 123 ) ## number literal
+#set( $fruit.sorts = ["Apple", "Pear", "Orange"] ) ## List
+#set( $fruit.shapes = {"Apple" : "round", "Pear" : "conical"}) ## Map</programlisting>
+
+ <para>NOTE: For the List example the elements defined with the
+ <literal>[..]</literal> operator are accessible using the methods
+ defined in the <literal>java.util.List</literal> class. So, for example,
+ you could access the first element above using
+ <literal>$fruit.sorts.get(0)</literal>.</para>
+
+ <para>Similarly, for the Map example, the elements defined within the
+ <literal>{..}</literal> operator are accessible using the methods
+ defined in the <literal>java.util.Map</literal> class. So, for example,
+ you could access the first element above using
+ <literal>$fruit.shapes.get("Granny")</literal> to return the String
+ <literal>round</literal>, or even
+ <literal>$fruit.shapes.Granny</literal> to return the same value.</para>
+
+ <para>The RHS can also be a simple arithmetic expression:</para>
+
+ <programlisting>#set( $value = $foo + 1 )
+#set( $value = $bar - 1 )
+#set( $value = $foo * $bar )
+#set( $value = $foo / $bar )</programlisting>
+
+ <para>If the RHS is a property or method reference that evaluates to
+ <literal>null</literal>, it will <emphasis>not</emphasis> be assigned to
+ the LHS. Depending on how Velocity is configured, it is usually not
+ possible to remove an existing reference from the context via this
+ mechanism. (Note that this can be permitted by changing a configuration
+ property). This can be confusing for newcomers to Velocity. For
+ example:</para>
+
+ <programlisting>#set( $result = $query.criteria("fruit") )
+The result of the first query is $result
+
+#set( $result = $query.criteria("customer") )
+The result of the second query is $result</programlisting>
+
+ <para>If <literal>$query.criteria("name")</literal> returns the string
+ "apple", and <literal>$query.criteria("customer")</literal> returns
+ <literal>null</literal>, the above VTL will render as the
+ following:</para>
+
+ <programlisting>The result of the first query is apple
+
+The result of the second query is apple</programlisting>
+
+ <para>Unfortunately, this can lead to hard-to-detect errors, for example
+ with <literal>#foreach</literal> loops that attempt to
+ <literal>#set</literal> a reference via a property or method reference,
+ then immediately test that reference with an <literal>#if</literal>
+ directive:</para>
+
+ <programlisting>#set( $criteria = ["fruit", "customer"] )
+
+#foreach( $criterion in $criteria )
+
+ #set( $result = $query.criteria($criterion) )
+
+ #if( $result )
+ Query was successful
+ #end
+
+#end</programlisting>
+
+ <para>In the above example, it would not be wise to rely on the
+ evaluation of <literal>$result</literal> to determine if a query was
+ successful. After <literal>$result</literal> has been
+ <literal>#set</literal> (added to the context), it cannot be set back to
+ <literal>null</literal> (removed from the context). The details of the
+ <literal>#if</literal> and <literal>#foreach</literal> directives are
+ covered later in this document.</para>
+
+ <para>One solution to this would be to pre-set
+ <literal>$result</literal> to <literal>false</literal>. Then if the
+ <literal>$query.criteria()</literal> call fails, you can check.</para>
+
+ <programlisting>#set( $criteria = ["name", "address"] )
+
+#foreach( $criterion in $criteria )
+
+ #set( $result = false )
+ #set( $result = $query.criteria($criterion) )
+
+ #if( $result )
+ Query was successful
+ #end
+
+#end</programlisting>
+
+ <para>However, the easiest way is to use the quiet reference
+ notation:</para>
+
+ <programlisting>#set( $criteria = ["name", "address"] )
+
+#foreach( $criterion in $criteria )
+
+ #set( $result = $!query.criteria($criterion) )
+
+ #if( $result != "" )
+ Query was successful
+ #end
+
+#end</programlisting>
+
+ <para>If the query fails, <literal>$result</literal> gets the empty
+ string assigned. In an <literal>#if</literal> directive, the empty
+ string evaluates to <emphasis>false</emphasis>.</para>
+
+ <para>Unlike some of the other Velocity directives, the
+ <literal>#set</literal> directive does not have an
+ <literal>#end</literal> statement.</para>
+
+ <section id="section-string-literals">
+ <title>String Literals</title>
+
+ <para>When using the <literal>#set</literal> directive, string
+ literals that are enclosed in double quote characters will be parsed
+ and rendered, as shown:</para>
+
+ <programlisting>#set( $directoryRoot = "www" )
+#set( $templateName = "index.vm" )
+#set( $template = "$directoryRoot/$templateName" )
+$template</programlisting>
+
+ <para>The output will be</para>
+
+ <programlisting>www/index.vm</programlisting>
+
+ <para>However, when the string literal is enclosed in single quote
+ characters, it will not be parsed:</para>
+
+ <programlisting>#set( $fruit = "apple" )
+$fruit
+
+#set( $veggie = '$fruit' )
+$veggie</programlisting>
+
+ <para>This renders as:</para>
+
+ <programlisting>apple $fruit</programlisting>
+
+ <para>By default, rendering unparsed text using single quotes is
+ activated in Velocity. This default can be changed by changing the
+ <literal>stringliterals.interpolate</literal> to read
+ <literal>false</literal> (The Developers Guide contains information on
+ how to do this).</para>
+ </section>
+ </section>
+
+ <section id="section-the-literal-directive">
+ <title>The #literal Directive</title>
+
+ <para>The <literal>#literal</literal> directive allows you to easily use
+ large chunks of uninterpreted content in VTL code. This can be
+ especially useful in place of escaping multiple directives.</para>
+
+ <programlisting>#literal()
+#foreach ($fruit in $basket)
+ nothing will happen to $fruit
+#end
+#end</programlisting>
+
+ <para>Renders as:</para>
+
+ <programlisting>#foreach ($fruit in $basket) nothing will happen
+ to $fruit #end</programlisting>
+ </section>
+
+ <section id="section-conditionals">
+ <title>Conditionals - #if/#elseif/#else</title>
+
+ <para>The <literal>#if</literal> directive in Velocity allows for text
+ to be included when the web page is generated, on the conditional that
+ the <emphasis>if-statement</emphasis> is true. For example:</para>
+
+ <programlisting>#if( $display )
+ <strong>Velocity!</strong>
+#end</programlisting>
+
+ <para>The variable <literal>$display</literal> is evaluated to determine
+ whether it is true, which will happen under one of two
+ circumstances:</para>
+
+ <para><itemizedlist spacing="compact">
+ <listitem>
+ <para><literal>$foo</literal> is a
+ <literal>java.lang.Boolean</literal> object (True/False) which has
+ a true value.</para>
+ </listitem>
+
+ <listitem>
+ <para>The value is not null.</para>
+ </listitem>
+ </itemizedlist>The Velocity context only contains Java objects, so any
+ method that returns a boolean primitive will automatically wrapped into
+ a <literal>java.lang.Boolean</literal> object.</para>
+
+ <para>The content between the <literal>#if</literal> and the
+ <literal>#end</literal> statements becomes the output if the evaluation
+ is true. In this case, if <literal>$foo</literal> is true, the output
+ will be: <computeroutput>Velocity!</computeroutput>. Conversely, if
+ <literal>$foo</literal> has a null value, or if it is a boolean false,
+ the statement evaluates as false, and there is no output.</para>
+
+ <para>An <literal>#elseif</literal> or <literal>#else</literal> element
+ can be used with an <literal>#if</literal> element. Note that the
+ Velocity Templating Engine will stop at the first expression that is
+ found to be true. In the following example, suppose that
+ <literal>$direction</literal> has a value of 15 and
+ <literal>$wind</literal> has a value of 6.</para>
+
+ <programlisting>#if( $direction < 10 )
+ <strong>Go North</strong>
+#elseif( $direction == 10 )
+ <strong>Go East</strong>
+#elseif( $wind == 6 )
+ <strong>Go South</strong>
+#else
+ <strong>Go West</strong>
+#end</programlisting>
+
+ <para>In this example, <literal>$direction</literal> is greater than 10,
+ so the first two comparisons fail. Next <literal>$wind</literal> is
+ compared to 6, which is true, so the output is <computeroutput>Go
+ South</computeroutput>.</para>
+
+ <para>When you wish to include text immediately following a
+ <literal>#else</literal> directive you need to use curly brackets
+ immediately surrounding the directive to differentiate it from the
+ following text:</para>
+
+ <programlisting>#if( $foo == $bar)it's true!#{else}it's not!#end</li></programlisting>
+
+ <section id="section-relational-and-logical-operators">
+ <title>Relational and Logical Operators</title>
+
+ <para>Velocity uses operators to determine the relationships between
+ variables.</para>
+
+ <table id="table-velocity-relational-and-logical-operators">
+ <title>Velocity Relational and logical operators</title>
+
+ <tgroup cols="3">
+ <thead>
+ <row>
+ <entry align="center">Type of operator</entry>
+
+ <entry align="center">short version</entry>
+
+ <entry>text version</entry>
+ </row>
+ </thead>
+
+ <tbody>
+ <row>
+ <entry>equal<footnote>
+ <para>Note that the semantics of the equal operator are
+ slightly different than Java where<literal>==</literal>
+ can only be used to test object equality. In Velocity the
+ equivalent operator can be used to directly compare
+ numbers, strings, or objects. When the objects are of
+ different classes, the string representations are obtained
+ by calling <literal>toString()</literal> for each object
+ and then compared.</para>
+ </footnote></entry>
+
+ <entry>==</entry>
+
+ <entry>eq</entry>
+ </row>
+
+ <row>
+ <entry>not equal</entry>
+
+ <entry>!=</entry>
+
+ <entry>ne</entry>
+ </row>
+
+ <row>
+ <entry>greater than</entry>
+
+ <entry>></entry>
+
+ <entry>gt</entry>
+ </row>
+
+ <row>
+ <entry>greater or equal than</entry>
+
+ <entry>>=</entry>
+
+ <entry>ge</entry>
+ </row>
+
+ <row>
+ <entry>less than</entry>
+
+ <entry><</entry>
+
+ <entry>lt</entry>
+ </row>
+
+ <row>
+ <entry>less or equal than</entry>
+
+ <entry><=</entry>
+
+ <entry>le</entry>
+ </row>
+
+ <row>
+ <entry>logical and</entry>
+
+ <entry>&&</entry>
+
+ <entry>and</entry>
+ </row>
+
+ <row>
+ <entry>logical or</entry>
+
+ <entry>||</entry>
+
+ <entry>or</entry>
+ </row>
+
+ <row>
+ <entry>logical not</entry>
+
+ <entry>!</entry>
+
+ <entry>not</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+
+ <para>Here is a simple example to illustrate how the equivalent
+ operator is used.</para>
+
+ <programlisting>#set ($foo = "deoxyribonucleic acid")
+#set ($bar = "ribonucleic acid")
+
+#if ($foo == $bar)
+ In this case it's clear they aren't equivalent. So...
+#else
+ They are not equivalent and this will be the output.
+#end</programlisting>
+
+ <para>The text versions of all logical operators can be used to avoid
+ problems with < and > in XML templates.</para>
+ </section>
+
+ <section id="section-the-and-operator">
+ <title>The AND Operator</title>
+
+ <programlisting>## logical AND
+
+#if( $foo && $bar )
+ <strong>This AND that</strong>
+#end</programlisting>
+
+ <para>The <literal>#if()</literal> directive will only evaluate to
+ true if both <literal>$foo</literal> and <literal>$bar</literal> are
+ true. If <literal>$foo</literal> is false, the expression will
+ evaluate to false; <literal>$bar</literal> will not be evaluated. If
+ <literal>$foo</literal> is true, the Velocity Templating Engine will
+ then check the value of <literal>$bar</literal>; if
+ <literal>$bar</literal> is true, then the entire expression is true
+ and This AND that becomes the output. If <literal>$bar</literal> is
+ false, then there will be no output as the entire expression is
+ false.</para>
+ </section>
+
+ <section id="the-or-operator">
+ <title>The OR Operator</title>
+
+ <para>Logical OR operators work the same way as AND operators, except
+ only one of the references need evaluate to true in order for the
+ entire expression to be considered true. Consider the following
+ example:</para>
+
+ <programlisting>## logical OR
+
+#if( $foo || $bar )
+ <strong>This OR That</strong>
+#end</programlisting>
+
+ <para>If <literal>$foo</literal> is true, the Velocity Templating
+ Engine has no need to look at <literal>$bar</literal>; whether
+ <literal>$bar</literal> is true or false, the expression will be true,
+ and This OR That will be output. If <literal>$foo</literal> is false,
+ however, <literal>$bar</literal> must be checked. In this case, if
+ <literal>$bar</literal> is also false, the expression evaluates to
+ false and there is no output. On the other hand, if
+ <literal>$bar</literal> is true, then the entire expression is true,
+ and the output is This OR That</para>
+ </section>
+
+ <section id="the-not-operator">
+ <title>The NOT Operator</title>
+
+ <para>With logical NOT operators, there is only one argument:</para>
+
+ <programlisting>##logical NOT
+
+#if( !$foo )
+ <strong>NOT that</strong>
+#end</programlisting>
+
+ <para>Here, the if <literal>$foo</literal> is true, then
+ <literal>!$foo</literal> evaluates to false, and there is no output.
+ If <literal>$foo</literal> is false, then <literal>!$foo</literal>
+ evaluates to true and <computeroutput>NOT that</computeroutput> will
+ be output. Be careful not to confuse this with the <emphasis>quiet
+ reference </emphasis><literal>$!foo</literal>.</para>
+ </section>
+ </section>
+
+ <section id="loops">
+ <title>Loops - #foreach</title>
+
+ <para>The <literal>#foreach</literal> element allows for looping:</para>
+
+ <programlisting><ul>
+ #foreach( $product in $allProducts )
+ <li>$product</li>
+ #end
+</ul></programlisting>
+
+ <para>This <literal>#foreach</literal> loop causes the
+ <literal>$allProducts</literal> list (the object) to be looped over for
+ all of the products (targets) in the list. Each time through the loop,
+ the value from <literal>$allProducts</literal> is placed into the
+ <literal>$product</literal> variable.</para>
+
+ <para>The contents of the <literal>$allProducts</literal> variable is a
+ Vector, a Hashtable or an Array. The value assigned to the
+ <literal>$product</literal> variable is a Java Object and can be
+ referenced from a variable as such. For example, if
+ <literal>$product</literal> was really a Product class in Java, its name
+ could be retrieved by referencing the <literal>$product.Name</literal>
+ method (ie: <literal>$Product.getName()</literal>).</para>
+
+ <para>Lets say that <literal>$allProducts</literal> is a Hashtable. If
+ you wanted to retrieve the key values for the Hashtable as well as the
+ objects within the Hashtable, you can use code like this:</para>
+
+ <programlisting><ul>
+ #foreach( $key in $allProducts.keySet() )
+ <li>Key: $key -> Value: $allProducts.get($key)</li>
+ #end
+</ul></programlisting>
+
+ <para>Velocity provides an easy way to get the loop counter so that you
+ can do something like the following:</para>
+
+ <programlisting><table>
+ #foreach( $customer in $customerList )
+ <tr><td>$velocityCount</td><td>$customer.Name</td></tr>
+ #end
+</table></programlisting>
+
+ <para>The default name for the loop counter variable reference, which is
+ specified in the velocity.properties file, is
+ <literal>$velocityCount</literal>. By default the counter starts at 1.
+ Both, the start value and the variable name can be changed through
+ properties in the Velocity configuration:</para>
+
+ <programlisting># Default name of the loop counter
+# variable reference.
+directive.foreach.counter.name = velocityCount
+
+# Default starting value of the loop
+# counter variable reference.
+directive.foreach.counter.initial.value = 1</programlisting>
+
+ <para>To avoid deadlocks and denial of service attacks, it's possible to
+ set a maximum allowed number of times that a loop may be executed. By
+ default there is no limit, but it can be set to an arbitrary number in
+ the Velocity configuration.</para>
+
+ <programlisting># The maximum allowed number of loops.
+directive.foreach.maxloops = -1</programlisting>
+ </section>
+
+ <section id="section-loading-resources">
+ <title>Loading resources</title>
+
+ <section id="section-file-inclusion">
+ <title>File inclusion - #include</title>
+
+ <para>The <literal>#include</literal> directive allows the template
+ designer to import a local file. Its contents replace the
+ <literal>#include</literal> directive in the template. These contents
+ are inserted as-is, they are not rendered through the template engine.
+ For security reasons, the file to be included may only be under
+ TEMPLATE_ROOT.</para>
+
+ <programlisting>#include( "one.txt" )</programlisting>
+
+ <para>The file to which the <literal>#include</literal> directive
+ refers is enclosed in quotes. If more than one file will be included,
+ they should be separated by commas:</para>
+
+ <programlisting>#include( "one.gif","two.txt","three.htm" )</programlisting>
+
+ <para>The file being included need not be referenced by name; in fact,
+ it is often preferable to use a variable instead of a filename. This
+ could be useful for targeting output according to criteria determined
+ when the page request is submitted. Here is an example showing both a
+ filename and a variable.</para>
+
+ <programlisting>#set ($seasonalgreetings = "christmas.txt")
+#include( "greetings.txt", $seasonalgreetings )</programlisting>
+ </section>
+
+ <section id="section-template-inclusion">
+ <title>Template inclusion - #parse</title>
+
+ <para>The <literal>#parse</literal> script element allows the template
+ designer to import a local file that contains VTL. Velocity will parse
+ the VTL and render the template specified. The output will replace the
+ <literal>#parse</literal> directive in the importing template.</para>
+
+ <programlisting>#parse( "me.vm" )</programlisting>
+
+ <para>Like the <literal>#include</literal> directive,
+ <literal>#parse</literal> can take a variable rather than a template.
+ Any templates to which <literal>#parse</literal> refers must be
+ located under TEMPLATE_ROOT. Unlike the <literal>#include</literal>
+ directive, <literal>#parse</literal> will only take a single
+ argument.</para>
+
+ <para>VTL templates can have <literal>#parse</literal> statements
+ referring to templates that in turn have <literal>#parse</literal>
+ statements:</para>
+
+ <para>Recursion is permitted:</para>
+
+ <programlisting>## Template "countdown.vm"
+Count down.
+
+#set( $count = 8 )
+#parse( "counter.vm" )
+All done with countdown.vm!
+
+
+## Template "counter.vm
+$count
+#set( $count = $count - 1 )
+#if( $count > 0 )
+ #parse("counter.vm" )
+#else
+ All done with counter.vm!
+#end</programlisting>
+
+ <para>Rendering the <filename>countdown.vm</filename> template results
+ in the following output:</para>
+
+ <programlisting>Count down.
+8
+7
+6
+5
+4
+3
+2
+1
+0
+
+All done with counter.vm!
+All done with countdown.vm!</programlisting>
+
+ <para>To avoid infinitive recursion, the number of levels is limited
+ through a configuration property:</para>
+
+ <programlisting># Maximum number of #parse levels
+directive.parse.max.depth = 10</programlisting>
+ </section>
+ </section>
+
+ <section id="section-stop-template-rendering">
+ <title>Stop template rendering - #stop</title>
+
+ <para>The <literal>#stop</literal> directive stops the execution of the
+ template engine and return. The remaining part of the template after
+ this directive is discarded. The most common usage of this directive is
+ debugging templates.</para>
+
+ <programlisting>#stop</programlisting>
+
+ <para>Unlike most other directives, <literal>#stop</literal> has no
+ matching <literal>#end</literal> directive.</para>
+ </section>
+ </chapter>
+
+ <chapter id="chapter-velocity-macros">
+ <title>Velocity Macros</title>
+
+ <para>The <literal>#macro</literal> directive allows you to name a section
+ of a VTL template and re-insert it multiple times into the template.
+ Velocity macros (or short <firstterm>Velocimacros</firstterm>) can be used
+ in many different scenarios.</para>
+
+ <para>In the following example, a Velocimacro is created to save
+ keystrokes and minimizing typographic errors:</para>
+
+ <programlisting>#macro( d ) <tr><td></td></tr> #end</programlisting>
+
+ <para>This example defines a Velocimacro called <literal>d</literal>. It
+ now can be uses as any other VTL directive:</para>
+
+ <programlisting>#d()</programlisting>
+
+ <para>When this template is rendered, Velocity replaces
+ <literal>#d()</literal> with the HTML table row containing a single, empty
+ cell defined above. Using a macro in a template is called <firstterm>macro
+ invocation</firstterm>.</para>
+
+ <para>Velocimacros start with the <literal>#macro</literal> directive and
+ are ended with <literal>#end</literal>. The enclosed block is the
+ <firstterm>macro body</firstterm>. Whenever a Velocimacro is invoked, its
+ body is inserted in the template. It is rendered at every invokation
+ through the templating engine, with the invocation arguments replacing the
+ arguments in the macro definition.</para>
+
+ <para>A Velocimacro can take any number of arguments including zero, but
+ when it is invoked, it must be called with exactly the same number of
+ arguments with which it was defined.</para>
+
+ <para>Here is a Velocimacro that takes two arguments, a color and a list
+ of objects:</para>
+
+ <programlisting>#macro( tablerows $color $values )
+ #foreach( $value in $values )
+ <tr><td bgcolor=$color>$value</td></tr>
+ #end
+#end
+
+#set( $greatlakes = ["Superior","Michigan","Huron","Erie","Ontario"] )
+#set( $color = "blue" )
+
+<table>
+ #tablerows( $color $greatlakes )
+</table></programlisting>
+
+ <para>The <literal>tablerows</literal> macro takes exactly two arguments.
+ The first argument takes the place of <literal>$color</literal>, and the
+ second argument takes the place of <literal>$values</literal>. Anything
+ that can be put into a VTL template can go into the body of a
+ Velocimacro.</para>
+
+ <para>Notice that <literal>$greatlakes</literal> takes the place of
+ <literal>$values</literal>. When this template is rendered, the following
+ output is generated:</para>
+
+ <programlisting><table>
+<tr><td bgcolor="blue">Superior</td></tr>
+<tr><td bgcolor="blue">Michigan</td></tr>
+<tr><td bgcolor="blue">Huron</td></tr>
+<tr><td bgcolor="blue">Erie</td></tr>
+<tr><td bgcolor="blue">Ontario</td></tr>
+</table></programlisting>
+
+ <para>In the example above, the <literal>#tablerows</literal> macro was
+ defined <firstterm>inline</firstterm>. Velocimacros can be defined
+ <emphasis>inline</emphasis> or <emphasis>global</emphasis>. An inline
+ macro is only visible in the template where it is defined, a global macro
+ is accessible from all templates. Global definitions must be done in a a
+ Velocimacro template library, which is a template file that contains the
+ macros and they must be referenced explicitly through the Velocity
+ configuration. Please see the Velocity reference guide for more
+ information on how to define and load a Macro library.</para>
+
+ <para>If the <literal>#tablerows($color $values)</literal> Velocimacro is
+ defined a Velocimacro template library, it could be in any template. In
+ the fruit store it could be used to list fruits available:</para>
+
+ <programlisting>#set( $fruits = ["apple", "pear", "orange", "strawberry"] )
+#set($cellbgcol = "white" )
+
+<table>
+ #tablerows( $cellbgcol $fruits )
+</table></programlisting>
+
+ <para>When rendering this template, Velocitywould find the
+ <literal>#tablerows</literal> Velocimacro in a template library (defined
+ in the Velocity configuration) and generate the following output:</para>
+
+ <programlisting><table>
+ <tr><td bgcolor="white">apple</td></tr>
+ <tr><td bgcolor="white">pear</td></tr>
+ <tr><td bgcolor="white">orange</td></tr>
+ <tr><td bgcolor="white">strawberry</td></tr>
+</table></programlisting>
+
+ <section id="section-velocimacro-arguments">
+ <title>Velocimacro Arguments</title>
+
+ <para>Velocimacros can take as arguments any of the following VTL
+ elements:</para>
+
+ <itemizedlist spacing="compact">
+ <listitem>
+ <para>Reference : anything that starts with '$'</para>
+ </listitem>
+
+ <listitem>
+ <para>String literal : something like "$foo" or 'hello'</para>
+ </listitem>
+
+ <listitem>
+ <para>Number literal : 1, 2 etc</para>
+ </listitem>
+
+ <listitem>
+ <para>IntegerRange : [ 1..2] or [$foo .. $bar]</para>
+ </listitem>
+
+ <listitem>
+ <para>ObjectArray : [ "a", "b", "c"]</para>
+ </listitem>
+
+ <listitem>
+ <para>The words true and false: boolean values for true and
+ false</para>
+ </listitem>
+ </itemizedlist>
+
+ <para>When passing references as arguments to Velocimacros, please note
+ that references are passed <emphasis>by name</emphasis>. This means that
+ their value is evaluated each time it is used inside the Velocimacro.
+ This feature allows you to pass references with method calls and have
+ the method called at each use:</para>
+
+ <programlisting>#macro( callme $a )
+ $a $a $a
+#end
+
+#callme( $foo.bar() )</programlisting>
+
+ <para>results in the method <literal>bar()</literal> of the reference
+ <literal>$foo</literal> being called 3 times.</para>
+
+ <caution>
+ <para>If you are used to the behaviour of method or procedure calls in
+ programming languages like Java or C, please be sure to fully
+ understand the implications of the passing by name of references.
+ Unlike these programming languages, the reference is not evaluated at
+ macro invocation time but at every occurence inside the macro. Don't
+ treat macros as procedures or methods!</para>
+ </caution>
+
+ <para>The easiest way to avoid any gotchas is not passing any stateful
+ object into a Velocimacro. This can be done by assigning the result of a
+ method invocation to a new reference:</para>
+
+ <programlisting>#set( $myval = $foo.bar() )
+#callme( $myval )</programlisting>
+ </section>
+
+ <section id="section-velocimacro-properties">
+ <title>Velocimacro Properties</title>
+
+ <para>There are a number of properties in the Velocity configuration
+ that influence the behaviour of macros. A complete list of all
+ configuration options is in the Velocity Reference guide.</para>
+
+ <variablelist>
+ <varlistentry>
+ <term><literal>velocimacro.library</literal></term>
+
+ <listitem>
+ <para>A comma-separated list of all Velocimacro template
+ libraries. By default, Velocity looks for a single library:
+ <filename><literal>VM_global_library.vm</literal></filename>. The
+ configured template path is used to find the Velocimacro
+ libraries.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><literal>velocimacro.permissions.allow.inline</literal></term>
+
+ <listitem>
+ <para>This property, which has possible values of true or false,
+ determines whether Velocimacros can be defined in regular
+ templates. The default, true, allows template designers to define
+ Velocimacros in the templates themselves.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><literal>velocimacro.permissions.allow.inline.to.replace.global</literal></term>
+
+ <listitem>
+ <para>With possible values of true or false, this property allows
+ the user to specify if a Velocimacro defined inline in a template
+ can replace a globally defined template, one that was loaded on
+ startup via the <literal>velocimacro.library</literal> property.
+ The default, <literal>false</literal>, prevents Velocimacros
+ defined inline in a template from replacing those defined in the
+ template libraries loaded at startup.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><literal>velocimacro.permissions.allow.inline.local.scope</literal></term>
+
+ <listitem>
+ <para>This property, with possible values of true or false,
+ defaulting to false, controls if Velocimacros defined inline are
+ 'visible' only to the defining template. In other words, with this
+ property set to true, a template can define inline VMs that are
+ usable only by the defining template. You can use this for fancy
+ VM tricks - if a global VM calls another global VM, with inline
+ scope, a template can define a private implementation of the
+ second VM that will be called by the first VM when invoked by that
+ template. All other templates are unaffected.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><literal>velocimacro.context.localscope</literal></term>
+
+ <listitem>
+ <para>This property has the possible values true or false, and the
+ default is false. When true, any modifications to the context via
+ #set() within a Velocimacro are considered 'local' to the
+ Velocimacro, and will not permanently affect the context.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><literal>velocimacro.library.autoreload</literal></term>
+
+ <listitem>
+ <para>This property controls Velocimacro library autoloading. The
+ default value is <literal>false</literal>. When set to
+ <literal>true</literal> the source Velocimacro library for an
+ invoked Velocimacro will be checked for changes, and reloaded if
+ necessary. This allows you to change and test Velocimacro
+ libraries without having to restart your application or servlet
+ container, just like you can with regular templates. This mode
+ only works when caching is turned offin the resource loaders (see
+ the Velocity Reference guide on how to do this). This feature is
+ intended for development, not for production.</para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+
+ <section id="section-velocimacro-trivira">
+ <title>Velocimacro Trivia</title>
+
+ <para>Velocimacros must be defined before they are first used in a
+ template. This means that your inline <literal>#macro()</literal>
+ declarations must be found by the Engine before usage.</para>
+
+ <para>This is important to remember if you try to
+ <literal>#parse()</literal> a template containing inline
+ <literal>#macro()</literal> directives. Because the
+ <literal>#parse()</literal> invocation happens <emphasis>at
+ runtime</emphasis>, and the parser looks at the macro definitions
+ earlier, <emphasis>at parsetime</emphasis>. So loading a set of macro
+ definitions using <literal>#parse()</literal> does not work. If you need
+ to use a set of macros on more than one template, declare it as a
+ Velomacro Library in the Velocity configuration.</para>
+ </section>
+ </chapter>
+
+ <chapter id="chapter-escaping-vtl-directives">
+ <title>Escaping VTL Directives</title>
+
+ <para>VTL directives can be escaped with the backslash character ("\")
+ similar to valid VTL references.</para>
+
+ <programlisting>## #include( "a.txt" ) renders as <contents of a.txt>
+#include( "a.txt" )
+
+## \#include( "a.txt" ) renders as #include( "a.txt" )
+\#include( "a.txt" )
+
+## \\#include ( "a.txt" ) renders as \<contents of a.txt>
+\\#include ( "a.txt" )</programlisting>
+
+ <para>Extra care should be taken when escaping VTL directives that contain
+ multiple script elements in a single directive (such as in an if-else-end
+ statements). Here is a typical VTL if-statement:</para>
+
+ <programlisting>#if( $jazz )
+ Vyacheslav Ganelin
+#end</programlisting>
+
+ <para>If <literal>$jazz</literal> is true, the output is</para>
+
+ <programlisting>Vyacheslav Ganelin</programlisting>
+
+ <para>If <literal>$jazz</literal> is false, there is no output. Escaping
+ script elements alters the output. Consider the following case:</para>
+
+ <programlisting>\#if( $jazz )
+ Vyacheslav Ganelin
+\#end</programlisting>
+
+ <para>Whether <literal>$jazz</literal> is true or false, the output will
+ be</para>
+
+ <programlisting>#if($ jazz ) Vyacheslav Ganelin
+ #end</programlisting>
+
+ <para>In fact, because all script elements are escaped,
+ <literal>$jazz</literal> is never evaluated for its boolean value. Suppose
+ backslashes precede script elements that are legitimately escaped:</para>
+
+ <programlisting>\\#if( $jazz )
+ Vyacheslav Ganelin
+\\#end</programlisting>
+
+ <para>In this case, if <literal>$jazz</literal> is true, the output
+ is</para>
+
+ <para><programlisting>\ Vyacheslav Ganelin \</programlisting></para>
+
+ <para>To understand this, note that the <literal>#if( arg ) </literal>
+ when ended by a newline (return) will omit the newline from the output.
+ Therefore, the body of the <literal>#if()</literal> block follows the
+ first '\', rendered from the '\\' preceding the <literal>#if()</literal>.
+ The last \ is on a different line than the text because there is a newline
+ after 'Ganelin', so the final \\, preceding the <literal>#end</literal> is
+ part of the body of the block.</para>
+
+ <para>If <literal>$jazz</literal> is false, the output is</para>
+
+ <para><programlisting>\</programlisting></para>
+
+ <para>Note that things start to break if script elements are not properly
+ escaped.</para>
+
+ <programlisting>\\\#if( $jazz )
+ Vyacheslave Ganelin
+\\#end</programlisting>
+
+ <para>Here the <literal>#if</literal> is escaped, but there is an
+ <literal>#end</literal> remaining; having too many endings will cause a
+ parsing error.</para>
+ </chapter>
+
+ <chapter id="chapter-formatting-issues">
+ <title>Formatting Issues</title>
+
+ <para>Although VTL in this user guide is often displayed with newlines and
+ whitespaces, the VTL shown below</para>
+
+ <programlisting>#set( $fruits = ["apple", "pear", "orange", "strawberry"] )
+
+#foreach( $fruit in $fruits )
+ $fruit
+#end</programlisting>
+
+ <para>is equally valid as the following snippet that Geir Magnusson Jr.
+ posted to the Velocity user mailing list to illustrate a completely
+ unrelated point:</para>
+
+ <programlisting>Send me #set($foo=["$10 and ","a pie"])#foreach($a in $foo)$a#end please.</programlisting>
+
+ <para>Velocity's behaviour is to gobble up excess whitespace. The
+ preceding directive can be written as:</para>
+
+ <programlisting>Send me
+#set( $foo = ["$10 and ","a pie"] )
+#foreach( $a in $foo )
+$a
+#end
+please.</programlisting>
+
+ <para>or as</para>
+
+ <programlisting>Send me
+#set($foo = ["$10 and ","a pie"])
+ #foreach ($a in $foo )$a
+ #end please.</programlisting>
+
+ <para>In each case the output will be the same.</para>
+ </chapter>
+
+ <chapter id="chapter-other-features-and-miscellany">
+ <title>Other Features and Miscellany</title>
+
+ <section id="section-math">
+ <title>Math</title>
+
+ <para>Velocity has a number of built-in mathematical functions that can
+ be used in templates with the <literal>set</literal> directive. The
+ following equations are examples of addition, subtraction,
+ multiplication and division, respectively:</para>
+
+ <programlisting>#set( $foo = $bar + 3 )
+#set( $foo = $bar - 4 )
+#set( $foo = $bar * 6 )
+#set( $foo = $bar / 2 )</programlisting>
+
+ <para>When a division operation is performed between two integers, the
+ result will be an integer. Any remainder can be obtained by using the
+ modulus (<literal>%</literal>) operator.</para>
+
+ <programlisting>#set( $foo = $bar % 5 )</programlisting>
+ </section>
+
+ <section id="section-range-operator">
+ <title>Range Operator</title>
+
+ <para>The range operator can be used in conjunction with
+ <literal>#set</literal> and <literal>#foreach</literal> statements. It
+ creates an array of <literal>java.lang.Integer</literal> objects:</para>
+
+ <programlisting>[n..m]</programlisting>
+
+ <para>Both <literal>n</literal> and <literal>m</literal> must either be
+ or produce integers. If <literal>m</literal> is greater than
+ <literal>n</literal>, the range will count down:</para>
+
+ <programlisting>## Range: 1 2 3 4 5
+First example:
+#foreach( $cnt in [1..5] )
+ $cnt
+#end
+
+## Range: 2 1 0 -1 -2
+Second example:
+#foreach( $cnt in [2..-2] )
+ $cnt
+#end
+
+## Range: 0 1
+Third example:
+#set( $range = [0..1] )
+#foreach( $cnt in $range )
+ $cnt
+#end
+
+## Not a range (not in a #set or #foreach directive)
+Fourth example:
+[1..3]</programlisting>
+
+ <para>Produces the following output:</para>
+
+ <programlisting>First example: 1 2 3 4 5 Second example: 2 1 0 -1
+ -2 Third example: 0 1 Fourth example: [1..3]</programlisting>
+
+ <note>
+ <para>As any other operator, the range operator is only evaluated in
+ Velocity directives!</para>
+ </note>
+ </section>
+
+ <section id="section-advanced-issues">
+ <title>Advanced Issues: Escaping and !</title>
+
+ <para>When a reference is silenced with the <literal>!</literal>
+ character and the <literal>!</literal> character preceded by an
+ <literal>\</literal> escape character, the reference is handled in a
+ special way. Note the differences between regular escaping, and the
+ special case where <literal>\</literal> precedes <literal>!</literal>
+ follows it:</para>
+
+ <programlisting>#set( $foo = "bar" )
+$\!foo
+$\!{foo}
+$\\!foo
+$\\\!foo</programlisting>
+
+ <para>This renders as:</para>
+
+ <programlisting>$!foo $!{foo} $\!foo
+ $\\!foo</programlisting>
+
+ <para>Contrast this with regular escaping, where <literal>\</literal>
+ precedes <literal>$</literal>:</para>
+
+ <programlisting>\$foo
+\$!foo
+\$!{foo}
+\\$!{foo}</programlisting>
+
+ <para>This renders as:</para>
+
+ <programlisting>$foo $!foo $!{foo} \bar</programlisting>
+ </section>
+
+ <section id="section-velocimacro-miscellany">
+ <title>Velocimacro Miscellany</title>
+
+ <variablelist>
+ <varlistentry>
+ <term>Can I use a directive or another Velocimacro as an argument to
+ a Velocimacro?</term>
+
+ <listitem>
+ <programlisting>Example : <literal>#center( #bold("hello") )</literal></programlisting>
+
+ <para><emphasis>No</emphasis>. A directive isn't a valid argument
+ to a directive, and for most practical purposes, a Velocimacro is
+ a directive.</para>
+
+ <para>However, there are things you can do. One easy solution is
+ to take advantage of the fact that 'doublequote' (") renders its
+ contents. So you could do something like</para>
+
+ <programlisting>#set($stuff = "#bold('hello')" )
+#center( $stuff )</programlisting>
+
+ <para>You can save a step...</para>
+
+ <programlisting>#center( "#bold( 'hello' )" )</programlisting>
+
+ <para>Please note that in the latter example the arg is evaluated
+ <literal>inside</literal> the Velocimacro, not at the calling
+ level. In other words, the argument to the Velocimacro is passed
+ in in its entirety and evaluated within the Velocimacro it was
+ passed into. This allows you to do things like :</para>
+
+ <programlisting>#macro( inner $foo )
+ inner : $foo
+#end
+
+#macro( outer $foo )
+ #set($bar = "outerlala")
+ outer : $foo
+#end
+
+#set($bar = 'calltimelala')
+#outer( "#inner($bar)" )</programlisting>
+
+ <para>Where the output is</para>
+
+ <programlisting>Outer : inner : outerlala</programlisting>
+
+ <para>because the evaluation of the "#inner($bar)" happens inside
+ #outer(), so the $bar value set inside #outer() is the one that's
+ used.</para>
+
+ <para>This is an intentional and jealously guarded feature - args
+ are passed 'by name' into Velocimacros, so you can hand
+ Velocimacros things like stateful references such as</para>
+
+ <programlisting>#macro( foo $color )
+ <tr bgcolor=$color><td>Hi</td></tr>
+ <tr bgcolor=$color><td>There</td></tr>
+#end
+
+#foo($bar.rowColor() )</programlisting>
+
+ <para>And have rowColor() called repeatedly, rather than just
+ once. To avoid that, invoke the method outside of the Velocimacro,
+ and pass the value into the Velocimacro.</para>
+
+ <programlisting>#set($color = $bar.rowColor())
+#foo( $color )</programlisting>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>Can I register Velocimacros via #parse() ?</term>
+
+ <listitem>
+ <para>Currently, Velocimacros must be defined before they are
+ first used in a template. This means that your #macro()
+ declarations should come before using the Velocimacros.</para>
+
+ <para>This is important to remember if you try to #parse() a
+ template containing inline #macro() directives. Because the
+ #parse() happens at runtime, and the parser decides if a
+ Velocimacro-looking element in the template is a Velocimacro at
+ parsetime, #parse()-ing a set of Velocimacro declarations won't
+ work as expected. To get around this, simply use the
+ <literal>velocimacro.library</literal> facility to have Velocity
+ load your Velocimacros at startup.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>What is Velocimacro Autoreloading?</term>
+
+ <listitem>
+ <para>There is a property, meant to be used in
+ <literal>development</literal>, not production:</para>
+
+ <para><literal>velocimacro.library.autoreload</literal></para>
+
+ <para>which defaults to false. When set to true <literal>along
+ with</literal></para>
+
+ <para><literal><type>.resource.loader.cache =
+ false</literal></para>
+
+ <para>(where <type> is the name of the resource loader that
+ you are using, such as 'file') then the Velocity engine will
+ automatically reload changes to your Velocimacro library files
+ when you make them, so you do not have to dump the servlet engine
+ (or application) or do other tricks to have your Velocimacros
+ reloaded.</para>
+
+ <para>Here is what a simple set of configuration properties would
+ look like.</para>
+
+ <programlisting>file.resource.loader.path = templates
+file.resource.loader.cache = false
+velocimacro.library.autoreload = true</programlisting>
+
+ <para>Don't keep this on in production.</para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+
+ <section id="section-string-concatenation">
+ <title>String Concatenation</title>
+
+ <para>A common question that developers ask is <emphasis><literal>How do
+ I do String concatenation? Is there any analogue to the '+' operator in
+ Java?</literal></emphasis>.</para>
+
+ <para>To do concatenation of references in VTL, you just have to 'put
+ them together'. The context of where you want to put them together does
+ matter, so we will illustrate with some examples.</para>
+
+ <para>In the regular 'schmoo' of a template (when you are mixing it in
+ with regular content) :</para>
+
+ <programlisting>#set( $size = "Big" )
+#set( $name = "Ben" )
+
+The clock is $size$name.</programlisting>
+
+ <para>and the output will render as 'The clock is BigBen'. For more
+ interesting cases, such as when you want to concatenate strings to pass
+ to a method, or to set a new reference, just do</para>
+
+ <programlisting>#set( $size = "Big" )
+#set( $name = "Ben" )
+
+#set($clock = "$size$name" )
+
+The clock is $clock.</programlisting>
+
+ <para>Which will result in the same output. As a final example, when you
+ want to mix in 'static' strings with your references, you may need to
+ use 'formal references' :</para>
+
+ <programlisting>#set( $size = "Big" )
+#set( $name = "Ben" )
+
+#set($clock = "${size}Tall$name" )
+
+The clock is $clock.</programlisting>
+
+ <para>Now the output is 'The clock is BigTallBen'. The formal notation
+ is needed so the parser knows you mean to use the reference '$size'
+ versus '$sizeTall' which it would if the '{}' weren't there.</para>
+ </section>
+ </chapter>
+</book>
Propchange: jakarta/velocity/docbook/trunk/src/docbook/userguide/VelocityUsersGuide.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/velocity/docbook/trunk/src/docbook/userguide/VelocityUsersGuide.xml
------------------------------------------------------------------------------
svn:keywords = Id Author Date Revision
Added: jakarta/velocity/docbook/trunk/src/images/logo.png
URL: http://svn.apache.org/viewvc/jakarta/velocity/docbook/trunk/src/images/logo.png?rev=409603&view=auto
==============================================================================
Binary file - no diff available.
Propchange: jakarta/velocity/docbook/trunk/src/images/logo.png
------------------------------------------------------------------------------
svn:mime-type = image/png
Added: jakarta/velocity/docbook/trunk/src/styles/html.xsl
URL: http://svn.apache.org/viewvc/jakarta/velocity/docbook/trunk/src/styles/html.xsl?rev=409603&view=auto
==============================================================================
--- jakarta/velocity/docbook/trunk/src/styles/html.xsl (added)
+++ jakarta/velocity/docbook/trunk/src/styles/html.xsl Fri May 26 02:19:10 2006
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Copyright 2006 The Apache Software Foundation.
+
+ Licensed under the Apache License, Version 2.0 (the "License")
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ version='1.0'>
+
+ <xsl:import href="@file.prefix@@docbook.xsl@/html/chunk.xsl" />
+ <xsl:import href="@file.prefix@@src.dir@/styles/html/custom.xsl" />
+ <xsl:include href="@file.prefix@@tmp.dir@/html-titlepage.xsl" />
+
+ <!-- Do not use the file.prefix and make sure that you keep the trailing slash! -->
+ <xsl:param name="base.dir">@html.target.dir@/</xsl:param>
+</xsl:stylesheet>
+
Added: jakarta/velocity/docbook/trunk/src/styles/html/custom.xsl
URL: http://svn.apache.org/viewvc/jakarta/velocity/docbook/trunk/src/styles/html/custom.xsl?rev=409603&view=auto
==============================================================================
--- jakarta/velocity/docbook/trunk/src/styles/html/custom.xsl (added)
+++ jakarta/velocity/docbook/trunk/src/styles/html/custom.xsl Fri May 26 02:19:10 2006
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Copyright 2006 The Apache Software Foundation.
+
+ Licensed under the Apache License, Version 2.0 (the "License")
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ version='1.0'>
+
+<!-- Activate Graphics -->
+ <xsl:param name="admon.graphics" select="1"/>
+ <xsl:param name="admon.graphics.path">images/</xsl:param>
+ <xsl:param name="admon.graphics.extension">.gif</xsl:param>
+ <xsl:param name="callout.graphics" select="1" />
+ <xsl:param name="callout.graphics.path">images/callouts/</xsl:param>
+ <xsl:param name="callout.graphics.extension">.gif</xsl:param>
+
+ <xsl:param name="table.borders.with.css" select="1"/>
+ <xsl:param name="html.stylesheet">css/stylesheet.css</xsl:param>
+ <xsl:param name="html.stylesheet.type">text/css</xsl:param>
+ <xsl:param name="section.label.includes.component.label" select="1" />
+ <xsl:param name="section.autolabel" select="1" />
+ <xsl:param name="generate.toc">book toc,title</xsl:param>
+
+ <xsl:param name="admonition.title.properties">text-align: left</xsl:param>
+</xsl:stylesheet>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org