1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.dbforms.util;
25
26 import java.util.Locale;
27
28
29
30 /***
31 * handling of internal messages
32 *
33 * @author Henner Kollmann
34 */
35 public class MessageResourcesInternal {
36 private static String RESOURCE = "org.dbforms.resources.messages";
37 private static MessageResource msgRes = new MessageResource(RESOURCE);
38
39 /***
40 * Get the message from ResourceBundle. If not present, return the
41 * defaultMsg at the place of a null. To avoid to doing this condition
42 * everywhere in the code ...
43 *
44 * @param msgString </code> : Message key to lookup.
45 * @param localeLocale </code> : Locale object to map message with good
46 * ResourceBundle.
47 * @param defaultMsgString </code> : String to return if the lookup message
48 * key is not found.
49 *
50 * @return <code>String</code> : Message resolve.
51 */
52 public static String getMessage(String msg,
53 Locale locale,
54 String defaultMsg) {
55 String s = getMessage(msg, locale);
56
57 if (Util.isNull(s)) {
58 s = defaultMsg;
59 }
60
61 return s;
62 }
63
64
65 /***
66 * Retrieve message from ResourceBundle. If the ResourceBundle is not yet
67 * cached, cache it and retreive message.
68 *
69 * @param msgString </code> : Message key to lookup.
70 * @param locLocale </code> : Locale object to map message with good
71 * ResourceBundle.
72 *
73 * @return <code>String</code> : Message resolve, null if not found.
74 */
75 public static String getMessage(String msg,
76 Locale loc) {
77
78 String res = MessageResources.getMessage(msg, loc);
79
80 if (res == null) {
81 res = msgRes.getMessage(msg, loc);
82 }
83
84 return res;
85 }
86
87
88 /***
89 * Retrieve message from ResourceBundle and replace parameter "{x}" with
90 * values in parms array.
91 *
92 * @param msgString </code> : Message key to lookup.
93 * @param locLocale </code> : Locale object to map message with good
94 * ResourceBundle.
95 * @param parmsString[] </code> : Parameters to replace "{x}" in message .
96 *
97 * @return <code>String</code> : Message resolve with parameter replaced,
98 * null if message key not found.
99 */
100 public static String getMessage(String msg,
101 Locale loc,
102 String[] parms) {
103
104 String res = MessageResources.getMessage(msg, loc, parms);
105
106 if (res == null) {
107 res = msgRes.getMessage(msg, loc, parms);
108 }
109
110 return res;
111 }
112 }