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

TemplateEngineManager

public class TemplateEngineManager extends Object
The TemplateEngineManager will return a template engine for the template

Fields Summary
public static final String
DEFAULT_TEMPLATE_TYPE_CONFIG_KEY
public static final String
DEFAULT_TEMPLATE_TYPE
The default template extenstion is ftl.
Map
templateEngines
com.opensymphony.xwork2.inject.Container
container
String
defaultTemplateType
Constructors Summary
Methods Summary
public TemplateEnginegetTemplateEngine(Template template, java.lang.String templateTypeOverride)
Gets the TemplateEngine for the template name. If the template name has an extension (for instance foo.jsp), then this extension will be used to look up the appropriate TemplateEngine. If it does not have an extension, it will look for a Configuration setting "struts.ui.templateSuffix" for the extension, and if that is not set, it will fall back to "ftl" as the default.

param
template Template used to determine which TemplateEngine to return
param
templateTypeOverride Overrides the default template type
return
the engine.

        String templateType = DEFAULT_TEMPLATE_TYPE;
        String templateName = template.toString();
        if (templateName.indexOf(".") > 0) {
            templateType = templateName.substring(templateName.indexOf(".") + 1);
        } else if (templateTypeOverride !=null && templateTypeOverride.length() > 0) {
            templateType = templateTypeOverride;
        } else {
            String type = defaultTemplateType;
            if (type != null) {
                templateType = type;
            }
        }
        return templateEngines.get(templateType).create();
    
public voidregisterTemplateEngine(java.lang.String templateExtension, TemplateEngine templateEngine)
Registers the given template engine.

Will add the engine to the existing list of known engines.

param
templateExtension filename extension (eg. .jsp, .ftl, .vm).
param
templateEngine the engine.

        templateEngines.put(templateExtension, new EngineFactory() {
            public TemplateEngine create() {
                return templateEngine;
            }
        });
    
public voidsetContainer(com.opensymphony.xwork2.inject.Container container)

        this.container = container;
        Map<String,EngineFactory> map = new HashMap<String,EngineFactory>();
        Set<String> prefixes = container.getInstanceNames(TemplateEngine.class);
        for (String prefix : prefixes) {
            map.put(prefix, new LazyEngineFactory(prefix));
        }
        this.templateEngines = Collections.unmodifiableMap(map);
        
    
public voidsetDefaultTemplateType(java.lang.String type)

    
    
        
        this.defaultTemplateType = type;