KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > components > template > BaseTemplateEngine


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 JavaDoc;
8 import java.io.InputStream JavaDoc;
9 import java.util.HashMap JavaDoc;
10 import java.util.Map JavaDoc;
11 import java.util.Properties JavaDoc;
12
13 /**
14  * BaseTemplateEngine
15  * Date: Sep 28, 2004 3:47:22 PM
16  *
17  * @author jcarreira
18  */

19 public abstract class BaseTemplateEngine implements TemplateEngine {
20     private static final Log LOG = LogFactory.getLog(BaseTemplateEngine.class);
21
22     final Map JavaDoc themeProps = new HashMap JavaDoc();
23
24     public Map JavaDoc getThemeProps(Template template) {
25         synchronized (themeProps) {
26             Properties JavaDoc props = (Properties JavaDoc) themeProps.get(template.getTheme());
27             if (props == null) {
28                 String JavaDoc propName = template.getDir() + "/" + template.getTheme() + "/theme.properties";
29                 InputStream JavaDoc is = ClassLoaderUtil.getResourceAsStream(propName, getClass());
30                 props = new Properties JavaDoc();
31
32                 if (is != null) {
33                     try {
34                         props.load(is);
35                     } catch (IOException JavaDoc 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 JavaDoc getFinalTemplateName(Template template) {
48         String JavaDoc t = template.toString();
49         if (t.indexOf(".") <= 0) {
50             return t + "." + getSuffix();
51         }
52
53         return t;
54     }
55
56     protected abstract String JavaDoc getSuffix();
57 }
58
Popular Tags