001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau.internal; 014 015import java.util.*; 016 017/** 018 * Class-related utility methods. 019 * 020 * <h5 class='section'>See Also:</h5><ul> 021 022 * </ul> 023 */ 024public final class ResourceBundleUtils { 025 026 private static final ResourceBundle EMPTY = new ResourceBundle() { 027 @Override 028 protected Object handleGetObject(String key) { 029 return null; 030 } 031 @Override 032 public Enumeration<String> getKeys() { 033 return Collections.emptyEnumeration(); 034 } 035 }; 036 037 /** 038 * Same as {@link ResourceBundle#getBundle(String, Locale, ClassLoader)} but never throws a {@link MissingResourceException}. 039 * 040 * @param baseName The base name of the resource bundle, a fully qualified class name. 041 * @param locale The locale for which a resource bundle is desired. 042 * @param loader The class loader from which to load the resource bundle. 043 * @return The matching resource bundle, or <jk>null</jk> if it could not be found. 044 */ 045 public static ResourceBundle findBundle(String baseName, Locale locale, ClassLoader loader) { 046 try { 047 return ResourceBundle.getBundle(baseName, locale, loader); 048 } catch (MissingResourceException e) {} 049 return null; 050 } 051 052 /** 053 * Returns an empty resource bundle. 054 * 055 * @return An empty resource bundle. 056 */ 057 public static ResourceBundle empty() { 058 return EMPTY; 059 } 060}