JustTE4J - Java Web Template Engine
JustTE4J is a web template engine written in Java. It's core is based on JSoup HTML Parser and servlets. Therefore requires servlet container (preferably Tomcat). In general in consist of one servlet for handling data processing, JustTE4J library (one file) and dependencies.
Installation
In order to install JustTE4J follow these steps:
- create folder for your website in the webapps folder of servlet container,
- put static page data (html, css and js) in this folder,
- create folder named WEB-INF in the main folder. In it, create folder named lib,
- put dependencies in the lib folder (just jsoup-x.x.x.jar),
- put engine and servlet libraries in the lib folder (JustTE4J-x.x.jar, JustTE4JServlet-x.x.jar),
- create web.xml file in WEB-INF folder and configure it (instruction below).
And now templates
- create folder named 'template' (may be configured) in the main folder,
- create folder named 'form' and folder named 'data' (may be configured) in the 'template' folder,
- put template form (the base for templating) in the 'form' folder. Name it templateTE4J.html (may be configured).
- put data files in the 'data' folder. Name it pageName.ted (extention may be configured) where pageName is the name of requested page name. For example: contact.html corresponds to contact.ted. The name MUST be the same as html file unless servlet is configured to find names dynamically,
- reconfigure web.xml,
- restart server.
Ready site folder should look like this:
--tomcat
----webbapp
------mySite
--------index.html
--------WEB
----------web.xml
----------lib
------------jsoup-x.x.x.jar
------------JustTE4J-x.x.jar
------------JustTE4JServlet-x.x.jar
----------template
------------form
--------------templateTE4J.html
------------data
--------------pageDataA.ted
--------------pageDataB.ted
--------------pageDataC.ted
Configuration of web.xml
Proper configuration requires editing of web.xml file in two steps. The first is installation of the engine and the second - installation of data for pages.
Clean web.xml file (without engine) should look like this:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
First step is to configure the main servlet. You can do this by putting the following code within <web-app> tag (below </welcome-file-list> tag). Minimal web.xml (without changing the default values) should look like this:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<description></description>
<display-name>StaticJustTE4JServlet</display-name>
<servlet-name>StaticJustTE4JServlet</servlet-name>
<servlet-class>org.justte4j.servlet.StaticJustTE4JServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>StaticJustTE4JServlet</servlet-name>
<url-pattern>/StaticJustTE4JServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>StaticJustTE4JServlet</servlet-name>
<url-pattern>/justTE4JTest.html</url-pattern>
</servlet-mapping>
</web-app>
The above configuration assumes that default values for templating are used. This is:
TE4J_FILE_FOLDER=/template -> folder name where data and form folders are located,
DATA_FILE_FOLDER=/data -> folder name where data files are located,
FORM_FILE_FOLDER=/form -> folder name where form file is located,
FORM_FILE_NAME=/templateTE4J.html -> template file name.
If you want to change the default data you have to put parameters tags under the </servlet-mapping> tag. Choose one you require. The web.xml (with ) should look like this.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation=" http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>JustTE4JOpenSource</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<description></description>
<display-name>StaticJustTE4JServlet</display-name>
<servlet-name>StaticJustTE4JServlet</servlet-name>
<servlet-class>org.justte4j.servlet.StaticJustTE4JServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>StaticJustTE4JServlet</servlet-name>
<url-pattern>/StaticJustTE4JServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>StaticJustTE4JServlet</servlet-name>
<url-pattern>/justTE4JTest.html</url-pattern>
</servlet-mapping>
<!-- PARAMS START -->
<context-param>
<param-name>DATA_FILE_EXTENTION</param-name>
<param-value>.ted</param-value>
</context-param>
<context-param>
<param-name>TE4J_FILE_FOLDER</param-name>
<param-value>/template</param-value>
</context-param>
<context-param>
<param-name>DATA_FILE_FOLDER</param-name>
<param-value>/data</param-value>
</context-param>
<context-param>
<param-name>FORM_FILE_FOLDER</param-name>
<param-value>/form</param-value>
</context-param>
<context-param>
<param-name>FORM_FILE_NAME</param-name>
<param-value>/templateTE4J.html</param-value>
</context-param>
<!-- PARAMS END -->
</web-app>
Step 2 depends on how many pages you want to process. For every page you should put the following tags under </servlet-mapping> tag where /pageA.html is the name of the page.
<servlet-mapping>
<servlet-name>StaticJustTE4JServlet</servlet-name>
<url-pattern>/pageA.html</url-pattern>
</servlet-mapping>
Final (fully configured) web.xml file should look like this:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>JustTE4JOpenSource</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<description></description>
<display-name>StaticJustTE4JServlet</display-name>
<servlet-name>StaticJustTE4JServlet</servlet-name>
<servlet-class>org.justte4j.servlet.StaticJustTE4JServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>StaticJustTE4JServlet</servlet-name>
<url-pattern>/StaticJustTE4JServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>StaticJustTE4JServlet</servlet-name>
<url-pattern>/justTE4JTest.html</url-pattern>
</servlet-mapping>
<!-- PARAMS START -->
<context-param>
<param-name>DATA_FILE_EXTENTION</param-name>
<param-value>.ted</param-value>
</context-param>
<context-param>
<param-name>TE4J_FILE_FOLDER</param-name>
<param-value>/template</param-value>
</context-param>
<context-param>
<param-name>DATA_FILE_FOLDER</param-name>
<param-value>/data</param-value>
</context-param>
<context-param>
<param-name>FORM_FILE_FOLDER</param-name>
<param-value>/form</param-value>
</context-param>
<context-param>
<param-name>FORM_FILE_NAME</param-name>
<param-value>/templateTE4J.html</param-value>
</context-param>
<!-- PARAMS END -->
<!-- TEMPLATED PAGES-->
<servlet-mapping>
<servlet-name>StaticJustTE4JServlet</servlet-name>
<url-pattern>/index.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>StaticJustTE4JServlet</servlet-name>
<url-pattern>/pageA.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>StaticJustTE4JServlet</servlet-name>
<url-pattern>/pageB.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>StaticJustTE4JServlet</servlet-name>
<url-pattern>/pageC.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>StaticJustTE4JServlet</servlet-name>
<url-pattern>/pageD.html</url-pattern>
</servlet-mapping>
<!-- TEMPLATED PAGES END-->
</web-app>