Java 类org.apache.velocity.runtime.RuntimeInstance 实例源码

项目:gocd    文件:TestVelocityView.java   
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);
    }
}
项目:json-template-renderer    文件:VelocityHandler.java   
public VelocityHandler(JsonModel jsonModel, File templateDir) {
    this.jsonModel = jsonModel;
    engine = new VelocityEngine();
    engine.setProperty(RuntimeInstance.RESOURCE_LOADER, "file");
    engine.setProperty(RuntimeInstance.FILE_RESOURCE_LOADER_CACHE, "false");
    engine.setProperty(RuntimeInstance.FILE_RESOURCE_LOADER_PATH, templateDir.getAbsolutePath());
}
项目:plugins_github    文件:VelocityViewServlet.java   
@Inject
public VelocityViewServlet(
    @Named("PluginRuntimeInstance") final RuntimeInstance velocityRuntime,
    Provider<PluginVelocityModel> modelProvider,
    ScopedProvider<GitHubLogin> loginProvider,
    Provider<CurrentUser> userProvider,
    GitHubConfig config) {

  this.velocityRuntime = velocityRuntime;
  this.modelProvider = modelProvider;
  this.loginProvider = loginProvider;
  this.userProvider = userProvider;
  this.config = config;
}
项目:plugins_github    文件:PluginVelocityRuntimeProvider.java   
@Override
public RuntimeInstance get() {
  String pkg = "org.apache.velocity.runtime.resource.loader";

  Properties p = new Properties();
  p.setProperty(RuntimeConstants.VM_PERM_INLINE_LOCAL, "true");
  p.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, Slf4jLogChute.class.getName());
  p.setProperty(RuntimeConstants.RUNTIME_REFERENCES_STRICT, "true");
  p.setProperty("runtime.log.logsystem.log4j.category", "velocity");

  p.setProperty(VELOCITY_RESOURCE_LOADER, "file, class, jar");
  p.setProperty(VELOCITY_FILE_RESOURCE_LOADER_CLASS, pkg + ".FileResourceLoader");
  p.setProperty(
      VELOCITY_FILE_RESOURCE_LOADER_PATH,
      site.static_dir.getParent().toAbsolutePath().toString());
  p.setProperty(VELOCITY_CLASS_RESOURCE_LOADER_CLASS, ClasspathResourceLoader.class.getName());
  p.setProperty(VELOCITY_JAR_RESOURCE_LOADER_CLASS, JarResourceLoader.class.getName());
  p.setProperty(VELOCITY_JAR_RESOURCE_LOADER_PATH, detectPluginJar());

  RuntimeInstance ri = new RuntimeInstance();
  try {
    ri.init(p);
  } catch (Exception err) {
    throw new ProvisionException("Cannot configure Velocity templates", err);
  }
  return ri;
}
项目:gocd    文件:TestVelocityView.java   
public TestVelocityView(String templatePath, Map<String, Object> modelData) {
    this.templatePath = templatePath;
    this.modelData = modelData;

    this.additionalTemplates = new ArrayList<>();
    loader = mock(ResourceLoader.class);
    runtimeServices = spy(new RuntimeInstance());

    setupToolAttributes();
}
项目:gocd    文件:TestVelocityView.java   
private void setupContentResource(ResourceLoader loader, RuntimeInstance runtimeServices, String templateName, String fakeContent) {
    try {
        ContentResource resource = new ContentResource();
        resource.setRuntimeServices(runtimeServices);
        resource.setResourceLoader(loader);
        resource.setName(templateName);
        resource.setData(fakeContent);

        doReturn(resource).when(runtimeServices).getContent(templateName);
        doReturn(resource).when(runtimeServices).getContent(eq(templateName), Matchers.<String>any());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
项目:plugins_github    文件:GuiceHttpModule.java   
@Override
protected void configureServlets() {
  bind(HttpClient.class).toProvider(PooledHttpClientProvider.class);

  bind(new TypeLiteral<ScopedProvider<GitHubLogin>>() {}).to(GitHubLogin.Provider.class);
  bind(new TypeLiteral<ScopedProvider<GitImporter>>() {}).to(GitImporter.Provider.class);

  install(new FactoryModuleBuilder().build(RemoteSiteUser.Factory.class));

  install(
      new FactoryModuleBuilder()
          .implement(GitCloneStep.class, GitCloneStep.class)
          .build(GitCloneStep.Factory.class));
  install(
      new FactoryModuleBuilder()
          .implement(CreateProjectStep.class, CreateProjectStep.class)
          .build(CreateProjectStep.Factory.class));
  install(
      new FactoryModuleBuilder()
          .implement(ReplicateProjectStep.class, ReplicateProjectStep.class)
          .build(ReplicateProjectStep.Factory.class));
  install(
      new FactoryModuleBuilder()
          .implement(PullRequestImportJob.class, PullRequestImportJob.class)
          .build(PullRequestImportJob.Factory.class));
  install(
      new FactoryModuleBuilder()
          .implement(GitHubRepository.class, GitHubRepository.class)
          .build(GitHubRepository.Factory.class));

  bind(RuntimeInstance.class)
      .annotatedWith(Names.named("PluginRuntimeInstance"))
      .toProvider(PluginVelocityRuntimeProvider.class);

  bind(String.class).annotatedWith(GitHubURL.class).toProvider(GitHubURLProvider.class);

  bind(OAuthServiceProvider.class)
      .annotatedWith(Exports.named("github"))
      .to(GitHubOAuthServiceProvider.class);

  serve("*.css", "*.js", "*.png", "*.jpg", "*.woff", "*.gif", "*.ttf")
      .with(VelocityStaticServlet.class);
  serve("*.gh").with(VelocityControllerServlet.class);
  serve("/webhook").with(WebhookServlet.class);

  serve("/static/*").with(VelocityViewServlet.class);
  filterRegex("(?!/webhook).*").through(GitHubOAuthFilter.class);
}
项目:plugins_github    文件:VelocityStaticServlet.java   
@Inject
VelocityStaticServlet(
    @Named("PluginRuntimeInstance") final Provider<RuntimeInstance> velocityRuntimeProvider) {
  this.velocity = velocityRuntimeProvider.get();
}