Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FISH-9456 Resource Bundles #6903

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ private LogDomains() {}
*/
public static final String RESOURCE_BUNDLE = "LogStrings";

public static final String RESOURCE_BUNDLE_MESSAGES = "LogMessages";

/**
* Field
*/
Expand Down Expand Up @@ -363,26 +365,33 @@ public static Logger getLogger(final Class clazz, final String namePrefix, final
return logManager.getLogger(cLogger.getName());
}

private static ResourceBundle getResourceBundle(final String name, final Class clazz,
final ClassLoader resourceBundleLoader) {
final ResourceBundle classBundle = findResourceBundle(name, clazz, resourceBundleLoader);
private static ResourceBundle getResourceBundle (final String name, final Class<?> clazz, final ClassLoader resourceBundleLoader) {
ResourceBundle classBundle = findResourceBundle(name, clazz, resourceBundleLoader);
if (classBundle == null) { // EJB uses LogMessages instead of LogStrings, check for this file if necessary.
classBundle = findResourceBundle(name, clazz, resourceBundleLoader, RESOURCE_BUNDLE_MESSAGES);
}

if (classBundle != null) {
return classBundle;
}

Logger.getAnonymousLogger().log(Level.INFO, "Cannot find the resource bundle for the name {0} for {1} using {2}", new Object[]{name, clazz, resourceBundleLoader});
return null;
}

private static ResourceBundle findResourceBundle(final String name, final Class clazz,
final ClassLoader classLoader) {
final ResourceBundle packageRootBundle = tryTofindResourceBundle(name, classLoader);
private static ResourceBundle findResourceBundle (final String name, final Class<?> clazz, final ClassLoader classLoader) {
return findResourceBundle(name, clazz, classLoader, LogDomains.RESOURCE_BUNDLE);
}

private static ResourceBundle findResourceBundle (final String name, final Class<?> clazz, final ClassLoader classLoader, final String fileSuffix) {
final ResourceBundle packageRootBundle = tryToFindResourceBundle(name, classLoader, fileSuffix);
if (packageRootBundle != null) {
return packageRootBundle;
}
// not found. Ok, let's try to go through the class's package tree
final StringBuilder rbPackage = new StringBuilder(clazz.getPackage().getName());
while (true) {
final ResourceBundle subPkgBundle = tryTofindResourceBundle(rbPackage.toString(), classLoader);
final ResourceBundle subPkgBundle = tryToFindResourceBundle(rbPackage.toString(), classLoader, fileSuffix);
if (subPkgBundle != null) {
return subPkgBundle;
}
Expand All @@ -402,9 +411,9 @@ private static String getLoggerName(Class clazz, String logDomainsConstantName)
return loggerName;
}

private static ResourceBundle tryTofindResourceBundle(final String name, final ClassLoader classLoader) {
private static ResourceBundle tryToFindResourceBundle (final String name, final ClassLoader classLoader, final String fileSuffix) {
try {
return ResourceBundle.getBundle(name + "." + LogDomains.RESOURCE_BUNDLE, Locale.getDefault(), classLoader);
return ResourceBundle.getBundle(name + "." + fileSuffix, Locale.getDefault(), classLoader);
} catch (MissingResourceException e) {
return null;
}
Expand Down