A really simple JSP compiler that allows you to use JSP's for all templating not just web pages.
Based on GNUJsp.
Use JSP templates for generating emails, source code, files and other random things. Instead of usinga different a templating style each time, leverage JSP style templating in non-web environment.
For people who like their errors at compile time (scriptlets are good!), not runtime (JSTL is bad!).
Released under GPL.
public class CustomerOrder {
private String name;
private List itemsOrdered;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public List getItemsOrdered() {
return itemsOrdered;
}
public void setItemsOrdered(List itemsOrdered) {
this.itemsOrdered = itemsOrdered;
}
}
<%@ page extends="com.sample.CustomerOrder" %>
Hi <%= getName() %>,
Items you ordered:
<%
for (int i = 0; i < getItemsOrdered().size(); i++) {
String itemOrdered = (String) getItemsOrdered().get(i);
%> - <%= itemOrdered %>
<%
}
%>
Regards,
Sample Company.
<taskdef name="jsptem" classname="org.tuckey.jsptem.JspTemAntTask" classpath="classes">
<classpath refid="common.classpath" />
</taskdef>
<jsptem srcdir="src" destdir="src" listfiles="true"/>
GeneratedCustomerOrder customerOrderEmail = new GeneratedCustomerOrder();
List items = new ArrayList();
items.add("French Stick");
items.add("Apple");
customerOrderEmail.setItemsOrdered(items);
customerOrderEmail.setName("Bob");
// to a file
customerOrderEmail.writeToFile(myFile);
// to a string
String orderEmail = customerOrderEmail.writeToString();
// to a stream
customerOrderEmail.writeToStream(myStream);