$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
This document will serve as a reference guide to all Toolbox related command line utilities, Apache Ant Macros and FreeMarker Template Macros.
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.
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.
beangen <-templatedir dir>
<-template file>
<-beanfile file> | <-beandir dir>
<-outdir dir>
[-extension ext]
Table 1. beangen options
Option | Description |
---|---|
-templatedir | The directory to use when loading the FreeMarker Template. The script defaults this option to $TOOLBOX_HOME/templates. |
-template | The FreeMarker template to use. The script defaults this option to dao/DaoBeanTemplate.ftl. |
-beanfile | The path to an XML file containing the Java Bean definition. Specify this value if the -beandir option is not used. |
-beandir | The path to a directory containing Java Bean definition XML files. Specify this value if the -beanfile option is not used. |
-outdir | The path to the target directory where the Java Bean will be written. |
-extension | Use this switch if you do not want the generated file to have a .java extension. |
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
Option | Description |
---|---|
-list | List the supported modules. The indicates the capability of the tool. |
-module | The name of the module to invoke. |
-templatedir | The directory to use when loading the FreeMarker Template. The script defaults this option to $TOOLBOX_HOME/templates/servicegen. |
-javadir | The path to a directory where the java package structure must be created. |
-svcdir | The path to the target directory where the generated service configuration files must be written. Usually etc/services. |
-definition | The 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. |
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]
Table 3. confgen options
Option | Description |
---|---|
-list | Print a list of the supported configuration modules. |
-module | Specify the name of the module to execute. |
-templatedir | The directory to load the template from. The script defaults this option to $TOOLBOX_HOME/templates. |
-template | The FreeMarker template to use. Each module has a configured default that can be overridden with this option. |
-outdir | The path to the target directory where the configuration file will be written. |
-outfile | Write the output to this file and not the module default. |
-properties | The 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. |
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
Directory | Description |
---|---|
doc | All application documentation can be placed here. |
etc | All application configuration files can be created in this directory. This includes Java properties files, XML configuration and deployment descriptors. |
etc/beans | All XML bean definitions can be placed here. The files in this directory can be processed with the Bean Generator utility. |
etc/resources | Java ResourceBundles required by the application can be created in this directory. |
etc/services | All application component or service configuration files can be created in this directory. These are configuration files that only affect specific application services. |
htdocs | All 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. |
java | All 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
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
Property | Description | Value |
---|---|---|
Global properties | ||
dist | Directory where all distribution assembly files will be placed. | dist |
build | Directory where all compiled files will be placed. | build |
Properties to assemble WAR files. | ||
dist_war | Directory where all WAR assembly files will be placed. | ${dist}/war |
web_inf | ${dist_war}/WEB-INF | |
war_classes | All web application resources will be placed here. | ${web_inf}/classes |
war_lib | All web application jars will be placed here. | ${web_inf}/lib |
war_etc | All Toolbox related war configurations will be placed here. | ${web_inf}/etc |
war_docs | All display templates will be placed here. | ${dist_war}/htdocs |
war_lenient_xml | Indicates whether war xml configs must validated strict or lenient. Valid values yes|no | yes |
war_web_xml | The path to the web.xml deployment descriptor. | etc/web.xml |
war_configs_dir | The path to the directory containing all the Toolbox related war configurations. | etc |
war_configs | Comma separated list of Toolbox war configurations. | web_config.xml,view_servlet.xml,web_validator.xml, registry_finaliser.properties |
war_resources_dir | The path to the directory containing the required resources bundles. | etc/resources |
war_resources | Wild card indicating which resource bundles to include. | *.properties |
war_htdocs | The path to the directory containing all the required documents/templates to render the web application views. | htdocs |
war_index_html | The path to the index.html file. | htdocs/index.html |
Properties to assemble ZIP files containing application distributions. | ||
app_doc | The path to the directory containing all application documentation. | doc |
app_etc | The path to the directory containing all application configuration. | etc |
app_srv | The path to the directory containing all application service configurations. | etc/services |
app_lib | Directory that will contain all application jar files. | lib |
app_war | Directory that will contain the application war file. | war |
svc_lenient_xml | Indicates whether service xml configs must validated strict or lenient. Valid values yes|no | yes |
svc_services_xml | The path to the services.xml file. | etc/services.xml |
svc_env_xmls | Wildcard indicating all service environment configurations. | *_env.xml |
Java compilation properties. | ||
debug | Indicates whether debugging should be on or off. | on |
debug_level | Indicates the level of debugging. | source,lines |
servlet_jar | Location of the servler.jar file. | ${env.TOOLBOX_SERVLET_API} |
freemarker_jar | Location of the freemarker.jar file. | ${env.TOOLBOX_FM_HOME}/lib/freemarker.jar |
toolbox_core_jar | Location of the toolbox_core.jar file. | ${env.TOOLBOX_HOME}/lib/toolbox_core.jar |
toolbox_web_jar | Location of the toolbox_web.jar file. | ${env.TOOLBOX_HOME}/lib/toolbox_web.jar |
cp | The default classpath that will be used for compilation. | ${servlet_jar}:${freemarker_jar}:${toolbox_core_jar}:${toolbox_web_jar}:${build}:. |
Javadoc properties. | ||
javadoc_dir | The path to the directory where the generated documentation must be placed. | ../doc/api |
javadoc_source | The directory where the Java source files are located. | . |
javadoc_author | Boolean to indicate whether author names must be included in the generated documentation. | true |
JES Application Server deployment properties. | ||
jes_asadmin7 | The location of the appserver 7 asadmin executable | /opt/SUNWappserver7/bin/asadmin |
jes_asadmin8 | The location of the appserver 8 asadmin executable | /opt/sun/appserver/bin/asadmin |
jes_asuser | The admin server user name. | admin |
jes_aspass | The admin server password | admin |
jes_ashost | The admin server host | localhost |
jes_asport | The admin server port number | 4848 |
jes_assecure | Boolean indicating whether the admin server is running on a secure port. | false |
jes_asupload | Boolean indicating whether the deployed component must be uploaded to the admin server. | false |
jes_asinstance | The appserver 7 instance to deploy to. | server1 |
jes_asvirtualservers8 | The appserver 8 virtual servers to deploy to. | server |
JES Web Server deployment properties. | ||
jes_wswdeploy | The location of the wdeploy executable. | /opt/SUNWwbsvr/bin/https/bin/wdeploy |
Tomcat 4 deployment properties. | ||
tomcat_webapps | The path to the tomcat webapps directory. | /opt/jakarta/tomcat/webapps |
DocBook XSL properties. | ||
docbook_root | The path to the root directory of the docbook dtd's and stylesheets. | /opt/misc/docbook |
root_catalog | The path to the root XML catalog file. | ${docbook_root}/catalog.xml |
catalog_43 | The path to the docbook 4.3 dtd. | ${docbook_root}/dtd4.3/catalog.xml |
catalog_44 | The path to the docbook 4.4 dtd. | ${docbook_root}/dtd4.4/catalog.xml |
docbook_catalog_path | The XML catalog path. | ${root_catalog}:${catalog_43}:${catalog_44} |
docbook_html_xsl | The 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"/>
Table 6. ant macros
Macro | Description |
---|---|
tbwar | Macro to create a war file that includes all the Toolbox specific configurations and directories. |
tbsvcapp | Macro to create a zip archive that contains a Toolbox application distribution. The application must be based on the Toolbox services API. |
tbclean | Macro to perform clean up after the tbwar and tbsvcapp macros. |
tbjavac | Macro to perform Java compilations. |
tbjar | Macro to create jar files. |
tbjavadoc | Macro 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 |
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) | Description | Required | Default |
---|---|---|---|
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>
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) | Description | Required | Default |
---|---|---|---|
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>
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) | Description | Required | Default |
---|---|---|---|
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>
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) | Description | Required | Default |
---|---|---|---|
srcdir (A) | Directory containing sources. | Yes | |
cp (A) | Append this classpath to the default classpath. | No | Empty 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>
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) | Description | Required | Default |
---|---|---|---|
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>
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) | Description | Required | Default |
---|---|---|---|
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. | No | Empty 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>
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) | Description | Required | Default |
---|---|---|---|
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>
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) | Description | Required | Default |
---|---|---|---|
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>
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) | Description | Required | Default |
---|---|---|---|
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>
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) | Description | Required | Default |
---|---|---|---|
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>
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) | Description | Required | Default |
---|---|---|---|
name (A) | The name of the web application. | Yes | |
contextfile (A) | File containing a context definition. | No | Empty 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>
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) | Description | Required | Default |
---|---|---|---|
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>
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.
Table 19. freemarker macros
Macro | Description |
---|---|
xhtml | Macro to render the XHTML document type definition and html start and end tag. |
head | Macro to render the html head start and end tag. |
form | Macro to render the html form start and end tag. |
form_input | Macro to render the html input tag. |
form_textarea | Macro to render the html textarea tag. |
form_select | Macro to render the html select tag with options. |
form_submit | Macro to render html form submission input tags. |
table | Macro to render the html table tag with headers. |
table_tr | Macro to render the html tr tag. |
table_td | Macro to render the html td tag. |
messages | Macro 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>
<@xhtml.macro_name param1=value paramN=value/>
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>
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
Parameter | Description | Required | Default |
---|---|---|---|
title | Page title. | Yes | |
style | URL to a stylesheet. | No | /styles.css |
Example
<@xhtml.head title="My Page" style=/styles/mystyle.css"/>
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
Parameter | Description | Required | Default |
---|---|---|---|
name | The form name. | Yes | |
action | URL where form will be submitted to. | Yes | |
id | Unique id to assign to the form element. | No | Value of the name parameter. |
method | HTTP method to use when submitting. | No | post |
encoding | Specify an alternate encoding. | No | Empty string |
class | Styling class. | No | Empty string |
Example
<@xhtml.form name="myform" action="action/url"> ..... </@xhtml.form>
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
Parameter | Description | Required | Default |
---|---|---|---|
name | The name of the input. | Yes | |
id | Unique id to assign to the input element. | No | Value of the name parameter. |
class | Styling class. | No | Empty string |
type | Type of input. | No | text |
value | The value of the input element. | No | Empty string |
extra | Any additional information. Like "checked" for a checked checkbox input. | No | Empty string |
numformat | Use this format when displaying numerical data. | No | #,##0.00 |
events | Optional hash containing JavaScript events | No | Empty |
Example
<@xhtml.form_input name="myinput" value="foo"/>
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
Parameter | Description | Required | Default |
---|---|---|---|
name | The name of the textarea. | Yes | |
id | Unique id to assign to the textarea element. | No | Value of the name parameter. |
class | Styling class. | No | Empty string |
value | The value of the textarea element. | No | Empty string |
events | Optional hash containing JavaScript events | No | Empty |
Example
<@xhtml.form_textarea name="mytext" value="foo"/>
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
Parameter | Description | Required | Default |
---|---|---|---|
name | The name of the select. | Yes | |
id | Unique id to assign to the select element. | No | Value of the name parameter. |
class | Styling class. | No | Empty string |
selected | The value of the selected option element. | No | Empty string |
options | Sequence of hashes/scalars containing options. | Yes | |
displaykey | If the options sequence contain hashes, use this key to find the option display value. | No | display |
valuekey | If the options sequence contain hashes, use this key to find the option value. | No | value |
empty | Boolean to indicate whether the first option must be empty. | No | false |
events | Optional hash containing JavaScript events | No | Empty |
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>
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
Parameter | Description | Required | Default |
---|---|---|---|
type | Type of submission: submit/reset | Yes | |
value | Value to display on submission input. | Yes | |
id | Optional id for the input element. | No | Empty string |
class | Optional styling class. | No | Empty string |
events | Optional hash containing JavaScript events | No | Empty |
Example
<@xhtml.form_submit type="submit" value="Add"/>
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
Parameter | Description | Required | Default |
---|---|---|---|
headers | Sequence of strings to use as headers. | Yes | |
class | Table level styling class. | no | Empty string |
hclass | Header level styling class. | No | Empty string |
bclass | Body level styling class. | No | Empty string |
Example
<@xhtml.table headers=["name","surname"] > ... </@xhtml.table>
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
Parameter | Description | Required | Default |
---|---|---|---|
id | Id for the tr element. | No | |
class | Styling class. | No | Empty string |
Example
<@xhtml.table_tr> ... </@xhtml.table_tr>
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
Parameter | Description | Required | Default |
---|---|---|---|
value | The value of the td element. | No | Empty |
class | Styling class. | No | Empty string |
numformat | Use this format when displaying numbers. | No | #,##0.00 |
Example
<@xhtml.table_td value="foo"/>
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
Parameter | Description | Required | Default |
---|---|---|---|
req | The HttpServletRequest hash (request). | Yes | |
key | Use this key to obtain a sequence of messages from the request hash. | Yes | |
heading | Heading to use for the sequence of messages. | Yes | |
id | Option id for the ul element in the generated paragraph. | No | Empty string |
class | Styling class for the ul element in the generated paragraph. | No | Empty string |
Example
<@xhtml.messages req=request key="errors" heading=""/>