import org.antlr.stringtemplate.*; import org.antlr.stringtemplate.misc.*; public abstract class Page { /** My template library */ static StringTemplateGroup templates = new StringTemplateGroup("mygroup", "templates"); static { templates.setRefreshInterval(0); // don't cache templates } public void generate() { StringTemplate pageST = templates.getInstanceOf("page"); StringTemplate bodyST = generateBody(); pageST.setAttribute("body", bodyST); pageST.setAttribute("title", getTitle()); /* Uncomment to view graphically StringTemplateTreeView viz = new StringTemplateTreeView("viz",pageST); viz.setVisible(true); */ String page = pageST.toString(); // render page System.out.println(page); } public abstract StringTemplate generateBody(); public abstract String getTitle(); }