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.apache.commons.i18n;
25
26 import java.io.Serializable;
27 import java.util.Locale;
28
29 /***
30 * @author Daniel Florey
31 *
32 * The <code>LocalizedBundle</code> class represents a bundle of localized messages that
33 * belong together.
34 * The <code>LocalizedBundle</code> class itself contains the message id and the arguments
35 * that might be used to include dynamic values into the message text and knows nothing
36 *
37 */
38 public class LocalizedBundle implements Serializable {
39 public final static String ID = "id";
40 public final static String ARGUMENTS = "arguments";
41
42 protected String id;
43 protected Object[] arguments;
44
45 /***
46 * @param messageId The messageId refers the corresponding bundle in the file containing
47 * the localized messages. The format of the message file depends on the implementation of the
48 * MessageManager.
49 */
50 public LocalizedBundle(String messageId) {
51 this.id = messageId;
52 this.arguments = new Object[0];
53 }
54
55 /***
56 * @param messageId The messageId refers the corresponding bundle in the file containing
57 * the localized messages. The format of the message file depends on the implementation of the
58 * MessageManager.
59 * @param arguments An array of objects containing argument for the messages. These arguments
60 * are used to insert dynamic values into the localized messages.
61 */
62 public LocalizedBundle(String messageId, Object[] arguments) {
63 this.id = messageId;
64 this.arguments = arguments;
65 }
66
67 /***
68 * @return returns the id of this bundle
69 */
70 public String getId() {
71 return id;
72 }
73
74 /***
75 * @return returns the arguments associated with this message bundle
76 */
77 public Object[] getArguments() {
78 return arguments;
79 }
80
81 /***
82 * @param key the key of the specific message entry in the message bundle
83 * @param locale the locale for that this message should be rendered
84 * @return returns the localized text
85 * @throws MessageNotFoundException if an entry with the given key can not be found
86 * in this bundle
87 */
88 public String getText(String key, Locale locale) throws MessageNotFoundException {
89 return MessageManager.getText(id, key, arguments, locale);
90 }
91
92 /***
93 * @param key the key of the specific message entry in the message bundle
94 * @param locale the locale for that this message should be rendered
95 * @param defaultText the text to be returned if no entry was found for the given key
96 * @return returns the localized text
97 */
98 public String getText(String key, String defaultText, Locale locale) {
99 return MessageManager.getText(id, key, arguments, locale, defaultText);
100 }
101 }