Package africa.absa.inception.mail
Class FreeMarkerTemplateLoader
- java.lang.Object
-
- africa.absa.inception.mail.FreeMarkerTemplateLoader
-
- All Implemented Interfaces:
freemarker.cache.TemplateLoader
public class FreeMarkerTemplateLoader extends Object implements freemarker.cache.TemplateLoader
The FreeMarkerTemplateLoader class implements the Apache FreeMarker template loader.- Author:
- Marcus Portmann
-
-
Constructor Summary
Constructors Constructor Description FreeMarkerTemplateLoader(IMailService mailService)Constructs a new FreeMarkerTemplateLoader.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcloseTemplateSource(Object templateSource)Closes the template source, releasing any resources held that are only required for reading the template and/or its metadata.ObjectfindTemplateSource(String name)Finds the template in the backing storage and returns an object that identifies the storage location where the template can be loaded from.longgetLastModified(Object templateSource)Returns the time of last modification of the specified template source.ReadergetReader(Object templateSource, String encoding)Returns the character stream of a template represented by the specified template source.
-
-
-
Constructor Detail
-
FreeMarkerTemplateLoader
public FreeMarkerTemplateLoader(IMailService mailService)
Constructs a new FreeMarkerTemplateLoader.- Parameters:
mailService- the Mail Service
-
-
Method Detail
-
closeTemplateSource
public void closeTemplateSource(Object templateSource) throws IOException
Closes the template source, releasing any resources held that are only required for reading the template and/or its metadata. This is the last method that is called by theTemplateCachefor a template source, except thatObject.equals(Object)is might called later too.TemplateCacheensures that this method will be called on every object that is returned fromfindTemplateSource(String).- Specified by:
closeTemplateSourcein interfacefreemarker.cache.TemplateLoader- Parameters:
templateSource- the template source that should be closed.- Throws:
IOException
-
findTemplateSource
public Object findTemplateSource(String name) throws IOException
Finds the template in the backing storage and returns an object that identifies the storage location where the template can be loaded from. See the return value for more information.- Specified by:
findTemplateSourcein interfacefreemarker.cache.TemplateLoader- Parameters:
name- The name of the template, already localized and normalized by thecache.- Returns:
- An object representing the template source, which can be supplied in subsequent calls
to
getLastModified(Object)andgetReader(Object, String), when those are called on the sameTemplateLoader.nullmust be returned if the source for the template doesn't exist - Throws:
IOException
-
getLastModified
public long getLastModified(Object templateSource)
Returns the time of last modification of the specified template source. This method is called after findTemplateSource().- Specified by:
getLastModifiedin interfacefreemarker.cache.TemplateLoader- Parameters:
templateSource- an object representing a template source, obtained through a prior call tofindTemplateSource(String)- Returns:
- the time of last modification of the specified template source, or -1 if the time is not known.
-
getReader
public Reader getReader(Object templateSource, String encoding) throws IOException
Returns the character stream of a template represented by the specified template source. This method is possibly called for multiple times for the same template source object, and it must always return aReaderthat reads the template from its beginning. Before this method is called for the second time (or later), its caller must close the previously returnedReader, and it must not use it anymore. That is, this method is not required to support multiple concurrent readers for the same sourcetemplateSourceobject.Typically, this method is called if the template is missing from the cache, or if after calling
findTemplateSource(String)andgetLastModified(Object)it was determined that the cached copy of the template is stale. Then, if it turns out that theencodingparameter used doesn't match the actual template content (based on the#ftl encoding=...header), this method will be called for a second time with the correctencodingparameter value.- Specified by:
getReaderin interfacefreemarker.cache.TemplateLoader- Parameters:
templateSource- an object representing a template source, obtained through a prior call tofindTemplateSource(String). This must be an object on whichTemplateLoader.closeTemplateSource(Object)wasn't applied yet.encoding- the character encoding used to translate source bytes to characters. Some loaders may not have access to the byte representation of the template stream, and instead directly obtain a character stream. These loaders should ignore the encoding parameter.- Returns:
- A
Readerrepresenting the template character stream. It's the responsibility of the caller (which isTemplateCacheusually) toclose()it. TheReaderis not required to work after thetemplateSourcewas closed (closeTemplateSource(Object)). - Throws:
IOException
-
-