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 019 020import java.util.*; 021import static org.apache.juneau.commons.utils.Shorts.*; 022 023/** 024 * Class-related utility methods. 025 * 026 */ 027@SuppressWarnings({ 028 "java:S1192" // Duplicated literals (argument/property names) read more clearly inline than as constants 029}) 030public class ResourceBundleUtils { 031 032 /** 033 * Prevents instantiation. 034 */ 035 private ResourceBundleUtils() {} 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. Must not be <jk>null</jk>. 041 * @param locale The locale for which a resource bundle is desired. Must not be <jk>null</jk>. 042 * @param loader The class loader from which to load the resource bundle. Must not be <jk>null</jk>. 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 reqnn("loader", loader); 047 try { 048 return ResourceBundle.getBundle(baseName, locale, loader); 049 } catch (@SuppressWarnings("unused") MissingResourceException e) { 050 // Resource bundle not found, return null 051 } 052 return null; 053 } 054}