@Override public String buildRecoveryPasswordUrl(final User user, final String urlTemplate) { final String token = generateRecoveryToken(user); final String username = user.getUsername(); return StringUtils.replaceEach( urlTemplate, new String[] {"{username}", "{token}"}, new String[] {username, token}); }
public void precompile(Collection<File> templates, File outputBaseDir, boolean purgeWhitespace) throws IOException { Context cx = Context.enter(); PrintWriter out = null; File outputFile = null; try { for (File template : templates) { outputFile = new File(outputBaseDir, template.getName() + ".js"); out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(outputFile), encoding)); LOG.info("precompile " + template + " to " + outputFile); out.print( "(function() {\n var template = Handlebars.template, " + "templates = Handlebars.templates = Handlebars.templates || {};\n"); // Rhino for Handlebars Template ScriptableObject global = cx.initStandardObjects(); InputStreamReader in = new InputStreamReader(handlebarsUrl.openStream()); cx.evaluateReader(global, in, handlebarsName, 1, null); IOUtils.closeQuietly(in); String data = FileUtils.readFileToString(template, encoding); if (purgeWhitespace) data = StringUtils.replaceEach( data, new String[] {"\n", "\r", "\t"}, new String[] {"", "", ""}); ScriptableObject.putProperty(global, "data", data); Object obj = cx.evaluateString(global, "Handlebars.precompile(String(data));", "<cmd>", 1, null); out.println( "templates['" + FilenameUtils.getBaseName(template.getName()) + "']=template(" + obj.toString() + ");"); } } finally { Context.exit(); if (out != null) out.println("})();"); IOUtils.closeQuietly(out); } }
private String clean(String path) { return StringUtils.replaceEach( path, new String[] {"/", "\\"}, new String[] {separator, separator}); }
public static String encode(String s) { return StringUtils.replaceEach(s, mapChars, mappedEscapes); }