Class FreemarkerPrinter<T>

  • Type Parameters:
    T - The type of the input context
    All Implemented Interfaces:
    TemplateEngine<T>
    Direct Known Subclasses:
    ExceptionPrinter

    public class FreemarkerPrinter<T>
    extends Object
    implements TemplateEngine<T>

    Printer that is based on freemarker. It will persist according to the given template files

    Since:
    1.0
    Author:
    Oliver Krauss, Andreas Pointner
    • Field Detail

      • configuration

        protected freemarker.template.Configuration configuration
    • Constructor Detail

      • FreemarkerPrinter

        public FreemarkerPrinter​(String templateDirectory)
        Creates the default configuration and set the template loading
        Parameters:
        templateDirectory - if null then this class will be used for template loading, otherwise the directory which was set is used
    • Method Detail

      • transform

        public void transform​(String template,
                              Object o)
      • applyTemplate

        protected void applyTemplate​(String templateName,
                                     Map<String,​Object> data)
        Helper function to actually apply the template
        Parameters:
        templateName - to be applied
        data - to be printed into the template
      • addTemplate

        public void addTemplate​(String name,
                                String templateFile)
      • addAdditionalTemplateValue

        public void addAdditionalTemplateValue​(String key,
                                               Object value)
        Adds a value that has to be used by the template (does override if exists)
        Parameters:
        key - to be used
        value - to be applied to the template
      • removeAdditionalTemplateValue

        public void removeAdditionalTemplateValue​(String key)
        Removes a value from the template
        Parameters:
        key - to be removed
      • setFormat

        public void setFormat​(String format)
      • addTemplatePreprocessor

        public <S> void addTemplatePreprocessor​(TemplatePreprocessor<S> templatePreprocessor)
      • removeTemplatePreprocessor

        public <S> void removeTemplatePreprocessor​(TemplatePreprocessor<S> templatePreprocessor)
      • process

        public void process​(T context,
                            String templateFile,
                            Writer destinationWriter)
        Description copied from interface: TemplateEngine
        Runs the engine
        Specified by:
        process in interface TemplateEngine<T>
        Parameters:
        context - the context in which this should happen
        templateFile - the template file
        destinationWriter - the writer for the result