public class Templater {
public static String render(String templateFile, Context context) {
try {
Velocity.init(getDefaultVelocityProperties());
} catch (Exception e) {
throw new HiveRuntimeException("Failed to initialize Velocity templatng engine.");
}
Template template = null;
try {
template = Velocity.getTemplate(templateFile);
} catch (ResourceNotFoundException e) {
throw new HiveRuntimeException("Unable to locate template: " + templateFile);
} catch (ParseErrorException e) {
throw new HiveRuntimeException("Error parsing template: " + templateFile);
} catch (Exception e) {
throw new RuntimeException(e);
}
StringWriter writer = new StringWriter();
try {
template.merge(context, writer);
} catch (Exception e) {
throw new HiveRuntimeException(e);
}
return writer.toString();
}