Search in sources :

Example 26 with Configuration

use of freemarker.template.Configuration 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 27 with Configuration

use of freemarker.template.Configuration 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 28 with Configuration

use of freemarker.template.Configuration in project deeplearning4j by deeplearning4j.

the class StaticPageUtil method renderHTMLContent.

public static String renderHTMLContent(Component... components) throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
    mapper.enable(SerializationFeature.INDENT_OUTPUT);
    Configuration cfg = new Configuration(new Version(2, 3, 23));
    // Where do we load the templates from:
    cfg.setClassForTemplateLoading(StaticPageUtil.class, "");
    // Some other recommended settings:
    cfg.setIncompatibleImprovements(new Version(2, 3, 23));
    cfg.setDefaultEncoding("UTF-8");
    cfg.setLocale(Locale.US);
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    ClassPathResource cpr = new ClassPathResource("assets/dl4j-ui.js");
    String scriptContents = IOUtils.toString(cpr.getInputStream(), "UTF-8");
    Map<String, Object> pageElements = new HashMap<>();
    List<ComponentObject> list = new ArrayList<>();
    int i = 0;
    for (Component c : components) {
        list.add(new ComponentObject(String.valueOf(i), mapper.writeValueAsString(c)));
        i++;
    }
    pageElements.put("components", list);
    pageElements.put("scriptcontent", scriptContents);
    Template template = cfg.getTemplate("staticpage.ftl");
    Writer stringWriter = new StringWriter();
    template.process(pageElements, stringWriter);
    return stringWriter.toString();
}
Also used : Configuration(freemarker.template.Configuration) Template(freemarker.template.Template) StringWriter(java.io.StringWriter) Version(freemarker.template.Version) Component(org.deeplearning4j.ui.api.Component) ObjectMapper(org.nd4j.shade.jackson.databind.ObjectMapper) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 29 with Configuration

use of freemarker.template.Configuration in project moco by dreamhead.

the class TemplateResourceReader method createTemplate.

private Template createTemplate(final MessageContent messageContent) throws IOException {
    TemplateLoader templateLoader = createTemplateLoader(messageContent);
    Configuration cfg = createConfiguration(templateLoader, messageContent.getCharset());
    return cfg.getTemplate(TEMPLATE_NAME);
}
Also used : Configuration(freemarker.template.Configuration) StringTemplateLoader(freemarker.cache.StringTemplateLoader) TemplateLoader(freemarker.cache.TemplateLoader)

Example 30 with Configuration

use of freemarker.template.Configuration in project pinot by linkedin.

the class GenerateAnomalyReport method buildEmailTemplateAndSendAlert.

void buildEmailTemplateAndSendAlert(Map<String, Object> paramMap) {
    HtmlEmail email = new HtmlEmail();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try (Writer out = new OutputStreamWriter(baos, AlertTaskRunner.CHARSET)) {
        Configuration freemarkerConfig = new Configuration(Configuration.VERSION_2_3_21);
        freemarkerConfig.setClassForTemplateLoading(getClass(), "/com/linkedin/thirdeye/detector");
        freemarkerConfig.setDefaultEncoding(AlertTaskRunner.CHARSET);
        freemarkerConfig.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
        Template template = freemarkerConfig.getTemplate("custom-anomaly-report.ftl");
        template.process(paramMap, out);
        String alertEmailSubject = "Thirdeye : Daily anomaly report";
        String alertEmailHtml = new String(baos.toByteArray(), AlertTaskRunner.CHARSET);
        EmailHelper.sendEmailWithHtml(email, smtpConfiguration, alertEmailSubject, alertEmailHtml, "thirdeye-dev@linkedin.com", emailRecipients);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : SmtpConfiguration(com.linkedin.thirdeye.anomaly.SmtpConfiguration) ThirdEyeAnomalyConfiguration(com.linkedin.thirdeye.anomaly.ThirdEyeAnomalyConfiguration) Configuration(freemarker.template.Configuration) HtmlEmail(org.apache.commons.mail.HtmlEmail) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) Template(freemarker.template.Template)

Aggregations

Configuration (freemarker.template.Configuration)56 Template (freemarker.template.Template)30 Writer (java.io.Writer)17 IOException (java.io.IOException)14 StringWriter (java.io.StringWriter)14 File (java.io.File)13 HashMap (java.util.HashMap)11 DefaultObjectWrapper (freemarker.template.DefaultObjectWrapper)8 TemplateException (freemarker.template.TemplateException)7 OutputStreamWriter (java.io.OutputStreamWriter)7 StringTemplateLoader (freemarker.cache.StringTemplateLoader)5 ThirdEyeAnomalyConfiguration (com.linkedin.thirdeye.anomaly.ThirdEyeAnomalyConfiguration)4 ClassTemplateLoader (freemarker.cache.ClassTemplateLoader)4 FileTemplateLoader (freemarker.cache.FileTemplateLoader)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 FileWriter (java.io.FileWriter)4 StringReader (java.io.StringReader)4 ArrayList (java.util.ArrayList)4 MultiTemplateLoader (freemarker.cache.MultiTemplateLoader)3 TemplateLoader (freemarker.cache.TemplateLoader)3