Search in sources :

Example 46 with Template

use of org.apache.velocity.Template in project gocd by gocd.

the class TestVelocityView method setupTemplate.

private Template setupTemplate(ResourceLoader loader, RuntimeInstance runtimeServices, String templateName, InputStream templateContents) {
    try {
        Template template = new Template();
        template.setRuntimeServices(runtimeServices);
        template.setResourceLoader(loader);
        template.setName(templateName);
        byte[] bytes = IOUtils.toByteArray(templateContents);
        templateContents.close();
        when(loader.getResourceStream(templateName)).thenReturn(new ByteArrayInputStream(bytes));
        doReturn(template).when(runtimeServices).getTemplate(templateName);
        doReturn(template).when(runtimeServices).getTemplate(eq(templateName), Matchers.<String>any());
        return template;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Template(org.apache.velocity.Template)

Example 47 with Template

use of org.apache.velocity.Template in project cxf by apache.

the class VelocityGenerator method doWrite.

public void doWrite(String templateName, Writer outputs) throws ToolException {
    Template tmpl = null;
    try {
        tmpl = Velocity.getTemplate(templateName);
    } catch (Exception e) {
        Message msg = new Message("TEMPLATE_MISSING", LOG, templateName);
        throw new ToolException(msg, e);
    }
    VelocityContext ctx = new VelocityContext();
    for (Map.Entry<String, Object> entry : attributes.entrySet()) {
        ctx.put(entry.getKey(), entry.getValue());
    }
    VelocityWriter writer = new VelocityWriter(outputs);
    ctx.put("out", writer);
    try {
        tmpl.merge(ctx, writer);
        writer.close();
    } catch (Exception e) {
        Message msg = new Message("VELOCITY_ENGINE_WRITE_ERRORS", LOG);
        throw new ToolException(msg, e);
    }
}
Also used : Message(org.apache.cxf.common.i18n.Message) VelocityContext(org.apache.velocity.VelocityContext) HashMap(java.util.HashMap) Map(java.util.Map) IOException(java.io.IOException) Template(org.apache.velocity.Template)

Example 48 with Template

use of org.apache.velocity.Template in project winery by eclipse.

the class BpelPlanArtefactWriter method completeInvokerXsdTemplate.

public String completeInvokerXsdTemplate() {
    LOGGER.debug("Retrieving service invoker XSD");
    VelocityContext context = new VelocityContext();
    Template invokerXsdTemplate = Velocity.getTemplate(TEMPLATE_PATH + "invoker.xsd");
    StringWriter xsdWriter = new StringWriter();
    invokerXsdTemplate.merge(context, xsdWriter);
    return xsdWriter.toString();
}
Also used : StringWriter(java.io.StringWriter) VelocityContext(org.apache.velocity.VelocityContext) Template(org.apache.velocity.Template)

Example 49 with Template

use of org.apache.velocity.Template in project winery by eclipse.

the class BpelPlanArtefactWriter method completeInvokerWsdlTemplate.

public String completeInvokerWsdlTemplate() {
    LOGGER.debug("Retrieving service invoker WSDL");
    VelocityContext context = new VelocityContext();
    Template invokerWsdlTemplate = Velocity.getTemplate(TEMPLATE_PATH + "invoker.wsdl");
    StringWriter wsdlWriter = new StringWriter();
    invokerWsdlTemplate.merge(context, wsdlWriter);
    return wsdlWriter.toString();
}
Also used : StringWriter(java.io.StringWriter) VelocityContext(org.apache.velocity.VelocityContext) Template(org.apache.velocity.Template)

Example 50 with Template

use of org.apache.velocity.Template in project winery by eclipse.

the class BpelPlanArtefactWriter method completeDeploymentDescriptorTemplate.

public String completeDeploymentDescriptorTemplate() {
    LOGGER.debug("Retrieving Apache ODE deployment descriptor");
    VelocityContext context = new VelocityContext();
    Template invokerXsdTemplate = Velocity.getTemplate(TEMPLATE_PATH + "deploy.xml");
    StringWriter xsdWriter = new StringWriter();
    invokerXsdTemplate.merge(context, xsdWriter);
    return xsdWriter.toString();
}
Also used : StringWriter(java.io.StringWriter) VelocityContext(org.apache.velocity.VelocityContext) Template(org.apache.velocity.Template)

Aggregations

Template (org.apache.velocity.Template)59 VelocityContext (org.apache.velocity.VelocityContext)41 StringWriter (java.io.StringWriter)28 VelocityEngine (org.apache.velocity.app.VelocityEngine)21 ResourceNotFoundException (org.apache.velocity.exception.ResourceNotFoundException)12 IOException (java.io.IOException)11 ParseErrorException (org.apache.velocity.exception.ParseErrorException)8 Writer (java.io.Writer)7 File (java.io.File)6 Map (java.util.Map)6 Properties (java.util.Properties)6 FileWriter (java.io.FileWriter)5 ClasspathResourceLoader (org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader)5 PrintWriter (java.io.PrintWriter)4 MethodInvocationException (org.apache.velocity.exception.MethodInvocationException)4 SystemException (com.github.bordertech.wcomponents.util.SystemException)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 FileOutputStream (java.io.FileOutputStream)3 HashMap (java.util.HashMap)3 UIContext (com.github.bordertech.wcomponents.UIContext)2