FileDocCategorySizeDatePackage
BaseTemplateEngine.javaAPI DocExample3669Mon Jul 23 13:26:36 BST 2007org.apache.struts2.components.template

BaseTemplateEngine

public abstract class BaseTemplateEngine extends Object implements TemplateEngine
Base class for template engines.

Fields Summary
private static final Log
LOG
public static final String
DEFAULT_THEME_PROPERTIES_FILE_NAME
The default theme properties file name. Default is 'theme.properties'
final Map
themeProps
Constructors Summary
Methods Summary
protected java.lang.StringgetFinalTemplateName(Template template)

        String t = template.toString();
        if (t.indexOf(".") <= 0) {
            return t + "." + getSuffix();
        }

        return t;
    
protected abstract java.lang.StringgetSuffix()

protected java.lang.StringgetThemePropertiesFileName()

        return DEFAULT_THEME_PROPERTIES_FILE_NAME;
    
public java.util.MapgetThemeProps(Template template)


        
        synchronized (themeProps) {
            Properties props = (Properties) themeProps.get(template.getTheme());
            if (props == null) {
                String propName = template.getDir() + "/" + template.getTheme() + "/"+getThemePropertiesFileName();

//              WW-1292
                // let's try getting it from the filesystem
                File propFile = new File(propName);
                InputStream is = null;
                try {
                    if (propFile.exists()) {
                        is = new FileInputStream(propFile);
                    }
                }
                catch(FileNotFoundException e) {
                    LOG.warn("Unable to find file in filesystem ["+propFile.getAbsolutePath()+"]");
                }

                if (is == null) {
                    // if its not in filesystem. let's try the classpath
                    is = ClassLoaderUtil.getResourceAsStream(propName, getClass());
                }

                props = new Properties();

                if (is != null) {
                    try {
                        props.load(is);
                    } catch (IOException e) {
                        LOG.error("Could not load " + propName, e);
                    }
                }

                themeProps.put(template.getTheme(), props);
            }

            return props;
        }