01: /**
02: *
03: */package net.sf.oval.internal;
04:
05: import java.util.Map;
06: import java.util.Map.Entry;
07:
08: import net.sf.oval.internal.util.StringUtils;
09:
10: /**
11: * @author Sebastian Thomschke
12: *
13: */
14: public final class MessageRenderer {
15: private MessageRenderer() {
16: // do nothing
17: }
18:
19: public static String renderMessage(final String messageKey,
20: final Map<String, String> messageValues) {
21: String message = MessageResolverHolder.getMessageResolver()
22: .getMessage(messageKey);
23: if (message == null)
24: message = messageKey;
25:
26: // if there are no place holders in the message simply return it
27: if (message.indexOf('{') == -1)
28: return message;
29:
30: if (messageValues != null && messageValues.size() > 0) {
31: for (final Entry<String, String> entry : messageValues
32: .entrySet()) {
33: message = StringUtils.replaceAll(message, "{"
34: + entry.getKey() + "}", entry.getValue());
35: }
36: }
37: return message;
38: }
39:
40: public static String renderMessage(final String messageKey,
41: final String[][] messageValues) {
42: String message = MessageResolverHolder.getMessageResolver()
43: .getMessage(messageKey);
44: if (message == null)
45: message = messageKey;
46:
47: // if there are no place holders in the message simply return it
48: if (message.indexOf('{') == -1)
49: return message;
50:
51: if (messageValues != null && messageValues.length > 0) {
52: for (final String[] entry : messageValues) {
53: message = StringUtils.replaceAll(message, "{"
54: + entry[0] + "}", entry[1]);
55: }
56: }
57: return message;
58: }
59: }
|