Java Template library similar to ZPT (attribute language)

1.2k views Asked by At

I've been using ZPT in python recently and I love the templating language. I was looking for something similar for Java but couldn't really find anything I liked as well. The closest thing is FreeMarker.

The problem with FreeMarker and the other Java template engines I looked at was their JSP style syntax that allows for non-conforming XML. I was just wondering if there was a Java template engine that is similar to Zope Page Templates such that it's an "attribute" language that requires valid xml.

7

There are 7 answers

0
Bernd On BEST ANSWER

I think think there quite some of the template engines your looking for:

Other approaches supporting valid html are:

0
AudioBubble On

FreeMarker has a nasty dependency on AWT. It makes it impossible to use with things like Google App Engine.

I prefer to use StringTemplate for all my Java templating needs. It is the only Java based template system that strictly separates the logic from the template.

StringTemplate is a java template engine (with ports for C#, Python, Ruby, and Scala) for generating source code, web pages, emails, or any other formatted text output. StringTemplate is particularly good at multi-targeted code generators, multiple site skins, and internationalization/localization

Its distinguishing characteristic is that it strictly enforces model-view separation unlike other engines. Strict separation makes websites and code generators more flexible and maintainable; it also provides an excellent defense against malicious template authors.

Since you are generating XML

Another solution that isn't obvious at first sight is using JAXB. We have a project here that requires us to generate XML, we have very well defined XSD files for the output files, building the objects and marshalling them is super easy and very painless.

0
Scott On

There is also Apache Velocity. Although it doesn't require that your templates be valid XML. That may be a deal breaker for you given the question. You could likely enforce that rule with extensions to the core classes though.

0
Dave Newton On

What about GXP?

There's also LSP and xtempore.

0
Martijn Pieters On

There are currently two implementations for Java that I know of:

0
Daniel Fernández On

The java template engine you will find to be most similar to Chameleon is Thymeleaf.

0
Kernel James On

There is Distal for client based templating.