package com.yeejoin.amos.avic.face.utils;

import freemarker.cache.StringTemplateLoader;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;

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

public class StringUtils {
	public static String format(String content, HashMap<String, Object> variables) {
		StringTemplateLoader stringLoader = new StringTemplateLoader();
	    Configuration cfg = new Configuration();

	    cfg.setTemplateLoader(stringLoader);
	    String template = "content";
	    stringLoader.putTemplate(template, content);
	    try {
	      Template templateCon = cfg.getTemplate(template);
	      StringWriter writer = new StringWriter();
	      templateCon.process(variables, writer);
	      return writer.toString();
	    } catch (IOException e) {
	      e.printStackTrace();
	    } catch (TemplateException e) {
	      e.printStackTrace();
	    }
	    return null;
	}
}
