%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.commons.jelly.tags.fmt.LocalizationContext |
|
|
1 | /* |
|
2 | * Copyright 2002,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 | 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 | // the localization context's resource bundle |
|
41 | final private ResourceBundle bundle; |
|
42 | ||
43 | // the localization context's locale |
|
44 | final private Locale locale; |
|
45 | ||
46 | /** |
|
47 | * Constructs an empty I18N localization context. |
|
48 | */ |
|
49 | 0 | public LocalizationContext() { |
50 | 0 | bundle = null; |
51 | 0 | locale = null; |
52 | 0 | } |
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 | 6 | public LocalizationContext(ResourceBundle bundle, Locale locale) { |
65 | 6 | this.bundle = bundle; |
66 | 6 | this.locale = locale; |
67 | 6 | } |
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 | 0 | public LocalizationContext(ResourceBundle bundle) { |
78 | 0 | this.bundle = bundle; |
79 | 0 | this.locale = bundle.getLocale(); |
80 | 0 | } |
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 | 12 | 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 | 9 | return locale; |
101 | } |
|
102 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |