for (String var : varList) {
String tempVar = var.replaceAll("#", "");
for (Plugin p : pluginList) {
HashVariablePlugin hashVariablePlugin = (HashVariablePlugin) p;
if (tempVar.startsWith(hashVariablePlugin.getPrefix() + ".")) {
tempVar = tempVar.replaceFirst(hashVariablePlugin.getPrefix() + ".", "");
HashVariablePlugin cachedPlugin = hashVariablePluginCache.get(hashVariablePlugin.getClassName());
if (cachedPlugin == null) {
cachedPlugin = (HashVariablePlugin) pluginManager.getPlugin(hashVariablePlugin.getClassName());
//get default plugin properties
if (appDef == null) {
appDef = AppUtil.getCurrentAppDefinition();
}
PluginDefaultProperties pluginDefaultProperties = pluginDefaultPropertiesDao.loadById(cachedPlugin.getClassName(), appDef);
if (pluginDefaultProperties != null && pluginDefaultProperties.getPluginProperties() != null && pluginDefaultProperties.getPluginProperties().trim().length() > 0) {
cachedPlugin.setProperties(PropertyUtil.getPropertiesValueFromJson(pluginDefaultProperties.getPluginProperties()));
}
//put appDef & wfAssignment to properties
cachedPlugin.setProperty("appDefinition", appDef);
cachedPlugin.setProperty("workflowAssignment", wfAssignment);
hashVariablePluginCache.put(hashVariablePlugin.getClassName(), cachedPlugin);
}
String nestedHashVar = tempVar;
//process nested hash
while (nestedHashVar.contains("{") && nestedHashVar.contains("}")) {
Pattern nestedPattern = Pattern.compile("\\{([^\\{^\\}])*\\}");
Matcher nestedMatcher = nestedPattern.matcher(nestedHashVar);
while (nestedMatcher.find()) {
String nestedHash = nestedMatcher.group();
String nestedHashString = nestedHash.replace("{", "#");
nestedHashString = nestedHashString.replace("}", "#");
String processedNestedHashValue = processHashVariable(nestedHashString, wfAssignment, escapeFormat, replaceMap, appDef);
//if being process
if (!nestedHashString.equals(processedNestedHashValue)) {
tempVar = tempVar.replaceAll(StringUtil.escapeString(nestedHash, StringUtil.TYPE_REGEX, null), StringUtil.escapeString(processedNestedHashValue, escapeFormat, replaceMap));
}
//remove nested hash
nestedHashVar = nestedHashVar.replaceAll(StringUtil.escapeString(nestedHash, StringUtil.TYPE_REGEX, null), StringUtil.escapeString(processedNestedHashValue, escapeFormat, replaceMap));
}
}
//unescape hash variable
tempVar = StringEscapeUtils.unescapeJavaScript(tempVar);
//get result from plugin
String value = cachedPlugin.processHashVariable(tempVar);
if (value != null && !StringUtil.TYPE_REGEX.equals(escapeFormat) && !StringUtil.TYPE_JSON.equals(escapeFormat)) {
value = StringUtil.escapeRegex(value);
}
//escape special char in HashVariable
var = cachedPlugin.escapeHashVariable(var);
//replace
if (value != null) {
// clean to prevent XSS
value = StringUtil.stripHtmlRelaxed(value);