Merge "Apply secure logs" 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, AllElementsDeleter> pTimeZoneMap(new (std::nothrow) HashMap());
500
501         SysTryReturn(NID_LCL, pTimeZoneMap, null, E_OUT_OF_MEMORY,
502                         "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
503         pTimeZoneMap->Construct();
504         result r = E_SUCCESS;
505         int resultLength = -1;
506         UErrorCode ec = U_ZERO_ERROR;
507         const char* pIcuTZStr = pIcuTZStrList->next(&resultLength, ec);
508         IMap* pTZMap = GetAvailableTimeZonesN();
509
510         r = GetLastResult();
511         SysTryReturn(NID_LCL, pTZMap, null, r, "[%s] Fail to get available time zone list", GetErrorMessage(r));
512
513         while (pIcuTZStr != null)
514         {
515                 std::unique_ptr< String > pTimeZone(new (std::nothrow) String(pIcuTZStr));
516                 SysTryReturn(NID_LCL, pTimeZone, null, E_OUT_OF_MEMORY,
517                                         "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
518                 if (!pTimeZoneMap->ContainsKey(*(pTimeZone.get())) && pTZMap->ContainsKey(*(pTimeZone.get())))
519                 {
520                         std::unique_ptr< String > pDummyValue(new  (std::nothrow) String());
521                         SysTryReturn(NID_LCL, pDummyValue, null, E_OUT_OF_MEMORY,"[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
522                         r = pTimeZoneMap->Add(*(pTimeZone.get()), *(pDummyValue.get()));
523                         if (IsFailed(r))
524                         {
525                                 pTZMap->RemoveAll();
526                                 delete pTZMap;
527                                 SetLastResult(E_SYSTEM);
528                                 return null;
529                         }
530                         pTimeZone.release();
531                         pDummyValue.release();
532                 }
533
534                 pIcuTZStr = pIcuTZStrList->next(&resultLength, ec);
535         }
536         SetLastResult(E_SUCCESS);
537         pTZMap->RemoveAll();
538         delete pTZMap;
539         return pTimeZoneMap.release();
540 }
541
542
543 IMap*
544 _LocaleManagerImpl::GetAvailableTimeZonesN(void)
545 {
546         File file;
547         String tzFilePath(TIMEZONE_LIST_FILE_PATH);
548         result r = E_SUCCESS;
549
550         std::unique_ptr<HashMap, AllElementsDeleter> pTimeZoneMap(new (std::nothrow) HashMap());
551         SysTryCatch(NID_LCL, pTimeZoneMap, null, E_OUT_OF_MEMORY,
552                         "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
553         r = file.Construct(tzFilePath, "r");
554         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.");
555
556         pTimeZoneMap->Construct();
557
558         do
559         {
560                 std::unique_ptr<String> pTimeZone(new (std::nothrow) String());
561                 SysTryCatch(NID_LCL, pTimeZone, null, E_OUT_OF_MEMORY,
562                                 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
563                 r = file.Read(*(pTimeZone.get()));
564                 if ( r == E_END_OF_FILE)
565                 {
566                         break;
567                 }
568                 SysTryCatch(NID_LCL, r == E_SUCCESS, , r, "[%s] It is failed to read the tzlist.", GetErrorMessage(r));
569                 pTimeZone->Replace(L"\n", L"\0");
570
571                 if (!pTimeZoneMap->ContainsKey(*(pTimeZone.get())))
572                 {
573                         std::unique_ptr<String> pDummyValue(new (std::nothrow) String());
574                         SysTryCatch(NID_LCL, pDummyValue, null, E_OUT_OF_MEMORY,
575                                         "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
576
577                         r = pTimeZoneMap->Add(*(pTimeZone.get()), *(pDummyValue.get()));
578                         SysTryCatch(NID_LCL, r == E_SUCCESS, , r,"[%s] It is failed to add the tz into the tz map.", GetErrorMessage(r));
579                         pTimeZone.release();
580                         pDummyValue.release();
581                 }
582         }while (1);
583
584         SetLastResult(E_SUCCESS);
585         return pTimeZoneMap.release();
586
587 CATCH:
588         return GetAvailableTimeZonesFallbackN();
589 }
590
591
592 IMap*
593 _LocaleManagerImpl::GetAvailableTimeZonesFallbackN(void)
594 {
595         std::unique_ptr<HashMap, AllElementsDeleter> pTimeZoneMap(new (std::nothrow) HashMap());
596         SysTryReturn(NID_LCL, pTimeZoneMap, null, E_OUT_OF_MEMORY,
597                         "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
598
599         result r = E_SUCCESS;
600         int index = 0;
601                 
602         pTimeZoneMap->Construct();
603         
604         do
605         {
606                 std::unique_ptr< String > pTimeZone(new (std::nothrow) String(TimeZoneList[index++]));
607                 SysTryReturn(NID_LCL, pTimeZone, null, E_OUT_OF_MEMORY,
608                         "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
609
610                 if (!pTimeZoneMap->ContainsKey(*(pTimeZone.get())))
611                 {
612                         std::unique_ptr< String > pDummyValue (new  (std::nothrow) String());
613                         SysTryReturn(NID_LCL, pDummyValue, null, E_OUT_OF_MEMORY,"[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
614
615                         r = pTimeZoneMap->Add(*(pTimeZone.get()), *(pDummyValue.get()));
616                         SysTryReturn(NID_LCL, !IsFailed(r), null, E_SYSTEM, "It is failed to make Timezone list.");
617                         
618                         pTimeZone.release();
619                         pDummyValue.release();
620                 }
621         }while (index < TIMEZONE_MAX);
622
623         SetLastResult(E_SUCCESS);
624         return pTimeZoneMap.release();
625 }
626
627
628 IMap*
629 _LocaleManagerImpl::GetAvailableTimeZonesN(int rawOffset)
630 {
631         return GetAvailableTimeZonesN(U_ICU_NAMESPACE::TimeZone::createEnumeration(rawOffset * _TimeZoneImpl::ONE_MIN_IN_MILLISEC));
632 }
633
634
635 TimeZone
636 _LocaleManagerImpl::GetSystemTimeZone(void)
637 {
638         char tz[PATH_MAX + 1];
639         int len = readlink("/opt/etc/localtime", tz, PATH_MAX);
640
641         SysTryReturn(NID_LCL, len > 0, TimeZone(-1, ""), E_SYSTEM, "It is failed to get System Time Zone");
642         tz[len] = '\0';
643         SysTryReturn(NID_LCL, len > 20, TimeZone(-1, ""), E_SYSTEM, "It is failed to get System Time Zone");
644
645         String tzId(tz + 20);
646         SysLog(NID_LCL, "System TimeZone id [%ls]", tzId.GetPointer());
647         TimeZone timeZone;
648         result r = Tizen::Locales::TimeZone::GetTimeZone(tzId, timeZone);
649         SysTryReturn(NID_LCL, r == E_SUCCESS, TimeZone(-1, ""), r, "[%s] error occurs.", GetErrorMessage(r));
650         return timeZone;
651 }
652
653 result
654 _LocaleManagerImpl::IsSupportedLocale(const Tizen::Locales::Locale& locale, bool& isSupportedLocale)
655 {
656         isSupportedLocale = _LocaleImpl::IsSupported(locale);
657         return E_SUCCESS;
658 }
659
660 };
661 };      // Tizen::Locales