Java Tutorial - Java Script :
Tea
Tea is a simple template language that, when used in conjunction with the TeaServlet, can be used to create powerful, dynamic Web applications. Tea was originally created by the Walt Disney Internet Group and is distributed under The Tea Software License, Version 1.0, which is based on The Apache Software License. Summary information about Tea can be found in the following table.
The Tea architecture is divided into two general areas, the Tea compiler and Tea runtime (see Figure 6.2). Tea templates consist of code regions and text regions. Code regions contain programming instructions based on the Tea template language, and text regions contain text, which is output without modification by the template engine. Once coded, the Tea template is compiled with the aforementioned Tea compiler and generates standard Java byte-code for use by the host JVM
The runtime environment configures and executes the context class, which provides the print(Object) and the toString(Object) functions. The Tea model enforces the separation between data acquisition and data presentation.
The purpose of the template under the Tea architecture is truly that of a template; it can’t retrieve or modify data, it depends on the host environment to provide data to it. Let’s take a look at how this is accomplished within the Tea architecture. We will start by setting up our Tea environment.
Installing the Tea Servlet:
To install Tea for the examples that follow, you will need to download both the TeaKettle and TeaServlet files. Unzip these files into separate directories. TeaServlet needs to be installed into the Tomcat environment. Follow these steps to install the TeaServlet into Tomcat:
1. Set up the following directory structure within your Tomcat container:
<tomcat_root>\webapps\tea
<tomcat_root>\webapps\tea\WEB-INF
<tomcat_root>\webapps\tea\WEB-INF\classes
<tomcat_root>\webapps\tea\WEB-INF\templates
<tomcat_root>\webapps\tea\WEB-INF\templateClasses
<tomcat_root>\webapps\tea\WEB-INF\lib
2. Create the TeaServlet.properties file as shown in the following code, and place it into the \WEB-INF directory. # TeaServlet properties. # Path to locate Tea templates, in .tea files. template.path /jakarta/tomcat4.1/webapps/tea/WEB-INF/templates
# Optional path to write compiled templates, as .class files.
template.classes = \
/jakarta/tomcat4.1/webapps/tea/WEB-INF/templateClasses
# Applications to load into the TeaServlet.
applications {
“System” {
# The SystemApplication provides TeaServlet
# administration support.
class = com.go.teaservlet.AdminApplication
init {
# The security key for the Admin page.
admin.key = admin
admin.value = true
}
log {
debug = true
info = true
warn = true
error = true
}
}
“HelloMyCity” {
class = HelloMyCityApplication
}
}
log.debug = true
log.info = true
log.warn = true
log.error = true
NOTE
You may want to edit the sample properties file, which can be found in the samples directory below where TeaServlet.zip was unzipped.
The values for template.path and template.classes should be adjusted to match your system.
3. Copy the TeaServlet.jar file from the directory where you unzipped the TeaServlet.zip file, and place it into the \WEBINF\ lib directory.
4. Create a web.xml file in the TOMCAT_ROOT/webapps/teaservlet/
WEB-INF directory, as follows:
<?xml version=”1.0” encoding=”UTF-8”?>
<!DOCTYPE web-app PUBLIC
“-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN”
“http://java.sun.com/dtd/web-app_2_3.dtd”>
<web-app>
<servlet>
<servlet-name>
teaservlet
</servlet-name>
<servlet-class>
com.go.teaservlet.TeaServlet
</servlet-class>
<init-param>
<param-name>properties.file</param-name>
<param-value>c:/jakarta/tomcat/webapps/tea/WEBINF/
TeaServlet.properties</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>teaservlet</servlet-name>
<url-pattern>/dynamic/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>teaservlet</servlet-name>
<url-pattern>*.tea</url-pattern>
</servlet-mapping>
</web-app>
Note that the parameter properties.file needs to be set to the location of the TeaServlet.properties file on your system.
5. Restart Tomcat.
6. To ensure that the installation process was successful, invoke the TeaServlet Administration Console with the following URL: http://localhost:8080/tea/dynamic/system/teaservlet/Admin?admin=true If the installation was successful, you should see the screen shown in Figure 6.3.
