You probably want to test the rhythm pattern mechanism , with good performance (2 to 3 times faster than speed) and elegant syntax (.net Razor like), and was developed specifically for the Java programmer.
Template, generate a string of usernames separated by "," from the list of users
@args List<User> users @for (User user: users) { @user.getName() @user_sep }
Template: if-else demo
@args User user @if (user.isAdmin()) { <div id="admin-panel">...</div> } else { <div id="user-panel">...</div> }
Calling a Template Using a Template File
// pass render args by name Map<String, Object> renderArgs = ... String s = Rythm.render("/path/to/my/template.txt", renderArgs); // or pass render arguments by position String s = Rythm.render("/path/to/my/template.txt", "arg1", 2, true, ...);
Invoke a template using inline text
User user = ...; String s = Rythm.render("@args User user;Hello @user.getName()", user);
Invoke a string interpolation pattern
User user = ...; String s = Rythm.render("Hello @name", user.getName());
ToString mode
public class Address { public String unitNo; public String streetNo; ... public String toString() { return Rythm.toString("@_.unitNo @_.streetNo @_.street, @_.suburb, @_.state, @_.postCode", this); } }
Auto ToString mode (follow apache commons lang reflectionToStringBuilder, but faster than it)
public class Address { public String unitNo; public String streetNo; ... public String toString() { return Rythm.toString(this); } }
The document can be found at http://www.playframework.org/modules/rythm . The full demo application runs on GAE: http://play-rythm-demo.appspot.com .
Note. Demo and doc are created for the play-rythm plugin for Play! Framework, but most of the content also applies to the clean rhythm template engine.
Source: