Search in sources :

Example 1 with Template

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

Example 2 with Template

use of org.apache.velocity.Template in project Ebselen by Ardesco.

the class IDEToEbselen method generateJavaFile.

/**
     * Writes Sky Selenium format test code into a Java file ready for tests to be run
     *
     * @param name - Name of the test
     * @throws Exception
     */
public void generateJavaFile(String name) throws Exception {
    Properties props = new Properties();
    props.setProperty("resource.loader", "class");
    props.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
    props.setProperty("class.resource.loader.description", "Velocity Classpath Resource Loader");
    VelocityEngine ve = new VelocityEngine(props);
    VelocityContext context = new VelocityContext();
    context.put("template", name);
    context.put("templateclass", name + ".class");
    context.put("testname", name);
    context.put("testdata", testCode);
    Template ebselenTemplate = ve.getTemplate(ebselenTestTemplate);
    FileHandler convertedFile = new FileHandler(conversionLocation + File.separator + name + ".java", true);
    StringWriter writer = new StringWriter();
    ebselenTemplate.merge(context, writer);
    convertedFile.write(writer.toString());
    convertedFile.close();
    LOGGER.info("Selenium IDE test converted and saved as '" + convertedFile.getFilePath() + convertedFile.getFileName() + "'");
}
Also used : VelocityEngine(org.apache.velocity.app.VelocityEngine) StringWriter(java.io.StringWriter) VelocityContext(org.apache.velocity.VelocityContext) Properties(java.util.Properties) CleanerProperties(org.htmlcleaner.CleanerProperties) Template(org.apache.velocity.Template) FileHandler(com.lazerycode.ebselen.handlers.FileHandler)

Example 3 with Template

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

Example 4 with Template

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

Example 5 with Template

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

Aggregations

Template (org.apache.velocity.Template)160 VelocityContext (org.apache.velocity.VelocityContext)118 StringWriter (java.io.StringWriter)76 VelocityEngine (org.apache.velocity.app.VelocityEngine)39 Test (org.junit.Test)33 File (java.io.File)21 IOException (java.io.IOException)19 ResourceNotFoundException (org.apache.velocity.exception.ResourceNotFoundException)17 Writer (java.io.Writer)14 FileWriter (java.io.FileWriter)12 ClasspathResourceLoader (org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader)12 ParseErrorException (org.apache.velocity.exception.ParseErrorException)11 MethodInvocationException (org.apache.velocity.exception.MethodInvocationException)9 APITemplateException (org.wso2.carbon.apimgt.impl.template.APITemplateException)9 FileOutputStream (java.io.FileOutputStream)8 PrintWriter (java.io.PrintWriter)8 Map (java.util.Map)8 Properties (java.util.Properties)8 VelocityException (org.apache.velocity.exception.VelocityException)7 OutputStreamWriter (java.io.OutputStreamWriter)6