//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package kinosearch.webapp.template;

import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import java.io.File;
import java.io.IOException;
import java.io.Writer;
import java.util.Map;

public class FreemakerProcessor implements TemplateProcessor {
    private Configuration config;

    public void process(String templateName, Map<String, Object> model, Writer writer) throws IOException {
        try {
            if (this.config == null) {
                if (model.containsKey(".templatedir")) {
                    this.init((String)model.get(".templatedir"));
                } else {
                    this.init();
                }
            }

            Template template = this.config.getTemplate(templateName);
            template.process(model, writer);
        } catch (TemplateException e) {
            throw new IOException(e);
        }
    }

    private void init(String templateDir) throws IOException {
        this.config = new Configuration(Configuration.VERSION_2_3_23);
        this.config.setDirectoryForTemplateLoading(new File(templateDir));
    }

    private void init() {
        this.config = new Configuration(Configuration.VERSION_2_3_23);
        this.config.setClassForTemplateLoading(this.getClass(), "/");
    }
}
