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