/* * Copyright 2012 NGDATA nv * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.lilyproject.tools.recordrowvisualizer; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; import java.util.Map; import freemarker.template.Configuration; import freemarker.template.Template; import freemarker.template.TemplateException; public class TemplateRenderer { private Configuration conf; public TemplateRenderer() { Configuration conf = new Configuration(); conf.setClassForTemplateLoading(TemplateRenderer.class, "/org/lilyproject/tools/recordrowvisualizer"); this.conf = conf; } public void render(String templateName, Map<String, Object> variables, OutputStream os) throws IOException, TemplateException { Template template = conf.getTemplate(templateName); Writer out = new OutputStreamWriter(os, "UTF-8"); template.process(variables, out); out.flush(); } }