FreeMarker
Encyclopedia
FreeMarker is a Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

-based template engine
Template engine
A template engine is software that is designed to process web templates and content information to produce output web documents. It runs in the context of a template system.-Types:...

 focusing on the MVC
Model-view-controller
Model–view–controller is a software architecture, currently considered an architectural pattern used in software engineering. The pattern isolates "domain logic" from the user interface , permitting independent development, testing and maintenance of each .Model View Controller...

 software architecture
Software architecture
The software architecture of a system is the set of structures needed to reason about the system, which comprise software elements, relations among them, and properties of both...

. Although it's mostly used for Servlet-based Web Application development, it can be used for any other kind of text output, such as generating CSS
CSS
-Computing:*Cascading Style Sheets, a language used to describe the style of document presentations in web development*Central Structure Store in the PHIGS 3D API*Closed source software, software that is not distributed with source code...

, Java source code, etc. Unlike JSP
JavaServer Pages
JavaServer Pages is a Java technology that helps software developers serve dynamically generated web pages based on HTML, XML, or other document types...

, it is not dependent on the Servlet architecture or on HTTP. Thus it can be used for non-Web tasks as well. FreeMarker is Free software
Free software
Free software, software libre or libre software is software that can be used, studied, and modified without restriction, and which can be copied and redistributed in modified or unmodified form either without restriction, or with restrictions that only ensure that further recipients can also do...

.

History

FreeMarker has a somewhat hectic history, caused by paradigm shift
Paradigm shift
A Paradigm shift is, according to Thomas Kuhn in his influential book The Structure of Scientific Revolutions , a change in the basic assumptions, or paradigms, within the ruling theory of science...

s and other significant changes at multiple occasions. FreeMarker 1 (now known as FreeMarker Classic, a separate project) was originally written by Benjamin Geer and Mike Bayer.
From 2002, the new project lead was Jonathan Revusky, who released FreeMarker 2, which started a sequence of several substantial changes. The main aim of the changes was to make the template language more strict, i.e., to detect as many of the typos and other typical mistakes as early as possible. Also, the automatic object wrapping was introduced, along with the gradual advancement of the type system of the template language. Last but not least, the language has gained a lot of power-user features, such as more powerful macro programming capabilities. The language didn't reach a reasonably settled state until version 2.3, released in 2004 Q3. Since then, the product has remained fully backward compatible, however some not entirely backward compatible changes are still expected in 2.4, which was tentatively scheduled to be released in 2008 Q4 but is still actively being developed.

Example

The following template:




Hello ${name}! You have the following messages:
<#list messages as m>

${m.from}: ${m.body}







processed by FreeMarker will produce something like:




Hello Joe! You have the following messages:

Tim: Please don't forget to bring the conference papers!


Cindy: Can you give me visit afternoon?


Richard: Man, this time don't forget the papers!






Variables like "name" and "messages" are coming from outside the template, and thus the template author has to deal with the presentation issues only. The template remains the same regardless if these variables are coming from a database or from a cookie or calculated on whatever other ways. Also the exact Java API (and hence the class) of the values can be hidden in FreeMarker using a technique called object wrapping. For example, "messages" seems to be a list or array of Java beans that have "from" and "body" properties, but it might be as well something very different, and the template is not affected (as long as a proper object wrapper is used).

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK