All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nl.hsac.fitnesse.fixture.util.FreeMarkerHelper Maven / Gradle / Ivy

There is a newer version: 5.3.17
Show newest version
package nl.hsac.fitnesse.fixture.util;

import freemarker.template.Configuration;
import freemarker.template.Template;

import java.io.IOException;
import java.io.StringWriter;

/**
 * Helper to facilitate our FreeMarker usage
 */
public class FreeMarkerHelper {
    /**
     * @param name name of template to retrieve
     * @return template with specified name
     */
    public Template getTemplate(Configuration conf, String name) {
        Template result = null;
        try {
            result = conf.getTemplate(name, "UTF-8");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return result;
    }

    /**
     * @param t template to apply
     * @param model model to supply to template
     * @return string containing template output
     */
    public String processTemplate(Template t, Object model) {
        StringWriter sw = new StringWriter();
        try {
            t.process(model, sw);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        String result = sw.toString();
        return result;
    }
    

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy