本文整理汇总了Java中groovy.text.Template.make方法的典型用法代码示例。如果您正苦于以下问题:Java Template.make方法的具体用法?Java Template.make怎么用?Java Template.make使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类groovy.text.Template
的用法示例。
在下文中一共展示了Template.make方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: renderDocument
import groovy.text.Template; //导入方法依赖的package包/类
@Override
public void renderDocument(final Map<String, Object> model, final String templateName, final Writer writer) throws RenderingException {
try {
Template template = findTemplate(templateName);
Writable writable = template.make(wrap(model));
writable.writeTo(writer);
} catch (Exception e) {
throw new RenderingException(e);
}
}
示例2: renderDocument
import groovy.text.Template; //导入方法依赖的package包/类
@Override
public void renderDocument(final Map<String, Object> model, final String templateName, final Writer writer) throws RenderingException {
try {
Template template = templateEngine.createTemplateByPath(templateName);
Map<String, Object> wrappedModel = wrap(model);
Writable writable = template.make(wrappedModel);
writable.writeTo(writer);
} catch (Exception e) {
throw new RenderingException(e);
}
}
示例3: generateModuleCodeFromTemplate
import groovy.text.Template; //导入方法依赖的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;
}
示例4: fillTemplate
import groovy.text.Template; //导入方法依赖的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());
}
}
示例5: handleAction
import groovy.text.Template; //导入方法依赖的package包/类
/**
* Sends data to the HL7 recipient. Template data, recipient name and template name are in the parameters map.
*
* @param parameters the parameters map
* @throws ParserConfigurationException, SAXException, IOException, ClassNotFoundException when cannot generate data
* @throws TemplateNotFoundException when a template does not exist in database
* @throws RecipientNotFoundException when a recipient does not exist
* from xml template or when template is incorrect
*/
@Transactional
public void handleAction(Map<String, Object> parameters) throws IOException, ClassNotFoundException,
ParserConfigurationException, SAXException {
String templateName = (String) parameters.get(Constants.TEMPLATE_NAME_PARAM);
String recipientName = (String) parameters.get(Constants.RECIPIENT_NAME_PARAM);
CdaTemplate cdaTemplate = iheTemplateDataService.findByName(templateName);
if (cdaTemplate == null) {
LOGGER.error("Cannot find {} template", templateName);
throw new TemplateNotFoundException(templateName);
}
HL7Recipient hl7Recipient = hl7RecipientsService.getRecipientbyName(recipientName);
if (hl7Recipient == null) {
LOGGER.error("Cannot find {} recipient", recipientName);
throw new RecipientNotFoundException(templateName);
}
Byte[] templateData = (Byte[]) iheTemplateDataService.getDetachedField(cdaTemplate, TEMPLATE_DATA_FIELD_NAME);
StreamingTemplateEngine streamingTemplateEngine = new StreamingTemplateEngine();
Template template = streamingTemplateEngine.createTemplate(new String(ArrayUtils.toPrimitive(templateData)));
Writable writable = template.make(parameters);
LOGGER.info("Template with name {}:\n{}", cdaTemplate.getTemplateName(), writable.toString());
if (hl7Recipient.getRecipientUsername() != null && hl7Recipient.getRecipientPassword() != null) {
iheTemplateService.sendTemplateToRecipientUrlWithBasicAuthentication(hl7Recipient, writable.toString());
} else {
iheTemplateService.sendTemplateToRecipientUrl(hl7Recipient.getRecipientUrl(), writable.toString());
}
}
示例6: renderString
import groovy.text.Template; //导入方法依赖的package包/类
@Override
public void renderString(String templateContent, Map<String, Object> model, Writer writer) {
try {
Template groovyTemplate = engine.createTemplate(templateContent);
PippoGroovyTemplate gt = (PippoGroovyTemplate) groovyTemplate.make(model);
gt.setup(getLanguages(), getMessages(), getRouter());
gt.writeTo(writer);
} catch (Exception e) {
log.error("Error processing Groovy template {} ", templateContent, e);
throw new PippoRuntimeException(e);
}
}
示例7: process
import groovy.text.Template; //导入方法依赖的package包/类
private static ArrayList<String> process(File template_file, HashMap<String, Object> all_mail_vars) throws IOException, CompilationFailedException, ClassNotFoundException {
Template template = template_engine.createTemplate(template_file);
Writable writable = template.make(all_mail_vars);
TemplateWriter tw = new TemplateWriter();
writable.writeTo(tw);
return tw.getContent();
}
示例8: prepareErrorHtml
import groovy.text.Template; //导入方法依赖的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;
}
示例9: doGenerate
import groovy.text.Template; //导入方法依赖的package包/类
@Override
public void doGenerate(final Map<String, Object> map, final Path output, final Path templateFile) {
Object _get = map.get("u");
final GeneratorUtils utils = ((GeneratorUtils) _get);
final IClass iClass = utils.getIclass();
try {
final Template template = this.engine.createTemplate(templateFile.toFile());
final Writable generatedCode = template.make(map);
File _file = output.toFile();
FileWriter _fileWriter = new FileWriter(_file);
final Function1<FileWriter, Writer> _function = (FileWriter it) -> {
try {
return generatedCode.writeTo(it);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
};
Using.<FileWriter, Writer>using(_fileWriter, _function);
} catch (final Throwable _t) {
if (_t instanceof Exception) {
final Exception e = (Exception)_t;
GenerationException.getInstance().addException(e);
boolean _matched = false;
if (Objects.equal(e, MissingPropertyException.class)) {
_matched=true;
JFrame _frame = utils.getFrame();
String _message = e.getMessage();
String _plus = ("Cannot found property :" + _message);
String _plus_1 = (_plus + ". model : ");
String _name = iClass.getName();
String _plus_2 = (_plus_1 + _name);
JOptionPane.showMessageDialog(_frame, _plus_2);
}
if (!_matched) {
JFrame _frame_1 = utils.getFrame();
String _message_1 = e.getMessage();
String _plus_3 = (_message_1 + ".\n in model : ");
String _name_1 = iClass.getName();
String _plus_4 = (_plus_3 + _name_1);
JOptionPane.showMessageDialog(_frame_1, _plus_4);
}
} else {
throw Exceptions.sneakyThrow(_t);
}
}
}