Merge "Resolve result cancel issue of DataControl provider." into tizen_2.1
[platform/framework/native/appfw.git] / src / locales / FLcl_LocaleManagerImpl.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18 * @file         FLcl_LocaleManagerImpl.cpp
19 * @brief        This is the implementation file for _LocaleManagerImpl class.
20 */
21 #include <unique_ptr.h>
22 #include <limits.h>
23 #include <runtime_info.h>
24 #include <unicode/calendar.h>
25 #include <unicode/timezone.h>
26 #include <libxml/parser.h>
27 #include <libxml/tree.h>
28
29 #include <FIo.h>
30 #include <FBaseSysLog.h>
31 #include <FBase_StringConverter.h>
32
33 #include "FLcl_LocaleImpl.h"
34 #include "FLcl_TimeZoneImpl.h"
35 #include "FLcl_LocaleManagerImpl.h"
36
37
38 using namespace Tizen::Base;
39 using namespace Tizen::Base::Utility;
40 using namespace Tizen::Base::Collection;
41 using namespace Tizen::Io;
42
43 namespace Tizen { namespace Locales
44 {
45 static const char* LANGUAGE_LIST_FILE_PATH ="/opt/data/setting/langlist.xml";
46 static const char* TIMEZONE_LIST_FILE_PATH = "/opt/data/setting/tzlist.ini";
47 static const char* CLOCALE_LIST_FILE_PATH = "/opt/usr/etc/clocale.list";
48
49 static const int TIMEZONE_MAX = 224;
50 static const char* TimeZoneList[TIMEZONE_MAX] =
51 {
52         "Africa/Abidjan",
53         "Africa/Accra",
54         "Africa/Addis_Ababa",
55         "Africa/Algiers",
56         "Africa/Asmara",
57         "Africa/Bamako",
58         "Africa/Bangui",
59         "Africa/Bissau",
60         "Africa/Cairo",
61         "Africa/Casablanca",
62         "Africa/Conakry",
63         "Africa/Dakar",
64         "Africa/Dar_es_Salaam",
65         "Africa/Djibouti",
66         "Africa/Douala",
67         "Africa/Freetown",
68         "Africa/Gaborone",
69         "Africa/Harare",
70         "Africa/Johannesburg",
71         "Africa/Kampala",
72         "Africa/Khartoum",
73         "Africa/Kinshasa",
74         "Africa/Lagos",
75         "Africa/Luanda",
76         "Africa/Lubumbashi",
77         "Africa/Lusaka",
78         "Africa/Malabo",
79         "Africa/Maputo",
80         "Africa/Mogadishu",
81         "Africa/Monrovia",
82         "Africa/Nairobi",
83         "Africa/Ndjamena",
84         "Africa/Niamey",
85         "Africa/Nouakchott",
86         "Africa/Ouagadougou",
87         "Africa/Tripoli",
88         "Africa/Tunis",
89         "America/Anchorage",
90         "America/Antigua",
91         "America/Argentina/Buenos_Aires",
92         "America/Asuncion",
93         "America/Barbados",
94         "America/Belize",
95         "America/Bogota",
96         "America/Caracas",
97         "America/Cayenne",
98         "America/Chicago",
99         "America/Costa_Rica",
100         "America/Denver",
101         "America/Detroit",
102         "America/El_Salvador",
103         "America/Godthab",
104         "America/Guadeloupe",
105         "America/Guatemala",
106         "America/Guayaquil",
107         "America/Guyana",
108         "America/Halifax",
109         "America/Havana",
110         "America/Indiana/Indianapolis",
111         "America/Jamaica",
112         "America/Kentucky/Louisville",
113         "America/La_Paz",
114         "America/Lima",
115         "America/Los_Angeles",
116         "America/Managua",
117         "America/Marigot",
118         "America/Martinique",
119         "America/Mazatlan",
120         "America/Mexico_City",
121         "America/Montevideo",
122         "America/Montreal",
123         "America/New_York",
124         "America/Nome",
125         "America/Panama",
126         "America/Paramaribo",
127         "America/Phoenix",
128         "America/Port-au-Prince",
129         "America/Puerto_Rico",
130         "America/Recife",
131         "America/Regina",
132         "America/Santiago",
133         "America/Santo_Domingo",
134         "America/Sao_Paulo",
135         "America/St_Johns",
136         "America/St_Thomas",
137         "America/Tegucigalpa",
138         "America/Tijuana",
139         "America/Toronto",
140         "America/Tortola",
141         "America/Vancouver",
142         "America/Winnipeg",
143         "Asia/Aden",
144         "Asia/Almaty",
145         "Asia/Amman",
146         "Asia/Anadyr",
147         "Asia/Ashgabat",
148         "Asia/Baghdad",
149         "Asia/Bahrain",
150         "Asia/Baku",
151         "Asia/Bangkok",
152         "Asia/Beirut",
153         "Asia/Bishkek",
154         "Asia/Colombo",
155         "Asia/Damascus",
156         "Asia/Dhaka",
157         "Asia/Dubai",
158         "Asia/Dushanbe",
159         "Asia/Ho_Chi_Minh",
160         "Asia/Hong_Kong",
161         "Asia/Hovd",
162         "Asia/Irkutsk",
163         "Asia/Istanbul",
164         "Asia/Jakarta",
165         "Asia/Jayapura",
166         "Asia/Jerusalem",
167         "Asia/Kabul",
168         "Asia/Kamchatka",
169         "Asia/Karachi",
170         "Asia/Kathmandu",
171         "Asia/Kolkata",
172         "Asia/Krasnoyarsk",
173         "Asia/Kuala_Lumpur",
174         "Asia/Kuwait",
175         "Asia/Macau",
176         "Asia/Magadan",
177         "Asia/Makassar",
178         "Asia/Manila",
179         "Asia/Muscat",
180         "Asia/Novokuznetsk",
181         "Asia/Novosibirsk",
182         "Asia/Omsk",
183         "Asia/Phnom_Penh",
184         "Asia/Pyongyang",
185         "Asia/Qatar",
186         "Asia/Rangoon",
187         "Asia/Riyadh",
188         "Asia/Sakhalin",
189         "Asia/Seoul",
190         "Asia/Shanghai",
191         "Asia/Singapore",
192         "Asia/Taipei",
193         "Asia/Tashkent",
194         "Asia/Tbilisi",
195         "Asia/Tehran",
196         "Asia/Tokyo",
197         "Asia/Ulan_Bator",
198         "Asia/Vladivostok",
199         "Asia/Yakutsk",
200         "Asia/Yekaterinburg",
201         "Asia/Yerevan",
202         "Atlantic/Azores",
203         "Atlantic/Canary",
204         "Atlantic/Reykjavik",
205         "Atlantic/South_Georgia",
206         "Australia/Adelaide",
207         "Australia/Brisbane",
208         "Australia/Canberra",
209         "Australia/Darwin",
210         "Australia/Hobart",
211         "Australia/Melbourne",
212         "Australia/Perth",
213         "Australia/Sydney",
214         "CST6CDT",
215         "EST5EDT",
216         "Europe/Amsterdam",
217         "Europe/Athens",
218         "Europe/Belgrade",
219         "Europe/Berlin",
220         "Europe/Bratislava",
221         "Europe/Brussels",
222         "Europe/Bucharest",
223         "Europe/Budapest",
224         "Europe/Chisinau",
225         "Europe/Copenhagen",
226         "Europe/Dublin",
227         "Europe/Helsinki",
228         "Europe/Istanbul",
229         "Europe/Kaliningrad",
230         "Europe/Kiev",
231         "Europe/Lisbon",
232         "Europe/Ljubljana",
233         "Europe/London",
234         "Europe/Luxembourg",
235         "Europe/Madrid",
236         "Europe/Malta",
237         "Europe/Minsk",
238         "Europe/Moscow",
239         "Europe/Paris",
240         "Europe/Podgorica",
241         "Europe/Prague",
242         "Europe/Riga",
243         "Europe/Rome",
244         "Europe/Samara",
245         "Europe/San_Marino",
246         "Europe/Skopje",
247         "Europe/Sofia",
248         "Europe/Stockholm",
249         "Europe/Tallinn",
250         "Europe/Vaduz",
251         "Europe/Vienna",
252         "Europe/Vilnius",
253         "Europe/Volgograd",
254         "Europe/Warsaw",
255         "Europe/Zagreb",
256         "Europe/Zurich",
257         "Indian/Antananarivo",
258         "Indian/Chagos",
259         "Indian/Maldives",
260         "Indian/Mauritius",
261         "Indian/Reunion",
262         "MST7MDT",
263         "Pacific/Auckland",
264         "Pacific/Easter",
265         "Pacific/Fiji",
266         "Pacific/Galapagos",
267         "Pacific/Guam",
268         "Pacific/Honolulu",
269         "Pacific/Midway",
270         "Pacific/Noumea",
271         "Pacific/Pago_Pago",
272         "Pacific/Tahiti",
273         "Pacific/Tarawa",
274         "Pacific/Tongatapu",
275         "PST8PDT"
276 };
277
278 Locale
279 _LocaleManagerImpl::GetSystemLocale(void)
280 {
281         char* pRegionPtr;
282         if (runtime_info_get_value_string(RUNTIME_INFO_KEY_REGION, &pRegionPtr) == RUNTIME_INFO_ERROR_NONE)
283         {
284                 SetLastResult(E_SUCCESS);
285
286                 Locale ospLoc = _LocaleImpl(pRegionPtr).GetOspLocale();
287                 free(pRegionPtr);
288                 return ospLoc;
289         }
290
291         SetLastResult(E_SYSTEM);
292         return Locale(LANGUAGE_INVALID, COUNTRY_INVALID, null);
293 }
294
295
296 IMap*
297 _LocaleManagerImpl::GetAvailableEglibcLocaesN(void)
298 {
299         File file;
300         result r = E_SUCCESS;
301         String clocaleFilePath(CLOCALE_LIST_FILE_PATH);
302         
303         std::unique_ptr<HashMap> pClocaleMap(new (std::nothrow) HashMap(SingleObjectDeleter));
304         SysTryReturn(NID_LCL, pClocaleMap, null, E_OUT_OF_MEMORY,
305                         "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
306         r = file.Construct(clocaleFilePath, "r");
307         SysTryReturn(NID_LCL, r == E_SUCCESS, null,E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] It is failed to get the clocale list from the list file.");
308
309         pClocaleMap->Construct();
310
311         do
312         {
313                 String strBuf;
314                 r = file.Read(strBuf);
315                 if ( r == E_END_OF_FILE)
316                 {
317                         break;
318                 }
319                 SysTryReturn(NID_LCL, r == E_SUCCESS, null, r, "[%s] It is failed to read the clocale list.", GetErrorMessage(r));
320                 std::unique_ptr< String > pClocaleId(new (std::nothrow) String());
321                 SysTryReturn(NID_LCL, pClocaleId, null, E_OUT_OF_MEMORY,
322                         "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
323                 r = strBuf.SubString(0, 5, *pClocaleId);
324                 if (IsFailed(r))
325                 {
326                         continue;
327                 }
328
329                 if (!pClocaleMap->ContainsKey(*(pClocaleId.get())))
330                 {
331                         std::unique_ptr<String> pDummyValue(new (std::nothrow) String());
332                         SysTryReturn(NID_LCL, pDummyValue, null, E_OUT_OF_MEMORY,
333                                 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
334
335                         r = pClocaleMap->Add(*(pClocaleId.get()), *(pDummyValue.get()));
336                         SysTryReturn(NID_LCL, r == E_SUCCESS, null, r,
337                                 "[%s] It is failed to add the clocale id into the clocale map.", GetErrorMessage(r));
338                         pClocaleId.release();
339                         pDummyValue.release();
340                 }
341         }while(1);
342         return pClocaleMap.release();
343 }
344
345 IList*
346 _LocaleManagerImpl::GetAvailableLocalesN(void)
347 {
348         result r = E_SUCCESS;
349         int count = 0;
350         const U_ICU_NAMESPACE::Locale* pIcuLocaleList = U_ICU_NAMESPACE::Locale::getAvailableLocales(count);
351         SysTryReturn(NID_LCL, count > 0, null, E_SYSTEM,
352                 "[%s] The method cannot proceed due to a severe system error.", GetErrorMessage(E_SYSTEM));
353
354         std::unique_ptr<LinkedList> pAvailableLocaleList(new (std::nothrow) LinkedList(SingleObjectDeleter));
355         SysTryReturn(NID_LCL, pAvailableLocaleList, null, E_OUT_OF_MEMORY,
356                 "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
357
358         std::unique_ptr< IMap > pClocaleMap(GetAvailableEglibcLocaesN());
359
360         for (int i = 0; i < count; i++)
361         {
362                 const U_ICU_NAMESPACE::Locale* pIcuLocale = (pIcuLocaleList + i);
363                 SysTryReturn(NID_LCL, pIcuLocale, null, E_SYSTEM,
364                         "[%s] The method cannot proceed due to a severe system error.",GetErrorMessage(E_SYSTEM));
365                 Locale ospLocale = _LocaleImpl(*pIcuLocale).GetOspLocale();
366                 if (_LocaleImpl::IsSupported(ospLocale))
367                 {
368                         std::unique_ptr< Locale > pLocale(new (std::nothrow) Locale(ospLocale));
369                         SysTryReturn(NID_LCL, pLocale, null, E_OUT_OF_MEMORY,
370                                                 "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
371
372                         String localeId(pIcuLocale->getLanguage());
373                         localeId = localeId + L"_" + String(pIcuLocale->getCountry());
374
375                         if (!pAvailableLocaleList->Contains(*(pLocale.get())) && pClocaleMap->ContainsKey(localeId))
376                         {
377                                 r = pAvailableLocaleList->Add(*(pLocale.get()));
378                                 SysTryReturn(NID_LCL, !IsFailed(r), null, E_SYSTEM, "It is failed to make the locale list");
379                                 pLocale.release();
380                         }
381                 }
382         }
383
384         SetLastResult(E_SUCCESS);
385         return pAvailableLocaleList.release();
386 }
387
388 String
389 _LocaleManagerImpl::GetSelectedLanguage(void)
390 {
391         char* pLanguagePtr;
392
393         int ret = runtime_info_get_value_string(RUNTIME_INFO_KEY_LANGUAGE, &pLanguagePtr);
394         SysTryReturn(NID_LCL, ret == RUNTIME_INFO_ERROR_NONE, String(), E_SYSTEM,
395                         "[%s] The method cannot proceed due to a severe system error.", GetErrorMessage(E_SYSTEM));
396         String language(_LocaleImpl(pLanguagePtr).GetLanguageCodeString(false));
397         free(pLanguagePtr);
398
399         return language;
400 }
401
402 IList*
403 _LocaleManagerImpl::GetAvailableLanguagesN(void)
404 {
405         xmlDocPtr doc = null;
406         xmlNodePtr cur = null;
407
408         std::unique_ptr<ArrayList, AllElementsDeleter> pAvailableLanguageList(new (std::nothrow) ArrayList());
409         SysTryCatch(NID_LCL, pAvailableLanguageList, null, E_OUT_OF_MEMORY,"[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
410
411         doc = xmlParseFile(LANGUAGE_LIST_FILE_PATH);
412         SysTryCatch(NID_LCL, doc != null, , E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] It is failed to get the langlist from the resource.");
413
414         cur = xmlDocGetRootElement(doc);
415         SysTryCatch(NID_LCL, cur != null, , E_EMPTY_BODY, "[E_EMPTY_BODY] It is empty document.");
416         SysTryCatch(NID_LCL, xmlStrcmp(cur->name, (const xmlChar *) "langlist") == 0, , E_INVALID_CONTENT, "[E_INVALID_CONTENT] The document is wrong type");
417
418         cur = cur->xmlChildrenNode;
419
420         pAvailableLanguageList->Construct();
421
422         for (xmlNodePtr cur_node = cur; cur_node; cur_node = cur_node->next)
423         {
424                 if (cur_node->type == XML_ELEMENT_NODE)
425                 {
426                         char* pLocId = (char*)xmlGetProp(cur_node, (const xmlChar *)"id");
427                         Locale loc = _LocaleImpl(pLocId).GetOspLocale();
428                         std::unique_ptr<String> pLanguageLocaleID(new (std::nothrow) String(loc.GetLanguageCodeString()));
429                         SysTryCatch(NID_LCL, pLanguageLocaleID, null, E_OUT_OF_MEMORY,"[%s] Memory allocation failed",GetErrorMessage(E_OUT_OF_MEMORY));
430
431                         result r = pAvailableLanguageList->Add(pLanguageLocaleID.get());
432                         SysTryCatch(NID_LCL, r == E_SUCCESS, null, E_SYSTEM,
433                                         "[%s] It is failed to add a locale string [%ls].", GetErrorMessage(E_SYSTEM), pLanguageLocaleID->GetPointer());
434                         pLanguageLocaleID.release();
435                 }
436         }
437
438         SetLastResult(E_SUCCESS);
439
440         if (doc)
441         {
442                 xmlFreeDoc(doc);
443         }
444
445         return pAvailableLanguageList.release();
446
447 CATCH:
448         if (doc)
449         {
450                 xmlFreeDoc(doc);
451         }
452         SysLog(NID_LCL, "It is calling fallback api.");
453         return GetAvailableLanguagesFallbackN();
454 }
455
456
457 IList*
458 _LocaleManagerImpl::GetAvailableLanguagesFallbackN(void)
459 {
460         std::unique_ptr<IList, AllElementsDeleter> pLocaleList (GetAvailableLocalesN());
461         std::unique_ptr<HashMap> pLanguageMap(new (std::nothrow) HashMap());
462
463         SysTryReturn(NID_LCL, pLanguageMap, null, E_OUT_OF_MEMORY,"[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
464
465         pLanguageMap->Construct();
466
467         for (int i = 0; i < pLocaleList->GetCount() ; i++)
468         {
469                 Locale* pLocale = (Locale*)pLocaleList->GetAt(i);
470                 std::unique_ptr<String> pLanguageCode(new (std::nothrow) String(pLocale->GetLanguageCodeString()));
471                 SysTryReturn(NID_LCL, pLanguageCode, null, E_OUT_OF_MEMORY,"[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
472
473                 if (!pLanguageMap->ContainsKey(*pLanguageCode))
474                 {
475                         std::unique_ptr<String> pDummyValue(new (std::nothrow) String());
476                         SysTryReturn(NID_LCL, pDummyValue, null, E_OUT_OF_MEMORY,"[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
477
478                         result r = pLanguageMap->Add(*(pLanguageCode.get()), *(pDummyValue.get()));
479                         SysTryReturn(NID_LCL, !IsFailed(r), null, E_SYSTEM, "It is failed to make a language list.");
480                         pLanguageCode.release();
481                         pDummyValue.release();
482                 }
483         }
484
485         IList* pAvailableLanguageList;
486         pAvailableLanguageList = pLanguageMap->GetKeysN();
487         SetLastResult(E_SUCCESS);
488         pLanguageMap->RemoveAll();
489         return pAvailableLanguageList;
490 }
491
492
493 IMap*
494 _LocaleManagerImpl::GetAvailableTimeZonesN(U_ICU_NAMESPACE::StringEnumeration* pIcuTZStrList)
495 {
496         SysTryReturn(NID_LCL, pIcuTZStrList, null, E_SYSTEM,
497                 "[%s] The method cannot proceed due to a severe system error.",GetErrorMessage(E_SYSTEM));
498
499         std::unique_ptr<HashMap> pTimeZoneMap(new (std::nothrow) HashMap(SingleObjectDeleter));
500         SysTryReturn(NID_LCL, pTimeZoneMap, null, E_OUT_OF_MEMORY,
501                 "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
502         pTimeZoneMap->Construct();
503
504         result r = E_SUCCESS;
505         int resultLength = -1;
506         UErrorCode ec = U_ZERO_ERROR;
507         const char* pIcuTZStr = pIcuTZStrList->next(&resultLength, ec);
508         std::unique_ptr<IMap> pTZMap(GetAvailableTimeZonesN());
509         r = GetLastResult();
510         SysTryReturn(NID_LCL, pTZMap, null, r, "[%s] Fail to get available time zone list", GetErrorMessage(r));
511
512         while (pIcuTZStr != null)
513         {
514                 std::unique_ptr< String > pTimeZone(new (std::nothrow) String(pIcuTZStr));
515                 SysTryReturn(NID_LCL, pTimeZone, null, E_OUT_OF_MEMORY,
516                                         "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
517                 if (!pTimeZoneMap->ContainsKey(*(pTimeZone.get())) && pTZMap->ContainsKey(*(pTimeZone.get())))
518                 {
519                         std::unique_ptr< String > pDummyValue(new  (std::nothrow) String());
520                         SysTryReturn(NID_LCL, pDummyValue, null, E_OUT_OF_MEMORY,"[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
521                         r = pTimeZoneMap->Add(*(pTimeZone.get()), *(pDummyValue.get()));
522                         SysTryReturn(NID_LCL, !IsFailed(r), null, E_SYSTEM, "[E_SYSTEM] It is failed to add a TZ into Map.");
523                         pTimeZone.release();
524                         pDummyValue.release();
525                 }
526
527                 pIcuTZStr = pIcuTZStrList->next(&resultLength, ec);
528         }
529         SetLastResult(E_SUCCESS);
530         return pTimeZoneMap.release();
531 }
532
533
534 IMap*
535 _LocaleManagerImpl::GetAvailableTimeZonesN(void)
536 {
537         File file;
538         String tzFilePath(TIMEZONE_LIST_FILE_PATH);
539         result r = E_SUCCESS;
540
541         std::unique_ptr<HashMap> pTimeZoneMap(new (std::nothrow) HashMap(SingleObjectDeleter));
542         SysTryCatch(NID_LCL, pTimeZoneMap, null, E_OUT_OF_MEMORY,
543                         "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
544         r = file.Construct(tzFilePath, "r");
545         SysTryCatch(NID_LCL, r == E_SUCCESS, ,E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] It is failed to get the tzlist from the ini file.");
546
547         pTimeZoneMap->Construct();
548
549         do
550         {
551                 std::unique_ptr<String> pTimeZone(new (std::nothrow) String());
552                 SysTryCatch(NID_LCL, pTimeZone, null, E_OUT_OF_MEMORY,
553                                 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
554                 r = file.Read(*(pTimeZone.get()));
555                 if ( r == E_END_OF_FILE)
556                 {
557                         break;
558                 }
559                 SysTryCatch(NID_LCL, r == E_SUCCESS, , r, "[%s] It is failed to read the tzlist.", GetErrorMessage(r));
560                 pTimeZone->Replace(L"\n", L"\0");
561
562                 if (!pTimeZoneMap->ContainsKey(*(pTimeZone.get())))
563                 {
564                         std::unique_ptr<String> pDummyValue(new (std::nothrow) String());
565                         SysTryCatch(NID_LCL, pDummyValue, null, E_OUT_OF_MEMORY,
566                                         "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
567
568                         r = pTimeZoneMap->Add(*(pTimeZone.get()), *(pDummyValue.get()));
569                         SysTryCatch(NID_LCL, r == E_SUCCESS, , r,"[%s] It is failed to make the tz list.", GetErrorMessage(r));
570                         pTimeZone.release();
571                         pDummyValue.release();
572                 }
573         }while (1);
574
575         SetLastResult(E_SUCCESS);
576         return pTimeZoneMap.release();
577
578 CATCH:
579         return GetAvailableTimeZonesFallbackN();
580 }
581
582
583 IMap*
584 _LocaleManagerImpl::GetAvailableTimeZonesFallbackN(void)
585 {
586         std::unique_ptr<HashMap> pTimeZoneMap(new (std::nothrow) HashMap(SingleObjectDeleter));
587         SysTryReturn(NID_LCL, pTimeZoneMap, null, E_OUT_OF_MEMORY,
588                         "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
589
590         result r = E_SUCCESS;
591         int index = 0;
592                 
593         pTimeZoneMap->Construct();
594         
595         do
596         {
597                 std::unique_ptr< String > pTimeZone(new (std::nothrow) String(TimeZoneList[index++]));
598                 SysTryReturn(NID_LCL, pTimeZone, null, E_OUT_OF_MEMORY,
599                         "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
600
601                 if (!pTimeZoneMap->ContainsKey(*(pTimeZone.get())))
602                 {
603                         std::unique_ptr< String > pDummyValue (new  (std::nothrow) String());
604                         SysTryReturn(NID_LCL, pDummyValue, null, E_OUT_OF_MEMORY,"[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
605
606                         r = pTimeZoneMap->Add(*(pTimeZone.get()), *(pDummyValue.get()));
607                         SysTryReturn(NID_LCL, !IsFailed(r), null, E_SYSTEM, "It is failed to make Timezone list.");
608                         
609                         pTimeZone.release();
610                         pDummyValue.release();
611                 }
612         }while (index < TIMEZONE_MAX);
613
614         SetLastResult(E_SUCCESS);
615         return pTimeZoneMap.release();
616 }
617
618
619 IMap*
620 _LocaleManagerImpl::GetAvailableTimeZonesN(int rawOffset)
621 {
622         std::unique_ptr<U_ICU_NAMESPACE::StringEnumeration> pIcuTzList(U_ICU_NAMESPACE::TimeZone::createEnumeration(rawOffset * _TimeZoneImpl::ONE_MIN_IN_MILLISEC));
623         SysTryReturn(NID_LCL, pIcuTzList, null, E_SYSTEM, "[E_SYSTEM] It is failed to get Icu TZ list.");
624         IMap* pTzList =  GetAvailableTimeZonesN(pIcuTzList.get());
625         return pTzList;
626 }
627
628
629 TimeZone
630 _LocaleManagerImpl::GetSystemTimeZone(void)
631 {
632         char tz[PATH_MAX + 1];
633         int len = readlink("/opt/etc/localtime", tz, PATH_MAX);
634
635         SysTryReturn(NID_LCL, len > 0, TimeZone(-1, ""), E_SYSTEM, "It is failed to get System Time Zone");
636         tz[len] = '\0';
637         SysTryReturn(NID_LCL, len > 20, TimeZone(-1, ""), E_SYSTEM, "It is failed to get System Time Zone");
638
639         String tzId(tz + 20);
640         SysLog(NID_LCL, "System TimeZone id [%ls]", tzId.GetPointer());
641         TimeZone timeZone;
642         result r = Tizen::Locales::TimeZone::GetTimeZone(tzId, timeZone);
643         SysTryReturn(NID_LCL, r == E_SUCCESS, TimeZone(-1, ""), r, "[%s] error occurs.", GetErrorMessage(r));
644         return timeZone;
645 }
646
647 result
648 _LocaleManagerImpl::IsSupportedLocale(const Tizen::Locales::Locale& locale, bool& isSupportedLocale)
649 {
650         isSupportedLocale = _LocaleImpl::IsSupported(locale);
651         return E_SUCCESS;
652 }
653
654 };
655 };      // Tizen::Locales