Search in sources :

Example 16 with VelocityContext

use of org.apache.velocity.VelocityContext in project titan by thinkaurelius.

the class AbstractTitanAssemblyIT method parseTemplateAndRunExpect.

protected void parseTemplateAndRunExpect(String expectTemplateName, Map<String, String> contextVars) throws IOException, InterruptedException {
    VelocityContext context = new VelocityContext();
    for (Map.Entry<String, String> ent : contextVars.entrySet()) {
        context.put(ent.getKey(), ent.getValue());
    }
    Template template = Velocity.getTemplate(expectTemplateName);
    String inputPath = EXPECT_DIR + File.separator + expectTemplateName;
    String outputPath = inputPath.substring(0, inputPath.length() - 3);
    Writer output = new FileWriter(outputPath);
    template.merge(context, output);
    output.close();
    expect(ZIPFILE_EXTRACTED, outputPath);
}
Also used : VelocityContext(org.apache.velocity.VelocityContext) FileWriter(java.io.FileWriter) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) FileWriter(java.io.FileWriter) Writer(java.io.Writer) Template(org.apache.velocity.Template)

Example 17 with VelocityContext

use of org.apache.velocity.VelocityContext 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();
}
Also used : VelocityEngine(org.apache.velocity.app.VelocityEngine) StringWriter(java.io.StringWriter) VelocityContext(org.apache.velocity.VelocityContext) Properties(java.util.Properties) File(java.io.File) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Template(org.apache.velocity.Template)

Example 18 with VelocityContext

use of org.apache.velocity.VelocityContext 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();
}
Also used : VelocityContext(org.apache.velocity.VelocityContext) Template(org.apache.velocity.Template)

Example 19 with VelocityContext

use of org.apache.velocity.VelocityContext 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();
}
Also used : VelocityContext(org.apache.velocity.VelocityContext) Template(org.apache.velocity.Template)

Example 20 with VelocityContext

use of org.apache.velocity.VelocityContext 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();
}
Also used : VelocityContext(org.apache.velocity.VelocityContext) Template(org.apache.velocity.Template)

Aggregations

VelocityContext (org.apache.velocity.VelocityContext)98 StringWriter (java.io.StringWriter)26 Template (org.apache.velocity.Template)20 IOException (java.io.IOException)16 VelocityEngine (org.apache.velocity.app.VelocityEngine)13 File (java.io.File)10 ArrayList (java.util.ArrayList)8 ExecuteResult (com.ctrip.platform.dal.daogen.entity.ExecuteResult)7 Progress (com.ctrip.platform.dal.daogen.entity.Progress)7 Writer (java.io.Writer)7 Map (java.util.Map)7 Callable (java.util.concurrent.Callable)7 JavaCodeGenContext (com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)6 OutputStreamWriter (java.io.OutputStreamWriter)6 Properties (java.util.Properties)6 PrintWriter (java.io.PrintWriter)5 HashMap (java.util.HashMap)5 CSharpCodeGenContext (com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 FileOutputStream (java.io.FileOutputStream)3