This is a Java implementation of Zope Page Templates (ZPT).
Download here: Sourceforge project page
WARNING: this implementation is not fully compliant to the specs at this
point in time. Read on.
This software is under GPL. Read on.
For more information about Zope, click here.
For the lazy: "Zope is a leading open source application server,
specializing in content management, portals, and custom applications."
For more information about ZPT, click
For the lazy: "This project [ZPT] sought to establish website production
harmony through the seamless integration of the three separate domains:
Presentation, Content and Logic."
For those who never heard of ZPT: Zope Page Templates are yet another
HTML templating solution. They are born as a project within Zope, but they
have been engineered in such a way that their concept is independent of
the language and platform. The unique feature of these templates is that
they do not use ad-hoc tags, therefore the template code remains legal
HTML, both for a browser and a visual editor, like Macromedia Dreamweaver.
The extra informations needed for using the template are stored as
special attributes inside the normal HTML tags. With these attributes - that
all begin with "tal:" - it is possible to mark certain chunks of html code as
conditional, express loops, omit tags, replace tags, add and replace tag
attributes, and so forth.
ZPT are a very powerful templating mechanism, and yet enough unobtrusive
to allow a visual html editor to work seaminglessly with the template.
What is this?
This is my first quick effort to implement ZPT from the official specifications.
I am working on a Java project, but strongly desire ZPT. Since I could
not find anything quickly on the web, I decided to implement it myself, and
release my work to the public domain.
This implementation is not 100% complete with respect to the specs, but
I tried to stay compliant. So far TAL is complete, TALES has path:,
not: and string:.
METAL is not implemented yet. I will probably implement it some time in the
near future, since it looks like I will soon need it for my project.
Data is passed to the template through a Context. A context is like a tree
structure, like a file-system. In my implementation the context is made of
a handful of classes that wrap the functionalities of HashMap and Vector, so
The template is parsed at construction time, so that at evaluation
time only the parse tree needs to be traversed and executed. This way
the rendering of a finished html page should be quite fast, if all the
necessary templates are initialized in the servlets at startup.
The low level html parsing is done through a free library that I found
from quiotix.com (thanks!). It's the first chunk of code that I found.
I initially tried with a more formal approach, involving xhtml, but I
soon realized that a full xml validating parser was way too
complicated for my simple purpose. The quotix parser is very simple though
and does not support tag attributes name spaces. Therefore I had to
work around this limitation... furthermore it's not very good at detecting
quoted text. So far it seems like working fine with xhtml, but with brutal
handwritten html, chances are that it bails out. So, I should probably
try to find a better low level parser. This is not in my near-future-todo-list
though because, as I said, it works fine with xhtml.
Feel free to contact me for any questions and/or comments about my
Java implementation of Zope Page Templates.
Copyright (C) 2003 Stefano Masini <email@example.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
You can find a copy of the Gnu Public Licence (GPL) here.