SourceForge Logo

Presentation Examples Features/principles Benefits Requirements Installation Download Documentation News





JDynamiTe


Dynamic Template in Java




Presentation

JDynamiTe is a simple yet powerful tool used to create dynamic documents from "template" documents. It is based on the same concept as those of "FastTemplate", which is a very popular PHP extension used in many Web sites to create dynamic HTML pages. Note: JDynamiTe is not a Java port of FastTemplate.

The main benefit of JDynamiTe is to allow a true separation between the presentation (HTML, XML, etc) and content generation code (written in Java). JDynamiTe is not another template language, or a complete framework. It is a simple "brick" in your "MVC" architecture, "glue" between views and models.

JDynamiTe is a "pure" Java package, which is designed to be flexible and open.
JDynamiTe is free, under the GNU Library General Public License.
This project is hosted in SourceForge domain.


Examples

First simple example
A simple example is better than a long explanation. Below is an example of a dynamic HTML document generation, from JSP (Java Server Page).
There are the three steps in JDynamiTe process:

1. Create a “Template Document”.

This is the input file. You can see the HTML source code here, and visualize the page here.
2. Use JDynamiTe Java code to parse and develop it.
Click here to see the JSP code.
3. Output the result to a file, to an HTTP client, etc.
Click here to see the result.
Note:
- There is no HTML code in JSP code.
- There is only “pure” HTML in a template document (JDynamiTe tags are enclosed in HTML comments).
- You can find this example in the “main” method of the JDynamiTe class.
- See the "News" chapter which uses this example again with an interesting new feature.

Simple example with the "Ignored block" feature
This example is similar to the first example, but it shows the use of the "Ignored Element" block new feature (since JDynamiTe 1.1).

1. Create a “Template Document”.

Now we can insert concrete data in this input file. This page is more realistic and can be a true working document for designers. You can see the new HTML source code here, and visualize the page here.
2. Use JDynamiTe Java code to parse and develop it.
This is the same code as in the first example ! Because "ignored blocks" are only helpful for page designers, not for programmers. Click here to see the JSP code.
3. Output the result to a file, to an HTTP client, etc.
We obtain the same page as the first example. Click here to see the result.

Another simple example with the "getVariableKeys" method (since JDynamiTe 1.2)
Look at this small piece of code in the javadoc of "getVariableKeys".


Features/Principles

  • JDynamiTe is not another template language, it is a Java package.
  • It is very simple to use : you only need to use one class and 4 or 5 methods to parse and develop dynamic documents from templates (see example).
  • These template documents can be any ASCII or Unicode texts.
  • To work JDynamiTe only needs to recognize three kinds of “tag” in the template document (“Variable”, “Begin Dynamic Element”, “End Dynamic Element”). A "Dynamic Element" is a "block" which can be dynamically developed. Example of use: list, table, enumeration, etc. See documentation for more details.
  • Since JDynamiTe analyser is highly customizable, any syntax can be defined for these tags. For example with the HTML template document (default syntax), the three tags are enclosed within the HTML comments.
  • It enables template reuse (one analyse and several dynamic generations).
  • It enables “Dynamic Elements” nesting.
  • It enables template nesting (because a JDynamiTe object is a “Dynamic Element” !).
  • An optional tag is available that allows inserting "ignored blocks" in the template document.
  • Since JDynamite 1.2, the list of template document "Variable keys" are available (because computed during pre-analysis of the document). See the "News" chapter to understand the benefits of this feature.

  • Benefits

  • Separates presentation (HTML, XML, ...) from the content generation code.
  • JDynamiTe HTML templates can be designed with your preferred HTML builder, or by a “true” HTML designer.
  • HTML designers do not have to know JSP, Java, or any new template language.
  • Ideal for example to create HTML pages from JSP (Java Server Page).

  • Requirements

  • JRE 1.2 or higher
  • “gnu.regexp” package 1.0.8 (included in JDynamiTe distribution) or higher
  • JDynamiTe is a "lightweight" package : less than 15 kb for jdynamite.jar

  • Installation

    Extract “jdynamite.jar” and “gnu-regexp-1.0.8.jar” from the distribution and copy it in a place in such a way that the “import cb.jdynamite.*” Java sentence works !


    Download

    Download last version in JDynamiTe SourceForge domain.


    Documentation

    JDynamiTe is the unique class you need to know.
    See the documentation of this class in javadoc.


    News

    December 2002:
    JDynamiTe 1.2 released !

    Main new feature : now all the Variable keys of the template document are recorded during analysis (i.e. in the "setInput" method). All the values of these key/value pairs are initialized with an empty string value.
    Benefits :

    See here an simple example of use of this new feature.

    Other news in JDynamiTe 1.2 version :


    September
    2001:
    JDynamiTe 1.1 is available.

    The main new feature is the "Ignored Element" block.
    This optional element can be used in template documents. An "Ignored Element" is a "block" which will be completely ignored (skipped during document analysis). It will not be part of the output document.
    The greatest benefit is that it will allow HTML designers to build more realistic pages, with concrete data, giving a better idea of the possible dynamic page look and feel.
    An "Ignored Element" can be inserted anywhere in the template document, even inside "Dynamic Element".

    The better is to look at this simple example.



    SourceForge Logo