KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibm > icu > impl > CalendarData


1 /*
2  *******************************************************************************
3  * Copyright (C) 2004-2005, International Business Machines Corporation and *
4  * others. All Rights Reserved. *
5  *******************************************************************************
6  */

7
8 package com.ibm.icu.impl;
9
10 import java.util.MissingResourceException JavaDoc;
11
12 import com.ibm.icu.util.ULocale;
13 import com.ibm.icu.util.UResourceBundle;
14
15
16
17 /**
18  * This class abstracts access to calendar (Calendar and DateFormat) data.
19  * @internal ICU 3.0
20  */

21 public class CalendarData {
22     /**
23      * Construct a CalendarData from the given locale.
24      * @param loc locale to use. The 'calendar' keyword will be ignored.
25      * @param type calendar type. NULL indicates the gregorian calendar.
26      * No default lookup is done.
27      */

28     public CalendarData(ULocale loc, String JavaDoc type) {
29         this((ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, loc), type);
30     }
31     
32     public CalendarData(ICUResourceBundle b, String JavaDoc type) {
33         fBundle = b;
34         if((type == null) || (type.equals("")) || (type.equals("gregorian"))) {
35             fMainType = "gregorian";
36             fFallbackType = null;
37         } else {
38             fMainType = type;
39             fFallbackType ="gregorian";
40         }
41     }
42     
43     /**
44      * Load data for calendar. Note, this object owns the resources, do NOT call ures_close()!
45      *
46      * @param key Resource key to data
47      * @internal
48      */

49     public ICUResourceBundle get(String JavaDoc key) {
50         try {
51             return fBundle.getWithFallback("calendar/" + fMainType + "/" + key);
52         } catch(MissingResourceException JavaDoc m) {
53             if(fFallbackType != null) {
54                 return fBundle.getWithFallback("calendar/" + fFallbackType + "/" + key);
55             }
56             throw m;
57             
58         }
59     }
60
61     /**
62      * Load data for calendar. Note, this object owns the resources, do NOT call ures_close()!
63      * There is an implicit key of 'format'
64      * data is located in: "calendar/key/format/subKey"
65      * for example, calendar/dayNames/format/abbreviated
66      *
67      * @param key Resource key to data
68      * @param subKey Resource key to data
69      * @internal
70      */

71     public ICUResourceBundle get(String JavaDoc key, String JavaDoc subKey) {
72         try {
73             return fBundle.getWithFallback("calendar/" + fMainType + "/" + key + "/format/" + subKey);
74         } catch(MissingResourceException JavaDoc m) {
75             if(fFallbackType != null) {
76                 return fBundle.getWithFallback("calendar/" + fFallbackType + "/" + key + "/format/" + subKey);
77             }
78             throw m;
79             
80         }
81     }
82
83     /**
84      * Load data for calendar. Note, this object owns the resources, do NOT call ures_close()!
85      * data is located in: "calendar/key/contextKey/subKey"
86      * for example, calendar/dayNames/stand-alone/narrow
87      *
88      * @param key Resource key to data
89      * @param contextKey Resource key to data
90      * @param subKey Resource key to data
91      * @internal
92      */

93     public ICUResourceBundle get(String JavaDoc key, String JavaDoc contextKey, String JavaDoc subKey) {
94         try {
95             return fBundle.getWithFallback("calendar/" + fMainType + "/" + key + "/" + contextKey + "/" + subKey);
96         } catch(MissingResourceException JavaDoc m) {
97             if(fFallbackType != null) {
98                 return fBundle.getWithFallback("calendar/" + fFallbackType + "/" + key + "/" + contextKey + "/" + subKey);
99             }
100             throw m;
101             
102         }
103     }
104     
105     public String JavaDoc[] getStringArray(String JavaDoc key) {
106         return get(key).getStringArray();
107     }
108
109     public String JavaDoc[] getStringArray(String JavaDoc key, String JavaDoc subKey) {
110         return get(key, subKey).getStringArray();
111     }
112
113     public String JavaDoc[] getStringArray(String JavaDoc key, String JavaDoc contextKey, String JavaDoc subKey) {
114         return get(key, contextKey, subKey).getStringArray();
115     }
116     public String JavaDoc[] getEras(String JavaDoc subkey){
117         ICUResourceBundle bundle = get("eras/"+subkey);
118         return bundle.getStringArray();
119     }
120     public ULocale getULocale() {
121         return fBundle.getULocale();
122     }
123
124     private ICUResourceBundle fBundle;
125     private String JavaDoc fMainType;
126     private String JavaDoc fFallbackType;
127 }
128
Popular Tags