public String expandQueryVariables(String query, Map<String, Object> params) { if (params != null && params.size() > 0) { TextTemplate tmpl = new TextTemplate(); for (String key : params.keySet()) { Object val = params.get(key); if (val == null) { continue; } else if (val instanceof Calendar) { tmpl.setVariable(key, Long.toString(((Calendar) val).getTime().getTime())); } else if (val instanceof Date) { tmpl.setVariable(key, Long.toString(((Date) val).getTime())); } else { tmpl.setVariable(key, val.toString()); } } query = tmpl.processText(query); } return query; }
private void preprocessVars() { processedVars = preprocessVars(vars); }
/** * @since 7.4 */ public String processText(String text) { if (text == null) { return null; } boolean doneProcessing = false; int recursionLevel = 0; while (!doneProcessing) { doneProcessing = true; String processedText = processString(vars, text); if (!processedText.equals(text)) { doneProcessing = false; text = processedText; } recursionLevel++; // Avoid infinite replacement loops if (!doneProcessing && recursionLevel > MAX_RECURSION_LEVEL) { log.warn("Detected potential infinite loop when processing the following text\n" + text); break; } } return unescape(text); }
final TextTemplate templateParser = new TextTemplate(config); templateParser.setKeepEncryptedAsVar(true); templateParser.setTrim(true); templateParser.setTextParsingExtensions( config.getProperty(ConfigurationGenerator.PARAM_TEMPLATES_PARSING_EXTENSIONS, "xml,properties,nx")); templateParser.setFreemarkerParsingExtensions( config.getProperty(ConfigurationGenerator.PARAM_TEMPLATES_FREEMARKER_EXTENSIONS, "nxftl")); for (File in : listFiles) { newFilesList.addAll(templateParser.processDirectory(in, new File(outputDirectory, in.getName())));
/** * Read the classpath parameter from the template and expand parameters with their value. It allow classpath of the * form ${nuxeo.home}/nxserver/bundles/... * * @param template The name of the template */ // VisibleForTesting String getClasspathForTemplate(String template) { String classPath = configurationGenerator.getUserConfig().getProperty(template + PARAM_CHECK_CLASSPATH_SUFFIX); TextTemplate templateParser = new TextTemplate(configurationGenerator.getUserConfig()); return templateParser.processText(classPath); }
if (processAsFreemarker) { log.debug("Process as FreeMarker " + in.getPath()); processFreemarker(in, out); } else if (processAsText) { log.debug("Process as Text " + in.getPath()); try (InputStream is = new FileInputStream(in); OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(out), "UTF-8")) { processText(is, os); newFiles.addAll(processDirectory(file, out));
public String processText(InputStream in) throws IOException { String text = IOUtils.toString(in, UTF_8); return processText(text); }
public void processFreemarker(File in, File out) throws IOException, TemplateException { if (freemarkerConfiguration == null) { initFreeMarker(); } freemarkerConfiguration.setDirectoryForTemplateLoading(in.getParentFile()); Template nxtpl = freemarkerConfiguration.getTemplate(in.getName()); try (Writer writer = new EscapeVariableFilter(new FileWriter(out))) { nxtpl.process(freemarkerVars, writer); } }
ttProps.put(PARAM_DB_USER, dbUser); ttProps.put(PARAM_DB_PWD, dbPassword); TextTemplate tt = new TextTemplate(ttProps); String url = tt.processText(connectionUrl); Properties conProps = new Properties(); conProps.put("user", dbUser);
public void processText(InputStream is, OutputStreamWriter os) throws IOException { String text = IOUtils.toString(is, UTF_8); text = processText(text); os.write(text); }
ttProps.put(PARAM_DB_USER, dbUser); ttProps.put(PARAM_DB_PWD, dbPassword); TextTemplate tt = new TextTemplate(ttProps); String url = tt.processText(connectionUrl); Properties conProps = new Properties(); conProps.put("user", dbUser);
String replacementValue = processString(newVars, newVarsValue); if (!replacementValue.equals(newVarsValue)) { doneProcessing = false; return unescape(newVars);
public void initFreeMarker() { freemarkerConfiguration = new Configuration(Configuration.getVersion()); preprocessVars(); freemarkerVars = new HashMap<>(); Map<String, Object> currentMap;