Skip to content
Closed
Show file tree
Hide file tree
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
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -116,22 +116,18 @@ public class HostLocaleProviderAdapterImpl {
private static final String nativeDisplayLanguage;
static {
Set<Locale> tmpSet = new HashSet<>();
if (initialize()) {
// Assuming the default locales do not include any extensions, so
// no stripping is needed here.
Control c = Control.getNoFallbackControl(Control.FORMAT_DEFAULT);
String displayLocale = getDefaultLocale(CAT_DISPLAY);
Locale l = Locale.forLanguageTag(displayLocale.replace('_', '-'));
// Assuming the default locales do not include any extensions, so
// no stripping is needed here.
Control c = Control.getNoFallbackControl(Control.FORMAT_DEFAULT);
String displayLocale = getDefaultLocale(CAT_DISPLAY);
Locale l = Locale.forLanguageTag(displayLocale.replace('_', '-'));
tmpSet.addAll(c.getCandidateLocales("", l));
nativeDisplayLanguage = l.getLanguage();

String formatLocale = getDefaultLocale(CAT_FORMAT);
if (!formatLocale.equals(displayLocale)) {
l = Locale.forLanguageTag(formatLocale.replace('_', '-'));
tmpSet.addAll(c.getCandidateLocales("", l));
nativeDisplayLanguage = l.getLanguage();

String formatLocale = getDefaultLocale(CAT_FORMAT);
if (!formatLocale.equals(displayLocale)) {
l = Locale.forLanguageTag(formatLocale.replace('_', '-'));
tmpSet.addAll(c.getCandidateLocales("", l));
}
} else {
nativeDisplayLanguage = "";
}
supportedLocaleSet = Collections.unmodifiableSet(tmpSet);
}
Expand Down Expand Up @@ -850,7 +846,6 @@ private static Locale getNumberLocale(Locale src) {
// native methods

// initialize
private static native boolean initialize();
private static native String getDefaultLocale(int cat);

// For DateFormatProvider
Expand Down
82 changes: 15 additions & 67 deletions src/java.base/windows/native/libjava/HostLocaleProviderAdapter_md.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -39,15 +39,6 @@
#define CALENDAR_STYLE_SHORT_MASK 0x00000001 // Calendar.SHORT
#define CALENDAR_STYLE_STANDALONE_MASK 0x00008000 // Calendar.STANDALONE

// global variables
typedef int (WINAPI *PGLIE)(const jchar *, LCTYPE, LPWSTR, int);
typedef int (WINAPI *PGCIE)(const jchar *, CALID, LPCWSTR, CALTYPE, LPWSTR, int, LPDWORD);
typedef int (WINAPI *PECIEE)(CALINFO_ENUMPROCEXEX, const jchar *, CALID, LPCWSTR, CALTYPE, LPARAM);
PGLIE pGetLocaleInfoEx;
PGCIE pGetCalendarInfoEx;
PECIEE pEnumCalendarInfoExEx;
BOOL initialized = FALSE;

// prototypes
int getLocaleInfoWrapper(const jchar *langtag, LCTYPE type, LPWSTR data, int buflen);
int getCalendarInfoWrapper(const jchar *langtag, CALID id, LPCWSTR reserved, CALTYPE type, LPWSTR data, int buflen, LPDWORD val);
Expand Down Expand Up @@ -178,31 +169,6 @@ WCHAR * fixes[2][2][3][16] =
}
};

/*
* Class: sun_util_locale_provider_HostLocaleProviderAdapterImpl
* Method: initialize
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_initialize
(JNIEnv *env, jclass cls) {
if (!initialized) {
pGetLocaleInfoEx = (PGLIE)GetProcAddress(
GetModuleHandle("kernel32.dll"),
"GetLocaleInfoEx");
pGetCalendarInfoEx = (PGCIE)GetProcAddress(
GetModuleHandle("kernel32.dll"),
"GetCalendarInfoEx");
pEnumCalendarInfoExEx = (PECIEE)GetProcAddress(
GetModuleHandle("kernel32.dll"),
"EnumCalendarInfoExEx");
initialized =TRUE;
}

return pGetLocaleInfoEx != NULL &&
pGetCalendarInfoEx != NULL &&
pEnumCalendarInfoExEx != NULL;
}

/*
* Class: sun_util_locale_provider_HostLocaleProviderAdapterImpl
* Method: getDefaultLocale
Expand Down Expand Up @@ -768,34 +734,20 @@ JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapte
}

int getLocaleInfoWrapper(const jchar *langtag, LCTYPE type, LPWSTR data, int buflen) {
if (pGetLocaleInfoEx) {
if (wcscmp(L"und", (LPWSTR)langtag) == 0) {
// defaults to "en"
return pGetLocaleInfoEx(L"en", type, data, buflen);
} else {
return pGetLocaleInfoEx((LPWSTR)langtag, type, data, buflen);
}
if (wcscmp(L"und", (LPWSTR)langtag) == 0) {
// defaults to "en"
return GetLocaleInfoEx(L"en", type, data, buflen);
} else {
// If we ever wanted to support WinXP, we will need extra module from
// MS...
// return GetLocaleInfo(DownlevelLocaleNameToLCID(langtag, 0), type, data, buflen);
return 0;
return GetLocaleInfoEx((LPWSTR)langtag, type, data, buflen);
}
}

int getCalendarInfoWrapper(const jchar *langtag, CALID id, LPCWSTR reserved, CALTYPE type, LPWSTR data, int buflen, LPDWORD val) {
if (pGetCalendarInfoEx) {
if (wcscmp(L"und", (LPWSTR)langtag) == 0) {
// defaults to "en"
return pGetCalendarInfoEx(L"en", id, reserved, type, data, buflen, val);
} else {
return pGetCalendarInfoEx((LPWSTR)langtag, id, reserved, type, data, buflen, val);
}
if (wcscmp(L"und", (LPWSTR)langtag) == 0) {
// defaults to "en"
return GetCalendarInfoEx(L"en", id, reserved, type, data, buflen, val);
} else {
// If we ever wanted to support WinXP, we will need extra module from
// MS...
// return GetCalendarInfo(DownlevelLocaleNameToLCID(langtag, 0), ...);
return 0;
return GetCalendarInfoEx((LPWSTR)langtag, id, reserved, type, data, buflen, val);
}
}

Expand Down Expand Up @@ -1000,17 +952,13 @@ void getFixPart(const jchar * langtag, const jint numberStyle, BOOL positive, BO
}

int enumCalendarInfoWrapper(const jchar *langtag, CALID calid, CALTYPE type, LPWSTR buf, int buflen) {
if (pEnumCalendarInfoExEx) {
if (wcscmp(L"und", (LPWSTR)langtag) == 0) {
// defaults to "en"
return pEnumCalendarInfoExEx(&EnumCalendarInfoProc, L"en",
calid, NULL, type, (LPARAM)buf);
} else {
return pEnumCalendarInfoExEx(&EnumCalendarInfoProc, langtag,
calid, NULL, type, (LPARAM)buf);
}
if (wcscmp(L"und", (LPWSTR)langtag) == 0) {
// defaults to "en"
return EnumCalendarInfoExEx(&EnumCalendarInfoProc, L"en",
calid, NULL, type, (LPARAM)buf);
} else {
return 0;
return EnumCalendarInfoExEx(&EnumCalendarInfoProc, langtag,
calid, NULL, type, (LPARAM)buf);
}
}

Expand Down