package com.bloatit.framework.webprocessor.annotations;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Matcher;

public class MessageFormater {

    private Map<String, String> params = new HashMap<String, String>();

    public MessageFormater(final String name, final String value) {
        params.put("%paramName%", name);
        params.put("%value%", value);
    }

    public void addParameter(final String name, final String value) {
        params.put(name, value);
    }

    public String format(final String message) {
        String errorMsg = message;
        for (final Entry<String, String> formatter : params.entrySet()) {
            if (!formatter.getValue().isEmpty()) {
                errorMsg = message.replaceAll(formatter.getKey(), Matcher.quoteReplacement(formatter.getValue()));
            } else {
                errorMsg = message.replaceAll(formatter.getKey(), "null");
            }
        }
        return errorMsg;
    }
}

@@ -756,39 +756,40 @@
      errorMsg = 
-message
+errorMsg
 .replaceAll(form
@@ -901,23 +901,24 @@
 orMsg = 
-message
+errorMsg
 .replace

fix message formatter for errors