
org.jppf.utils.LocalizationUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jppf-common Show documentation
Show all versions of jppf-common Show documentation
JPPF, the open source grid computing solution
/*
* JPPF.
* Copyright (C) 2005-2015 JPPF Team.
* http://www.jppf.org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jppf.utils;
import java.io.File;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import org.slf4j.*;
/**
* Utility methods to localize messages in the JPPF components.
* @author Laurent Cohen
* @exclude
*/
public final class LocalizationUtils {
/**
* Logger for this class.
*/
private static Logger log = LoggerFactory.getLogger(LocalizationUtils.class);
/**
* Determines whether debug-level logging is enabled.
*/
private static boolean debugEnabled = log.isDebugEnabled();
/**
* Whether to log the {@link MissingResourceException}s.
*/
private static final boolean SHOW_EXCEPTIONS = JPPFConfiguration.getProperties().getBoolean("jppf.show.localization.errors", false);
/**
* Cache of resources bundles that were already found missing, to avoid repeating the search and filling the log uselessly.
*/
private static final Map notFoundBundleCache = new ConcurrentHashMap<>();
/**
* Get a localized property value.
* @param baseName the base name to use, in combination with the default locale, to lookup the appropriate resource bundle.
* @param key the key for the localized value to lookup.
* @return the name localized through the default locale information, or the key itself if it could not be localized.
*/
public static String getLocalized(final String baseName, final String key) {
return getLocalized(baseName, key, key);
}
/**
* Get a localized array of property values.
* @param baseName the base name to use, in combination with the default locale, to lookup the appropriate resource bundle.
* @param keys the keys for which to lookup a localized value.
* @return an array of localized values looked up using the default locale. If a key could not be localized, it is returned as the value.
*/
public static String[] getLocalized(final String baseName, final String...keys) {
return getLocalized(baseName, Locale.getDefault(), keys);
}
/**
* Get a localized array of property values.
* @param baseName the base name to use, in combination with the default locale, to lookup the appropriate resource bundle.
* @param locale the locale for which to lookup localized values.
* @param keys the keys for which to lookup a localized value.
* @return an array of localized values looked up using the default locale. If a key could not be localized, it is returned as the value.
*/
public static String[] getLocalized(final String baseName, final Locale locale, final String...keys) {
if (keys == null) return new String[0];
String[] localized = new String[keys.length];
for (int i=0; i= 0) result = result.substring(0, idx);
result = base + '/' + result;
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy