Toolbox Reference Guide

$Id: reference.xml,v 1.27 2011/03/18 08:38:54 hannes Exp $

Copyright © 2006 - 2012 Hannes Holtzhausen

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.


Table of Contents

1. Introduction
2. Command Line Utilities
2.1. Bean Generator
2.2. Service Generator
2.3. Configuration Generator
2.4. Directory Generator
3. Apache Ant Macros
3.1. Macro: tbwar
3.2. Macro: tbsvcapp
3.3. Macro: tbclean
3.4. Macro: tbjavac
3.5. Macro: tbjar
3.6. Macro: tbjavadoc
3.7. Macro: tbcompileclean
3.8. Macro: tbjesas7wardeploy
3.9. Macro: tbjesas8wardeploy
3.10. Macro: tbjeswswardeploy
3.11. Macro: tbtomcat4wardeploy
3.12. Macro: tbdocbook
4. FreeMarker XHTML Template Macros
4.1. Macro: xhtml
4.2. Macro: head
4.3. Macro: form
4.4. Macro: form_input
4.5. Macro: form_textarea
4.6. Macro: form_select
4.7. Macro: form_submit
4.8. Macro: table
4.9. Macro: table_tr
4.10. Macro: table_td
4.11. Macro: messages

1. Introduction

This document will serve as a reference guide to all Toolbox related command line utilities, Apache Ant Macros and FreeMarker Template Macros.

2. Command Line Utilities

The Toolbox provides the following command line utilities:

  • beangen: Utility to generate Java classes conforming to the Java Bean conventions using FreeMarker templates.

  • confgen: Utility to generate Toolbox XML configuration and properties files using FreeMarker templates.

  • dirgen: Utility to generate a source tree file system.

  • docbook: Utility to generate an HTML document from the DocBook XML source. Requires the DocBook XSL stylesheets.

  • servicegen: Utility to generate the required Java source files and configuration files to create toolbox.services implemenations. The generated services are ready to be exposed as an API and Web Services.

  • simplexslt: Utility to run an XSL stylesheet transformation.

2.1. Bean Generator

The Bean Generator provides a utility to generate Java classes conforming to the Java Bean conventions. The utility requires two pieces of information to generate a Java Bean(s).

  • An XML file defining the Java Bean properties. The XML definition must have the following structure:

    <?xml version="1.0"?>
    <Bean>
      <Name>MyBean</Name>
      <Package>package.name</Package>
      <Imports></Imports>
      <Comment><![CDATA[ My first generated bean. 
                         <p>My second para</p>]]></Comment>
    
      <Properties>
        <Property>
          <Name>prop1</Name>
          <Type>Double</Type>
          <Comment><![CDATA[Represents the amount.]]></Comment>
        </Property>
        <Property>
          <Name>prop2</Name>
          <Type>Date</Type>
          <Comment><![CDATA[Represents the date.]]></Comment>
        </Property>
      </Properties>
    
      <Mappings>
        <Mapping>
          <PropertyName>prop1</PropertyName>
          <MapKey>db_prop1</MapKey>
        </Mapping>
        <Mapping>
          <PropertyName>prop2</PropertyName>
          <MapKey>db_prop2</MapKey>
        </Mapping>
      </Mappings>
    </Bean>
                  

  • A FreeMarker template defining a Java source code template that must be merged with the XML definition to create the Java Bean. The default template (DaoBeanTemplate.ftl) is located in the Toolbox distribution in the templates/dao directory.

The utility can be invoked using the beangen script located in the bin directory of the Toolbox distribution. The command has the following synopsis:

beangen <-templatedir dir> <-template file> <-beanfile file> | <-beandir dir> <-outdir dir> [-extension ext]

Table 1. beangen options

OptionDescription
-templatedirThe directory to use when loading the FreeMarker Template. The script defaults this option to $TOOLBOX_HOME/templates.
-templateThe FreeMarker template to use. The script defaults this option to dao/DaoBeanTemplate.ftl.
-beanfileThe path to an XML file containing the Java Bean definition. Specify this value if the -beandir option is not used.
-beandirThe path to a directory containing Java Bean definition XML files. Specify this value if the -beanfile option is not used.
-outdirThe path to the target directory where the Java Bean will be written.
-extensionUse this switch if you do not want the generated file to have a .java extension.

2.2. Service Generator

The toolbox.services package simplifies the development of coarse grained services capable of exposing logic at various levels. The Service Generator is capable of generating toolbox.services implementation classes and configuration that is ready to be exposed as an API or Web Services. The utility can be invoked using the servicegen script located in the bin directory of the Toolbox distribution. The command has the following synopsis:

servicegen <-list> | <-module module> <-templatedir dir> <-javadir dir> <-svcdir dir> <-definition file>

Table 2. servicegen options

OptionDescription
-listList the supported modules. The indicates the capability of the tool.
-moduleThe name of the module to invoke.
-templatedirThe directory to use when loading the FreeMarker Template. The script defaults this option to $TOOLBOX_HOME/templates/servicegen.
-javadirThe path to a directory where the java package structure must be created.
-svcdirThe path to the target directory where the generated service configuration files must be written. Usually etc/services.
-definitionThe path to an XML instance document containing the definintion of the service to generate. The share/xsd/servicegen directory contains the XSD's supported by the tool.

2.3. Configuration Generator

The Toolbox APIs provide various classes and interfaces to develop applications and utilities. Most of these API's require some form of configuration to achieve the desired outcome. The configurations are based in XML and Java properties. The process of setting up the initial configurations for an application or utility can be tedious and error prone. For this reason the Toolbox provides a utility that can generate the initial configuration for the desired Toolbox API's.

The Configuration Generator contains a module for each type of configuration it supports. Each module is associated with a default FreeMarker template that is responsible for rendering the desired configuration. The default templates can be changed to accomodate different environments and settings.

The utility has the following command synopsis and can be invoked using the confgen script located in the bin directory of the Toolbox distribution.

confgen <-list> | <-module module> <-templatedir dir> [-template file] <-outdir dir> [-outfile file] [-properties file]

The utility will run interactively if the -properties option is omitted.

Table 3. confgen options

OptionDescription
-listPrint a list of the supported configuration modules.
-moduleSpecify the name of the module to execute.
-templatedirThe directory to load the template from. The script defaults this option to $TOOLBOX_HOME/templates.
-templateThe FreeMarker template to use. Each module has a configured default that can be overridden with this option.
-outdirThe path to the target directory where the configuration file will be written.
-outfileWrite the output to this file and not the module default.
-propertiesThe path to a properties file containing the names and values of the configuration parameters that the module requires to generate the configuration file. If this option is specified the utility will run silently and won't prompt for any configuration parameters.

2.4. Directory Generator

When developing source code, developers create a source tree, or file system, to store and organise the application source code, configuration and documentation. The dirgen utility is a simple script that generates a very generic directory structure that can be used as an initial source tree. The source tree does not resemble a specific deployment structure like WAR or EAR. This keeps the source code independent of it's deployment platform, making the source tree adaptable to any assembly and deployment scenario.

                            <myapp>
                               |
                  ----------------------------
                  |        |        |        |
                 doc      etc     htdocs   java
                           |
                 --------------------
                 |         |        |
               beans   resources  services
        

Table 4. source tree description

DirectoryDescription
docAll application documentation can be placed here.
etcAll application configuration files can be created in this directory. This includes Java properties files, XML configuration and deployment descriptors.
etc/beansAll XML bean definitions can be placed here. The files in this directory can be processed with the Bean Generator utility.
etc/resourcesJava ResourceBundles required by the application can be created in this directory.
etc/servicesAll application component or service configuration files can be created in this directory. These are configuration files that only affect specific application services.
htdocsAll internet source files can be created in this directory, if we are developing a web application. This includes HTML, JSP, CSS, JavaScript and any other files required for the generation of a web front-end.
javaAll Java sources relating to the application can be created in this directory.

Follow these steps to successfully execute the dirgen utility:

  • Create your source root directory. This should probably reflect the name of the application, library or utility you will be building.

  • Change directory to the source root directory you created.

  • Execute the dirgen utility: $TOOLBOX_HOME/bin/dirgen

3. Apache Ant Macros

Apache Ant, like other build tools, allow us to group commands into targets within a configuration file. The targets can then be executed using a single invocation of the ant build tool. This greatly simplifies the process of building application distributions.

Developing build.xml files can become a tedious task. Especially when developing multiple applications with more or less the same components and configuration. For this reason the Toolbox provides a set of custom tasks developed using the Ant macrodef task. These tasks can be used to simplify the process of compiling, assembling and deploying applications developed using the Toolbox API's. The macro definitions can be found in the toolbox_macros.xml file located in the $TOOLBOX_HOME/share/ant directory of the Toolbox distribution.

All of the macro definitions are driven by a set of properties defined in the toolbox_marcos.properties file. The main objective of these properties are to provide default values for most of the defined macro attributes. The properties can also be referenced in the build files utilising the macro definitions. The properties can be accessed using the prefix "tbm". The following table contains a list of the defined properties and their meaning: (A windows properties file exists, only the unix values are presented in this document).

Table 5. ant macro properties

PropertyDescriptionValue
Global properties
distDirectory where all distribution assembly files will be placed.dist
buildDirectory where all compiled files will be placed.build
Properties to assemble WAR files.
dist_warDirectory where all WAR assembly files will be placed.${dist}/war
web_inf ${dist_war}/WEB-INF
war_classesAll web application resources will be placed here.${web_inf}/classes
war_libAll web application jars will be placed here.${web_inf}/lib
war_etcAll Toolbox related war configurations will be placed here. ${web_inf}/etc
war_docsAll display templates will be placed here. ${dist_war}/htdocs
war_lenient_xmlIndicates whether war xml configs must validated strict or lenient. Valid values yes|no yes
war_web_xmlThe path to the web.xml deployment descriptor. etc/web.xml
war_configs_dirThe path to the directory containing all the Toolbox related war configurations. etc
war_configsComma separated list of Toolbox war configurations. web_config.xml,view_servlet.xml,web_validator.xml, registry_finaliser.properties
war_resources_dirThe path to the directory containing the required resources bundles. etc/resources
war_resourcesWild card indicating which resource bundles to include. *.properties
war_htdocsThe path to the directory containing all the required documents/templates to render the web application views. htdocs
war_index_htmlThe path to the index.html file. htdocs/index.html
Properties to assemble ZIP files containing application distributions.
app_docThe path to the directory containing all application documentation. doc
app_etcThe path to the directory containing all application configuration. etc
app_srvThe path to the directory containing all application service configurations. etc/services
app_libDirectory that will contain all application jar files. lib
app_warDirectory that will contain the application war file. war
svc_lenient_xmlIndicates whether service xml configs must validated strict or lenient. Valid values yes|no yes
svc_services_xmlThe path to the services.xml file. etc/services.xml
svc_env_xmlsWildcard indicating all service environment configurations. *_env.xml
Java compilation properties.
debugIndicates whether debugging should be on or off. on
debug_levelIndicates the level of debugging. source,lines
servlet_jarLocation of the servler.jar file. ${env.TOOLBOX_SERVLET_API}
freemarker_jarLocation of the freemarker.jar file. ${env.TOOLBOX_FM_HOME}/lib/freemarker.jar
toolbox_core_jarLocation of the toolbox_core.jar file. ${env.TOOLBOX_HOME}/lib/toolbox_core.jar
toolbox_web_jarLocation of the toolbox_web.jar file. ${env.TOOLBOX_HOME}/lib/toolbox_web.jar
cpThe default classpath that will be used for compilation. ${servlet_jar}:${freemarker_jar}:${toolbox_core_jar}:${toolbox_web_jar}:${build}:.
Javadoc properties.
javadoc_dirThe path to the directory where the generated documentation must be placed. ../doc/api
javadoc_sourceThe directory where the Java source files are located. .
javadoc_authorBoolean to indicate whether author names must be included in the generated documentation. true
JES Application Server deployment properties.
jes_asadmin7The location of the appserver 7 asadmin executable /opt/SUNWappserver7/bin/asadmin
jes_asadmin8The location of the appserver 8 asadmin executable /opt/sun/appserver/bin/asadmin
jes_asuserThe admin server user name. admin
jes_aspassThe admin server password admin
jes_ashostThe admin server host localhost
jes_asportThe admin server port number 4848
jes_assecureBoolean indicating whether the admin server is running on a secure port. false
jes_asuploadBoolean indicating whether the deployed component must be uploaded to the admin server. false
jes_asinstanceThe appserver 7 instance to deploy to. server1
jes_asvirtualservers8The appserver 8 virtual servers to deploy to. server
JES Web Server deployment properties.
jes_wswdeployThe location of the wdeploy executable. /opt/SUNWwbsvr/bin/https/bin/wdeploy
Tomcat 4 deployment properties.
tomcat_webappsThe path to the tomcat webapps directory. /opt/jakarta/tomcat/webapps
DocBook XSL properties.
docbook_rootThe path to the root directory of the docbook dtd's and stylesheets. /opt/misc/docbook
root_catalogThe path to the root XML catalog file. ${docbook_root}/catalog.xml
catalog_43The path to the docbook 4.3 dtd. ${docbook_root}/dtd4.3/catalog.xml
catalog_44The path to the docbook 4.4 dtd. ${docbook_root}/dtd4.4/catalog.xml
docbook_catalog_pathThe XML catalog path. ${root_catalog}:${catalog_43}:${catalog_44}
docbook_html_xslThe location of the docbook XSL stylesheet to perform HTML transformations. ${docbook_root}/docbook-xsl/html/docbook.xsl

To be able to use the defined macros you have to import the the toolbox_macros.xml file into your ant project. This can be done with the following ant task

<property environment="sysenv"/> <import file="${sysenv.TOOLBOX_HOME}/share/ant/toolbox_macros.xml"/>

The following table contains a list of all the Ant Macros with links to more detailed information regarding each macro.

Table 6. ant macros

MacroDescription
tbwarMacro to create a war file that includes all the Toolbox specific configurations and directories.
tbsvcappMacro to create a zip archive that contains a Toolbox application distribution. The application must be based on the Toolbox services API.
tbcleanMacro to perform clean up after the tbwar and tbsvcapp macros.
tbjavac Macro to perform Java compilations.
tbjarMacro to create jar files.
tbjavadocMacro to generate Javadoc API documentation.
tbcompileclean Macro to perform clean up after tbjavac, tbjar and tbjavadoc operations.
tbjesas7wardeploy Macro to deploy a war to the Java Enterpise System Application Server 7.
tbjesas8wardeploy Macro to deploy a war to the Java Enterpise System Application Server 8.
tbjeswswardeploy Macro to deploy a war to the Java Enterpise System Web Server.
tbtomcat4wardeploy Macro to deploy a war to a Tomcat 4 Servlet Container.
tbdocbook Macro to perform DocBook XSL transformations using the Ant XSLT task

3.1. Macro: tbwar

Macro to create a war file that includes all the Toolbox specific configurations and directories. The following table contains all the attributes and elements supported by the macro. The default values of optional attributes make reference to ant macro properties.

Table 7. tbwar attributes/elements

Attribute(A)/Element(E)DescriptionRequiredDefault
warname (A)The base name that will be used to create the war file.Yes 
webxml (A)Path to the web.xml descriptor to use. No${war_web_xml}
configs (A)Includes pattern to include required Toolbox configuration No${war_configs}
configsdir (A)Directory in your source tree where configurations are located. No${war_configs_dir}
resources (A)Includes pattern to include required resource bundles in the WEB-INF/classes directory. No${war_resources}
resourcesdir (A)Directory in your source tree where resource bundles are located. No${war_resources_dir}
docsdir (A)Directory in your source that contains all web templates. No${war_htdocs}
indexfile (A)Path the the index file that will be used to render the default view. No${war_index_html}
lenientxml (A)Indicates whether war configs must be validated strict or lenient. Valid values yes|no. No${war_lenient_xml}
webinf (E)Element that may contain <fileset> elements that point to files required in the WEB-INF. No 
webinfclasses (E)Element that may contain <fileset> elements that point to the resource files required. No 
webinflib (E)Element that may contain <fileset> elements that point to the jar files required. No 

Example

Use the following target definintion to create a war file with the name mywebapp.war and jars located in the directory java.

<target name="war" depends="tbmproperties">
  <tbwar warname="mywebapp">
    <webinflib>
      <fileset dir="java" includes="*.jar"/>
    </webinflib>
  </tbwar>
</target>
        

3.2. Macro: tbsvcapp

Macro to create a zip archive that contains a Toolbox application distribution. The application must be based on the Toolbox services API. The following table contains all the attributes and elements supported by the macro. The default values of optional attributes make reference to ant macro properties.

Table 8. tbsvcapp attributes/elements

Attribute(A)/Element(E)DescriptionRequiredDefault
appname (A)Base name that will be used to create the zip archive and locate the web component of the application. Yes 
servicesxml (A)Path the the services.xml configuration in your source tree. No${svc_services_xml}
envxmls (A)Includes pattern for all service environment configurations No${svc_env_xmls},${svc_env_props}
servicesdir (A)Directory on your source tree containing the application service conifgurations. No${app_srv}
docsdir (A)Directory on your source tree containing the application documentation. No${app_doc}
warfile (A)The web component for the application. No@{appname}.war
lenientxml (A)Indicates whether service configs must be validated strict or lenient. Valid values yes|no. No${svc_lenient_xml}
applib (E)Element that may contain <fileset> elements that point to all jar files required. Yes 
miscdir (E)Add any additional directory creation and file copying tasks inside this nested element. No 

Example

Use the following target definintion to create a zip file with the name myapp.zip and jars located in the directory java.

<target name="app" depends="tbmproperties">
  <tbsvcapp appname="myapp">
    <applib>
      <fileset dir="java" includes="*.jar"/>
    </applib>
  </tbsvcapp>
</target>
        

3.3. Macro: tbclean

Macro to perform clean up after the tbwar and tbsvcapp macros. It will delete the application zip file, war file and the ${dist} directory. The following table contains all the attributes and elements supported by the macro. The default values of optional attributes make reference to ant macro properties.

Table 9. tbclean attributes/elements

Attribute(A)/Element(E)DescriptionRequiredDefault
appname (A)Base name to locate the application zip file. Yes 
warname (A)Base name to locate the war file. No@{appname}.war

Example

Use the following target definintion to clean the build results of an application with a zip file named myapp.zip and a war file named mywebapp.war.

<target name="clean" depends="tbmproperties">
  <tbclean appname="myapp" warname="mywebapp"/>
</target>
        

3.4. Macro: tbjavac

Macro to perform Java compilations. The following table contains all the attributes and elements supported by the macro. The default values of optional attributes make reference to ant macro properties.

Table 10. tbjavac attributes/elements

Attribute(A)/Element(E)DescriptionRequiredDefault
srcdir (A)Directory containing sources. Yes 
cp (A)Append this classpath to the default classpath. NoEmpty string
destdir (A)Destination directory of compiled sources. No${build}

Example

Use the following target definition to compile the sources in the directory my/java/package

<target name="mypackage" depends="tbmproperties">
  <tbjavac srcdir="my/java/package"/>
</target>
        

3.5. Macro: tbjar

Macro to create jar files. The following table contains all the attributes and elements supported by the macro. The default values of optional attributes make reference to ant macro properties.

Table 11. tbjar attributes/elements

Attribute(A)/Element(E)DescriptionRequiredDefault
jarfile (A)The name of the jar file to create. Yes 
basedir (A)Base directory to start jar file. No${build}

Example

Use the following target definition to create a jar file named myapp.jar

<target name="jar" depends="tbmproperties">
  <tbjar jarfile="myapp.jar"/>
</target>
        

3.6. Macro: tbjavadoc

Macro to generate Javadoc API documentation. The following table contains all the attributes and elements supported by the macro. The default values of optional attributes make reference to ant macro properties.

Table 12. tbjavadoc attributes/elements

Attribute(A)/Element(E)DescriptionRequiredDefault
srcdir (A)Directory where source packages are located. No${javadoc_source}
destdir (A)Documentation destination directory. No${javadoc_dir}
cp (A)Append this classpath to the default classpath. NoEmpty string
windowtitle (A)Title to display in browser window. Yes 
doctitle (A)HTML document title. Yes 
author (A)Boolean to indicate whether to include author name. No${javadoc_author}

Example

Use the following target definition to generate the API documentation for all packages in the current directory.

<target name="api-doc" depends="tbmproperties">
  <tbjavadoc windowtitle="My API Docs"
                doctitle="<h2>My API Docs</h2>"/>
</target>
        

3.7. Macro: tbcompileclean

Macro perform clean up after tbjavac, tbjar and tbjavadoc operations. The following table contains all the attributes and elements supported by the macro. The default values of optional attributes make reference to ant macro properties.

Table 13. tbcompileclean attributes/elements

Attribute(A)/Element(E)DescriptionRequiredDefault
jarfile (A)Jar file to delete. Yes 
classdir (A)Directory containing compiled classes. No${build}
javadocdir (A)Directory containing Javadoc documentation. No${javadoc_dir}

Example

Use the following target definition to perform clean up after compilation.

<target name="clean" depends="tbmproperties">
  <tbcompileclean jarfile="myapp.jar"/>
</target>
        

3.8. Macro: tbjesas7wardeploy

Macro to deploy a war to the Java Enterpise System Application Server 7. The following table contains all the attributes and elements supported by the macro. The default values of optional attributes make reference to ant macro properties.

Table 14. tbjesas7wardeploy attributes/elements

Attribute(A)/Element(E)DescriptionRequiredDefault
asadmin (A)Location of asadmin executable. No${jes_asadmin7}
asuser (A)Admin server user name. No${jes_asuser}
aspassword (A)Admin server user password. No${jes_aspass}
ashost (A)Admin server host. No${jes_ashost}
asport (A)Admin server port. No${jes_asport}
assecure (A)Boolean indicating whether the admin server is running on a secure port. No${jes_assecure}
name (A)Name of web application to deploy. Yes 
context (A)Context root of application if different from name. No@{name}
upload (A)Must the war be uploaded to the admin server. No${jes_asupload}
asinstance (A)Which application server instance. No${jes_asinstance}
asvirtualservers (A)To which virtualserver must the application be deployed to. No@{asinstance}
war (A)Location of the war file to deploy. Yes 

Example

Use the following target definition to deploy a war file named mywebapp.war.

<target name="deploy" depends="tbmproperties">
  <tbjesas7wardeploy name="mywebapp" war="mywebapp.war"/>
</target>
        

3.9. Macro: tbjesas8wardeploy

Macro to deploy a war to the Java Enterpise System Application Server 8. The following table contains all the attributes and elements supported by the macro. The default values of optional attributes make reference to ant macro properties.

Table 15. tbjesas8wardeploy attributes/elements

Attribute(A)/Element(E)DescriptionRequiredDefault
asadmin (A)Location of asadmin executable. No${jes_asadmin8}
asuser (A)Admin server user name. No${jes_asuser}
aspassword (A)Admin server user password. No${jes_aspass}
ashost (A)Admin server host. No${jes_ashost}
asport (A)Admin server port. No${jes_asport}
assecure (A)Boolean indicating whether the admin server is running on a secure port. No${jes_assecure}
name (A)Name of web application to deploy. Yes 
context (A)Context root of application if different from name. No@{name}
upload (A)Must the war be uploaded to the admin server. No${jes_asupload}
asvirtualservers (A)To which virtualserver must the application be deployed to. No@{jes_asvirtualservers8}
war (A)Location of the war file to deploy. Yes 

Example

Use the following target definition to deploy a war file named mywebapp.war.

<target name="deploy" depends="tbmproperties">
  <tbjesas8wardeploy name="mywebapp" war="mywebapp.war"/>
</target>
        

3.10. Macro: tbjeswswardeploy

Macro to deploy a war to the Java Enterpise System Web Server. The following table contains all the attributes and elements supported by the macro. The default values of optional attributes make reference to ant macro properties.

Table 16. tbjeswswardeploy attributes/elements

Attribute(A)/Element(E)DescriptionRequiredDefault
wdeploy (A)Location of wdeploy executable. No${jes_wswdeploy}
context (A)The context root of the application. Yes 
wsinstance (A)The web server instance to deploy to. Yes 
wsvsid (A)The web server virtual server to deploy to. Yes 
war (A)Location of the war file to deploy. Yes 

Example

Use the following target definition to deploy a war file named mywebapp.war to the virtual server with id foo.com on the instance https-blah.com.

<target name="deploy" depends="tbmproperties">
  <tbjeswswardeploy context="mywebapp" 
                       wsintance="blah.com" 
                       wsvsid="foo.com" 
                       war="mywebapp.war"/>
</target>
        

3.11. Macro: tbtomcat4wardeploy

Macro to deploy a war to a Tomcat 4 Servlet Container. The following table contains all the attributes and elements supported by the macro. The default values of optional attributes make reference to ant macro properties.

Table 17. tbtomcat4wardeploy attributes/elements

Attribute(A)/Element(E)DescriptionRequiredDefault
name (A)The name of the web application. Yes 
contextfile (A)File containing a context definition. NoEmpty string
webapps (A)The location of the Tomcat webapps directory. No${tomcat_webapps}
war (A)Location of the war file to deploy. Yes 

Example

Use the following target definition to deploy a war file named mywebapp.war.

<target name="deploy" depends="tbmproperties">
  <tbtomcat4wardeploy name="mywebapp" war="mywebapp.war"/>
</target>
        

3.12. Macro: tbdocbook

Macro to perform DocBook XSL transformations using the Ant XSLT task. The following table contains all the attributes and elements supported by the macro. The default values of optional attributes make reference to ant macro properties.

Table 18. tbdocbook attributes/elements

Attribute(A)/Element(E)DescriptionRequiredDefault
style (A)Location of the xsl stylesheet to use in the transform. No${docbook_html_xsl}
in (A)File containing XML source to transform. Yes 
out (A)Destination file of the transform. Yes 
params (E)Pass any additional stylesheet parameters using this element. No 

Example

Use the following target definition to create a HTML file named out.html from an XML file named mydoc.xml.

<target name="doc" depends="tbmproperties">
  <tbdocbook in="mydoc.xml" out="out.html"/>
</target>
        

4. FreeMarker XHTML Template Macros

From the FreeMarker site: 'FreeMarker is a "template engine"; a generic tool to generate text output (anything from HTML to autogenerated source code) based on templates. It's a Java package, a class library for Java programmers. It's not an application for end-users in itself, but something that programmers can embed into their products.'

The FreeMarker template engine is an extremely powerful and useful templating solution. It provides a very flexibly and simple Java API to expose any complex Java object as a template model. (A template model is any object that can be placed in the data model of a template.)

In the Toolbox API's and utilities the FreeMarker template engine is used for various tasks, but is primarily intended to be used in web application development as the view component. The toolbox.web package provides a servlet implementation (ViewServlet) that acts as a wrapper for the template engine and exposes the three primary scope variables as template models:

  • context: Contains a template model wrapping the ServletContext.

  • session: Contains a template model wrapping the HttpSession

  • request: Contains a template model wrapping the HttpServletRequest.

The ViewServlet only enable us to access the template engine in a web application context. To be able to render HTML web pages we must develop template files and place them under the control of the ViewServlet instance of the web application. Developing HTML pages can become a tedious task. For this reason the Toolbox provides a set of Macros to address XHTML page development. These Macros are developed using the FreeMarker macro directive (<#macro ..>). The following table contains a list of the supported macros, located in the $TOOLBOX_HOME/share/freemarker/xhtml1_base.ftl file, with links to more detailed information.

Table 19. freemarker macros

MacroDescription
xhtmlMacro to render the XHTML document type definition and html start and end tag.
headMacro to render the html head start and end tag.
formMacro to render the html form start and end tag.
form_inputMacro to render the html input tag.
form_textareaMacro to render the html textarea tag.
form_selectMacro to render the html select tag with options.
form_submitMacro to render html form submission input tags.
tableMacro to render the html table tag with headers.
table_trMacro to render the html tr tag.
table_tdMacro to render the html td tag.
messagesMacro to render an html paragraph to display a sequence of informational messages.

To be able to access the macros, the definitions must be imported using the FreeMarker import directive as follows:

<#import "xhtml1_base.ftl" as xhtml>

The import directive will import all macro definitions, contained in the named file, into the namespace xhtml in the template currently being processed. Any of the macros can then be accessed with the following syntax:

<@xhtml.macro_name param1=value paramN=value/>

4.1. Macro: xhtml

Macro to render the XHTML document type definition and html start and end tag. This macro does not support any parameters. This macro supports nested content. The entire template's content should be wrapped inside this macro.

Example

          <@xhtml.xhtml>
            <body>
              <p>Hello World</p>
            </body>
          </@xhtml.xhtml>
        

4.2. Macro: head

Macro to render the html head tag. This macro supports nested content. All html head related markup should be nested inside this macro. The following table contains a list of all the parameters supported by this macro.

Table 20. head parameters

ParameterDescriptionRequiredDefault
titlePage title.Yes 
styleURL to a stylesheet.No/styles.css

Example

          <@xhtml.head title="My Page" style=/styles/mystyle.css"/>
        

4.3. Macro: form

Macro to render the html form tag. This macro supports nested content. All html form related markup should be nested inside this macro. The following table contains a list of all the parameters supported by this macro.

Table 21. form parameters

ParameterDescriptionRequiredDefault
nameThe form name.Yes 
actionURL where form will be submitted to.Yes 
idUnique id to assign to the form element.NoValue of the name parameter.
methodHTTP method to use when submitting. Nopost
encodingSpecify an alternate encoding. NoEmpty string
classStyling class. NoEmpty string

Example

          <@xhtml.form name="myform" 
                          action="action/url">
            .....

          </@xhtml.form>
        

4.4. Macro: form_input

Macro to render the html input tag. This macro does not support nested content. This macro should be used inside the form macro. The following table contains a list of all the parameters supported by this macro.

Table 22. form_input parameters

ParameterDescriptionRequiredDefault
nameThe name of the input.Yes 
idUnique id to assign to the input element.NoValue of the name parameter.
classStyling class. NoEmpty string
typeType of input.Notext
valueThe value of the input element.NoEmpty string
extraAny additional information. Like "checked" for a checked checkbox input. NoEmpty string
numformatUse this format when displaying numerical data. No#,##0.00
eventsOptional hash containing JavaScript eventsNoEmpty

Example

          <@xhtml.form_input name="myinput" value="foo"/>
        

4.5. Macro: form_textarea

Macro to render the html textarea tag. This macro does not support nested content. This macro should be used inside the form macro. The following table contains a list of all the parameters supported by this macro.

Table 23. form_textarea parameters

ParameterDescriptionRequiredDefault
nameThe name of the textarea.Yes 
idUnique id to assign to the textarea element.NoValue of the name parameter.
classStyling class. NoEmpty string
valueThe value of the textarea element.NoEmpty string
eventsOptional hash containing JavaScript eventsNoEmpty

Example

          <@xhtml.form_textarea name="mytext" value="foo"/>
        

4.6. Macro: form_select

Macro to render the html select tag with options. This macro does not support nested content. This macro should be used inside the form macro. The following table contains a list of all the parameters supported by this macro.

Table 24. form_select parameters

ParameterDescriptionRequiredDefault
nameThe name of the select.Yes 
idUnique id to assign to the select element.NoValue of the name parameter.
classStyling class. NoEmpty string
selectedThe value of the selected option element.NoEmpty string
optionsSequence of hashes/scalars containing options. Yes 
displaykeyIf the options sequence contain hashes, use this key to find the option display value. Nodisplay
valuekeyIf the options sequence contain hashes, use this key to find the option value. Novalue
emptyBoolean to indicate whether the first option must be empty. Nofalse
eventsOptional hash containing JavaScript eventsNoEmpty

Example

          Given the following sequence of hashes: 

          optionSeq=[{"product":"prod1","productcode":"001"},
                     {"product":"prod2","productcode":"002"}]
         
          This template fragment:

          <@xhtml.form_select name="myselect" 
                                 options=optionSeq
                                 displaykey="product"
                                 valuekey="productcode"/>
 
          Will render the following html:

          <select id="myselect"
                     name="myselect"
                     class="">

            <option value="001">prod1</option>
            <option value="002">prod2</option>
          </select>
        

4.7. Macro: form_submit

Macro to render the html submission input tags. This macro does not support nested content. This macro should be used inside the form macro. The following table contains a list of all the parameters supported by this macro.

Table 25. form_submit parameters

ParameterDescriptionRequiredDefault
typeType of submission: submit/resetYes 
valueValue to display on submission input.Yes 
idOptional id for the input element. NoEmpty string
classOptional styling class.NoEmpty string
eventsOptional hash containing JavaScript eventsNoEmpty

Example

          <@xhtml.form_submit type="submit" value="Add"/>
        

4.8. Macro: table

Macro to render the html table tag with headers. This macro supports nested content. All table rows and columns must be nested inside this macro. The following table contains a list of all the parameters supported by this macro.

Table 26. table parameters

ParameterDescriptionRequiredDefault
headersSequence of strings to use as headers.Yes 
classTable level styling class.noEmpty string
hclassHeader level styling class. NoEmpty string
bclassBody level styling class.NoEmpty string

Example

          <@xhtml.table headers=["name","surname"] >
            ...
          </@xhtml.table>
        

4.9. Macro: table_tr

Macro to render the html tr tag. This macro supports nested content. All table columns can be nested inside this macro. The following table contains a list of all the parameters supported by this macro.

Table 27. table_tr parameters

ParameterDescriptionRequiredDefault
idId for the tr element.No 
classStyling class.NoEmpty string

Example

          <@xhtml.table_tr>
            ...
          </@xhtml.table_tr>
        

4.10. Macro: table_td

Macro to render the html td tag. This macro does not support nested content. The following table contains a list of all the parameters supported by this macro.

Table 28. table_td parameters

ParameterDescriptionRequiredDefault
valueThe value of the td element.NoEmpty
classStyling class.NoEmpty string
numformatUse this format when displaying numbers.No#,##0.00

Example

          <@xhtml.table_td value="foo"/>
        

4.11. Macro: messages

Macro to render an html paragraph to display a sequence of informational messages. This macro does not support nested content. The following table contains a list of all the parameters supported by this macro.

Table 29. messages parameters

ParameterDescriptionRequiredDefault
reqThe HttpServletRequest hash (request).Yes 
keyUse this key to obtain a sequence of messages from the request hash. Yes 
headingHeading to use for the sequence of messages.Yes 
idOption id for the ul element in the generated paragraph.NoEmpty string
classStyling class for the ul element in the generated paragraph. NoEmpty string

Example

          <@xhtml.messages req=request key="errors" heading=""/>