@Inject public VelocityDefaultConfigurationFactory(@Optional final ServletContext servletContext) { String loader = "class"; Velocity.setProperty("class.resource.loader.class", ClasspathResourceLoader.class.getName()); Velocity.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, "true"); if (servletContext != null) { Velocity.setProperty("webapp.resource.loader.class", WebappResourceLoader.class.getName()); Velocity.setProperty("webapp.resource.loader.path", "/"); Velocity.setApplicationAttribute("javax.servlet.ServletContext", servletContext); loader += ",webapp"; } Velocity.setProperty(RuntimeConstants.RESOURCE_LOADER, loader); configuration = new Configuration(); }
@Override protected void postProcessVelocityEngine(VelocityEngine velocityEngine) { super.postProcessVelocityEngine(velocityEngine); velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "webapp,file,class,url,jar,spring,springMacro"); velocityEngine.setProperty("webapp.resource.loader.class", WebappResourceLoader.class.getName()); velocityEngine.setProperty("file.resource.loader.class", FileResourceLoader.class.getName()); velocityEngine.setProperty("class.resource.loader.class", ClasspathResourceLoader.class.getName()); velocityEngine.setProperty("url.resource.loader.class", URLResourceLoader.class.getName()); velocityEngine.setProperty("jar.resource.loader.class", JarResourceLoader.class.getName()); velocityEngine.setProperty("resource.manager.cache.class", ResourceCacheImpl.class.getName()); velocityEngine.setProperty("resource.manager.cache.size", 2048); velocityEngine.setProperty("resource.manager.class", ResourceManagerImpl.class.getName()); velocityEngine.setProperty(RuntimeConstants.COUNTER_INITIAL_VALUE, 1); velocityEngine.setProperty(RuntimeConstants.INPUT_ENCODING, inputEncoding); velocityEngine.setProperty(RuntimeConstants.OUTPUT_ENCODING, outputEncoding); velocityEngine.setProperty("contentType", contentType); // org.apache.velocity.runtime.log.AvalonLogChute // org.apache.velocity.runtime.log.Log4JLogChute // org.apache.velocity.runtime.log.CommonsLogLogChute // org.apache.velocity.runtime.log.ServletLogChute // org.apache.velocity.runtime.log.JdkLogChute velocityEngine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, new Log4JLogChute()); velocityEngine.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, true); }