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();
}
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();
}
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();
}
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);
}
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();
}
}
Aggregations