/*
 * Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
 * Haulmont Technology proprietary and confidential.
 * Use is subject to license terms.

 * Author: Dmitry Abramov
 * Created: 26.01.2009 16:15:29
 * $Id$
 */
package com.haulmont.cuba.core.global;

import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.cache.StringTemplateLoader;
import freemarker.ext.beans.BeansWrapper;

import java.util.Map;
import java.util.HashMap;
import java.io.StringWriter;

/**
 * Use static methods of this class to process Freemarker templates.
 * Does not cache templates.
 */
public class TemplateHelper {

    public static String processTemplate(String templateStr, Map<String, Object> parameterValues) {

        Map<String, Object> params = new HashMap<String, Object>(parameterValues);
        params.put("statics", BeansWrapper.getDefaultInstance().getStaticModels());

        final StringWriter writer = new StringWriter();

        try {
            final Configuration configuration = new Configuration();

            final StringTemplateLoader templateLoader = new StringTemplateLoader();
            templateLoader.putTemplate("template", templateStr);
            configuration.setTemplateLoader(templateLoader);

            final Template template = configuration.getTemplate("template");
            template.process(params, writer);

            return writer.toString();
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
    }
}

@@ -271,24 +271,71 @@
 .global;%0D%0A%0D%0A
+import com.haulmont.cuba.core.sys.AppContext;%0D%0A
 import freem
@@ -990,24 +990,177 @@
 dels());%0D%0A%0D%0A
+        for (String name : AppContext.getPropertyNames()) %7B%0D%0A            params.put(name.replace(%22.%22, %22_%22), AppContext.getProperty(name));%0D%0A        %7D%0D%0A%0D%0A
         fina

Add AppContext properties to Freemarker parameters