}
}
- /**
- * Load data for calendar. Note, this object owns the resources, do NOT call ures_close()!
- * There is an implicit key of 'format'
- * data is located in: "calendar/key/format/subKey"
- * for example, calendar/dayNames/format/abbreviated
- *
- * @param key Resource key to data
- * @param subKey Resource key to data
- * @internal
- */
- public ICUResourceBundle get(String key, String subKey) {
- try {
- return fBundle.getWithFallback("calendar/" + fMainType + "/" + key + "/format/" + subKey);
- } catch(MissingResourceException m) {
- if(fFallbackType != null) {
- return fBundle.getWithFallback("calendar/" + fFallbackType + "/" + key + "/format/" + subKey);
- }
- throw m;
-
- }
- }
-
- /**
- * Load data for calendar. Note, this object owns the resources, do NOT call ures_close()!
- * data is located in: "calendar/key/contextKey/subKey"
- * for example, calendar/dayNames/stand-alone/narrow
- *
- * @param key Resource key to data
- * @param contextKey Resource key to data
- * @param subKey Resource key to data
- * @internal
- */
- public ICUResourceBundle get(String key, String contextKey, String subKey) {
- try {
- return fBundle.getWithFallback("calendar/" + fMainType + "/" + key + "/" + contextKey + "/" + subKey);
- } catch(MissingResourceException m) {
- if(fFallbackType != null) {
- return fBundle.getWithFallback("calendar/" + fFallbackType + "/" + key + "/" + contextKey + "/" + subKey);
- }
- throw m;
-
- }
- }
-
public String[] getDateTimePatterns(){
ICUResourceBundle bundle = get("DateTimePatterns");
ArrayList<String> list = new ArrayList<String>();
// DateTimePatterns start at index 9 in the array.
return patterns[9 + offset];
}
-
- public String[] getOverrides(){
- ICUResourceBundle bundle = get("DateTimePatterns");
- ArrayList<String> list = new ArrayList<String>();
- UResourceBundleIterator iter = bundle.getIterator();
- while (iter.hasNext()) {
- UResourceBundle patResource = iter.next();
- int resourceType = patResource.getType();
- switch (resourceType) {
- case UResourceBundle.STRING:
- list.add(null);
- break;
- case UResourceBundle.ARRAY:
- String[] items = patResource.getStringArray();
- list.add(items[1]);
- break;
- }
- }
- return list.toArray(new String[list.size()]);
- }
private ICUResourceBundle fBundle;
private String fMainType;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
import com.ibm.icu.impl.CalendarData;
import com.ibm.icu.impl.ICUCache;
+import com.ibm.icu.impl.ICUData;
+import com.ibm.icu.impl.ICUResourceBundle;
import com.ibm.icu.impl.SimpleCache;
import com.ibm.icu.impl.SimpleFormatterImpl;
import com.ibm.icu.text.DateIntervalInfo.PatternInfo;
import com.ibm.icu.util.TimeZone;
import com.ibm.icu.util.ULocale;
import com.ibm.icu.util.ULocale.Category;
+import com.ibm.icu.util.UResourceBundle;
+import com.ibm.icu.util.UResourceTypeMismatchException;
/**
// move this up here since we need it for fallbacks
if (time.length() != 0 && date.length() != 0) {
- // Need the Date/Time pattern for concatnation the date with
+ // Need the Date/Time pattern for concatenating the date with
// the time interval.
// The date/time pattern ( such as {0} {1} ) is saved in
// calendar, that is why need to get the CalendarData here.
- CalendarData calData = new CalendarData(locale, null);
- String[] patterns = calData.getDateTimePatterns();
- fDateTimeFormat = patterns[8];
+ fDateTimeFormat = getConcatenationPattern(locale);
}
boolean found = genSeparateDateTimePtn(normalizedDateSkeleton,
return intervalPatterns;
}
+ /**
+ * Retrieves the concatenation DateTime pattern from the resource bundle.
+ * @param locale Locale to retrieve.
+ * @return Concatenation DateTime pattern.
+ */
+ private String getConcatenationPattern(ULocale locale) {
+ ICUResourceBundle rb = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, locale);
+ ICUResourceBundle dtPatternsRb = rb.getWithFallback("calendar/gregorian/DateTimePatterns");
+ ICUResourceBundle concatenationPatternRb = (ICUResourceBundle) dtPatternsRb.get(8);
+ if (concatenationPatternRb.getType() == UResourceBundle.STRING) {
+ return concatenationPatternRb.getString();
+ } else {
+ return concatenationPatternRb.getString(0);
+ }
+ }
/*
* Generate fall back interval pattern given a calendar field,
import com.ibm.icu.text.DateFormat;
import com.ibm.icu.text.DateFormatSymbols;
import com.ibm.icu.text.SimpleDateFormat;
+import com.ibm.icu.text.UTF16;
import com.ibm.icu.util.ULocale.Category;
/**
if (patternData == null) {
// Cache missed. Get one from bundle
try {
- CalendarData calData = new CalendarData(loc, calType);
- patternData = new PatternData(calData.getDateTimePatterns(),
- calData.getOverrides());
+ patternData = getPatternData(loc, calType);
} catch (MissingResourceException e) {
patternData = new PatternData(DEFAULT_PATTERNS, null);
}
}
}
+ /**
+ * Retrieves the DateTime patterns and overrides from the resource bundle and generates a
+ * new PatternData object.
+ * @param locale Locale to retrieve.
+ * @param calType Calendar type to retrieve. If not found will fallback to gregorian.
+ * @return PatternData object for this locale and calendarType.
+ */
+ private static PatternData getPatternData(ULocale locale, String calType) {
+ ICUResourceBundle rb =
+ (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, locale);
+ ICUResourceBundle dtPatternsRb = rb.findWithFallback("calendar/" + calType + "/DateTimePatterns");
+ if (dtPatternsRb == null) {
+ dtPatternsRb = rb.getWithFallback("calendar/gregorian/DateTimePatterns");
+ }
+
+ int patternsSize = dtPatternsRb.getSize();
+ String[] dateTimePatterns = new String[patternsSize];
+ String[] dateTimePatternsOverrides = new String[patternsSize];
+ for (int i = 0; i < patternsSize; i++) {
+ ICUResourceBundle concatenationPatternRb = (ICUResourceBundle) dtPatternsRb.get(i);
+ switch (concatenationPatternRb.getType()) {
+ case UResourceBundle.STRING:
+ dateTimePatterns[i] = concatenationPatternRb.getString();
+ break;
+ case UResourceBundle.ARRAY:
+ dateTimePatterns[i] = concatenationPatternRb.getString(0);
+ dateTimePatternsOverrides[i] = concatenationPatternRb.getString(1);
+ break;
+ }
+ }
+ return new PatternData(dateTimePatterns, dateTimePatternsOverrides);
+ }
+
/**
* @internal
* @deprecated This API is ICU internal only.