本文整理汇总了Java中groovy.text.SimpleTemplateEngine类的典型用法代码示例。如果您正苦于以下问题:Java SimpleTemplateEngine类的具体用法?Java SimpleTemplateEngine怎么用?Java SimpleTemplateEngine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SimpleTemplateEngine类属于groovy.text包,在下文中一共展示了SimpleTemplateEngine类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: generate
import groovy.text.SimpleTemplateEngine; //导入依赖的package包/类
@Override
public void generate() {
try {
target.getParentFile().mkdirs();
SimpleTemplateEngine templateEngine = new SimpleTemplateEngine();
String templateText = Resources.asCharSource(templateURL, CharsetToolkit.getDefaultSystemCharset()).read();
Template template = templateEngine.createTemplate(templateText);
Writer writer = Files.asCharSink(target, Charsets.UTF_8).openStream();
try {
template.make(bindings).writeTo(writer);
} finally {
writer.close();
}
} catch (Exception ex) {
throw new GradleException("Could not generate file " + target + ".", ex);
}
}
开发者ID:lxxlxx888,项目名称:Reer,代码行数:18,代码来源:SimpleTemplateOperation.java
示例2: initializeEclipseConfig
import groovy.text.SimpleTemplateEngine; //导入依赖的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);
}
}
开发者ID:jochenseeber,项目名称:gradle-project-config,代码行数:26,代码来源:EclipseConfigPlugin.java
示例3: expand
import groovy.text.SimpleTemplateEngine; //导入依赖的package包/类
public void expand(final Map<String, ?> properties) {
transformers.add(new Transformer<Reader, Reader>() {
public Reader transform(Reader original) {
try {
Template template;
try {
SimpleTemplateEngine engine = new SimpleTemplateEngine();
template = engine.createTemplate(original);
} finally {
original.close();
}
StringWriter writer = new StringWriter();
template.make(properties).writeTo(writer);
return new StringReader(writer.toString());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
});
}
开发者ID:lxxlxx888,项目名称:Reer,代码行数:21,代码来源:FilterChain.java
示例4: buildNotifyJson
import groovy.text.SimpleTemplateEngine; //导入依赖的package包/类
private String buildNotifyJson( @Nonnull final AbstractBuild build,
@Nonnull final Map<String,?> env )
{
Map<String,?> binding = new HashMap<String, Object>(){{
put( "jenkins", notNull( Jenkins.getInstance(), "Jenkins instance" ));
put( "build", notNull( build, "Build instance" ));
put( "env", notNull( env, "Build environment" ));
}};
String json = null;
String template = "<%\n\n" + JSON_FUNCTION + "\n\n%>\n\n" +
notBlank( notifyTemplate, "Notify template" );
try
{
json = notBlank( new SimpleTemplateEngine( getClass().getClassLoader()).
createTemplate( template ).
make( binding ).toString(), "Payload JSON" ).trim();
Asserts.check(( json.startsWith( "{" ) && json.endsWith( "}" )) ||
( json.startsWith( "[" ) && json.endsWith( "]" )),
"Illegal JSON content: should start and end with {} or []" );
Asserts.notNull( new JsonSlurper().parseText( json ), "Parsed JSON" );
}
catch ( Exception e )
{
throwError(( json == null ?
String.format( "Failed to parse Groovy template:%s%s%s",
LINE, template, LINE ) :
String.format( "Failed to validate JSON payload (check with http://jsonlint.com/):%s%s%s",
LINE, json, LINE )), e );
}
return json;
}
开发者ID:evgeny-goldin,项目名称:jenkins-notify-plugin,代码行数:37,代码来源:NotifyRecorder.java
示例5: generateStartScriptContentFromTemplate
import groovy.text.SimpleTemplateEngine; //导入依赖的package包/类
private String generateStartScriptContentFromTemplate(final Map<String, String> binding) {
return IoUtils.get(getTemplate().asReader(), new Transformer<String, Reader>() {
@Override
public String transform(Reader reader) {
try {
SimpleTemplateEngine engine = new SimpleTemplateEngine();
Template template = engine.createTemplate(reader);
String output = template.make(binding).toString();
return TextUtil.convertLineSeparators(output, lineSeparator);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
});
}
开发者ID:lxxlxx888,项目名称:Reer,代码行数:16,代码来源:DefaultTemplateBasedStartScriptGenerator.java
示例6: findTemplate
import groovy.text.SimpleTemplateEngine; //导入依赖的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;
}
开发者ID:ghaseminya,项目名称:jbake-rtl-jalaali,代码行数:11,代码来源:GroovyTemplateEngine.java
示例7: getTemplate
import groovy.text.SimpleTemplateEngine; //导入依赖的package包/类
protected Template getTemplate(SimpleTemplateEngine templateEngine, String templateString) {
Template bodyTemplate;
try {
bodyTemplate = templateEngine.createTemplate(templateString);
} catch (Exception e) {
throw new RuntimeException("Unable to compile Groovy template", e);
}
return bodyTemplate;
}
开发者ID:pfurini,项目名称:cuba-component-forgot-password,代码行数:10,代码来源:NexbitUserManagementServiceBean.java
示例8: loadDefaultTemplate
import groovy.text.SimpleTemplateEngine; //导入依赖的package包/类
protected Template loadDefaultTemplate(String templatePath, SimpleTemplateEngine templateEngine) {
String defaultTemplateContent = resources.getResourceAsString(templatePath);
if (defaultTemplateContent == null) {
throw new IllegalStateException("Unable to find default template for reset password link email");
}
//noinspection UnnecessaryLocalVariable
Template template = getTemplate(templateEngine, defaultTemplateContent);
return template;
}
开发者ID:pfurini,项目名称:cuba-component-forgot-password,代码行数:11,代码来源:NexbitUserManagementServiceBean.java
示例9: changePasswordsAtLogonAndSendEmails
import groovy.text.SimpleTemplateEngine; //导入依赖的package包/类
@Override
public Integer changePasswordsAtLogonAndSendEmails(List<UUID> userIds) {
checkNotNullArgument(userIds, "Null users list");
checkUpdatePermission(User.class);
if (userIds.isEmpty())
return 0;
Map<User, String> modifiedUsers = updateUserPasswords(userIds, true);
// email templates
String resetPasswordBodyTemplate = serverConfig.getResetPasswordEmailBodyTemplate();
String resetPasswordSubjectTemplate = serverConfig.getResetPasswordEmailSubjectTemplate();
SimpleTemplateEngine templateEngine = new SimpleTemplateEngine(scripting.getClassLoader());
Map<String, Template> localizedBodyTemplates = new HashMap<>();
Map<String, Template> localizedSubjectTemplates = new HashMap<>();
// load default
Template bodyDefaultTemplate = loadDefaultTemplate(resetPasswordBodyTemplate, templateEngine);
Template subjectDefaultTemplate = loadDefaultTemplate(resetPasswordSubjectTemplate, templateEngine);
for (Map.Entry<User, String> userPasswordEntry : modifiedUsers.entrySet()) {
User user = userPasswordEntry.getKey();
if (StringUtils.isNotEmpty(user.getEmail())) {
EmailTemplate template = getResetPasswordTemplate(user, templateEngine,
resetPasswordSubjectTemplate, resetPasswordBodyTemplate,
subjectDefaultTemplate, bodyDefaultTemplate,
localizedSubjectTemplates, localizedBodyTemplates);
String password = userPasswordEntry.getValue();
sendResetPasswordEmail(user, password, template.getSubjectTemplate(), template.getBodyTemplate());
}
}
return modifiedUsers.size();
}
开发者ID:cuba-platform,项目名称:cuba,代码行数:39,代码来源:UserManagementServiceBean.java
示例10: loadDefaultTemplate
import groovy.text.SimpleTemplateEngine; //导入依赖的package包/类
protected Template loadDefaultTemplate(String templatePath, SimpleTemplateEngine templateEngine) {
String defaultTemplateContent = resources.getResourceAsString(templatePath);
if (defaultTemplateContent == null) {
throw new IllegalStateException("Not found default email template for reset passwords operation");
}
//noinspection UnnecessaryLocalVariable
Template template = getTemplate(templateEngine, defaultTemplateContent);
return template;
}
开发者ID:cuba-platform,项目名称:cuba,代码行数:11,代码来源:UserManagementServiceBean.java
示例11: generateModuleCodeFromTemplate
import groovy.text.SimpleTemplateEngine; //导入依赖的package包/类
public static String generateModuleCodeFromTemplate(String moduleName, String codeTemplate) {
try {
Map bindings = new HashMap();
bindings.put("moduleName", moduleName);
SimpleTemplateEngine simpleTemplateEngine = new SimpleTemplateEngine();
Template template = simpleTemplateEngine.createTemplate(codeTemplate);
Writable writable = template.make(bindings);
String finalScript = writable.toString();
return finalScript;
} catch (Exception ex) {
logger.log(Level.SEVERE, ex.getMessage(), ex);
}
return null;
}
开发者ID:hybridbpm,项目名称:hybridbpm,代码行数:15,代码来源:HybridbpmCoreUtil.java
示例12: fillTemplate
import groovy.text.SimpleTemplateEngine; //导入依赖的package包/类
public static String fillTemplate(String templateString, Map bindings) throws RuntimeException {
try {
SimpleTemplateEngine simpleTemplateEngine = new SimpleTemplateEngine();
Template template = simpleTemplateEngine.createTemplate(templateString);
Writable writable = template.make(bindings);
String finalScript = writable.toString();
return finalScript;
} catch (CompilationFailedException | ClassNotFoundException | IOException ex) {
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
}
}
开发者ID:hybridbpm,项目名称:hybridbpm,代码行数:13,代码来源:HybridbpmCoreUtil.java
示例13: initialize
import groovy.text.SimpleTemplateEngine; //导入依赖的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);
}
}
开发者ID:jub77,项目名称:grafikon,代码行数:9,代码来源:TextTemplateGroovy.java
示例14: setupUsers
import groovy.text.SimpleTemplateEngine; //导入依赖的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));
}
}
开发者ID:hongliangpan,项目名称:manydesigns.cn,代码行数:33,代码来源:ApplicationWizard.java
示例15: testDifferentTemplateEngine
import groovy.text.SimpleTemplateEngine; //导入依赖的package包/类
@Test
public void testDifferentTemplateEngine() throws Exception {
String templateValue = "<% import static org.apache.commons.lang3.text.WordUtils.capitalize %>${capitalize(foo)} ${capitalize(baz)} ${capitalize(moo)}";
PlainTextTestResource resource = new PlainTextTestResource(templateValue);
Map<String, String> variables = new HashMap<>();
variables.put("foo", "a");
variables.put("baz", "b");
variables.put("moo", "c");
GroovyTemplateTestResource testResource = new GroovyTemplateTestResource(new SimpleTemplateEngine(),
resource, variables);
assertEquals("A B C", testResource.getValue());
}
开发者ID:uoa-group-applications,项目名称:morc,代码行数:16,代码来源:GroovyTemplateTestResourceTest.java
示例16: main
import groovy.text.SimpleTemplateEngine; //导入依赖的package包/类
public static void main(String... args) throws ClassNotFoundException, IOException {
Method[] methodDeclarations = Class.forName("com.github.timofeevda.gwt.rxjs.interop.observable.Observable")
.getDeclaredMethods();
Set<String> importsSet = generateImportsSet(methodDeclarations);
List<GeneratedMethodDefinition> generatedMethodDefinitions = generateMethodsDefintions(methodDeclarations);
SimpleTemplateEngine templateEngine = new SimpleTemplateEngine();
InputStream templateStream = MethodDefinitionsTestsGenerator.class.getResourceAsStream("/definitions.template");
Map<String, Object> templateBindings = new HashMap<>();
templateBindings.put("methods", generatedMethodDefinitions);
templateBindings.put("importsSet", importsSet);
File destinationFile = new File(args[0]);
destinationFile.mkdirs();
File testDefinitonsFile = new File(args[0] + File.separator + "MethodsDefinitionsTest.java");
testDefinitonsFile.createNewFile();
Writable writable = templateEngine.createTemplate(new BufferedReader(new InputStreamReader(templateStream))).make(templateBindings);
writable.writeTo(new PrintWriter(new FileOutputStream(testDefinitonsFile)));
}
开发者ID:timofeevda,项目名称:gwt-rxjs-jsinterop,代码行数:26,代码来源:MethodDefinitionsTestsGenerator.java
示例17: sendResetPasswordLinks
import groovy.text.SimpleTemplateEngine; //导入依赖的package包/类
@Override
public @NotNull Map<UUID, ResetPasswordLinkInfo> sendResetPasswordLinks(@NotNull List<UUID> userIds,
@NotNull String baseUrl,
boolean includeInactive) {
checkNotNullArgument(userIds, "userIds must not be null");
checkNotNullArgument(baseUrl, "baseUrl must not be null");
if (userIds.isEmpty())
return Collections.emptyMap();
// email templates
final String resetPasswordBodyTemplate = forgotPasswordConfig.getResetPasswordLinkEmailBodyTemplate();
final String resetPasswordSubjectTemplate = forgotPasswordConfig.getResetPasswordLinkEmailSubjectTemplate();
final SimpleTemplateEngine templateEngine = new SimpleTemplateEngine();
Map<String, Template> localizedBodyTemplates = new HashMap<>();
Map<String, Template> localizedSubjectTemplates = new HashMap<>();
// load default
Template bodyDefaultTemplate = loadDefaultTemplate(resetPasswordBodyTemplate, templateEngine);
Template subjectDefaultTemplate = loadDefaultTemplate(resetPasswordSubjectTemplate, templateEngine);
final Map<UUID, ResetPasswordLinkInfo> results = new HashMap<>();
final Map<User, String> tokens = generateResetPasswordTokens(new LinkedHashSet<>(userIds), includeInactive);
for (Map.Entry<User, String> entry : tokens.entrySet()) {
final User user = entry.getKey();
if (entry.getValue() == null) // if includeInactive == false and user is not active
results.put(user.getId(), ResetPasswordLinkInfo.KO_NOT_ACTIVE);
else if (StringUtils.isBlank(user.getEmail())) {
results.put(user.getId(), ResetPasswordLinkInfo.KO_MISSING_EMAIL);
} else {
EmailTemplate template = getResetPasswordTemplate(user, templateEngine,
resetPasswordSubjectTemplate, resetPasswordBodyTemplate,
subjectDefaultTemplate, bodyDefaultTemplate,
localizedSubjectTemplates, localizedBodyTemplates);
// send email
String link = generateResetLink(baseUrl, entry.getValue());
sendResetPasswordEmail(user, link, template.subjectTemplate, template.bodyTemplate);
results.put(user.getId(), ResetPasswordLinkInfo.OK);
}
}
for (UUID id : userIds) {
results.putIfAbsent(id, ResetPasswordLinkInfo.KO_NOT_FOUND);
}
return results;
}
开发者ID:pfurini,项目名称:cuba-component-forgot-password,代码行数:49,代码来源:NexbitUserManagementServiceBean.java
示例18: prepareErrorHtml
import groovy.text.SimpleTemplateEngine; //导入依赖的package包/类
protected String prepareErrorHtml(HttpServletRequest req, Throwable exception) {
Messages messages = AppBeans.get(Messages.NAME);
Configuration configuration = AppBeans.get(Configuration.NAME);
WebConfig webConfig = configuration.getConfig(WebConfig.class);
GlobalConfig globalConfig = configuration.getConfig(GlobalConfig.class);
// SimpleTemplateEngine requires mutable map
Map<String, Object> binding = new HashMap<>();
binding.put("tryAgainUrl", "?restartApp");
binding.put("productionMode", webConfig.getProductionMode());
binding.put("messages", messages);
binding.put("exception", exception);
binding.put("exceptionName", exception.getClass().getName());
binding.put("exceptionMessage", exception.getMessage());
binding.put("exceptionStackTrace", ExceptionUtils.getStackTrace(exception));
Locale locale = resolveLocale(req, messages, globalConfig);
String serverErrorPageTemplatePath = webConfig.getServerErrorPageTemplate();
String localeString = messages.getTools().localeToString(locale);
String templateContent = getLocalizedTemplateContent(resources, serverErrorPageTemplatePath, localeString);
if (templateContent == null) {
templateContent = resources.getResourceAsString(serverErrorPageTemplatePath);
if (templateContent == null) {
throw new IllegalStateException("Unable to find server error page template " + serverErrorPageTemplatePath);
}
}
SimpleTemplateEngine templateEngine = new SimpleTemplateEngine(getServletContext().getClassLoader());
Template template = getTemplate(templateEngine, templateContent);
Writable writable = template.make(binding);
String html;
try {
html = writable.writeTo(new StringWriter()).toString();
} catch (IOException e) {
throw new RuntimeException("Unable to write server error page", e);
}
return html;
}
开发者ID:cuba-platform,项目名称:cuba,代码行数:46,代码来源:CubaApplicationServlet.java
示例19: setupUsers
import groovy.text.SimpleTemplateEngine; //导入依赖的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("hashIterations", "1");
String[] algoAndEncoding = encryptionAlgorithm.split(":");
bindings.put("hashAlgorithm", '"' + algoAndEncoding[0] + '"');
if(algoAndEncoding[1].equals("plaintext")) {
bindings.put("hashFormat", "null");
} else if(algoAndEncoding[1].equals("hex")) {
bindings.put("hashFormat", "new org.apache.shiro.crypto.hash.format.HexFormat()");
} else if(algoAndEncoding[1].equals("base64")) {
bindings.put("hashFormat", "new org.apache.shiro.crypto.hash.format.Base64Format()");
}
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));
}
}
开发者ID:ManyDesigns,项目名称:Portofino,代码行数:44,代码来源:ApplicationWizard.java
示例20: GroovyGenerator
import groovy.text.SimpleTemplateEngine; //导入依赖的package包/类
public GroovyGenerator() {
SimpleTemplateEngine _simpleTemplateEngine = new SimpleTemplateEngine();
this.engine = _simpleTemplateEngine;
}
开发者ID:s-hosoai,项目名称:astahm2t,代码行数:5,代码来源:GroovyGenerator.java
注:本文中的groovy.text.SimpleTemplateEngine类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论