private static final Pattern POLICY_PARAM_PATTERN = Pattern
.compile("params\\['(.+)'\\]");
static final EngineMessages toEngineMessages(
PolicyEnforcementResult evalResult) {
EngineMessages msgs = new EngineMessages();
List<JahiaPasswordPolicyRule> rules = evalResult.getViolatedRules();
for (JahiaPasswordPolicyRule theRule : rules) {
List<JahiaPasswordPolicyRuleParam> params = theRule.getActionParameters();
if (params.size() > 0) {
Map<String, String> paramMap = theRule.getActionParametersValues();
String msgKey = (String) paramMap.get("message");
if (msgKey == null) {
// get the first one in the list
msgKey = ((JahiaPasswordPolicyRuleParam) params.get(0))
.getValue();
}
List<String> arguments = new LinkedList<String>();
for (int i = 0; i < params.size() - 1; i++) {
arguments.add(paramMap.get("arg" + i));
}
while (arguments.size() > 0
&& arguments.get(arguments.size() - 1) == null) {
arguments.remove(arguments.size() - 1);
}
if (arguments.size() > 0) {
// evaluate arguments first
List<String> argValues = new LinkedList<String>();
Map<String, String> condParams = theRule.getConditionParametersValues();
for (String argParam : arguments) {
String value = argParam;
if (argParam != null) {
Matcher argMatcher = POLICY_PARAM_PATTERN
.matcher(argParam);
if (argMatcher.find()
&& argMatcher.groupCount() > 0) {
String condParamName = argMatcher.group(1);
if (condParams.containsKey(condParamName)) {
value = (String) condParams
.get(condParamName);
}
}
}
argValues.add(value);
}
msgs.add(new EngineMessage(msgKey, argValues.toArray()));
} else {
msgs.add(new EngineMessage(msgKey));
}
}
}
return msgs;