Search in sources :

Example 36 with Template

use of freemarker.template.Template in project bamboobsc by billchen198318.

the class CodeGeneratorUtil method generatorProcess.

private static void generatorProcess(String packageName, String headName, String templateFilePath) throws Exception {
    Configuration cfg = new Configuration(Configuration.VERSION_2_3_21);
    cfg.setClassForTemplateLoading(CodeGeneratorUtil.class, "");
    Template template = cfg.getTemplate(templateFilePath, "utf-8");
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("packageName", packageName);
    params.put("headName", headName);
    params.put("headNameSmall", headName.substring(0, 1).toLowerCase() + headName.substring(1, headName.length()));
    String outDir = System.getProperty("user.dir") + "/out";
    String outFilePath = outDir + "/" + getOutFileFootName(headName, templateFilePath);
    Writer file = new FileWriter(new File(outFilePath));
    template.process(params, file);
    file.flush();
    file.close();
}
Also used : Configuration(freemarker.template.Configuration) HashMap(java.util.HashMap) FileWriter(java.io.FileWriter) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer) Template(freemarker.template.Template)

Example 37 with Template

use of freemarker.template.Template in project opennms by OpenNMS.

the class NavBarController method afterPropertiesSet.

/**
 * <p>afterPropertiesSet</p>
 * @throws IOException
 */
@Override
public void afterPropertiesSet() throws IOException {
    Assert.state(m_navBarItems != null, "navBarItems property has not been set");
    // Initialize the Freemarker engine and fetch our template
    Configuration cfg = new Configuration(Configuration.VERSION_2_3_21);
    cfg.setDefaultEncoding(StandardCharsets.UTF_8.name());
    cfg.setClassForTemplateLoading(NavBarController.class, "");
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
    Template template = cfg.getTemplate("navbar.ftl");
    m_view = new FreemarkerView(template);
}
Also used : Configuration(freemarker.template.Configuration) Template(freemarker.template.Template)

Example 38 with Template

use of freemarker.template.Template in project bamboobsc by billchen198318.

the class ComponentResourceUtils method generatorResource.

public static String generatorResource(Class<?> c, String type, String metaInfFile, Map<String, Object> params) throws Exception {
    StringTemplateLoader templateLoader = new StringTemplateLoader();
    templateLoader.putTemplate("resourceTemplate", getResourceSrc(c, type, metaInfFile));
    Configuration cfg = new Configuration(Configuration.VERSION_2_3_21);
    cfg.setTemplateLoader(templateLoader);
    Template template = cfg.getTemplate("resourceTemplate", Constants.BASE_ENCODING);
    Writer out = new StringWriter();
    template.process(params, out);
    return out.toString();
}
Also used : StringTemplateLoader(freemarker.cache.StringTemplateLoader) Configuration(freemarker.template.Configuration) StringWriter(java.io.StringWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Template(freemarker.template.Template)

Example 39 with Template

use of freemarker.template.Template in project hub-alert by blackducksoftware.

the class ChannelFreemarkerTemplatingService method getResolvedTemplate.

public String getResolvedTemplate(final Map<String, Object> model, final String templateName) throws TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException, TemplateException {
    final StringWriter stringWriter = new StringWriter();
    final Template template = configuration.getTemplate(templateName);
    template.process(model, stringWriter);
    return stringWriter.toString();
}
Also used : StringWriter(java.io.StringWriter) Template(freemarker.template.Template)

Example 40 with Template

use of freemarker.template.Template in project hub-alert by blackducksoftware.

the class ChannelFreemarkerTemplatingService method getResolvedSubjectLine.

public String getResolvedSubjectLine(final Map<String, Object> model) throws IOException, TemplateException {
    String subjectLine = (String) model.get(EmailProperties.TEMPLATE_KEY_SUBJECT_LINE);
    if (StringUtils.isBlank(subjectLine)) {
        subjectLine = "Default Subject Line - please define one";
    }
    final Template subjectLineTemplate = new Template("subjectLineTemplate", subjectLine, configuration);
    final StringWriter stringWriter = new StringWriter();
    subjectLineTemplate.process(model, stringWriter);
    return stringWriter.toString();
}
Also used : StringWriter(java.io.StringWriter) Template(freemarker.template.Template)

Aggregations

Template (freemarker.template.Template)81 StringWriter (java.io.StringWriter)35 IOException (java.io.IOException)34 Configuration (freemarker.template.Configuration)33 HashMap (java.util.HashMap)28 Writer (java.io.Writer)27 TemplateException (freemarker.template.TemplateException)24 OutputStreamWriter (java.io.OutputStreamWriter)13 File (java.io.File)9 Map (java.util.Map)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 SimpleHash (freemarker.template.SimpleHash)6 JSONObject (org.json.JSONObject)6 DefaultObjectWrapper (freemarker.template.DefaultObjectWrapper)5 ThirdEyeAnomalyConfiguration (com.linkedin.thirdeye.anomaly.ThirdEyeAnomalyConfiguration)4 StringTemplateLoader (freemarker.cache.StringTemplateLoader)4 Environment (freemarker.core.Environment)4 BufferedWriter (java.io.BufferedWriter)4 FileOutputStream (java.io.FileOutputStream)4 StringReader (java.io.StringReader)4