/** * Merges the specified template using the supplied mapping of string keys to objects. * * @return a string containing the merged text. */ protected String mergeTemplate (String template, Map<String, Object> data) throws IOException { Reader reader = new InputStreamReader(getClass().getClassLoader().getResourceAsStream(template), UTF_8); return convertEols(Mustache.compiler().escapeHTML(false).compile(reader).execute(data)); }
/** * Compiles a mustache template with a given scope (map of fields and values). * @param context a map of fields and values * @param template a Mustache template * @return the compiled template string */ public static String compileMustache(Map<String, Object> context, String template) { if (context == null || StringUtils.isBlank(template)) { return ""; } Writer writer = new StringWriter(); try { Mustache.compiler().escapeHTML(false).emptyStringIsFalse(true).compile(template).execute(context, writer); } finally { try { writer.close(); } catch (IOException e) { logger.error(null, e); } } return writer.toString(); }
public TemplateHolder(JSONObject configuration) { JSONObject search = configuration.optJSONObject("search"); String searchString = search.getString("template"); Template searchTemplate = Mustache.compiler().escapeHTML(false).standardsMode(true).withLoader(s -> getReader(searchString)).compile(getReader(searchString)); Template searchUrlTemplate = createTemplate(search.optString("url", "")); if (bulk != null) { Template bulkUrlTemplate = createTemplate(bulk.optString("url")); Template bulkTemplate = Mustache.compiler().escapeHTML(false).standardsMode(true).withLoader(s -> getReader(add.optString("template"))).compile(getReader(bulk.optString("template"))); this.bulk = new TemplateRequest(bulk.optString("method", "POST"), bulkUrlTemplate, bulkTemplate);
private static Mustache.Compiler createCompiler() { return Mustache.compiler().escapeHTML(false); }
@Bean public Mustache.Compiler mustacheCompiler(TemplateLoader loader) { return compiler().escapeHTML(false).withLoader(loader); }
protected Template getTemplate(String key, Locale locale) { return Mustache.compiler().escapeHTML(false).compile(getTemplateString(key, locale)); }
private static Mustache.Compiler createCompiler() { return Mustache.compiler().escapeHTML(false); }
public void afterPropertiesSet() throws Exception { templateLoader.setPrefix(prefix); templateLoader.setSuffix(suffix); if (compiler == null) { compiler = Mustache.compiler() .escapeHTML(escapeHTML) .standardsMode(standardsMode) .withLoader(templateLoader); } }
protected Path resolvePath(Path path, String relative, Object scope) { return path.resolve(Mustaches.execute( Mustache.compiler().escapeHTML(false).compile(relative), scope)); }
protected Path resolvePath(Path path, String relative, Object scope) { return path.resolve(Mustaches.execute( Mustache.compiler().escapeHTML(false).compile(relative), scope)); }
public void afterPropertiesSet() throws Exception { templateLoader.setPrefix(prefix); templateLoader.setSuffix(suffix); if (compiler == null) { compiler = Mustache.compiler() .escapeHTML(escapeHTML) .standardsMode(standardsMode) .withLoader(templateLoader); } }