001: /*
002: *******************************************************************************
003: * Copyright (C) 2004-2005, International Business Machines Corporation and *
004: * others. All Rights Reserved. *
005: *******************************************************************************
006: */
007:
008: package com.ibm.icu.impl;
009:
010: import java.util.MissingResourceException;
011:
012: import com.ibm.icu.util.ULocale;
013: import com.ibm.icu.util.UResourceBundle;
014:
015: /**
016: * This class abstracts access to calendar (Calendar and DateFormat) data.
017: * @internal ICU 3.0
018: */
019: public class CalendarData {
020: /**
021: * Construct a CalendarData from the given locale.
022: * @param loc locale to use. The 'calendar' keyword will be ignored.
023: * @param type calendar type. NULL indicates the gregorian calendar.
024: * No default lookup is done.
025: */
026: public CalendarData(ULocale loc, String type) {
027: this ((ICUResourceBundle) UResourceBundle.getBundleInstance(
028: ICUResourceBundle.ICU_BASE_NAME, loc), type);
029: }
030:
031: public CalendarData(ICUResourceBundle b, String type) {
032: fBundle = b;
033: if ((type == null) || (type.equals(""))
034: || (type.equals("gregorian"))) {
035: fMainType = "gregorian";
036: fFallbackType = null;
037: } else {
038: fMainType = type;
039: fFallbackType = "gregorian";
040: }
041: }
042:
043: /**
044: * Load data for calendar. Note, this object owns the resources, do NOT call ures_close()!
045: *
046: * @param key Resource key to data
047: * @internal
048: */
049: public ICUResourceBundle get(String key) {
050: try {
051: return fBundle.getWithFallback("calendar/" + fMainType
052: + "/" + key);
053: } catch (MissingResourceException m) {
054: if (fFallbackType != null) {
055: return fBundle.getWithFallback("calendar/"
056: + fFallbackType + "/" + key);
057: }
058: throw m;
059:
060: }
061: }
062:
063: /**
064: * Load data for calendar. Note, this object owns the resources, do NOT call ures_close()!
065: * There is an implicit key of 'format'
066: * data is located in: "calendar/key/format/subKey"
067: * for example, calendar/dayNames/format/abbreviated
068: *
069: * @param key Resource key to data
070: * @param subKey Resource key to data
071: * @internal
072: */
073: public ICUResourceBundle get(String key, String subKey) {
074: try {
075: return fBundle.getWithFallback("calendar/" + fMainType
076: + "/" + key + "/format/" + subKey);
077: } catch (MissingResourceException m) {
078: if (fFallbackType != null) {
079: return fBundle.getWithFallback("calendar/"
080: + fFallbackType + "/" + key + "/format/"
081: + subKey);
082: }
083: throw m;
084:
085: }
086: }
087:
088: /**
089: * Load data for calendar. Note, this object owns the resources, do NOT call ures_close()!
090: * data is located in: "calendar/key/contextKey/subKey"
091: * for example, calendar/dayNames/stand-alone/narrow
092: *
093: * @param key Resource key to data
094: * @param contextKey Resource key to data
095: * @param subKey Resource key to data
096: * @internal
097: */
098: public ICUResourceBundle get(String key, String contextKey,
099: String subKey) {
100: try {
101: return fBundle.getWithFallback("calendar/" + fMainType
102: + "/" + key + "/" + contextKey + "/" + subKey);
103: } catch (MissingResourceException m) {
104: if (fFallbackType != null) {
105: return fBundle.getWithFallback("calendar/"
106: + fFallbackType + "/" + key + "/" + contextKey
107: + "/" + subKey);
108: }
109: throw m;
110:
111: }
112: }
113:
114: public String[] getStringArray(String key) {
115: return get(key).getStringArray();
116: }
117:
118: public String[] getStringArray(String key, String subKey) {
119: return get(key, subKey).getStringArray();
120: }
121:
122: public String[] getStringArray(String key, String contextKey,
123: String subKey) {
124: return get(key, contextKey, subKey).getStringArray();
125: }
126:
127: public String[] getEras(String subkey) {
128: ICUResourceBundle bundle = get("eras/" + subkey);
129: return bundle.getStringArray();
130: }
131:
132: public ULocale getULocale() {
133: return fBundle.getULocale();
134: }
135:
136: private ICUResourceBundle fBundle;
137: private String fMainType;
138: private String fFallbackType;
139: }
|