KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > servlet > jsp > jstl > fmt > LocalizationContext


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package javax.servlet.jsp.jstl.fmt;
18
19 import java.util.Locale JavaDoc;
20 import java.util.ResourceBundle JavaDoc;
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 &lt;fmt:message&gt; for mapping
29  * message keys to localized messages, and the locale component is used by the
30  * &lt;fmt:message&gt;, &lt;fmt:formatNumber&gt;, &lt;fmt:parseNumber&gt;, &lt;fmt:formatDate&gt;,
31  * and &lt;fmt:parseDate&gt; actions as their formatting or parsing locale, respectively.
32  *
33  * @author Jan Luehe
34  */

35
36 public class LocalizationContext {
37
38     // the localization context's resource bundle
39
final private ResourceBundle JavaDoc bundle;
40
41     // the localization context's locale
42
final private Locale JavaDoc locale;
43
44     /**
45      * Constructs an empty I18N localization context.
46      */

47     public LocalizationContext() {
48     bundle = null;
49     locale = null;
50     }
51
52     /**
53      * Constructs an I18N localization context from the given resource bundle
54      * and locale.
55      *
56      * <p> The specified locale is the application- or browser-based preferred
57      * locale that led to the resource bundle match.
58      *
59      * @param bundle The localization context's resource bundle
60      * @param locale The localization context's locale
61      */

62     public LocalizationContext(ResourceBundle JavaDoc bundle, Locale JavaDoc locale) {
63     this.bundle = bundle;
64     this.locale = locale;
65     }
66
67     /**
68      * Constructs an I18N localization context from the given resource bundle.
69      *
70      * <p> The localization context's locale is taken from the given
71      * resource bundle.
72      *
73      * @param bundle The resource bundle
74      */

75     public LocalizationContext(ResourceBundle JavaDoc bundle) {
76     this.bundle = bundle;
77     this.locale = bundle.getLocale();
78     }
79
80     /**
81      * Gets the resource bundle of this I18N localization context.
82      *
83      * @return The resource bundle of this I18N localization context, or null
84      * if this I18N localization context is empty
85      */

86     public ResourceBundle JavaDoc getResourceBundle() {
87     return bundle;
88     }
89
90     /**
91      * Gets the locale of this I18N localization context.
92      *
93      * @return The locale of this I18N localization context, or null if this
94      * I18N localization context is empty, or its resource bundle is a
95      * (locale-less) root resource bundle.
96      */

97     public Locale JavaDoc getLocale() {
98     return locale;
99     }
100 }
101
102
Popular Tags