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 */ 020public final class ResourceBundleUtils { 021 022 private static final ResourceBundle EMPTY = new ResourceBundle() { 023 @Override 024 protected Object handleGetObject(String key) { 025 return null; 026 } 027 @Override 028 public Enumeration<String> getKeys() { 029 return Collections.emptyEnumeration(); 030 } 031 }; 032 033 /** 034 * Same as {@link ResourceBundle#getBundle(String, Locale, ClassLoader)} but never throws a {@link MissingResourceException}. 035 * 036 * @param baseName The base name of the resource bundle, a fully qualified class name. 037 * @param locale The locale for which a resource bundle is desired. 038 * @param loader The class loader from which to load the resource bundle. 039 * @return The matching resource bundle, or <jk>null</jk> if it could not be found. 040 */ 041 public static ResourceBundle findBundle(String baseName, Locale locale, ClassLoader loader) { 042 try { 043 return ResourceBundle.getBundle(baseName, locale, loader); 044 } catch (MissingResourceException e) {} 045 return null; 046 } 047 048 /** 049 * Returns an empty resource bundle. 050 * 051 * @return An empty resource bundle. 052 */ 053 public static ResourceBundle empty() { 054 return EMPTY; 055 } 056}