jdk/src/share/classes/sun/util/locale/provider/CalendarNameProviderImpl.java
changeset 15658 55b829ca2334
parent 15646 b065aeb8e26b
child 16852 60207b2b4b42
--- a/jdk/src/share/classes/sun/util/locale/provider/CalendarNameProviderImpl.java	Tue Feb 12 16:02:14 2013 +0400
+++ b/jdk/src/share/classes/sun/util/locale/provider/CalendarNameProviderImpl.java	Tue Feb 12 09:25:43 2013 -0800
@@ -50,8 +50,16 @@
 
     @Override
     public String getDisplayName(String calendarType, int field, int value, int style, Locale locale) {
+        return getDisplayNameImpl(calendarType, field, value, style, locale, false);
+    }
+
+    public String getCldrDisplayName(String calendarType, int field, int value, int style, Locale locale) {
+        return getDisplayNameImpl(calendarType, field, value, style, locale, true);
+    }
+
+    public String getDisplayNameImpl(String calendarType, int field, int value, int style, Locale locale, boolean cldr) {
         String name = null;
-        String key = getResourceKey(calendarType, field, style);
+        String key = getResourceKey(calendarType, field, style, cldr);
         if (key != null) {
             String[] strings = LocaleProviderAdapter.forType(type).getLocaleResources(locale).getCalendarNames(key);
             if (strings != null && strings.length > 0) {
@@ -79,24 +87,32 @@
         SHORT_STANDALONE, LONG_FORMAT, LONG_STANDALONE,
         NARROW_FORMAT, NARROW_STANDALONE
     };
+
     @Override
     public Map<String, Integer> getDisplayNames(String calendarType, int field, int style, Locale locale) {
         Map<String, Integer> names;
         if (style == ALL_STYLES) {
-            names = getDisplayNamesImpl(calendarType, field, SHORT_FORMAT, locale);
+            names = getDisplayNamesImpl(calendarType, field, SHORT_FORMAT, locale, false);
             for (int st : REST_OF_STYLES) {
-                names.putAll(getDisplayNamesImpl(calendarType, field, st, locale));
+                names.putAll(getDisplayNamesImpl(calendarType, field, st, locale, false));
             }
         } else {
             // specific style
-            names = getDisplayNamesImpl(calendarType, field, style, locale);
+            names = getDisplayNamesImpl(calendarType, field, style, locale, false);
         }
         return names.isEmpty() ? null : names;
     }
 
+    // NOTE: This method should be used ONLY BY JSR 310 classes.
+    public Map<String, Integer> getCldrDisplayNames(String calendarType, int field, int style, Locale locale) {
+        Map<String, Integer> names;
+        names = getDisplayNamesImpl(calendarType, field, style, locale, true);
+        return names.isEmpty() ? null : names;
+    }
+
     private Map<String, Integer> getDisplayNamesImpl(String calendarType, int field,
-                                                     int style, Locale locale) {
-        String key = getResourceKey(calendarType, field, style);
+                                                     int style, Locale locale, boolean cldr) {
+        String key = getResourceKey(calendarType, field, style, cldr);
         Map<String, Integer> map = new TreeMap<>(LengthBasedComparator.INSTANCE);
         if (key != null) {
             String[] strings = LocaleProviderAdapter.forType(type).getLocaleResources(locale).getCalendarNames(key);
@@ -204,7 +220,7 @@
         return false;
     }
 
-    private String getResourceKey(String type, int field, int style) {
+    private String getResourceKey(String type, int field, int style, boolean cldr) {
         int baseStyle = getBaseStyle(style);
         boolean isStandalone = (style != baseStyle);
 
@@ -213,6 +229,10 @@
         }
         boolean isNarrow = (baseStyle == NARROW_FORMAT);
         StringBuilder key = new StringBuilder();
+        // If cldr is true, use prefix "cldr.".
+        if (cldr) {
+            key.append("cldr.");
+        }
         switch (field) {
         case ERA:
             if (type != null) {
@@ -225,6 +245,11 @@
                 // due to historical reasons. (JRE DateFormatSymbols.getEras returns
                 // abbreviations while other getShort*() return abbreviations.)
                 if (this.type == LocaleProviderAdapter.Type.JRE) {
+                    if (cldr) {
+                        if (baseStyle == LONG) {
+                            key.append("long.");
+                        }
+                    }
                     if (baseStyle == SHORT) {
                         key.append("short.");
                     }