1 package com.opensymphony.webwork.components.template; 2 3 import com.opensymphony.webwork.config.Configuration; 4 5 import java.util.HashMap ; 6 import java.util.Map ; 7 8 14 public class TemplateEngineManager { 15 public static final String DEFAULT_TEMPLATE_TYPE_CONFIG_KEY = "webwork.ui.templateSuffix"; 16 17 private static final TemplateEngineManager MANAGER = new TemplateEngineManager(); 18 public static final String DEFAULT_TEMPLATE_TYPE = "ftl"; 19 20 Map templateEngines = new HashMap (); 21 22 private TemplateEngineManager() { 23 templateEngines.put("ftl", new FreemarkerTemplateEngine()); 24 templateEngines.put("vm", new VelocityTemplateEngine()); 25 templateEngines.put("jsp", new JspTemplateEngine()); 26 } 27 28 public static void registerTemplateEngine(String templateExtension, TemplateEngine templateEngine) { 29 MANAGER.templateEngines.put(templateExtension, templateEngine); 30 } 31 32 38 public static TemplateEngine getTemplateEngine(Template template) { 39 String templateType = DEFAULT_TEMPLATE_TYPE; 40 String templateName = template.toString(); 41 if (templateName.indexOf(".") > 0) { 42 templateType = templateName.substring(templateName.indexOf(".") + 1); 43 } else { 44 if (Configuration.isSet(DEFAULT_TEMPLATE_TYPE_CONFIG_KEY)) { 45 templateType = (String ) Configuration.get(DEFAULT_TEMPLATE_TYPE_CONFIG_KEY); 46 } 47 } 48 return (TemplateEngine) MANAGER.templateEngines.get(templateType); 49 } 50 51 52 } 53 | Popular Tags |