1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.tags.fmt;
17
18 import java.util.ResourceBundle;
19 import java.util.Locale;
20
21
22 /***
23 * Class representing an I18N localization context.
24 *
25 * <p> An I18N localization context has two components: a resource bundle and
26 * the locale that led to the resource bundle match.
27 *
28 * <p> The resource bundle component is used by <fmt:message> for mapping
29 * message keys to localized messages, and the locale component is used by the
30 * <fmt:message>, <fmt:formatNumber>, <fmt:parseNumber>, <fmt:formatDate>,
31 * and <fmt:parseDate> actions as their formatting locale.
32 *
33 * @see javax.servlet.jsp.jstl.fmt.LocalizationContext
34 *
35 * @author <a href="mailto:willievu@yahoo.com">Willie Vu</a>
36 * @version 1.1
37 */
38 public class LocalizationContext {
39
40
41 final private ResourceBundle bundle;
42
43
44 final private Locale locale;
45
46 /***
47 * Constructs an empty I18N localization context.
48 */
49 public LocalizationContext() {
50 bundle = null;
51 locale = null;
52 }
53
54 /***
55 * Constructs an I18N localization context from the given resource bundle
56 * and locale.
57 *
58 * <p> The specified locale is the application- or browser-based preferred
59 * locale that led to the resource bundle match.
60 *
61 * @param bundle The localization context's resource bundle
62 * @param locale The localization context's locale
63 */
64 public LocalizationContext(ResourceBundle bundle, Locale locale) {
65 this.bundle = bundle;
66 this.locale = locale;
67 }
68
69 /***
70 * Constructs an I18N localization context from the given resource bundle.
71 *
72 * <p> The localization context's locale is taken from the given
73 * resource bundle.
74 *
75 * @param bundle The resource bundle
76 */
77 public LocalizationContext(ResourceBundle bundle) {
78 this.bundle = bundle;
79 this.locale = bundle.getLocale();
80 }
81
82 /***
83 * Gets the resource bundle of this I18N localization context.
84 *
85 * @return The resource bundle of this I18N localization context, or null
86 * if this I18N localization context is empty
87 */
88 public ResourceBundle getResourceBundle() {
89 return bundle;
90 }
91
92 /***
93 * Gets the locale of this I18N localization context.
94 *
95 * @return The locale of this I18N localization context, or null if this
96 * I18N localization context is empty, or its resource bundle is a
97 * (locale-less) root resource bundle.
98 */
99 public Locale getLocale() {
100 return locale;
101 }
102 }