private static String replaceParameters(String msg, Object[] messageParameters,
            Locale locale) {
        if (messageParameters != null) {
            int count = 0;
            for (Object param : messageParameters) {
                if (param != null) {
                    if (String.class.isAssignableFrom(param.getClass())) {
                        // Make sure the string parameters are not more than 80 characters long. 
                        String last = param.toString().replaceAll(
                                System.getProperty("line.separator"), " ");
                        String newParam = "";
                        while (last.length() > MAX_LINE_LENGHT) {
                            int idx = MAX_LINE_LENGHT;
                            while (last.charAt(idx) != ' ' && idx > 0) {
                                idx--;
                            }
                            if (idx <= 0) {
                                idx = MAX_LINE_LENGHT;
                            }
                            newParam = newParam + last.substring(0, idx)
                                    + System.getProperty("line.separator");
                            if (idx == MAX_LINE_LENGHT) {
                                // Forced a break at 80 chars so make sure the 80th char is included
                                // in the message.
                                idx--;
                            }
                            last = last.substring(idx + 1);
                        }
                        messageParameters[count] = newParam + last;
                    }
                }
                count++;
            }
            MessageFormat formatter = new MessageFormat(msg, locale);
            msg = formatter.format(messageParameters);
        }
        return msg;
    }