64 |
64 |
65 public static String retrieveFieldValueName(String id, int field, int value, int style, Locale locale) { |
65 public static String retrieveFieldValueName(String id, int field, int value, int style, Locale locale) { |
66 LocaleServiceProviderPool pool = |
66 LocaleServiceProviderPool pool = |
67 LocaleServiceProviderPool.getPool(CalendarNameProvider.class); |
67 LocaleServiceProviderPool.getPool(CalendarNameProvider.class); |
68 return pool.getLocalizedObject(CalendarFieldValueNameGetter.INSTANCE, locale, normalizeCalendarType(id), |
68 return pool.getLocalizedObject(CalendarFieldValueNameGetter.INSTANCE, locale, normalizeCalendarType(id), |
69 field, value, style); |
69 field, value, style, false); |
|
70 } |
|
71 |
|
72 public static String retrieveCldrFieldValueName(String id, int field, int value, int style, Locale locale) { |
|
73 LocaleServiceProviderPool pool = |
|
74 LocaleServiceProviderPool.getPool(CalendarNameProvider.class); |
|
75 String name; |
|
76 name = pool.getLocalizedObject(CalendarFieldValueNameGetter.INSTANCE, locale, normalizeCalendarType(id), |
|
77 field, value, style, true); |
|
78 if (name == null) { |
|
79 name = pool.getLocalizedObject(CalendarFieldValueNameGetter.INSTANCE, locale, normalizeCalendarType(id), |
|
80 field, value, style, false); |
|
81 } |
|
82 return name; |
70 } |
83 } |
71 |
84 |
72 public static Map<String, Integer> retrieveFieldValueNames(String id, int field, int style, Locale locale) { |
85 public static Map<String, Integer> retrieveFieldValueNames(String id, int field, int style, Locale locale) { |
73 LocaleServiceProviderPool pool = |
86 LocaleServiceProviderPool pool = |
74 LocaleServiceProviderPool.getPool(CalendarNameProvider.class); |
87 LocaleServiceProviderPool.getPool(CalendarNameProvider.class); |
75 return pool.getLocalizedObject(CalendarFieldValueNamesMapGetter.INSTANCE, locale, |
88 return pool.getLocalizedObject(CalendarFieldValueNamesMapGetter.INSTANCE, locale, |
76 normalizeCalendarType(id), field, style); |
89 normalizeCalendarType(id), field, style, false); |
77 } |
90 } |
78 |
91 |
79 private static String normalizeCalendarType(String requestID) { |
92 public static Map<String, Integer> retrieveCldrFieldValueNames(String id, int field, int style, Locale locale) { |
|
93 LocaleServiceProviderPool pool = |
|
94 LocaleServiceProviderPool.getPool(CalendarNameProvider.class); |
|
95 Map<String, Integer> map; |
|
96 map = pool.getLocalizedObject(CalendarFieldValueNamesMapGetter.INSTANCE, locale, |
|
97 normalizeCalendarType(id), field, style, true); |
|
98 if (map == null) { |
|
99 map = pool.getLocalizedObject(CalendarFieldValueNamesMapGetter.INSTANCE, locale, |
|
100 normalizeCalendarType(id), field, style, false); |
|
101 } |
|
102 return map; |
|
103 } |
|
104 |
|
105 static String normalizeCalendarType(String requestID) { |
80 String type; |
106 String type; |
81 if (requestID.equals("gregorian") || requestID.equals("iso8601")) { |
107 if (requestID.equals("gregorian") || requestID.equals("iso8601")) { |
82 type = "gregory"; |
108 type = "gregory"; |
83 } else if (requestID.startsWith("islamic")) { |
109 } else if (requestID.startsWith("islamic")) { |
84 type = "islamic"; |
110 type = "islamic"; |
101 @Override |
127 @Override |
102 public String getObject(CalendarNameProvider calendarNameProvider, |
128 public String getObject(CalendarNameProvider calendarNameProvider, |
103 Locale locale, |
129 Locale locale, |
104 String requestID, // calendarType |
130 String requestID, // calendarType |
105 Object... params) { |
131 Object... params) { |
106 assert params.length == 3; |
132 assert params.length == 4; |
107 int field = (int) params[0]; |
133 int field = (int) params[0]; |
108 int value = (int) params[1]; |
134 int value = (int) params[1]; |
109 int style = (int) params[2]; |
135 int style = (int) params[2]; |
|
136 boolean cldr = (boolean) params[3]; |
|
137 |
|
138 // If cldr is true, resources from CLDR have precedence over JRE |
|
139 // native resources. |
|
140 if (cldr && calendarNameProvider instanceof CalendarNameProviderImpl) { |
|
141 String name; |
|
142 name = ((CalendarNameProviderImpl)calendarNameProvider) |
|
143 .getCldrDisplayName(requestID, field, value, style, locale); |
|
144 return name; |
|
145 } |
110 return calendarNameProvider.getDisplayName(requestID, field, value, style, locale); |
146 return calendarNameProvider.getDisplayName(requestID, field, value, style, locale); |
111 } |
147 } |
112 } |
148 } |
113 |
149 |
114 /** |
150 /** |
124 @Override |
160 @Override |
125 public Map<String, Integer> getObject(CalendarNameProvider calendarNameProvider, |
161 public Map<String, Integer> getObject(CalendarNameProvider calendarNameProvider, |
126 Locale locale, |
162 Locale locale, |
127 String requestID, // calendarType |
163 String requestID, // calendarType |
128 Object... params) { |
164 Object... params) { |
129 assert params.length == 2; |
165 assert params.length == 3; |
130 int field = (int) params[0]; |
166 int field = (int) params[0]; |
131 int style = (int) params[1]; |
167 int style = (int) params[1]; |
|
168 boolean cldr = (boolean) params[2]; |
|
169 |
|
170 // If cldr is true, resources from CLDR have precedence over JRE |
|
171 // native resources. |
|
172 if (cldr && calendarNameProvider instanceof CalendarNameProviderImpl) { |
|
173 Map<String, Integer> map; |
|
174 map = ((CalendarNameProviderImpl)calendarNameProvider) |
|
175 .getCldrDisplayNames(requestID, field, style, locale); |
|
176 return map; |
|
177 } |
132 return calendarNameProvider.getDisplayNames(requestID, field, style, locale); |
178 return calendarNameProvider.getDisplayNames(requestID, field, style, locale); |
133 } |
179 } |
134 } |
180 } |
135 |
181 |
136 private static class CalendarWeekParameterGetter |
182 private static class CalendarWeekParameterGetter |