Java 类org.apache.velocity.runtime.resource.loader.URLResourceLoader 实例源码

项目:sharding    文件:VelocityTemplateConfigurer.java   
@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);
}
项目:gerrit-ci    文件:VelocityProvider.java   
/**
 * Instantiates and initializes the velocityEngine field. Sets the ResourceLoader as
 * URLResourceLoader so that we can load the template files directly from a JAR file on the
 * filesystem.
 */
public VelocityProvider() {
    velocityEngine = new VelocityEngine();
    velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "url");
    velocityEngine.setProperty("url.resource.loader.class", URLResourceLoader.class.getName());

    // The current working directory is the root of the Gerrit server
    File baseDirectory = new File("plugins/gerrit-ci.jar");
    velocityEngine.setProperty("url.resource.loader.root",
        "jar:file://" + baseDirectory.getAbsolutePath() + "!/templates");

    velocityEngine.init();
}