use of org.apache.velocity.app.VelocityEngine in project jmxtrans by jmxtrans.
the class VelocityWriter method getVelocityEngine.
/**
* Sets velocity up to load resources from a list of paths.
*/
protected VelocityEngine getVelocityEngine(List<String> paths) {
VelocityEngine ve = new VelocityEngine();
ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "file");
ve.setProperty("cp.resource.loader.class", "org.apache.velocity.runtime.resource.loader.FileResourceLoader");
ve.setProperty("cp.resource.loader.cache", "true");
ve.setProperty("cp.resource.loader.path", StringUtils.join(paths, ","));
ve.setProperty("cp.resource.loader.modificationCheckInterval ", "10");
ve.setProperty("input.encoding", "UTF-8");
ve.setProperty("output.encoding", "UTF-8");
ve.setProperty("runtime.log", "");
return ve;
}
use of org.apache.velocity.app.VelocityEngine in project stashbot by palantir.
the class VelocityManagerTest method testVelocityTools.
@Test
public void testVelocityTools() {
VelocityEngine ve = vm.getVelocityEngine();
VelocityContext vc = vm.getVelocityContext();
// contains escape tool
Assert.assertTrue(vc.containsKey("esc"));
// escape tool works
Template test = ve.getTemplate("test-template.vm");
StringWriter testWriter = new StringWriter();
test.merge(vc, testWriter);
String result = testWriter.toString();
Assert.assertEquals("&\n", result);
}
use of org.apache.velocity.app.VelocityEngine in project camel by apache.
the class VelocityEndpoint method getVelocityEngine.
private synchronized VelocityEngine getVelocityEngine() throws Exception {
if (velocityEngine == null) {
velocityEngine = new VelocityEngine();
// set the class resolver as a property so we can access it from CamelVelocityClasspathResourceLoader
velocityEngine.addProperty("CamelClassResolver", getCamelContext().getClassResolver());
// set default properties
Properties properties = new Properties();
properties.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, isLoaderCache() ? "true" : "false");
properties.setProperty(RuntimeConstants.RESOURCE_LOADER, "file, class");
properties.setProperty("class.resource.loader.description", "Camel Velocity Classpath Resource Loader");
properties.setProperty("class.resource.loader.class", CamelVelocityClasspathResourceLoader.class.getName());
properties.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, CommonsLogLogChute.class.getName());
properties.setProperty(CommonsLogLogChute.LOGCHUTE_COMMONS_LOG_NAME, VelocityEndpoint.class.getName());
// load the velocity properties from property file which may overrides the default ones
if (ObjectHelper.isNotEmpty(getPropertiesFile())) {
InputStream reader = ResourceHelper.resolveMandatoryResourceAsInputStream(getCamelContext(), getPropertiesFile());
try {
properties.load(reader);
log.info("Loaded the velocity configuration file " + getPropertiesFile());
} finally {
IOHelper.close(reader, getPropertiesFile(), log);
}
}
log.debug("Initializing VelocityEngine with properties {}", properties);
// help the velocityEngine to load the CamelVelocityClasspathResourceLoader
ClassLoader old = Thread.currentThread().getContextClassLoader();
try {
ClassLoader delegate = new CamelVelocityDelegateClassLoader(old);
Thread.currentThread().setContextClassLoader(delegate);
velocityEngine.init(properties);
} finally {
Thread.currentThread().setContextClassLoader(old);
}
}
return velocityEngine;
}
use of org.apache.velocity.app.VelocityEngine in project camel by apache.
the class AbstractGeneratorMojo method getEngine.
protected static VelocityEngine getEngine() {
if (engine == null) {
// initialize velocity to load resources from class loader and use Log4J
Properties velocityProperties = new Properties();
velocityProperties.setProperty(RuntimeConstants.RESOURCE_LOADER, "cloader");
velocityProperties.setProperty("cloader.resource.loader.class", ClasspathResourceLoader.class.getName());
velocityProperties.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, Log4JLogChute.class.getName());
final Logger velocityLogger = LoggerFactory.getLogger("org.apache.camel.maven.Velocity");
velocityProperties.setProperty(Log4JLogChute.RUNTIME_LOG_LOG4J_LOGGER, velocityLogger.getName());
engine = new VelocityEngine(velocityProperties);
engine.init();
}
return engine;
}
use of org.apache.velocity.app.VelocityEngine in project camel by apache.
the class CamelSalesforceMojo method createVelocityEngine.
static VelocityEngine createVelocityEngine() {
// initialize velocity to load resources from class loader and use Log4J
final Properties velocityProperties = new Properties();
velocityProperties.setProperty(RuntimeConstants.RESOURCE_LOADER, "cloader");
velocityProperties.setProperty("cloader.resource.loader.class", ClasspathResourceLoader.class.getName());
velocityProperties.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, Log4JLogChute.class.getName());
velocityProperties.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM + ".log4j.logger", LOG.getName());
final VelocityEngine engine = new VelocityEngine(velocityProperties);
return engine;
}
Aggregations