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