src/macosx/native/sun/util/locale/provider/HostLocaleProviderAdapter_md.c

Print this page
rev 6794 : imported patch 7091601


  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include "sun_util_locale_provider_HostLocaleProviderAdapterImpl.h"
  27 #include <CoreFoundation/CoreFoundation.h>
  28 #include <stdio.h>
  29 
  30 #define BUFLEN 256
  31 
  32 static CFDateFormatterStyle convertDateFormatterStyle(jint javaStyle);
  33 static CFNumberFormatterStyle convertNumberFormatterStyle(jint javaStyle);
  34 static void copyArrayElements(JNIEnv *env, CFArrayRef cfarray, jobjectArray jarray, CFIndex sindex, int dindex, int count);
  35 static jstring getNumberSymbolString(JNIEnv *env, jstring jdefault, CFStringRef type);
  36 static jchar getNumberSymbolChar(jchar jdefault, CFStringRef type);

  37 
  38 // from java_props_macosx.c
  39 extern char * getMacOSXLocale(int cat);
  40 extern char * getPosixLocale(int cat);
  41 
  42 /*
  43  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
  44  * Method:    getDefaultLocale
  45  * Signature: (I)Ljava/lang/String;
  46  */
  47 JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getDefaultLocale
  48   (JNIEnv *env, jclass cls, jint cat) {
  49     char * localeString = NULL;
  50     int posixCat;
  51     jstring ret = NULL;
  52 
  53     switch (cat) {
  54         case sun_util_locale_provider_HostLocaleProviderAdapterImpl_CAT_DISPLAY:
  55             posixCat = LC_MESSAGES;
  56             break;


  61     }
  62 
  63     localeString = getMacOSXLocale(posixCat);
  64     if (localeString == NULL) {
  65         localeString = getPosixLocale(posixCat);
  66     }
  67     ret = (*env)->NewStringUTF(env, localeString);
  68     free(localeString);
  69 
  70     return ret;
  71 }
  72 
  73 /*
  74  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
  75  * Method:    getDateTimePatternNative
  76  * Signature: (IILjava/lang/String;)Ljava/lang/String;
  77  */
  78 JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getDateTimePatternNative
  79   (JNIEnv *env, jclass cls, jint dateStyle, jint timeStyle, jstring jlangtag) {
  80     jstring ret = NULL;
  81     CFLocaleRef cflocale = CFLocaleCopyCurrent();
  82 
  83     if (cflocale != NULL) {
  84         CFDateFormatterRef df = CFDateFormatterCreate(kCFAllocatorDefault,
  85                                                   cflocale,
  86                                                   convertDateFormatterStyle(dateStyle),
  87                                                   convertDateFormatterStyle(timeStyle));
  88         if (df != NULL) {
  89             char buf[BUFLEN];
  90             CFStringRef formatStr = CFDateFormatterGetFormat(df);
  91             CFStringGetCString(formatStr, buf, BUFLEN, kCFStringEncodingUTF8);
  92             ret = (*env)->NewStringUTF(env, buf);
  93             CFRelease(df);
  94         }
  95         CFRelease(cflocale);
  96     }
  97 
  98     return ret;
  99 }
 100 
 101 /*
 102  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 103  * Method:    getCalendarID
 104  * Signature: (Ljava/lang/String;)Ljava/lang/String;
 105  */
 106 JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getCalendarID
 107   (JNIEnv *env, jclass cls, jstring jlangtag) {
 108     jstring ret = NULL;
 109     CFLocaleRef cflocale = CFLocaleCopyCurrent();
 110 
 111     if (cflocale != NULL) {
 112         char buf[BUFLEN];
 113         CFTypeRef calid = CFLocaleGetValue(cflocale, kCFLocaleCalendarIdentifier);
 114         CFStringGetCString((CFStringRef)calid, buf, BUFLEN, kCFStringEncodingUTF8);
 115         ret = (*env)->NewStringUTF(env, buf);
 116         CFRelease(cflocale);
 117     }
 118 
 119     return ret;
 120 }
 121 
 122 /*
 123  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 124  * Method:    getAmPmStrings
 125  * Signature: (Ljava/lang/String;[Ljava/lang/String;)[Ljava/lang/String;
 126  */
 127 JNIEXPORT jobjectArray JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getAmPmStrings
 128   (JNIEnv *env, jclass cls, jstring jlangtag, jobjectArray ampms) {
 129     CFLocaleRef cflocale = CFLocaleCopyCurrent();
 130     if (cflocale != NULL) {
 131         CFDateFormatterRef df = CFDateFormatterCreate(kCFAllocatorDefault,
 132                                                   cflocale,
 133                                                   kCFDateFormatterFullStyle,
 134                                                   kCFDateFormatterFullStyle);
 135         if (df != NULL) {
 136             char buf[BUFLEN];
 137             CFStringRef amStr = CFDateFormatterCopyProperty(df, kCFDateFormatterAMSymbol);
 138             if (amStr != NULL) {
 139                 CFStringGetCString(amStr, buf, BUFLEN, kCFStringEncodingUTF8);
 140                 CFRelease(amStr);
 141                 (*env)->SetObjectArrayElement(env, ampms, 0, (*env)->NewStringUTF(env, buf));
 142             }
 143             CFStringRef pmStr = CFDateFormatterCopyProperty(df, kCFDateFormatterPMSymbol);
 144             if (pmStr != NULL) {
 145                 CFStringGetCString(pmStr, buf, BUFLEN, kCFStringEncodingUTF8);
 146                 CFRelease(pmStr);
 147                 (*env)->SetObjectArrayElement(env, ampms, 1, (*env)->NewStringUTF(env, buf));
 148             }
 149             CFRelease(df);
 150         }
 151         CFRelease(cflocale);
 152     }
 153 
 154     return ampms;
 155 }
 156 
 157 /*
 158  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 159  * Method:    getEras
 160  * Signature: (Ljava/lang/String;[Ljava/lang/String;)[Ljava/lang/String;
 161  */
 162 JNIEXPORT jobjectArray JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getEras
 163   (JNIEnv *env, jclass cls, jstring jlangtag, jobjectArray eras) {
 164     CFLocaleRef cflocale = CFLocaleCopyCurrent();
 165     if (cflocale != NULL) {
 166         CFDateFormatterRef df = CFDateFormatterCreate(kCFAllocatorDefault,
 167                                                   cflocale,
 168                                                   kCFDateFormatterFullStyle,
 169                                                   kCFDateFormatterFullStyle);
 170         if (df != NULL) {
 171             CFArrayRef cferas = CFDateFormatterCopyProperty(df, kCFDateFormatterEraSymbols);
 172             if (cferas != NULL) {
 173                 copyArrayElements(env, cferas, eras, 0, 0, CFArrayGetCount(cferas));
 174                 CFRelease(cferas);
 175             }
 176             CFRelease(df);
 177         }
 178         CFRelease(cflocale);
 179     }
 180 
 181     return eras;
 182 }
 183 
 184 /*
 185  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 186  * Method:    getMonths
 187  * Signature: (Ljava/lang/String;[Ljava/lang/String;)[Ljava/lang/String;
 188  */
 189 JNIEXPORT jobjectArray JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getMonths
 190   (JNIEnv *env, jclass cls, jstring jlangtag, jobjectArray months) {
 191     CFLocaleRef cflocale = CFLocaleCopyCurrent();
 192     if (cflocale != NULL) {
 193         CFDateFormatterRef df = CFDateFormatterCreate(kCFAllocatorDefault,
 194                                                   cflocale,
 195                                                   kCFDateFormatterFullStyle,
 196                                                   kCFDateFormatterFullStyle);
 197         if (df != NULL) {
 198             CFArrayRef cfmonths = CFDateFormatterCopyProperty(df, kCFDateFormatterMonthSymbols);
 199             if (cfmonths != NULL) {
 200                 copyArrayElements(env, cfmonths, months, 0, 0, CFArrayGetCount(cfmonths));
 201                 CFRelease(cfmonths);
 202             }
 203             CFRelease(df);
 204         }
 205         CFRelease(cflocale);
 206     }
 207 
 208     return months;
 209 }
 210 
 211 /*
 212  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 213  * Method:    getShortMonths
 214  * Signature: (Ljava/lang/String;[Ljava/lang/String;)[Ljava/lang/String;
 215  */
 216 JNIEXPORT jobjectArray JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getShortMonths
 217   (JNIEnv *env, jclass cls, jstring jlangtag, jobjectArray smonths) {
 218     CFLocaleRef cflocale = CFLocaleCopyCurrent();
 219     if (cflocale != NULL) {
 220         CFDateFormatterRef df = CFDateFormatterCreate(kCFAllocatorDefault,
 221                                                   cflocale,
 222                                                   kCFDateFormatterFullStyle,
 223                                                   kCFDateFormatterFullStyle);
 224         if (df != NULL) {
 225             CFArrayRef cfsmonths = CFDateFormatterCopyProperty(df, kCFDateFormatterShortMonthSymbols);
 226             if (cfsmonths != NULL) {
 227                 copyArrayElements(env, cfsmonths, smonths, 0, 0, CFArrayGetCount(cfsmonths));
 228                 CFRelease(cfsmonths);
 229             }
 230             CFRelease(df);
 231         }
 232         CFRelease(cflocale);
 233     }
 234 
 235     return smonths;
 236 }
 237 
 238 /*
 239  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 240  * Method:    getWeekdays
 241  * Signature: (Ljava/lang/String;[Ljava/lang/String;)[Ljava/lang/String;
 242  */
 243 JNIEXPORT jobjectArray JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getWeekdays
 244   (JNIEnv *env, jclass cls, jstring jlangtag, jobjectArray wdays) {
 245     CFLocaleRef cflocale = CFLocaleCopyCurrent();
 246     if (cflocale != NULL) {
 247         CFDateFormatterRef df = CFDateFormatterCreate(kCFAllocatorDefault,
 248                                                   cflocale,
 249                                                   kCFDateFormatterFullStyle,
 250                                                   kCFDateFormatterFullStyle);
 251         if (df != NULL) {
 252             CFArrayRef cfwdays = CFDateFormatterCopyProperty(df, kCFDateFormatterWeekdaySymbols);
 253             if (cfwdays != NULL) {
 254                 copyArrayElements(env, cfwdays, wdays, 0, 1, CFArrayGetCount(cfwdays));
 255                 CFRelease(cfwdays);
 256             }
 257             CFRelease(df);
 258         }
 259         CFRelease(cflocale);
 260     }
 261 
 262     return wdays;
 263 }
 264 
 265 /*
 266  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 267  * Method:    getShortWeekdays
 268  * Signature: (Ljava/lang/String;[Ljava/lang/String;)[Ljava/lang/String;
 269  */
 270 JNIEXPORT jobjectArray JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getShortWeekdays
 271   (JNIEnv *env, jclass cls, jstring jlangtag, jobjectArray swdays) {
 272     CFLocaleRef cflocale = CFLocaleCopyCurrent();
 273     if (cflocale != NULL) {
 274         CFDateFormatterRef df = CFDateFormatterCreate(kCFAllocatorDefault,
 275                                                   cflocale,
 276                                                   kCFDateFormatterFullStyle,
 277                                                   kCFDateFormatterFullStyle);
 278         if (df != NULL) {
 279             CFArrayRef cfswdays = CFDateFormatterCopyProperty(df, kCFDateFormatterShortWeekdaySymbols);
 280             if (cfswdays != NULL) {
 281                 copyArrayElements(env, cfswdays, swdays, 0, 1, CFArrayGetCount(cfswdays));
 282                 CFRelease(cfswdays);
 283             }
 284             CFRelease(df);
 285         }
 286         CFRelease(cflocale);
 287     }
 288 
 289     return swdays;
 290 }
 291 
 292 /*
 293  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 294  * Method:    getNumberPatternNative
 295  * Signature: (ILjava/lang/String;)Ljava/lang/String;
 296  */
 297 JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getNumberPatternNative
 298   (JNIEnv *env, jclass cls, jint numberStyle, jstring jlangtag) {
 299     jstring ret = NULL;
 300     CFLocaleRef cflocale = CFLocaleCopyCurrent();
 301     if (cflocale != NULL) {
 302         CFNumberFormatterRef nf = CFNumberFormatterCreate(kCFAllocatorDefault,
 303                                                   cflocale,
 304                                                   convertNumberFormatterStyle(numberStyle));
 305         if (nf != NULL) {
 306             char buf[BUFLEN];
 307             CFStringRef formatStr = CFNumberFormatterGetFormat(nf);
 308             CFStringGetCString(formatStr, buf, BUFLEN, kCFStringEncodingUTF8);
 309             ret = (*env)->NewStringUTF(env, buf);
 310             CFRelease(nf);
 311         }
 312         CFRelease(cflocale);
 313     }
 314 
 315     return ret;
 316 }
 317 
 318 /*
 319  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 320  * Method:    getCurrencySymbol
 321  * Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
 322  */
 323 JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getCurrencySymbol
 324   (JNIEnv *env, jclass cls, jstring jlangtag, jstring currencySymbol) {
 325     return getNumberSymbolString(env, currencySymbol, kCFNumberFormatterCurrencySymbol);
 326 }
 327 
 328 /*
 329  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 330  * Method:    getDecimalSeparator
 331  * Signature: (Ljava/lang/String;C)C
 332  */
 333 JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getDecimalSeparator
 334   (JNIEnv *env, jclass cls, jstring jlangtag, jchar decimalSeparator) {
 335     return getNumberSymbolChar(decimalSeparator, kCFNumberFormatterDecimalSeparator);
 336 }
 337 
 338 /*
 339  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 340  * Method:    getGroupingSeparator
 341  * Signature: (Ljava/lang/String;C)C
 342  */
 343 JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getGroupingSeparator
 344   (JNIEnv *env, jclass cls, jstring jlangtag, jchar groupingSeparator) {
 345     return getNumberSymbolChar(groupingSeparator, kCFNumberFormatterGroupingSeparator);
 346 }
 347 
 348 /*
 349  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 350  * Method:    getInfinity
 351  * Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
 352  */
 353 JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getInfinity
 354   (JNIEnv *env, jclass cls, jstring jlangtag, jstring infinity) {
 355     return getNumberSymbolString(env, infinity, kCFNumberFormatterInfinitySymbol);
 356 }
 357 
 358 /*
 359  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 360  * Method:    getInternationalCurrencySymbol
 361  * Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
 362  */
 363 JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getInternationalCurrencySymbol
 364   (JNIEnv *env, jclass cls, jstring jlangtag, jstring internationalCurrencySymbol) {
 365     return getNumberSymbolString(env, internationalCurrencySymbol, kCFNumberFormatterInternationalCurrencySymbol);
 366 }
 367 
 368 /*
 369  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 370  * Method:    getMinusSign
 371  * Signature: (Ljava/lang/String;C)C
 372  */
 373 JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getMinusSign
 374   (JNIEnv *env, jclass cls, jstring jlangtag, jchar minusSign) {
 375     return getNumberSymbolChar(minusSign, kCFNumberFormatterMinusSign);
 376 }
 377 
 378 /*
 379  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 380  * Method:    getMonetaryDecimalSeparator
 381  * Signature: (Ljava/lang/String;C)C
 382  */
 383 JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getMonetaryDecimalSeparator
 384   (JNIEnv *env, jclass cls, jstring jlangtag, jchar monetaryDecimalSeparator) {
 385     return getNumberSymbolChar(monetaryDecimalSeparator, kCFNumberFormatterCurrencyDecimalSeparator);
 386 }
 387 
 388 /*
 389  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 390  * Method:    getNaN
 391  * Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
 392  */
 393 JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getNaN
 394   (JNIEnv *env, jclass cls, jstring jlangtag, jstring nan) {
 395     return getNumberSymbolString(env, nan, kCFNumberFormatterNaNSymbol);
 396 }
 397 
 398 /*
 399  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 400  * Method:    getPercent
 401  * Signature: (Ljava/lang/String;C)C
 402  */
 403 JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getPercent
 404   (JNIEnv *env, jclass cls, jstring jlangtag, jchar percent) {
 405     return getNumberSymbolChar(percent, kCFNumberFormatterPercentSymbol);
 406 }
 407 
 408 /*
 409  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 410  * Method:    getPerMill
 411  * Signature: (Ljava/lang/String;C)C
 412  */
 413 JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getPerMill
 414   (JNIEnv *env, jclass cls, jstring jlangtag, jchar perMill) {
 415     return getNumberSymbolChar(perMill, kCFNumberFormatterPerMillSymbol);
 416 }
 417 
 418 /*
 419  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 420  * Method:    getZeroDigit
 421  * Signature: (Ljava/lang/String;C)C
 422  */
 423 JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getZeroDigit
 424   (JNIEnv *env, jclass cls, jstring jlangtag, jchar zeroDigit) {
 425     return getNumberSymbolChar(zeroDigit, kCFNumberFormatterZeroSymbol);





























 426 }
 427 
 428 /*
 429  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 430  * Method:    getExponentSeparator
 431  * Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
 432  */
 433 JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getExponentSeparator
 434   (JNIEnv *env, jclass cls, jstring jlangtag, jstring exponent) {
 435     return getNumberSymbolString(env, exponent, kCFNumberFormatterExponentSymbol);
 436 }
 437 
 438 /*
 439  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 440  * Method:    getCalendarInt
 441  * Signature: (Ljava/lang/String;I)I
 442  */
 443 JNIEXPORT jint JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getCalendarInt
 444   (JNIEnv *env, jclass cls, jstring jlangtag, jint type) {
 445     jint ret = 0;
 446     CFCalendarRef cfcal = CFCalendarCopyCurrent();
 447 
 448     if (cfcal != NULL) {
 449         switch (type) {
 450             case sun_util_locale_provider_HostLocaleProviderAdapterImpl_CD_FIRSTDAYOFWEEK:
 451                 ret = CFCalendarGetFirstWeekday(cfcal);
 452                 break;
 453             case sun_util_locale_provider_HostLocaleProviderAdapterImpl_CD_MINIMALDAYSINFIRSTWEEK:
 454                 ret = CFCalendarGetMinimumDaysInFirstWeek(cfcal);
 455                 break;


 608         case sun_util_locale_provider_HostLocaleProviderAdapterImpl_NF_INTEGER:
 609             return kCFNumberFormatterDecimalStyle;
 610         case sun_util_locale_provider_HostLocaleProviderAdapterImpl_NF_NUMBER:
 611             return kCFNumberFormatterDecimalStyle;
 612         case sun_util_locale_provider_HostLocaleProviderAdapterImpl_NF_PERCENT:
 613             return kCFNumberFormatterPercentStyle;
 614         default:
 615             return kCFNumberFormatterNoStyle;
 616     }
 617 }
 618 
 619 static void copyArrayElements(JNIEnv *env, CFArrayRef cfarray, jobjectArray jarray, CFIndex sindex, int dindex, int count) {
 620     char buf[BUFLEN];
 621 
 622     for (; count > 0; sindex++, dindex++, count--) {
 623         CFStringGetCString(CFArrayGetValueAtIndex(cfarray, sindex), buf, BUFLEN, kCFStringEncodingUTF8);
 624         (*env)->SetObjectArrayElement(env, jarray, dindex, (*env)->NewStringUTF(env, buf));
 625     }
 626 }
 627 
 628 static jstring getNumberSymbolString(JNIEnv *env, jstring jdefault, CFStringRef type) {
 629     char buf[BUFLEN];
 630     jstring ret = jdefault;
 631     CFLocaleRef cflocale = CFLocaleCopyCurrent();
 632 
 633     if (cflocale != NULL) {
 634         CFNumberFormatterRef nf = CFNumberFormatterCreate(kCFAllocatorDefault,
 635                                                   cflocale,
 636                                                   kCFNumberFormatterDecimalStyle);
 637         if (nf != NULL) {
 638             CFStringRef str = CFNumberFormatterCopyProperty(nf, type);
 639             if (str != NULL) {
 640                 CFStringGetCString(str, buf, BUFLEN, kCFStringEncodingUTF8);
 641                 CFRelease(str);
 642                 ret = (*env)->NewStringUTF(env, buf);
 643             }
 644 
 645             CFRelease(nf);
 646         }
 647 
 648         CFRelease(cflocale);
 649     }
 650 
 651     return ret;
 652 }
 653 
 654 static jchar getNumberSymbolChar(jchar jdefault, CFStringRef type) {
 655     char buf[BUFLEN];
 656     jchar ret = jdefault;
 657     CFLocaleRef cflocale = CFLocaleCopyCurrent();
 658 
 659     if (cflocale != NULL) {
 660         CFNumberFormatterRef nf = CFNumberFormatterCreate(kCFAllocatorDefault,
 661                                                   cflocale,
 662                                                   kCFNumberFormatterDecimalStyle);
 663         if (nf != NULL) {
 664             CFStringRef str = CFNumberFormatterCopyProperty(nf, type);
 665             if (str != NULL) {
 666                 CFStringGetCString(str, buf, BUFLEN, kCFStringEncodingUTF8);
 667                 CFRelease(str);
 668                 ret = buf[0];
 669             }
 670 
 671             CFRelease(nf);
 672         }
 673 
 674         CFRelease(cflocale);
 675     }
 676 



















 677     return ret;
 678 }


  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include "sun_util_locale_provider_HostLocaleProviderAdapterImpl.h"
  27 #include <CoreFoundation/CoreFoundation.h>
  28 #include <stdio.h>
  29 
  30 #define BUFLEN 256
  31 
  32 static CFDateFormatterStyle convertDateFormatterStyle(jint javaStyle);
  33 static CFNumberFormatterStyle convertNumberFormatterStyle(jint javaStyle);
  34 static void copyArrayElements(JNIEnv *env, CFArrayRef cfarray, jobjectArray jarray, CFIndex sindex, int dindex, int count);
  35 static jstring getNumberSymbolString(JNIEnv *env, jstring jlangtag, jstring jdefault, CFStringRef type);
  36 static jchar getNumberSymbolChar(JNIEnv *env, jstring jlangtag, jchar jdefault, CFStringRef type);
  37 static CFLocaleRef createCFLocale(JNIEnv *env, jstring jlangtag);
  38 
  39 // from java_props_macosx.c
  40 extern char * getMacOSXLocale(int cat);
  41 extern char * getPosixLocale(int cat);
  42 
  43 /*
  44  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
  45  * Method:    getDefaultLocale
  46  * Signature: (I)Ljava/lang/String;
  47  */
  48 JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getDefaultLocale
  49   (JNIEnv *env, jclass cls, jint cat) {
  50     char * localeString = NULL;
  51     int posixCat;
  52     jstring ret = NULL;
  53 
  54     switch (cat) {
  55         case sun_util_locale_provider_HostLocaleProviderAdapterImpl_CAT_DISPLAY:
  56             posixCat = LC_MESSAGES;
  57             break;


  62     }
  63 
  64     localeString = getMacOSXLocale(posixCat);
  65     if (localeString == NULL) {
  66         localeString = getPosixLocale(posixCat);
  67     }
  68     ret = (*env)->NewStringUTF(env, localeString);
  69     free(localeString);
  70 
  71     return ret;
  72 }
  73 
  74 /*
  75  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
  76  * Method:    getDateTimePatternNative
  77  * Signature: (IILjava/lang/String;)Ljava/lang/String;
  78  */
  79 JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getDateTimePatternNative
  80   (JNIEnv *env, jclass cls, jint dateStyle, jint timeStyle, jstring jlangtag) {
  81     jstring ret = NULL;
  82     CFLocaleRef cflocale = createCFLocale(env, jlangtag);
  83 
  84     if (cflocale != NULL) {
  85         CFDateFormatterRef df = CFDateFormatterCreate(kCFAllocatorDefault,
  86                                                   cflocale,
  87                                                   convertDateFormatterStyle(dateStyle),
  88                                                   convertDateFormatterStyle(timeStyle));
  89         if (df != NULL) {
  90             char buf[BUFLEN];
  91             CFStringRef formatStr = CFDateFormatterGetFormat(df);
  92             CFStringGetCString(formatStr, buf, BUFLEN, kCFStringEncodingUTF8);
  93             ret = (*env)->NewStringUTF(env, buf);
  94             CFRelease(df);
  95         }
  96         CFRelease(cflocale);
  97     }
  98 
  99     return ret;
 100 }
 101 
 102 /*
 103  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 104  * Method:    getCalendarID
 105  * Signature: (Ljava/lang/String;)Ljava/lang/String;
 106  */
 107 JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getCalendarID
 108   (JNIEnv *env, jclass cls, jstring jlangtag) {
 109     jstring ret = NULL;
 110     CFLocaleRef cflocale = createCFLocale(env, jlangtag);
 111 
 112     if (cflocale != NULL) {
 113         char buf[BUFLEN];
 114         CFTypeRef calid = CFLocaleGetValue(cflocale, kCFLocaleCalendarIdentifier);
 115         CFStringGetCString((CFStringRef)calid, buf, BUFLEN, kCFStringEncodingUTF8);
 116         ret = (*env)->NewStringUTF(env, buf);
 117         CFRelease(cflocale);
 118     }
 119 
 120     return ret;
 121 }
 122 
 123 /*
 124  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 125  * Method:    getAmPmStrings
 126  * Signature: (Ljava/lang/String;[Ljava/lang/String;)[Ljava/lang/String;
 127  */
 128 JNIEXPORT jobjectArray JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getAmPmStrings
 129   (JNIEnv *env, jclass cls, jstring jlangtag, jobjectArray ampms) {
 130     CFLocaleRef cflocale = createCFLocale(env, jlangtag);
 131     if (cflocale != NULL) {
 132         CFDateFormatterRef df = CFDateFormatterCreate(kCFAllocatorDefault,
 133                                                   cflocale,
 134                                                   kCFDateFormatterFullStyle,
 135                                                   kCFDateFormatterFullStyle);
 136         if (df != NULL) {
 137             char buf[BUFLEN];
 138             CFStringRef amStr = CFDateFormatterCopyProperty(df, kCFDateFormatterAMSymbol);
 139             if (amStr != NULL) {
 140                 CFStringGetCString(amStr, buf, BUFLEN, kCFStringEncodingUTF8);
 141                 CFRelease(amStr);
 142                 (*env)->SetObjectArrayElement(env, ampms, 0, (*env)->NewStringUTF(env, buf));
 143             }
 144             CFStringRef pmStr = CFDateFormatterCopyProperty(df, kCFDateFormatterPMSymbol);
 145             if (pmStr != NULL) {
 146                 CFStringGetCString(pmStr, buf, BUFLEN, kCFStringEncodingUTF8);
 147                 CFRelease(pmStr);
 148                 (*env)->SetObjectArrayElement(env, ampms, 1, (*env)->NewStringUTF(env, buf));
 149             }
 150             CFRelease(df);
 151         }
 152         CFRelease(cflocale);
 153     }
 154 
 155     return ampms;
 156 }
 157 
 158 /*
 159  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 160  * Method:    getEras
 161  * Signature: (Ljava/lang/String;[Ljava/lang/String;)[Ljava/lang/String;
 162  */
 163 JNIEXPORT jobjectArray JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getEras
 164   (JNIEnv *env, jclass cls, jstring jlangtag, jobjectArray eras) {
 165     CFLocaleRef cflocale = createCFLocale(env, jlangtag);
 166     if (cflocale != NULL) {
 167         CFDateFormatterRef df = CFDateFormatterCreate(kCFAllocatorDefault,
 168                                                   cflocale,
 169                                                   kCFDateFormatterFullStyle,
 170                                                   kCFDateFormatterFullStyle);
 171         if (df != NULL) {
 172             CFArrayRef cferas = CFDateFormatterCopyProperty(df, kCFDateFormatterEraSymbols);
 173             if (cferas != NULL) {
 174                 copyArrayElements(env, cferas, eras, 0, 0, CFArrayGetCount(cferas));
 175                 CFRelease(cferas);
 176             }
 177             CFRelease(df);
 178         }
 179         CFRelease(cflocale);
 180     }
 181 
 182     return eras;
 183 }
 184 
 185 /*
 186  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 187  * Method:    getMonths
 188  * Signature: (Ljava/lang/String;[Ljava/lang/String;)[Ljava/lang/String;
 189  */
 190 JNIEXPORT jobjectArray JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getMonths
 191   (JNIEnv *env, jclass cls, jstring jlangtag, jobjectArray months) {
 192     CFLocaleRef cflocale = createCFLocale(env, jlangtag);
 193     if (cflocale != NULL) {
 194         CFDateFormatterRef df = CFDateFormatterCreate(kCFAllocatorDefault,
 195                                                   cflocale,
 196                                                   kCFDateFormatterFullStyle,
 197                                                   kCFDateFormatterFullStyle);
 198         if (df != NULL) {
 199             CFArrayRef cfmonths = CFDateFormatterCopyProperty(df, kCFDateFormatterMonthSymbols);
 200             if (cfmonths != NULL) {
 201                 copyArrayElements(env, cfmonths, months, 0, 0, CFArrayGetCount(cfmonths));
 202                 CFRelease(cfmonths);
 203             }
 204             CFRelease(df);
 205         }
 206         CFRelease(cflocale);
 207     }
 208 
 209     return months;
 210 }
 211 
 212 /*
 213  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 214  * Method:    getShortMonths
 215  * Signature: (Ljava/lang/String;[Ljava/lang/String;)[Ljava/lang/String;
 216  */
 217 JNIEXPORT jobjectArray JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getShortMonths
 218   (JNIEnv *env, jclass cls, jstring jlangtag, jobjectArray smonths) {
 219     CFLocaleRef cflocale = createCFLocale(env, jlangtag);
 220     if (cflocale != NULL) {
 221         CFDateFormatterRef df = CFDateFormatterCreate(kCFAllocatorDefault,
 222                                                   cflocale,
 223                                                   kCFDateFormatterFullStyle,
 224                                                   kCFDateFormatterFullStyle);
 225         if (df != NULL) {
 226             CFArrayRef cfsmonths = CFDateFormatterCopyProperty(df, kCFDateFormatterShortMonthSymbols);
 227             if (cfsmonths != NULL) {
 228                 copyArrayElements(env, cfsmonths, smonths, 0, 0, CFArrayGetCount(cfsmonths));
 229                 CFRelease(cfsmonths);
 230             }
 231             CFRelease(df);
 232         }
 233         CFRelease(cflocale);
 234     }
 235 
 236     return smonths;
 237 }
 238 
 239 /*
 240  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 241  * Method:    getWeekdays
 242  * Signature: (Ljava/lang/String;[Ljava/lang/String;)[Ljava/lang/String;
 243  */
 244 JNIEXPORT jobjectArray JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getWeekdays
 245   (JNIEnv *env, jclass cls, jstring jlangtag, jobjectArray wdays) {
 246     CFLocaleRef cflocale = createCFLocale(env, jlangtag);
 247     if (cflocale != NULL) {
 248         CFDateFormatterRef df = CFDateFormatterCreate(kCFAllocatorDefault,
 249                                                   cflocale,
 250                                                   kCFDateFormatterFullStyle,
 251                                                   kCFDateFormatterFullStyle);
 252         if (df != NULL) {
 253             CFArrayRef cfwdays = CFDateFormatterCopyProperty(df, kCFDateFormatterWeekdaySymbols);
 254             if (cfwdays != NULL) {
 255                 copyArrayElements(env, cfwdays, wdays, 0, 1, CFArrayGetCount(cfwdays));
 256                 CFRelease(cfwdays);
 257             }
 258             CFRelease(df);
 259         }
 260         CFRelease(cflocale);
 261     }
 262 
 263     return wdays;
 264 }
 265 
 266 /*
 267  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 268  * Method:    getShortWeekdays
 269  * Signature: (Ljava/lang/String;[Ljava/lang/String;)[Ljava/lang/String;
 270  */
 271 JNIEXPORT jobjectArray JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getShortWeekdays
 272   (JNIEnv *env, jclass cls, jstring jlangtag, jobjectArray swdays) {
 273     CFLocaleRef cflocale = createCFLocale(env, jlangtag);
 274     if (cflocale != NULL) {
 275         CFDateFormatterRef df = CFDateFormatterCreate(kCFAllocatorDefault,
 276                                                   cflocale,
 277                                                   kCFDateFormatterFullStyle,
 278                                                   kCFDateFormatterFullStyle);
 279         if (df != NULL) {
 280             CFArrayRef cfswdays = CFDateFormatterCopyProperty(df, kCFDateFormatterShortWeekdaySymbols);
 281             if (cfswdays != NULL) {
 282                 copyArrayElements(env, cfswdays, swdays, 0, 1, CFArrayGetCount(cfswdays));
 283                 CFRelease(cfswdays);
 284             }
 285             CFRelease(df);
 286         }
 287         CFRelease(cflocale);
 288     }
 289 
 290     return swdays;
 291 }
 292 
 293 /*
 294  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 295  * Method:    getNumberPatternNative
 296  * Signature: (ILjava/lang/String;)Ljava/lang/String;
 297  */
 298 JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getNumberPatternNative
 299   (JNIEnv *env, jclass cls, jint numberStyle, jstring jlangtag) {
 300     jstring ret = NULL;
 301     CFLocaleRef cflocale = createCFLocale(env, jlangtag);
 302     if (cflocale != NULL) {
 303         CFNumberFormatterRef nf = CFNumberFormatterCreate(kCFAllocatorDefault,
 304                                                   cflocale,
 305                                                   convertNumberFormatterStyle(numberStyle));
 306         if (nf != NULL) {
 307             char buf[BUFLEN];
 308             CFStringRef formatStr = CFNumberFormatterGetFormat(nf);
 309             CFStringGetCString(formatStr, buf, BUFLEN, kCFStringEncodingUTF8);
 310             ret = (*env)->NewStringUTF(env, buf);
 311             CFRelease(nf);
 312         }
 313         CFRelease(cflocale);
 314     }
 315 
 316     return ret;
 317 }
 318 
 319 /*
 320  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 321  * Method:    getCurrencySymbol
 322  * Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
 323  */
 324 JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getCurrencySymbol
 325   (JNIEnv *env, jclass cls, jstring jlangtag, jstring currencySymbol) {
 326     return getNumberSymbolString(env, jlangtag, currencySymbol, kCFNumberFormatterCurrencySymbol);
 327 }
 328 
 329 /*
 330  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 331  * Method:    getDecimalSeparator
 332  * Signature: (Ljava/lang/String;C)C
 333  */
 334 JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getDecimalSeparator
 335   (JNIEnv *env, jclass cls, jstring jlangtag, jchar decimalSeparator) {
 336     return getNumberSymbolChar(env, jlangtag, decimalSeparator, kCFNumberFormatterDecimalSeparator);
 337 }
 338 
 339 /*
 340  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 341  * Method:    getGroupingSeparator
 342  * Signature: (Ljava/lang/String;C)C
 343  */
 344 JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getGroupingSeparator
 345   (JNIEnv *env, jclass cls, jstring jlangtag, jchar groupingSeparator) {
 346     return getNumberSymbolChar(env, jlangtag, groupingSeparator, kCFNumberFormatterGroupingSeparator);
 347 }
 348 
 349 /*
 350  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 351  * Method:    getInfinity
 352  * Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
 353  */
 354 JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getInfinity
 355   (JNIEnv *env, jclass cls, jstring jlangtag, jstring infinity) {
 356     return getNumberSymbolString(env, jlangtag, infinity, kCFNumberFormatterInfinitySymbol);
 357 }
 358 
 359 /*
 360  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 361  * Method:    getInternationalCurrencySymbol
 362  * Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
 363  */
 364 JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getInternationalCurrencySymbol
 365   (JNIEnv *env, jclass cls, jstring jlangtag, jstring internationalCurrencySymbol) {
 366     return getNumberSymbolString(env, jlangtag, internationalCurrencySymbol, kCFNumberFormatterInternationalCurrencySymbol);
 367 }
 368 
 369 /*
 370  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 371  * Method:    getMinusSign
 372  * Signature: (Ljava/lang/String;C)C
 373  */
 374 JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getMinusSign
 375   (JNIEnv *env, jclass cls, jstring jlangtag, jchar minusSign) {
 376     return getNumberSymbolChar(env, jlangtag, minusSign, kCFNumberFormatterMinusSign);
 377 }
 378 
 379 /*
 380  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 381  * Method:    getMonetaryDecimalSeparator
 382  * Signature: (Ljava/lang/String;C)C
 383  */
 384 JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getMonetaryDecimalSeparator
 385   (JNIEnv *env, jclass cls, jstring jlangtag, jchar monetaryDecimalSeparator) {
 386     return getNumberSymbolChar(env, jlangtag, monetaryDecimalSeparator, kCFNumberFormatterCurrencyDecimalSeparator);
 387 }
 388 
 389 /*
 390  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 391  * Method:    getNaN
 392  * Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
 393  */
 394 JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getNaN
 395   (JNIEnv *env, jclass cls, jstring jlangtag, jstring nan) {
 396     return getNumberSymbolString(env, jlangtag, nan, kCFNumberFormatterNaNSymbol);
 397 }
 398 
 399 /*
 400  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 401  * Method:    getPercent
 402  * Signature: (Ljava/lang/String;C)C
 403  */
 404 JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getPercent
 405   (JNIEnv *env, jclass cls, jstring jlangtag, jchar percent) {
 406     return getNumberSymbolChar(env, jlangtag, percent, kCFNumberFormatterPercentSymbol);
 407 }
 408 
 409 /*
 410  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 411  * Method:    getPerMill
 412  * Signature: (Ljava/lang/String;C)C
 413  */
 414 JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getPerMill
 415   (JNIEnv *env, jclass cls, jstring jlangtag, jchar perMill) {
 416     return getNumberSymbolChar(env, jlangtag, perMill, kCFNumberFormatterPerMillSymbol);
 417 }
 418 
 419 /*
 420  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 421  * Method:    getZeroDigit
 422  * Signature: (Ljava/lang/String;C)C
 423  */
 424 JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getZeroDigit
 425   (JNIEnv *env, jclass cls, jstring jlangtag, jchar zeroDigit) {
 426     // The following code *should* work, but not for some reason :o
 427     //
 428     //return getNumberSymbolChar(env, jlangtag, zeroDigit, kCFNumberFormatterZeroSymbol);
 429     //
 430     // so here is a workaround.
 431     jchar buf[BUFLEN];
 432     jchar ret = zeroDigit;
 433     CFLocaleRef cflocale = createCFLocale(env, jlangtag);
 434 
 435     if (cflocale != NULL) {
 436         CFNumberFormatterRef nf = CFNumberFormatterCreate(kCFAllocatorDefault,
 437                                                   cflocale,
 438                                                   kCFNumberFormatterNoStyle);
 439         if (nf != NULL) {
 440             int zero = 0;
 441             CFStringRef str = CFNumberFormatterCreateStringWithValue(kCFAllocatorDefault,
 442                               nf, kCFNumberIntType, &zero);
 443             if (str != NULL) {
 444                 CFStringGetCString(str, (char*)buf, sizeof(jchar)*BUFLEN, kCFStringEncodingUTF16);
 445                 CFRelease(str);
 446                 ret = buf[0];
 447             }
 448 
 449             CFRelease(nf);
 450         }
 451 
 452         CFRelease(cflocale);
 453     }
 454 
 455     return ret;
 456 }
 457 
 458 /*
 459  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 460  * Method:    getExponentSeparator
 461  * Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
 462  */
 463 JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getExponentSeparator
 464   (JNIEnv *env, jclass cls, jstring jlangtag, jstring exponent) {
 465     return getNumberSymbolString(env, jlangtag, exponent, kCFNumberFormatterExponentSymbol);
 466 }
 467 
 468 /*
 469  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
 470  * Method:    getCalendarInt
 471  * Signature: (Ljava/lang/String;I)I
 472  */
 473 JNIEXPORT jint JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getCalendarInt
 474   (JNIEnv *env, jclass cls, jstring jlangtag, jint type) {
 475     jint ret = 0;
 476     CFCalendarRef cfcal = CFCalendarCopyCurrent();
 477 
 478     if (cfcal != NULL) {
 479         switch (type) {
 480             case sun_util_locale_provider_HostLocaleProviderAdapterImpl_CD_FIRSTDAYOFWEEK:
 481                 ret = CFCalendarGetFirstWeekday(cfcal);
 482                 break;
 483             case sun_util_locale_provider_HostLocaleProviderAdapterImpl_CD_MINIMALDAYSINFIRSTWEEK:
 484                 ret = CFCalendarGetMinimumDaysInFirstWeek(cfcal);
 485                 break;


 638         case sun_util_locale_provider_HostLocaleProviderAdapterImpl_NF_INTEGER:
 639             return kCFNumberFormatterDecimalStyle;
 640         case sun_util_locale_provider_HostLocaleProviderAdapterImpl_NF_NUMBER:
 641             return kCFNumberFormatterDecimalStyle;
 642         case sun_util_locale_provider_HostLocaleProviderAdapterImpl_NF_PERCENT:
 643             return kCFNumberFormatterPercentStyle;
 644         default:
 645             return kCFNumberFormatterNoStyle;
 646     }
 647 }
 648 
 649 static void copyArrayElements(JNIEnv *env, CFArrayRef cfarray, jobjectArray jarray, CFIndex sindex, int dindex, int count) {
 650     char buf[BUFLEN];
 651 
 652     for (; count > 0; sindex++, dindex++, count--) {
 653         CFStringGetCString(CFArrayGetValueAtIndex(cfarray, sindex), buf, BUFLEN, kCFStringEncodingUTF8);
 654         (*env)->SetObjectArrayElement(env, jarray, dindex, (*env)->NewStringUTF(env, buf));
 655     }
 656 }
 657 
 658 static jstring getNumberSymbolString(JNIEnv *env, jstring jlangtag, jstring jdefault, CFStringRef type) {
 659     char buf[BUFLEN];
 660     jstring ret = jdefault;
 661     CFLocaleRef cflocale = createCFLocale(env, jlangtag);
 662 
 663     if (cflocale != NULL) {
 664         CFNumberFormatterRef nf = CFNumberFormatterCreate(kCFAllocatorDefault,
 665                                                   cflocale,
 666                                                   kCFNumberFormatterNoStyle);
 667         if (nf != NULL) {
 668             CFStringRef str = CFNumberFormatterCopyProperty(nf, type);
 669             if (str != NULL) {
 670                 CFStringGetCString(str, buf, BUFLEN, kCFStringEncodingUTF8);
 671                 CFRelease(str);
 672                 ret = (*env)->NewStringUTF(env, buf);
 673             }
 674 
 675             CFRelease(nf);
 676         }
 677 
 678         CFRelease(cflocale);
 679     }
 680 
 681     return ret;
 682 }
 683 
 684 static jchar getNumberSymbolChar(JNIEnv *env, jstring jlangtag, jchar jdefault, CFStringRef type) {
 685     jchar buf[BUFLEN];
 686     jchar ret = jdefault;
 687     CFLocaleRef cflocale = createCFLocale(env, jlangtag);
 688 
 689     if (cflocale != NULL) {
 690         CFNumberFormatterRef nf = CFNumberFormatterCreate(kCFAllocatorDefault,
 691                                                   cflocale,
 692                                                   kCFNumberFormatterNoStyle);
 693         if (nf != NULL) {
 694             CFStringRef str = CFNumberFormatterCopyProperty(nf, type);
 695             if (str != NULL) {
 696                 CFStringGetCString(str, (char*)buf, sizeof(jchar)*BUFLEN, kCFStringEncodingUTF16);
 697                 CFRelease(str);
 698                 ret = buf[0];
 699             }
 700 
 701             CFRelease(nf);
 702         }
 703 
 704         CFRelease(cflocale);
 705     }
 706 
 707     return ret;
 708 }
 709 
 710 static CFLocaleRef createCFLocale(JNIEnv *env, jstring jlangtag) {
 711     CFLocaleRef ret = NULL;
 712     const char *clangtag = (*env)->GetStringUTFChars(env, jlangtag, 0);
 713 
 714     if (clangtag != NULL) {
 715         CFStringRef localeID = CFStringCreateWithCString(kCFAllocatorDefault,
 716                                    clangtag,
 717                                    CFStringGetSystemEncoding());
 718         if (localeID != NULL) {
 719             ret = CFLocaleCreate(kCFAllocatorDefault, localeID);
 720             CFRelease(localeID);
 721         }
 722 
 723         (*env)->ReleaseStringUTFChars(env, jlangtag, clangtag);
 724     }
 725 
 726     return ret;
 727 }