use of org.apache.velocity.Template in project gocd by gocd.
the class VelocityFixture method renderMacro.
public String renderMacro(String template, HashMap model) throws Exception {
String path = new File("../server/webapp/WEB-INF/vm").getCanonicalPath();
Properties properties = new Properties();
properties.setProperty(Velocity.RESOURCE_LOADER, "file");
properties.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, path);
properties.setProperty(Velocity.FILE_RESOURCE_LOADER_CACHE, "false");
VelocityEngine engine = new VelocityEngine();
engine.init(properties);
Template t = engine.getTemplate(template + ".vm");
VelocityContext ctx = new VelocityContext();
for (Object key : model.keySet()) {
ctx.put((String) key, model.get(key));
}
ctx.put("req", new FakeRequest());
Writer writer = new StringWriter();
t.merge(ctx, writer);
return writer.toString();
}
use of org.apache.velocity.Template in project midpoint by Evolveum.
the class SchemaDocMojo method renderComplexTypeDefinition.
private void renderComplexTypeDefinition(ComplexTypeDefinition typeDefinition, PrismSchema schema, PrismContext prismContext, VelocityEngine velocityEngine, PathGenerator pathGenerator) throws IOException {
getLog().info(" Processing complex type definition: " + typeDefinition);
VelocityContext velocityContext = new VelocityContext();
populateVelocityContextBase(velocityContext, prismContext, pathGenerator, schema, "../..");
velocityContext.put(VELOCITY_CONTEXT_VAR_DEFINITION, typeDefinition);
Template template = velocityEngine.getTemplate(TEMPLATE_COMPLEX_TYPE_DEFINITION_NAME);
Writer writer = new FileWriter(pathGenerator.prepareTypeDefinitionOutputFile(schema, typeDefinition));
template.merge(velocityContext, writer);
writer.close();
}
use of org.apache.velocity.Template in project midpoint by Evolveum.
the class SchemaDocMojo method renderSchemaIndex.
private void renderSchemaIndex(SchemaRegistry schemaRegistry, PrismContext prismContext, VelocityEngine velocityEngine, PathGenerator pathGenerator) throws IOException {
getLog().info("Rendering schema index");
VelocityContext velocityContext = new VelocityContext();
populateVelocityContextBase(velocityContext, prismContext, pathGenerator, null, ".");
velocityContext.put(VELOCITY_CONTEXT_VAR_SCHEMA_REGISTRY, schemaRegistry);
Template template = velocityEngine.getTemplate(TEMPLATE_SCHEMA_INDEX_NAME);
Writer writer = new FileWriter(pathGenerator.prepareSchemaIndexOutputFile());
template.merge(velocityContext, writer);
writer.close();
}
use of org.apache.velocity.Template in project midpoint by Evolveum.
the class SchemaDocMojo method renderObjectDefinition.
private void renderObjectDefinition(PrismObjectDefinition objectDefinition, PrismSchema schema, PrismContext prismContext, VelocityEngine velocityEngine, PathGenerator pathGenerator) throws IOException {
getLog().info(" Processing object definition: " + objectDefinition);
VelocityContext velocityContext = new VelocityContext();
populateVelocityContextBase(velocityContext, prismContext, pathGenerator, schema, "../..");
velocityContext.put(VELOCITY_CONTEXT_VAR_DEFINITION, objectDefinition);
Template template = velocityEngine.getTemplate(TEMPLATE_OBJECT_DEFINITION_NAME);
Writer writer = new FileWriter(pathGenerator.prepareObjectDefinitionOutputFile(schema, objectDefinition));
template.merge(velocityContext, writer);
writer.close();
}
use of org.apache.velocity.Template in project opennms by OpenNMS.
the class GraphConfigGenerator method generateSnmpGraphInternal.
private String generateSnmpGraphInternal(Collection<Report> reports, String graphTemplate) {
Velocity.init();
VelocityContext context = new VelocityContext();
context.put("reportsList", reports.iterator());
context.put("reportsBody", reports.iterator());
Template template = Velocity.getTemplate(graphTemplate);
StringWriter sw = new StringWriter();
if (template != null) {
template.merge(context, sw);
}
return sw.toString();
}
Aggregations