Search in sources :

Example 1 with RuntimeServices

use of org.apache.velocity.runtime.RuntimeServices 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;
}
Also used : RuntimeServices(org.apache.velocity.runtime.RuntimeServices) InputStream(java.io.InputStream) StringReader(java.io.StringReader) File(java.io.File) SimpleNode(org.apache.velocity.runtime.parser.node.SimpleNode) Template(org.apache.velocity.Template)

Aggregations

File (java.io.File)1 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1 Template (org.apache.velocity.Template)1 RuntimeServices (org.apache.velocity.runtime.RuntimeServices)1 SimpleNode (org.apache.velocity.runtime.parser.node.SimpleNode)1