1 package com.opensymphony.webwork.components.template; 2 3 import com.opensymphony.util.ClassLoaderUtil; 4 import org.apache.commons.logging.Log; 5 import org.apache.commons.logging.LogFactory; 6 7 import java.io.IOException ; 8 import java.io.InputStream ; 9 import java.util.HashMap ; 10 import java.util.Map ; 11 import java.util.Properties ; 12 13 19 public abstract class BaseTemplateEngine implements TemplateEngine { 20 private static final Log LOG = LogFactory.getLog(BaseTemplateEngine.class); 21 22 final Map themeProps = new HashMap (); 23 24 public Map getThemeProps(Template template) { 25 synchronized (themeProps) { 26 Properties props = (Properties ) themeProps.get(template.getTheme()); 27 if (props == null) { 28 String propName = template.getDir() + "/" + template.getTheme() + "/theme.properties"; 29 InputStream is = ClassLoaderUtil.getResourceAsStream(propName, getClass()); 30 props = new Properties (); 31 32 if (is != null) { 33 try { 34 props.load(is); 35 } catch (IOException e) { 36 LOG.error("Could not load " + propName, e); 37 } 38 } 39 40 themeProps.put(template.getTheme(), props); 41 } 42 43 return props; 44 } 45 } 46 47 protected String getFinalTemplateName(Template template) { 48 String t = template.toString(); 49 if (t.indexOf(".") <= 0) { 50 return t + "." + getSuffix(); 51 } 52 53 return t; 54 } 55 56 protected abstract String getSuffix(); 57 } 58 | Popular Tags |