本文整理汇总了Java中groovy.text.TemplateEngine类的典型用法代码示例。如果您正苦于以下问题:Java TemplateEngine类的具体用法?Java TemplateEngine怎么用?Java TemplateEngine使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TemplateEngine类属于groovy.text包,在下文中一共展示了TemplateEngine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initializeEclipseConfig
import groovy.text.TemplateEngine; //导入依赖的package包/类
/**
* Initialize the Eclipse configuration
*
* @param eclipse Eclipse configuration to initialize
* @param project Current Gradle project
*/
@Defaults
public void initializeEclipseConfig(EclipseConfig eclipse, ProjectIdentifier project) {
try {
Map<String, Object> context = new HashMap<>();
context.put("project", project);
@NonNull URL resource = Validate
.notNull(Resources.getResource(EclipseConfigPlugin.class, "codetemplates.xml"));
String templateText = Resources.toString(resource, Charsets.UTF_8);
TemplateEngine engine = new SimpleTemplateEngine();
String templates = engine.createTemplate(templateText).make(context).toString();
eclipse.getUi().setCodeTemplates(templates);
}
catch (Exception e) {
throw new RuntimeException("Could not set code templates", e);
}
}
示例2: getTemplate
import groovy.text.TemplateEngine; //导入依赖的package包/类
private static Template getTemplate(TemplateEngine engine, String name)
throws CompilationFailedException, ClassNotFoundException, IOException {
File file = new File("templates", name);
if (file.exists()) {
return engine.createTemplate(file);
}
ClassLoader classLoader = GroovyTemplate.class.getClassLoader();
URL resource = classLoader.getResource("templates/" + name);
if (resource != null) {
return engine.createTemplate(resource);
}
return engine.createTemplate(name);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:17,代码来源:GroovyTemplate.java
示例3: generateScript
import groovy.text.TemplateEngine; //导入依赖的package包/类
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();
}
示例4: groovy
import groovy.text.TemplateEngine; //导入依赖的package包/类
/**
* @param template A template of the string resource containing template-appropriate variables for substitution
* @param dataSource A list of name=value pairs that will be used for var substitution. Each entry in the
* list will result in another resource being returned
* @param templateEngine The template engine, more can be found here: http://groovy.codehaus.org/Groovy+Templates
*/
default GroovyTemplateTestResource[] groovy(final TestResource<String> template, List<Map<String, String>> dataSource,
Class<? extends TemplateEngine> templateEngine) {
GroovyTemplateTestResource[] results = new GroovyTemplateTestResource[dataSource.size()];
try {
final TemplateEngine engine = templateEngine.newInstance();
int index = 0;
for (Map<String, String> variables : dataSource) {
results[index++] = new GroovyTemplateTestResource(engine, template, variables);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return results;
}
示例5: findTemplate
import groovy.text.TemplateEngine; //导入依赖的package包/类
private Template findTemplate(final String templateName) throws SAXException, ParserConfigurationException, ClassNotFoundException, IOException {
TemplateEngine ste = templateName.endsWith(".gxml") ? new XmlTemplateEngine() : new SimpleTemplateEngine();
File sourceTemplate = new File(templatesPath, templateName);
Template template = cachedTemplates.get(templateName);
if (template == null) {
template = ste.createTemplate(new InputStreamReader(new BufferedInputStream(new FileInputStream(sourceTemplate)), config.getString(Keys.TEMPLATE_ENCODING)));
cachedTemplates.put(templateName, template);
}
return template;
}
示例6: customTemplateEngine
import groovy.text.TemplateEngine; //导入依赖的package包/类
@Test
public void customTemplateEngine() 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");
assertNotNull(engine);
assertEquals(TestTemplateEngine.class, engine.getClass());
}
示例7: detectTemplateEngine
import groovy.text.TemplateEngine; //导入依赖的package包/类
@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");
assertNotNull(engine);
assertEquals(TestTemplateEngine.class, engine.getClass());
}
示例8: defaultTemplateEngine
import groovy.text.TemplateEngine; //导入依赖的package包/类
@Test
public void defaultTemplateEngine() throws Exception {
this.configurer.setApplicationContext(this.applicationContext);
this.configurer.afterPropertiesSet();
TemplateEngine engine = this.configurer.getTemplateEngine();
assertNotNull(engine);
assertEquals(MarkupTemplateEngine.class, engine.getClass());
MarkupTemplateEngine markupEngine = (MarkupTemplateEngine) engine;
TemplateConfiguration configuration = markupEngine.getTemplateConfiguration();
assertNotNull(configuration);
assertEquals(GroovyMarkupConfigurer.class, configuration.getClass());
}
示例9: customTemplateEngine
import groovy.text.TemplateEngine; //导入依赖的package包/类
@Test
public void customTemplateEngine() throws Exception {
this.configurer.setApplicationContext(this.applicationContext);
this.configurer.setTemplateEngine(new TestTemplateEngine());
this.configurer.afterPropertiesSet();
TemplateEngine engine = this.configurer.getTemplateEngine();
assertNotNull(engine);
assertEquals(TestTemplateEngine.class, engine.getClass());
}
示例10: customTemplateConfiguration
import groovy.text.TemplateEngine; //导入依赖的package包/类
@Test
public void customTemplateConfiguration() throws Exception {
this.configurer.setApplicationContext(this.applicationContext);
this.configurer.setCacheTemplates(false);
this.configurer.afterPropertiesSet();
TemplateEngine engine = this.configurer.getTemplateEngine();
assertNotNull(engine);
assertEquals(MarkupTemplateEngine.class, engine.getClass());
MarkupTemplateEngine markupEngine = (MarkupTemplateEngine) engine;
TemplateConfiguration configuration = markupEngine.getTemplateConfiguration();
assertNotNull(configuration);
assertFalse(configuration.isCacheTemplates());
}
示例11: template
import groovy.text.TemplateEngine; //导入依赖的package包/类
public static String template(TemplateEngine engine, String name,
Map<String, ?> model) throws IOException, CompilationFailedException,
ClassNotFoundException {
Writable writable = getTemplate(engine, name).make(model);
StringWriter result = new StringWriter();
writable.writeTo(result);
return result.toString();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:9,代码来源:GroovyTemplate.java
示例12: initialize
import groovy.text.TemplateEngine; //导入依赖的package包/类
private void initialize() throws GrafikonException {
TemplateEngine engine = new SimpleTemplateEngine();
try {
templateGString = engine.createTemplate(this.getTemplate());
} catch (Exception e) {
throw new GrafikonException("Cannot create template: " + e.getMessage(), e, GrafikonException.Type.TEXT_TEMPLATE);
}
}
示例13: setupUsers
import groovy.text.TemplateEngine; //导入依赖的package包/类
protected void setupUsers() {
try {
TemplateEngine engine = new SimpleTemplateEngine();
Template secTemplate = engine.createTemplate(ApplicationWizard.class.getResource("Security.groovy"));
Map<String, String> bindings = new HashMap<String, String>();
bindings.put("databaseName", connectionProvider.getDatabase().getDatabaseName());
bindings.put("userTableEntityName", userTable.getActualEntityName());
bindings.put("userIdProperty", userIdProperty);
bindings.put("userNameProperty", userNameProperty);
bindings.put("passwordProperty", userPasswordProperty);
bindings.put("userEmailProperty", userEmailProperty);
bindings.put("userTokenProperty", userTokenProperty);
bindings.put("groupTableEntityName", groupTable != null ? groupTable.getActualEntityName() : "");
bindings.put("groupIdProperty", StringUtils.defaultString(groupIdProperty));
bindings.put("groupNameProperty", StringUtils.defaultString(groupNameProperty));
bindings.put("userGroupTableEntityName", userGroupTable != null ? userGroupTable.getActualEntityName() : "");
bindings.put("groupLinkProperty", StringUtils.defaultString(groupLinkProperty));
bindings.put("userLinkProperty", StringUtils.defaultString(userLinkProperty));
bindings.put("adminGroupName", StringUtils.defaultString(adminGroupName));
bindings.put("encryptionAlgorithm", encryptionAlgorithm);
File gcp = (File) context.getServletContext().getAttribute(BaseModule.GROOVY_CLASS_PATH);
FileWriter fw = new FileWriter(new File(gcp, "Security.groovy"));
secTemplate.make(bindings).writeTo(fw);
IOUtils.closeQuietly(fw);
} catch (Exception e) {
logger.warn("Couldn't configure users", e);
SessionMessages.addWarningMessage(ElementsThreadLocals.getText("couldnt.set.up.user.management._", e));
}
}
示例14: parseCommands
import groovy.text.TemplateEngine; //导入依赖的package包/类
static String parseCommands(String value, GroovyMap bindMap) {
TemplateEngine templateEngine = new GStringTemplateEngine();
try {
return templateEngine.createTemplate(value).make(bindMap).toString();
} catch (ClassNotFoundException | IOException e) {
throw new IllegalArgumentException("Error while parsing command " + value
+ " , Invalid command or incomplete bind map");
}
}
示例15: groovyTemplateEngine
import groovy.text.TemplateEngine; //导入依赖的package包/类
@Bean
public TemplateEngine groovyTemplateEngine() {
return new GStringTemplateEngine();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:5,代码来源:SpringBootHypermediaApplication.java