Search in sources :

Example 1 with TemplateEngine

use of groovy.text.TemplateEngine in project airavata by apache.

the class GFacUtils method generateScript.

public static String generateScript(GroovyMap groovyMap, String templateName) throws GFacException {
    URL templateUrl = ApplicationSettings.loadFile(templateName);
    if (templateUrl == null) {
        String error = "Template file '" + templateName + "' not found";
        throw new GFacException(error);
    }
    File template = new File(templateUrl.getPath());
    TemplateEngine engine = new GStringTemplateEngine();
    Writable make;
    try {
        make = engine.createTemplate(template).make(groovyMap);
    } catch (Exception e) {
        throw new GFacException("Error while generating script using groovy map", e);
    }
    return make.toString();
}
Also used : TemplateEngine(groovy.text.TemplateEngine) GStringTemplateEngine(groovy.text.GStringTemplateEngine) Writable(groovy.lang.Writable) GStringTemplateEngine(groovy.text.GStringTemplateEngine) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) TException(org.apache.thrift.TException) UnknownHostException(java.net.UnknownHostException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 2 with TemplateEngine

use of groovy.text.TemplateEngine in project spring-framework by spring-projects.

the class GroovyMarkupConfigurerTests method customTemplateEngine.

@Test
public void customTemplateEngine() throws Exception {
    this.configurer.setApplicationContext(this.applicationContext);
    this.configurer.setTemplateEngine(new TestTemplateEngine());
    this.configurer.afterPropertiesSet();
    TemplateEngine engine = this.configurer.getTemplateEngine();
    assertThat(engine).isNotNull();
    assertThat(engine.getClass()).isEqualTo(TestTemplateEngine.class);
}
Also used : MarkupTemplateEngine(groovy.text.markup.MarkupTemplateEngine) TemplateEngine(groovy.text.TemplateEngine) Test(org.junit.jupiter.api.Test)

Example 3 with TemplateEngine

use of groovy.text.TemplateEngine in project spring-framework by spring-projects.

the class GroovyMarkupViewTests method detectTemplateEngine.

@Test
public void detectTemplateEngine() throws Exception {
    GroovyMarkupView view = new GroovyMarkupView();
    view.setTemplateEngine(new TestTemplateEngine());
    view.setApplicationContext(this.webAppContext);
    DirectFieldAccessor accessor = new DirectFieldAccessor(view);
    TemplateEngine engine = (TemplateEngine) accessor.getPropertyValue("engine");
    assertThat(engine).isNotNull();
    assertThat(engine.getClass()).isEqualTo(TestTemplateEngine.class);
}
Also used : MarkupTemplateEngine(groovy.text.markup.MarkupTemplateEngine) TemplateEngine(groovy.text.TemplateEngine) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.jupiter.api.Test)

Example 4 with TemplateEngine

use of groovy.text.TemplateEngine in project spring-framework by spring-projects.

the class GroovyMarkupConfigurerTests method customTemplateConfiguration.

@Test
public void customTemplateConfiguration() throws Exception {
    this.configurer.setApplicationContext(this.applicationContext);
    this.configurer.setCacheTemplates(false);
    this.configurer.afterPropertiesSet();
    TemplateEngine engine = this.configurer.getTemplateEngine();
    assertThat(engine).isNotNull();
    assertThat(engine.getClass()).isEqualTo(MarkupTemplateEngine.class);
    MarkupTemplateEngine markupEngine = (MarkupTemplateEngine) engine;
    TemplateConfiguration configuration = markupEngine.getTemplateConfiguration();
    assertThat(configuration).isNotNull();
    assertThat(configuration.isCacheTemplates()).isFalse();
}
Also used : MarkupTemplateEngine(groovy.text.markup.MarkupTemplateEngine) TemplateEngine(groovy.text.TemplateEngine) TemplateConfiguration(groovy.text.markup.TemplateConfiguration) MarkupTemplateEngine(groovy.text.markup.MarkupTemplateEngine) Test(org.junit.jupiter.api.Test)

Example 5 with TemplateEngine

use of groovy.text.TemplateEngine in project spring-framework by spring-projects.

the class GroovyMarkupConfigurerTests method defaultTemplateEngine.

@Test
public void defaultTemplateEngine() throws Exception {
    this.configurer.setApplicationContext(this.applicationContext);
    this.configurer.afterPropertiesSet();
    TemplateEngine engine = this.configurer.getTemplateEngine();
    assertThat(engine).isNotNull();
    assertThat(engine.getClass()).isEqualTo(MarkupTemplateEngine.class);
    MarkupTemplateEngine markupEngine = (MarkupTemplateEngine) engine;
    TemplateConfiguration configuration = markupEngine.getTemplateConfiguration();
    assertThat(configuration).isNotNull();
    assertThat(configuration.getClass()).isEqualTo(GroovyMarkupConfigurer.class);
}
Also used : MarkupTemplateEngine(groovy.text.markup.MarkupTemplateEngine) TemplateEngine(groovy.text.TemplateEngine) TemplateConfiguration(groovy.text.markup.TemplateConfiguration) MarkupTemplateEngine(groovy.text.markup.MarkupTemplateEngine) Test(org.junit.jupiter.api.Test)

Aggregations

TemplateEngine (groovy.text.TemplateEngine)6 MarkupTemplateEngine (groovy.text.markup.MarkupTemplateEngine)5 Test (org.junit.jupiter.api.Test)5 TemplateConfiguration (groovy.text.markup.TemplateConfiguration)2 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)2 Writable (groovy.lang.Writable)1 GStringTemplateEngine (groovy.text.GStringTemplateEngine)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 UnknownHostException (java.net.UnknownHostException)1 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)1 TException (org.apache.thrift.TException)1