Search in sources :

Example 1 with NullLogChute

use of org.apache.velocity.runtime.log.NullLogChute in project auto by google.

the class TemplateTest method setUp.

@Before
public void setUp() {
    velocityRuntimeInstance = new RuntimeInstance();
    // Ensure that $undefinedvar will produce an exception rather than outputting $undefinedvar.
    velocityRuntimeInstance.setProperty(RuntimeConstants.RUNTIME_REFERENCES_STRICT, "true");
    velocityRuntimeInstance.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, new NullLogChute());
    // Disable any logging that Velocity might otherwise see fit to do.
    velocityRuntimeInstance.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, new NullLogChute());
    velocityRuntimeInstance.init();
}
Also used : NullLogChute(org.apache.velocity.runtime.log.NullLogChute) RuntimeInstance(org.apache.velocity.runtime.RuntimeInstance) Before(org.junit.Before)

Example 2 with NullLogChute

use of org.apache.velocity.runtime.log.NullLogChute in project tomee by apache.

the class Container method copyTemplateTo.

private void copyTemplateTo(final File targetDir, final String filename) throws Exception {
    final File file = new File(targetDir, filename);
    if (file.exists()) {
        return;
    }
    // don't break apps using Velocity facade
    final VelocityEngine engine = new VelocityEngine();
    engine.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM, new NullLogChute());
    engine.setProperty(Velocity.RESOURCE_LOADER, "class");
    engine.setProperty("class.resource.loader.description", "Velocity Classpath Resource Loader");
    engine.setProperty("class.resource.loader.class", ClasspathResourceLoader.class.getName());
    engine.init();
    final Template template = engine.getTemplate("/org/apache/tomee/configs/" + filename);
    final VelocityContext context = new VelocityContext();
    context.put("tomcatHttpPort", Integer.toString(configuration.getHttpPort()));
    context.put("tomcatShutdownPort", Integer.toString(configuration.getStopPort()));
    final Writer writer = new FileWriter(file);
    template.merge(context, writer);
    writer.flush();
    writer.close();
}
Also used : VelocityEngine(org.apache.velocity.app.VelocityEngine) NullLogChute(org.apache.velocity.runtime.log.NullLogChute) VelocityContext(org.apache.velocity.VelocityContext) FileWriter(java.io.FileWriter) ClasspathResourceLoader(org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader) File(java.io.File) Writer(java.io.Writer) FileWriter(java.io.FileWriter) Template(org.apache.velocity.Template)

Aggregations

NullLogChute (org.apache.velocity.runtime.log.NullLogChute)2 File (java.io.File)1 FileWriter (java.io.FileWriter)1 Writer (java.io.Writer)1 Template (org.apache.velocity.Template)1 VelocityContext (org.apache.velocity.VelocityContext)1 VelocityEngine (org.apache.velocity.app.VelocityEngine)1 RuntimeInstance (org.apache.velocity.runtime.RuntimeInstance)1 ClasspathResourceLoader (org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader)1 Before (org.junit.Before)1