use of org.apache.velocity.Template in project stanbol by apache.
the class BenchmarkServlet method getTemplate.
/**
* @return
*/
private Template getTemplate(String templatePath) {
final Template t;
ClassLoader tcl = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(BenchmarkServlet.class.getClassLoader());
try {
t = velocity.getTemplate(templatePath);
} finally {
Thread.currentThread().setContextClassLoader(tcl);
}
return t;
}
use of org.apache.velocity.Template in project Gargoyle by callakrsos.
the class Mailer method sendMail.
public void sendMail(SenderMailInfo mailSenderInfo, Mail mail, VelocityContext velocityContext) throws Exception {
if (this.mailUseYn != null) {
if ("N".equals(this.mailUseYn)) {
throw new Exception("Mail Serivce's configuration is not set useYn Y ");
}
}
String _encoding = MailConst.MAILER_DEFAULT_ENCODING;
SimpleMailMessage message = new SimpleMailMessage();
if (mail.getMailFrom() != null) {
message.setFrom(mail.getMailFrom());
} else if (ValueUtil.isNotEmpty(mailFrom)) {
message.setFrom(mailFrom);
} else {
String fromAddr = ResourceLoader.getInstance().get("mail.from.address");
message.setFrom(fromAddr);
}
message.setTo(mail.getMailTo());
if (mail.getMailSubject() != null) {
message.setSubject(mail.getMailSubject());
} else {
message.setSubject(this.mailTitle);
}
if (encoding != null)
_encoding = encoding;
if (mailSenderInfo != null) {
String sendUserId = mailSenderInfo.getSendUserId();
String sendUserPassword = mailSenderInfo.getSendUserPassword();
if (ValueUtil.isEmpty(sendUserId) || ValueUtil.isEmpty(sendUserPassword)) {
throw new IllegalArgumentException("user id or password is empty...");
}
mailSender.setUsername(sendUserId);
mailSender.setPassword(sendUserPassword);
}
// MailUtil.getTemplate(velocityEngine,mail.getTemplateName(),this.mailTemplate);
Template template = MailUtil.getTemplateFromFile(mailTemplate);
template.setEncoding(_encoding);
StringWriter stringWriter = new StringWriter();
template.merge(velocityContext, stringWriter);
message.setText(stringWriter.toString());
// MimeMessage createMimeMessage = mailSender.createMimeMessage();
// createMimeMessage.addHeader("text/html", stringWriter.toString());
mailSender.send(message);
}
use of org.apache.velocity.Template in project Gargoyle by callakrsos.
the class MailUtil method getTemplateFromFile.
/**
* 파일로부터 템플릿 정보를 얻어온다.
*
* @Date 2015. 9. 13.
* @param templateFileName
* @return
* @throws Exception
* @User KYJ
*/
public static Template getTemplateFromFile(final String templateFileName) throws Exception {
String readFileToString = "";
if (templateFileName.startsWith("classpath:")) {
String res = templateFileName.replace("classpath:", "");
InputStream resourceAsStream = ClassLoader.getSystemClassLoader().getResourceAsStream(res);
readFileToString = ValueUtil.toString(resourceAsStream);
} else
readFileToString = FileUtils.readFileToString(new File(templateFileName));
RuntimeServices runtimeServices = RuntimeSingleton.getRuntimeServices();
StringReader reader = new StringReader(readFileToString);
SimpleNode node = runtimeServices.parse(reader, templateFileName);
Template template = new Template();
template.setRuntimeServices(runtimeServices);
template.setData(node);
template.initDocument();
return template;
}
Aggregations