use of org.apache.velocity.Template in project traccar by traccar.
the class NotificationFormatter method getTemplate.
public static Template getTemplate(Event event, String path) {
String templateFilePath;
Template template;
try {
templateFilePath = Paths.get(path, event.getType() + ".vm").toString();
template = Context.getVelocityEngine().getTemplate(templateFilePath, StandardCharsets.UTF_8.name());
} catch (ResourceNotFoundException error) {
Log.warning(error);
templateFilePath = Paths.get(path, "unknown.vm").toString();
template = Context.getVelocityEngine().getTemplate(templateFilePath, StandardCharsets.UTF_8.name());
}
return template;
}
use of org.apache.velocity.Template in project motech by motech.
the class VelocityTemplateParser method mergeTemplateIntoString.
public String mergeTemplateIntoString(String templateFilename, Map<String, Object> params) throws VelocityTemplateParsingException {
try (InputStream is = settingsFacade.getRawConfig(templateFilename)) {
StringReader reader = new StringReader(IOUtils.toString(is));
SimpleNode node = rs.parse(reader, templateFilename);
Template template = new Template();
template.setRuntimeServices(rs);
template.setData(node);
template.initDocument();
StringWriter writer = new StringWriter();
template.merge(new VelocityContext(params), writer);
return writer.toString();
} catch (ParseException | IOException e) {
throw new VelocityTemplateParsingException("Couldn't merge template into string", e);
}
}
use of org.apache.velocity.Template in project bioformats by openmicroscopy.
the class VelocityTools method processTemplate.
public static void processTemplate(VelocityEngine ve, VelocityContext context, String inFile, String outFile) throws // NB: No choice, as VelocityEngine.getTemplate(String) throws Exception
Exception {
System.out.print("Writing " + outFile + ": ");
Template t = ve.getTemplate(inFile);
StringWriter writer = new StringWriter();
t.merge(context, writer);
PrintWriter out = new PrintWriter(new File(outFile), "UTF-8");
out.print(writer.toString());
out.close();
System.out.println("done.");
}
use of org.apache.velocity.Template in project alien4cloud by alien4cloud.
the class VelocityUtil method generate.
public static void generate(String path, Writer outputWriter, Map<String, ?> properties) throws IOException {
Template template = VELOCITY_ENGINE.getTemplate(path, "UTF-8");
VelocityContext context = new VelocityContext();
for (Entry<String, ?> contextEntry : properties.entrySet()) {
context.put(contextEntry.getKey(), contextEntry.getValue());
}
putIfAbsent(context, "utils", new ToscaSerializerUtils());
putIfAbsent(context, "propertyUtils", new ToscaPropertySerializerUtils());
putIfAbsent(context, "importsUtils", new ToscaImportsUtils());
try {
template.merge(context, outputWriter);
} finally {
outputWriter.close();
}
}
use of org.apache.velocity.Template in project hutool by looly.
the class VelocityUtil method toWriter.
/**
* 生成内容写入流<br>
* 会自动关闭Writer
*
* @param templateFileName 模板文件名
* @param context 上下文
* @param writer 流
*/
public static void toWriter(String templateFileName, VelocityContext context, Writer writer) {
assertInit();
final Template template = Velocity.getTemplate(templateFileName);
merge(template, context, writer);
}
Aggregations