001: /*
002: * Copyright 1999-2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package clime.messadmin.taglib.jstl.fmt;
018:
019: //package javax.servlet.jsp.jstl.fmt;
020:
021: import java.util.Locale;
022: import java.util.ResourceBundle;
023:
024: /**
025: * Class representing an I18N localization context.
026: *
027: * <p> An I18N localization context has two components: a resource bundle and
028: * the locale that led to the resource bundle match.
029: *
030: * <p> The resource bundle component is used by <fmt:message> for mapping
031: * message keys to localized messages, and the locale component is used by the
032: * <fmt:message>, <fmt:formatNumber>, <fmt:parseNumber>, <fmt:formatDate>,
033: * and <fmt:parseDate> actions as their formatting or parsing locale, respectively.
034: *
035: * @author Jan Luehe
036: */
037:
038: public class LocalizationContext {
039:
040: // the localization context's resource bundle
041: final private ResourceBundle bundle;
042:
043: // the localization context's locale
044: final private Locale locale;
045:
046: /**
047: * Constructs an empty I18N localization context.
048: */
049: public LocalizationContext() {
050: bundle = null;
051: locale = null;
052: }
053:
054: /**
055: * Constructs an I18N localization context from the given resource bundle
056: * and locale.
057: *
058: * <p> The specified locale is the application- or browser-based preferred
059: * locale that led to the resource bundle match.
060: *
061: * @param bundle The localization context's resource bundle
062: * @param locale The localization context's locale
063: */
064: public LocalizationContext(ResourceBundle bundle, Locale locale) {
065: this .bundle = bundle;
066: this .locale = locale;
067: }
068:
069: /**
070: * Constructs an I18N localization context from the given resource bundle.
071: *
072: * <p> The localization context's locale is taken from the given
073: * resource bundle.
074: *
075: * @param bundle The resource bundle
076: */
077: public LocalizationContext(ResourceBundle bundle) {
078: this .bundle = bundle;
079: this .locale = bundle.getLocale();
080: }
081:
082: /**
083: * Gets the resource bundle of this I18N localization context.
084: *
085: * @return The resource bundle of this I18N localization context, or null
086: * if this I18N localization context is empty
087: */
088: public ResourceBundle getResourceBundle() {
089: return bundle;
090: }
091:
092: /**
093: * Gets the locale of this I18N localization context.
094: *
095: * @return The locale of this I18N localization context, or null if this
096: * I18N localization context is empty, or its resource bundle is a
097: * (locale-less) root resource bundle.
098: */
099: public Locale getLocale() {
100: return locale;
101: }
102: }
|