2 *******************************************************************************
\r
3 * Copyright (C) 2004-2009, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 *******************************************************************************
\r
7 package com.ibm.icu.impl;
\r
9 import java.util.ArrayList;
\r
10 import java.util.MissingResourceException;
\r
12 import com.ibm.icu.util.ULocale;
\r
13 import com.ibm.icu.util.UResourceBundle;
\r
14 import com.ibm.icu.util.UResourceBundleIterator;
\r
17 * This class abstracts access to calendar (Calendar and DateFormat) data.
\r
20 public class CalendarData {
\r
22 * Construct a CalendarData from the given locale.
\r
23 * @param loc locale to use. The 'calendar' keyword will be ignored.
\r
24 * @param type calendar type. NULL indicates the gregorian calendar.
\r
25 * No default lookup is done.
\r
27 public CalendarData(ULocale loc, String type) {
\r
28 this((ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, loc), type);
\r
31 public CalendarData(ICUResourceBundle b, String type) {
\r
33 if((type == null) || (type.equals("")) || (type.equals("gregorian"))) {
\r
34 fMainType = "gregorian";
\r
35 fFallbackType = null;
\r
38 fFallbackType ="gregorian";
\r
43 * Load data for calendar. Note, this object owns the resources, do NOT call ures_close()!
\r
45 * @param key Resource key to data
\r
48 public ICUResourceBundle get(String key) {
\r
50 return fBundle.getWithFallback("calendar/" + fMainType + "/" + key);
\r
51 } catch(MissingResourceException m) {
\r
52 if(fFallbackType != null) {
\r
53 return fBundle.getWithFallback("calendar/" + fFallbackType + "/" + key);
\r
61 * Load data for calendar. Note, this object owns the resources, do NOT call ures_close()!
\r
62 * There is an implicit key of 'format'
\r
63 * data is located in: "calendar/key/format/subKey"
\r
64 * for example, calendar/dayNames/format/abbreviated
\r
66 * @param key Resource key to data
\r
67 * @param subKey Resource key to data
\r
70 public ICUResourceBundle get(String key, String subKey) {
\r
72 return fBundle.getWithFallback("calendar/" + fMainType + "/" + key + "/format/" + subKey);
\r
73 } catch(MissingResourceException m) {
\r
74 if(fFallbackType != null) {
\r
75 return fBundle.getWithFallback("calendar/" + fFallbackType + "/" + key + "/format/" + subKey);
\r
83 * Load data for calendar. Note, this object owns the resources, do NOT call ures_close()!
\r
84 * data is located in: "calendar/key/contextKey/subKey"
\r
85 * for example, calendar/dayNames/stand-alone/narrow
\r
87 * @param key Resource key to data
\r
88 * @param contextKey Resource key to data
\r
89 * @param subKey Resource key to data
\r
92 public ICUResourceBundle get(String key, String contextKey, String subKey) {
\r
94 return fBundle.getWithFallback("calendar/" + fMainType + "/" + key + "/" + contextKey + "/" + subKey);
\r
95 } catch(MissingResourceException m) {
\r
96 if(fFallbackType != null) {
\r
97 return fBundle.getWithFallback("calendar/" + fFallbackType + "/" + key + "/" + contextKey + "/" + subKey);
\r
104 public String[] getStringArray(String key) {
\r
105 return get(key).getStringArray();
\r
108 public String[] getStringArray(String key, String subKey) {
\r
109 return get(key, subKey).getStringArray();
\r
112 public String[] getStringArray(String key, String contextKey, String subKey) {
\r
113 return get(key, contextKey, subKey).getStringArray();
\r
115 public String[] getEras(String subkey){
\r
116 ICUResourceBundle bundle = get("eras/"+subkey);
\r
117 return bundle.getStringArray();
\r
119 public String[] getDateTimePatterns(){
\r
120 ICUResourceBundle bundle = get("DateTimePatterns");
\r
121 ArrayList<String> list = new ArrayList<String>();
\r
122 UResourceBundleIterator iter = bundle.getIterator();
\r
123 while (iter.hasNext()) {
\r
124 UResourceBundle patResource = iter.next();
\r
125 int resourceType = patResource.getType();
\r
126 switch (resourceType) {
\r
127 case UResourceBundle.STRING:
\r
128 list.add(patResource.getString());
\r
130 case UResourceBundle.ARRAY:
\r
131 String[] items = patResource.getStringArray();
\r
132 list.add(items[0]);
\r
137 return list.toArray(new String[list.size()]);
\r
140 public String[] getOverrides(){
\r
141 ICUResourceBundle bundle = get("DateTimePatterns");
\r
142 ArrayList<String> list = new ArrayList<String>();
\r
143 UResourceBundleIterator iter = bundle.getIterator();
\r
144 while (iter.hasNext()) {
\r
145 UResourceBundle patResource = iter.next();
\r
146 int resourceType = patResource.getType();
\r
147 switch (resourceType) {
\r
148 case UResourceBundle.STRING:
\r
151 case UResourceBundle.ARRAY:
\r
152 String[] items = patResource.getStringArray();
\r
153 list.add(items[1]);
\r
157 return list.toArray(new String[list.size()]);
\r
160 public ULocale getULocale() {
\r
161 return fBundle.getULocale();
\r
164 private ICUResourceBundle fBundle;
\r
165 private String fMainType;
\r
166 private String fFallbackType;
\r