Package org.openbravo.client.kernel
Class BaseTemplateProcessor<T>
- java.lang.Object
-
- org.openbravo.client.kernel.BaseTemplateProcessor<T>
-
- All Implemented Interfaces:
TemplateProcessor
- Direct Known Subclasses:
FreemarkerTemplateProcessor
public abstract class BaseTemplateProcessor<T> extends Object implements TemplateProcessor
Contains generic code forTemplateProcessor
instances. The generics parameter T is the class of the template as it exists in the specific templating language.- Author:
- mtaal
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.openbravo.client.kernel.TemplateProcessor
TemplateProcessor.Qualifier, TemplateProcessor.Registry, TemplateProcessor.Selector
-
-
Constructor Summary
Constructors Constructor Description BaseTemplateProcessor()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
clearCache()
Is called by the kernel to signal that a template has changed and that TemplateProcessors should clear their cache and reload the templates.protected T
createSetFreeMarkerTemplateInCache(Template template, String source)
Checks the cache if there is already a template implementation for a certain template.protected abstract T
createTemplateImplementation(Template template, String source)
To be implemented by the subclass.protected String
createTemplateSource(Template template)
Creates the template source taking into account overriding templates and pre-prending depends-on templates.protected T
getTemplateImplementation(Template template)
Return the template language specific implementation of the template.String
process(Template template, Map<String,Object> data)
Processes a template and returns the result as a string.protected abstract String
processTemplate(T templateImplementation, Map<String,Object> data)
Run a template implementation for specific data set.protected String
readTemplateSourceFromClasspath(String path)
Reads the template source from the classpath-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.openbravo.client.kernel.TemplateProcessor
getTemplateLanguage, validate
-
-
-
-
Method Detail
-
process
public String process(Template template, Map<String,Object> data)
Description copied from interface:TemplateProcessor
Processes a template and returns the result as a string.- Specified by:
process
in interfaceTemplateProcessor
- Parameters:
template
- the template to process.data
- the data to use in the template- Returns:
- the template process result.
-
processTemplate
protected abstract String processTemplate(T templateImplementation, Map<String,Object> data)
Run a template implementation for specific data set.- Parameters:
templateImplementation
- the template to processdata
- the data which should be passed to the template- Returns:
- the template output
-
getTemplateImplementation
protected T getTemplateImplementation(Template template)
Return the template language specific implementation of the template.- Parameters:
template
- the template stored in the DB- Returns:
- the template implementation in the template language
-
createTemplateSource
protected String createTemplateSource(Template template)
Creates the template source taking into account overriding templates and pre-prending depends-on templates.- Parameters:
template
- the template to create the source for- Returns:
- a complete template source
- See Also:
TemplateResolver.resolve(Template)
-
createSetFreeMarkerTemplateInCache
protected T createSetFreeMarkerTemplateInCache(Template template, String source)
Checks the cache if there is already a template implementation for a certain template. If so that one is returned. If not then a new implementation is created.- Parameters:
template
-source
-
-
createTemplateImplementation
protected abstract T createTemplateImplementation(Template template, String source)
To be implemented by the subclass. Based on the template from the DB and the complete template source, create a language specific template implementation instance.- Parameters:
template
- the template object from the DBsource
- the complete source (after resolving and including all dependencies)- Returns:
- the template implementation
-
readTemplateSourceFromClasspath
protected String readTemplateSourceFromClasspath(String path)
Reads the template source from the classpath- Parameters:
path
- the path to the template file- Returns:
- the read template
-
clearCache
public void clearCache()
Description copied from interface:TemplateProcessor
Is called by the kernel to signal that a template has changed and that TemplateProcessors should clear their cache and reload the templates.- Specified by:
clearCache
in interfaceTemplateProcessor
-
-