Getting Started |
TemplateManagerTemplates are obtained from a TemplateManager. This class is thread-safe. It's a very "lightweight" class, but one instance can be used to obtain numerous templates. TextLoaderFactoryBefore use, a TemplateManager needs to be supplied with at least one TextLoaderFactory, an interface for classes that can load text templates to be parsed by the TemplateManager. If templates are to be loaded from a web application's own directories, a ServletContextTextLoaderFactory should be supplied: public class MyServlet extends HttpServlet { TemplateManager templateMgr=new TemplateManager(); public void init() throws ServletException { templateMgr.getTextLoadMgr().register( new ServletContextTextLoaderFactory(getServletContext()); ); } ... } There are also built-in TextLoaderFactories for loading from the file system, the Java classpath, and more. It's also fairly easy to write a custom one when necessary. Obtaining a templateOnce the TemplateManager is ready, obtaining a template is trivial: Section template=templateMgr.getTemplate("templates/MyTemplate.html"); If several concurrent threads ask for the same template from the same TemplateManager, each will receive its own unique copy. Next page: Section |