com.sun.faces.application.ApplicationResourceBundle Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jakarta.faces Show documentation
Show all versions of jakarta.faces Show documentation
EE4J Compatible Implementation for Jakarta Faces API
/* * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at * http://www.eclipse.org/legal/epl-2.0. * * This Source Code may also be made available under the following Secondary * Licenses when the conditions for such availability set forth in the * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, * version 2 with the GNU Classpath Exception, which is available at * https://www.gnu.org/software/classpath/license.html. * * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ package com.sun.faces.application; import static com.sun.faces.util.Util.coalesce; import static com.sun.faces.util.Util.getCurrentLoader; import java.util.HashMap; import java.util.Locale; import java.util.Map; import java.util.ResourceBundle; /** *
locale */ public ResourceBundle getResourceBundle(Locale locale) { if (locale == null) { locale = Locale.getDefault(); } ResourceBundle bundle = resources.get(locale); if (bundle == null) { ClassLoader loader = getCurrentLoader(this); synchronized (this) { bundle = resources.get(locale); if (bundle == null) { bundle = ResourceBundle.getBundle(baseName, locale, loader); resources.put(locale, bundle); } } } return bundle; } /** * @param locale a* Contains an application level resource bundle name and its associated descriptions, if any. *
*/ public class ApplicationResourceBundle { public static final String DEFAULT_KEY = "DEFAULT"; private final String baseName; private final MapdisplayNames; private final Map descriptions; private volatile Map resources; // ------------------------------------------------------------ Constructors /** * * Constructs a new ApplicationResourceBundle *
* * @param baseName the base name of theResourceBundle
* @param displayNames any display names that were associated with the resource bundle * definition in the configuration resource * @param descriptions any descriptions that were associated with the resource bundle definition * in the configuration resource */ public ApplicationResourceBundle(String baseName, MapdisplayNames, Map descriptions) { if (baseName == null) { throw new IllegalArgumentException(); } this.baseName = baseName; this.displayNames = displayNames; this.descriptions = descriptions; this.resources = new HashMap<>(4, 1.0f); } // ---------------------------------------------------------- Public Methods /** * @return the base name of the ResourceBundle
associated with this *ApplicationResourceBundle
instance */ public String getBaseName() { return baseName; } /** * @param locale aLocale
* @return return theResourceBundle
associated with the specified *Locale
* @return a text of adisplay-name
element associated with the specified * locale */ public String getDisplayName(Locale locale) { String displayName = null; if (displayNames != null) { displayName = queryMap(locale, displayNames); } return coalesce(displayName, ""); } /** * @param locale aLocale
* @return a text of adescription
element associated with the specified * locale */ public String getDescription(Locale locale) { String description = null; if (descriptions != null) { description = queryMap(locale, descriptions); } return coalesce(description, ""); } // --------------------------------------------------------- Private Methods /** ** Lookup and return the text for the specified
* * @param localeLocale
from within the specified *Map
. *Locale
if interest * @param map a map containing localized text keyed byLocale
* @return localized text, if any */ private String queryMap(Locale locale, Mapmap) { if (locale == null) { return map.get(DEFAULT_KEY); } String description = map.get(locale.toString()); if (description == null) { return map.get(DEFAULT_KEY); } return null; } }