001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Portions Copyright Apache Software Foundation.
007: *
008: * The contents of this file are subject to the terms of either the GNU
009: * General Public License Version 2 only ("GPL") or the Common Development
010: * and Distribution License("CDDL") (collectively, the "License"). You
011: * may not use this file except in compliance with the License. You can obtain
012: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
013: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
014: * language governing permissions and limitations under the License.
015: *
016: * When distributing the software, include this License Header Notice in each
017: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
018: * Sun designates this particular file as subject to the "Classpath" exception
019: * as provided by Sun in the GPL Version 2 section of the License file that
020: * accompanied this code. If applicable, add the following below the License
021: * Header, with the fields enclosed by brackets [] replaced by your own
022: * identifying information: "Portions Copyrighted [year]
023: * [name of copyright owner]"
024: *
025: * Contributor(s):
026: *
027: * If you wish your version of this file to be governed by only the CDDL or
028: * only the GPL Version 2, indicate your decision by adding "[Contributor]
029: * elects to include this software in this distribution under the [CDDL or GPL
030: * Version 2] license." If you don't indicate a single choice of license, a
031: * recipient has the option to distribute your version of this file under
032: * either the CDDL, the GPL Version 2 or to extend the choice of license to
033: * its licensees as provided above. However, if you add GPL Version 2 code
034: * and therefore, elected the GPL Version 2 license, then the option applies
035: * only if the new code is made subject to such option by the copyright
036: * holder.
037: */
038:
039: package javax.servlet.jsp.jstl.fmt;
040:
041: import java.util.Locale;
042: import java.util.ResourceBundle;
043:
044: /**
045: * Class representing an I18N localization context.
046: *
047: * <p> An I18N localization context has two components: a resource bundle and
048: * the locale that led to the resource bundle match.
049: *
050: * <p> The resource bundle component is used by <fmt:message> for mapping
051: * message keys to localized messages, and the locale component is used by the
052: * <fmt:message>, <fmt:formatNumber>, <fmt:parseNumber>, <fmt:formatDate>,
053: * and <fmt:parseDate> actions as their formatting or parsing locale, respectively.
054: *
055: * @author Jan Luehe
056: */
057:
058: public class LocalizationContext {
059:
060: // the localization context's resource bundle
061: final private ResourceBundle bundle;
062:
063: // the localization context's locale
064: final private Locale locale;
065:
066: /**
067: * Constructs an empty I18N localization context.
068: */
069: public LocalizationContext() {
070: bundle = null;
071: locale = null;
072: }
073:
074: /**
075: * Constructs an I18N localization context from the given resource bundle
076: * and locale.
077: *
078: * <p> The specified locale is the application- or browser-based preferred
079: * locale that led to the resource bundle match.
080: *
081: * @param bundle The localization context's resource bundle
082: * @param locale The localization context's locale
083: */
084: public LocalizationContext(ResourceBundle bundle, Locale locale) {
085: this .bundle = bundle;
086: this .locale = locale;
087: }
088:
089: /**
090: * Constructs an I18N localization context from the given resource bundle.
091: *
092: * <p> The localization context's locale is taken from the given
093: * resource bundle.
094: *
095: * @param bundle The resource bundle
096: */
097: public LocalizationContext(ResourceBundle bundle) {
098: this .bundle = bundle;
099: this .locale = bundle.getLocale();
100: }
101:
102: /**
103: * Gets the resource bundle of this I18N localization context.
104: *
105: * @return The resource bundle of this I18N localization context, or null
106: * if this I18N localization context is empty
107: */
108: public ResourceBundle getResourceBundle() {
109: return bundle;
110: }
111:
112: /**
113: * Gets the locale of this I18N localization context.
114: *
115: * @return The locale of this I18N localization context, or null if this
116: * I18N localization context is empty, or its resource bundle is a
117: * (locale-less) root resource bundle.
118: */
119: public Locale getLocale() {
120: return locale;
121: }
122: }
|