Merge "Update deprecated libprivilege-control API functions." into tizen
[platform/framework/native/appfw.git] / src / locales / FLcl_LocaleManagerImpl.cpp
index 714aca0..427213f 100644 (file)
@@ -1,5 +1,4 @@
 //
-// Open Service Platform
 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
 //
 // Licensed under the Apache License, Version 2.0 (the License);
 */
 #include <unique_ptr.h>
 #include <limits.h>
+#include <time.h>
 #include <runtime_info.h>
 #include <unicode/calendar.h>
 #include <unicode/timezone.h>
+#include <unicode/locid.h>
 #include <libxml/parser.h>
 #include <libxml/tree.h>
+#include <vconf.h>
 
+#include <FIo.h>
 #include <FBaseSysLog.h>
 #include <FBase_StringConverter.h>
 
 using namespace Tizen::Base;
 using namespace Tizen::Base::Utility;
 using namespace Tizen::Base::Collection;
+using namespace Tizen::Io;
 
-namespace Tizen { namespace Locales
+struct FreeXmlDoc
 {
-static const char* LANGLIST_FILE_PATH ="/opt/data/setting/langlist.xml";
-static const int TIMEZONE_MAX = 224;
-static const char* TimeZoneList[TIMEZONE_MAX] =
+       void operator ()(xmlDoc* p)
+       {
+               if (p != null)
+               {
+                       xmlFreeDoc(p);
+               }
+       }
+};
+
+struct FreeCharPtr
 {
-       "Africa/Abidjan",
-       "Africa/Accra",
-       "Africa/Addis_Ababa",
-       "Africa/Algiers",
-       "Africa/Asmara",
-       "Africa/Bamako",
-       "Africa/Bangui",
-       "Africa/Bissau",
-       "Africa/Cairo",
-       "Africa/Casablanca",
-       "Africa/Conakry",
-       "Africa/Dakar",
-       "Africa/Dar_es_Salaam",
-       "Africa/Djibouti",
-       "Africa/Douala",
-       "Africa/Freetown",
-       "Africa/Gaborone",
-       "Africa/Harare",
-       "Africa/Johannesburg",
-       "Africa/Kampala",
-       "Africa/Khartoum",
-       "Africa/Kinshasa",
-       "Africa/Lagos",
-       "Africa/Luanda",
-       "Africa/Lubumbashi",
-       "Africa/Lusaka",
-       "Africa/Malabo",
-       "Africa/Maputo",
-       "Africa/Mogadishu",
-       "Africa/Monrovia",
-       "Africa/Nairobi",
-       "Africa/Ndjamena",
-       "Africa/Niamey",
-       "Africa/Nouakchott",
-       "Africa/Ouagadougou",
-       "Africa/Tripoli",
-       "Africa/Tunis",
-       "America/Anchorage",
-       "America/Antigua",
-       "America/Argentina/Buenos_Aires",
-       "America/Asuncion",
-       "America/Barbados",
-       "America/Belize",
-       "America/Bogota",
-       "America/Caracas",
-       "America/Cayenne",
-       "America/Chicago",
-       "America/Costa_Rica",
-       "America/Denver",
-       "America/Detroit",
-       "America/El_Salvador",
-       "America/Godthab",
-       "America/Guadeloupe",
-       "America/Guatemala",
-       "America/Guayaquil",
-       "America/Guyana",
-       "America/Halifax",
-       "America/Havana",
-       "America/Indiana/Indianapolis",
-       "America/Jamaica",
-       "America/Kentucky/Louisville",
-       "America/La_Paz",
-       "America/Lima",
-       "America/Los_Angeles",
-       "America/Managua",
-       "America/Marigot",
-       "America/Martinique",
-       "America/Mazatlan",
-       "America/Mexico_City",
-       "America/Montevideo",
-       "America/Montreal",
-       "America/New_York",
-       "America/Nome",
-       "America/Panama",
-       "America/Paramaribo",
-       "America/Phoenix",
-       "America/Port-au-Prince",
-       "America/Puerto_Rico",
-       "America/Recife",
-       "America/Regina",
-       "America/Santiago",
-       "America/Santo_Domingo",
-       "America/Sao_Paulo",
-       "America/St_Johns",
-       "America/St_Thomas",
-       "America/Tegucigalpa",
-       "America/Tijuana",
-       "America/Toronto",
-       "America/Tortola",
-       "America/Vancouver",
-       "America/Winnipeg",
-       "Asia/Aden",
-       "Asia/Almaty",
-       "Asia/Amman",
-       "Asia/Anadyr",
-       "Asia/Ashgabat",
-       "Asia/Baghdad",
-       "Asia/Bahrain",
-       "Asia/Baku",
-       "Asia/Bangkok",
-       "Asia/Beirut",
-       "Asia/Bishkek",
-       "Asia/Colombo",
-       "Asia/Damascus",
-       "Asia/Dhaka",
-       "Asia/Dubai",
-       "Asia/Dushanbe",
-       "Asia/Ho_Chi_Minh",
-       "Asia/Hong_Kong",
-       "Asia/Hovd",
-       "Asia/Irkutsk",
-       "Asia/Istanbul",
-       "Asia/Jakarta",
-       "Asia/Jayapura",
-       "Asia/Jerusalem",
-       "Asia/Kabul",
-       "Asia/Kamchatka",
-       "Asia/Karachi",
-       "Asia/Kathmandu",
-       "Asia/Kolkata",
-       "Asia/Krasnoyarsk",
-       "Asia/Kuala_Lumpur",
-       "Asia/Kuwait",
-       "Asia/Macau",
-       "Asia/Magadan",
-       "Asia/Makassar",
-       "Asia/Manila",
-       "Asia/Muscat",
-       "Asia/Novokuznetsk",
-       "Asia/Novosibirsk",
-       "Asia/Omsk",
-       "Asia/Phnom_Penh",
-       "Asia/Pyongyang",
-       "Asia/Qatar",
-       "Asia/Rangoon",
-       "Asia/Riyadh",
-       "Asia/Sakhalin",
-       "Asia/Seoul",
-       "Asia/Shanghai",
-       "Asia/Singapore",
-       "Asia/Taipei",
-       "Asia/Tashkent",
-       "Asia/Tbilisi",
-       "Asia/Tehran",
-       "Asia/Tokyo",
-       "Asia/Ulan_Bator",
-       "Asia/Vladivostok",
-       "Asia/Yakutsk",
-       "Asia/Yekaterinburg",
-       "Asia/Yerevan",
-       "Atlantic/Azores",
-       "Atlantic/Canary",
-       "Atlantic/Reykjavik",
-       "Atlantic/South_Georgia",
-       "Australia/Adelaide",
-       "Australia/Brisbane",
-       "Australia/Canberra",
-       "Australia/Darwin",
-       "Australia/Hobart",
-       "Australia/Melbourne",
-       "Australia/Perth",
-       "Australia/Sydney",
-       "CST6CDT",
-       "EST5EDT",
-       "Europe/Amsterdam",
-       "Europe/Athens",
-       "Europe/Belgrade",
-       "Europe/Berlin",
-       "Europe/Bratislava",
-       "Europe/Brussels",
-       "Europe/Bucharest",
-       "Europe/Budapest",
-       "Europe/Chisinau",
-       "Europe/Copenhagen",
-       "Europe/Dublin",
-       "Europe/Helsinki",
-       "Europe/Istanbul",
-       "Europe/Kaliningrad",
-       "Europe/Kiev",
-       "Europe/Lisbon",
-       "Europe/Ljubljana",
-       "Europe/London",
-       "Europe/Luxembourg",
-       "Europe/Madrid",
-       "Europe/Malta",
-       "Europe/Minsk",
-       "Europe/Moscow",
-       "Europe/Paris",
-       "Europe/Podgorica",
-       "Europe/Prague",
-       "Europe/Riga",
-       "Europe/Rome",
-       "Europe/Samara",
-       "Europe/San_Marino",
-       "Europe/Skopje",
-       "Europe/Sofia",
-       "Europe/Stockholm",
-       "Europe/Tallinn",
-       "Europe/Vaduz",
-       "Europe/Vienna",
-       "Europe/Vilnius",
-       "Europe/Volgograd",
-       "Europe/Warsaw",
-       "Europe/Zagreb",
-       "Europe/Zurich",
-       "Indian/Antananarivo",
-       "Indian/Chagos",
-       "Indian/Maldives",
-       "Indian/Mauritius",
-       "Indian/Reunion",
-       "MST7MDT",
-       "Pacific/Auckland",
-       "Pacific/Easter",
-       "Pacific/Fiji",
-       "Pacific/Galapagos",
-       "Pacific/Guam",
-       "Pacific/Honolulu",
-       "Pacific/Midway",
-       "Pacific/Noumea",
-       "Pacific/Pago_Pago",
-       "Pacific/Tahiti",
-       "Pacific/Tarawa",
-       "Pacific/Tongatapu",
-       "PST8PDT"
+       void operator ()(char* p)
+       {
+               if (p != null)
+               {
+                       free(p);
+               }
+       }
 };
 
+namespace Tizen { namespace Locales
+{
+static const char* LANGUAGE_LIST_FILE_PATH ="/opt/usr/data/setting/langlist.xml";
+static const char* TIMEZONE_LIST_FILE_PATH = "/opt/usr/data/clock/tzlist.ini";
+static const char* CLOCALE_LIST_FILE_PATH = "/opt/usr/etc/clocale.list";
+
+
 Locale
 _LocaleManagerImpl::GetSystemLocale(void)
 {
@@ -288,6 +89,71 @@ _LocaleManagerImpl::GetSystemLocale(void)
        return Locale(LANGUAGE_INVALID, COUNTRY_INVALID, null);
 }
 
+U_ICU_NAMESPACE::Locale
+_LocaleManagerImpl::GetSystemIcuLocale(void)
+{
+       char* pRegionPtr;
+       if (runtime_info_get_value_string(RUNTIME_INFO_KEY_REGION, &pRegionPtr) == RUNTIME_INFO_ERROR_NONE)
+       {
+               SetLastResult(E_SUCCESS);
+               U_ICU_NAMESPACE::Locale locale(pRegionPtr);
+
+               free(pRegionPtr);
+               return locale;
+       }
+       return U_ICU_NAMESPACE::Locale();
+}
+
+
+IMap*
+_LocaleManagerImpl::GetAvailableEglibcLocaesN(void)
+{
+       File file;
+       result r = E_SUCCESS;
+       String clocaleFilePath(CLOCALE_LIST_FILE_PATH);
+       
+       std::unique_ptr<HashMap> pClocaleMap(new (std::nothrow) HashMap(SingleObjectDeleter));
+       SysTryReturn(NID_LCL, pClocaleMap, null, E_OUT_OF_MEMORY,
+                       "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
+       r = file.Construct(clocaleFilePath, "r");
+       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.");
+
+       pClocaleMap->Construct();
+
+       do
+       {
+               String strBuf;
+               r = file.Read(strBuf);
+               if ( r == E_END_OF_FILE)
+               {
+                       break;
+               }
+               SysTryReturn(NID_LCL, r == E_SUCCESS, null, r, "[%s] It is failed to read the clocale list.", GetErrorMessage(r));
+               std::unique_ptr< String > pClocaleId(new (std::nothrow) String());
+               SysTryReturn(NID_LCL, pClocaleId, null, E_OUT_OF_MEMORY,
+                        "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
+               r = strBuf.SubString(0, 5, *pClocaleId);
+               if (IsFailed(r))
+               {
+                       continue;
+               }
+
+               if (!pClocaleMap->ContainsKey(*(pClocaleId.get())))
+               {
+                       std::unique_ptr<String> pDummyValue(new (std::nothrow) String());
+                       SysTryReturn(NID_LCL, pDummyValue, null, E_OUT_OF_MEMORY,
+                               "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+                       r = pClocaleMap->Add(pClocaleId.get(), pDummyValue.get());
+                       SysTryReturn(NID_LCL, r == E_SUCCESS, null, r,
+                               "[%s] It is failed to add the clocale id into the clocale map.", GetErrorMessage(r));
+                       pClocaleId.release();
+                       pDummyValue.release();
+               }
+       }while(1);
+       return pClocaleMap.release();
+}
+
 IList*
 _LocaleManagerImpl::GetAvailableLocalesN(void)
 {
@@ -295,32 +161,34 @@ _LocaleManagerImpl::GetAvailableLocalesN(void)
        int count = 0;
        const U_ICU_NAMESPACE::Locale* pIcuLocaleList = U_ICU_NAMESPACE::Locale::getAvailableLocales(count);
        SysTryReturn(NID_LCL, count > 0, null, E_SYSTEM,
-                               "[%s] The method cannot proceed due to a severe system error.", GetErrorMessage(E_SYSTEM));
+               "[%s] The method cannot proceed due to a severe system error.", GetErrorMessage(E_SYSTEM));
 
-       std::unique_ptr<LinkedList, AllElementsDeleter> pAvailableLocaleList(new (std::nothrow) LinkedList());
+       std::unique_ptr<LinkedList> pAvailableLocaleList(new (std::nothrow) LinkedList(SingleObjectDeleter));
        SysTryReturn(NID_LCL, pAvailableLocaleList, null, E_OUT_OF_MEMORY,
-                               "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
+               "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       std::unique_ptr< IMap > pClocaleMap(GetAvailableEglibcLocaesN());
 
        for (int i = 0; i < count; i++)
        {
-               SysTryReturn(NID_LCL, (pIcuLocaleList + i) != null, null, E_SYSTEM,
-                                       "[%s] The method cannot proceed due to a severe system error.",GetErrorMessage(E_SYSTEM));
-
-               Locale ospLocale = _LocaleImpl(*(pIcuLocaleList + i)).GetOspLocale();
+               const U_ICU_NAMESPACE::Locale* pIcuLocale = (pIcuLocaleList + i);
+               SysTryReturn(NID_LCL, pIcuLocale, null, E_SYSTEM,
+                       "[%s] The method cannot proceed due to a severe system error.",GetErrorMessage(E_SYSTEM));
+               Locale ospLocale = _LocaleImpl(*pIcuLocale).GetOspLocale();
                if (_LocaleImpl::IsSupported(ospLocale))
                {
-                       Locale* pLocale = new (std::nothrow) Locale(ospLocale);
+                       std::unique_ptr< Locale > pLocale(new (std::nothrow) Locale(ospLocale));
                        SysTryReturn(NID_LCL, pLocale, null, E_OUT_OF_MEMORY,
                                                "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
-                       if (!pAvailableLocaleList->Contains(*pLocale))
+
+                       String localeId(pIcuLocale->getLanguage());
+                       localeId = localeId + L"_" + String(pIcuLocale->getCountry());
+
+                       if (!pAvailableLocaleList->Contains(*(pLocale.get())) && pClocaleMap->ContainsKey(localeId))
                        {
-                               r = pAvailableLocaleList->Add(*pLocale);
-                               if (IsFailed(r))
-                               {
-                                       delete pLocale;
-                                       SetLastResult(E_SYSTEM);
-                                       return null;
-                               }
+                               r = pAvailableLocaleList->Add(pLocale.get());
+                               SysTryReturn(NID_LCL, !IsFailed(r), null, E_SYSTEM, "It is failed to make the locale list");
+                               pLocale.release();
                        }
                }
        }
@@ -346,18 +214,17 @@ _LocaleManagerImpl::GetSelectedLanguage(void)
 IList*
 _LocaleManagerImpl::GetAvailableLanguagesN(void)
 {
-       xmlDocPtr doc;
-       xmlNodePtr cur;
+       std::unique_ptr<ArrayList> pAvailableLanguageList(new (std::nothrow) ArrayList(SingleObjectDeleter));
+       SysTryReturn(NID_LCL, pAvailableLanguageList, null, E_OUT_OF_MEMORY,"[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
 
-       std::unique_ptr<ArrayList, AllElementsDeleter> pAvailableLanguageList(new (std::nothrow) ArrayList());
-       SysTryCatch(NID_LCL, pAvailableLanguageList, null, E_OUT_OF_MEMORY,"[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
+       xmlNodePtr cur = null;
+       std::unique_ptr< xmlDoc, FreeXmlDoc > pDoc(xmlParseFile(LANGUAGE_LIST_FILE_PATH));
 
-       doc = xmlParseFile(LANGLIST_FILE_PATH);
-       SysTryCatch(NID_LCL, doc != null, , E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] It is failed to get the langlist from the resource.");
+       SysTryReturn(NID_LCL, pDoc, null, E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] It is failed to get the langlist from the resource.");
 
-       cur = xmlDocGetRootElement(doc);
-       SysTryCatch(NID_LCL, cur != null, , E_EMPTY_BODY, "[E_EMPTY_BODY] It is empty document.");
-       SysTryCatch(NID_LCL, xmlStrcmp(cur->name, (const xmlChar *) "langlist") == 0, , E_INVALID_CONTENT, "[E_INVALID_CONTENT] The document is wrong type");
+       cur = xmlDocGetRootElement(pDoc.get());
+       SysTryReturn(NID_LCL, cur != null, null, E_EMPTY_BODY, "[E_EMPTY_BODY] It is empty document.");
+       SysTryReturn(NID_LCL, xmlStrcmp(cur->name, (const xmlChar *) "langlist") == 0, null, E_INVALID_CONTENT, "[E_INVALID_CONTENT] The document is wrong type");
 
        cur = cur->xmlChildrenNode;
 
@@ -367,75 +234,68 @@ _LocaleManagerImpl::GetAvailableLanguagesN(void)
        {
                if (cur_node->type == XML_ELEMENT_NODE)
                {
-                       char* pLocId = (char*)xmlGetProp(cur_node, (const xmlChar *)"id");
-                       Locale loc = _LocaleImpl(pLocId).GetOspLocale();
+                       std::unique_ptr < char, FreeCharPtr > pLocId((char*)xmlGetProp(cur_node, (const xmlChar *)"id"));
+                       Locale loc = _LocaleImpl(pLocId.get()).GetOspLocale();
                        std::unique_ptr<String> pLanguageLocaleID(new (std::nothrow) String(loc.GetLanguageCodeString()));
-                       SysTryCatch(NID_LCL, pLanguageLocaleID, null, E_OUT_OF_MEMORY,"[%s] Memory allocation failed",GetErrorMessage(E_OUT_OF_MEMORY));
+                       SysTryReturn(NID_LCL, pLanguageLocaleID, null, E_OUT_OF_MEMORY,"[%s] Memory allocation failed",GetErrorMessage(E_OUT_OF_MEMORY));
 
-                       result r = pAvailableLanguageList->Add(pLanguageLocaleID.get());
-                       SysTryCatch(NID_LCL, r == E_SUCCESS, null, E_SYSTEM,
+                       if (!pAvailableLanguageList->Contains(*(pLanguageLocaleID.get())))
+                       {
+                               result r = pAvailableLanguageList->Add(pLanguageLocaleID.get());
+                               SysTryReturn(NID_LCL, r == E_SUCCESS, null, E_SYSTEM,
                                        "[%s] It is failed to add a locale string [%ls].", GetErrorMessage(E_SYSTEM), pLanguageLocaleID->GetPointer());
-                       pLanguageLocaleID.release();
+                               pLanguageLocaleID.release();
+                       }
                }
        }
 
        SetLastResult(E_SUCCESS);
-
-       if (doc)
-       {
-               xmlFreeDoc(doc);
-       }
-
        return pAvailableLanguageList.release();
-
-CATCH:
-       if (doc)
-       {
-               xmlFreeDoc(doc);
-       }
-       SysLog(NID_LCL, "It is calling fallback api.");
-       return GetAvailableLanguagesFallBackN();
 }
 
-
 IList*
-_LocaleManagerImpl::GetAvailableLanguagesFallBackN(void)
+_LocaleManagerImpl::GetAvailableLanguageLocalesN(void)
 {
-       std::unique_ptr<IList, AllElementsDeleter> pLocaleList (GetAvailableLocalesN());
-       std::unique_ptr<HashMap> pLanguageMap(new (std::nothrow) HashMap());
+       std::unique_ptr<ArrayList> pAvailableLanguageList(new (std::nothrow) ArrayList(SingleObjectDeleter));
+       SysTryReturn(NID_LCL, pAvailableLanguageList, null, E_OUT_OF_MEMORY,"[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
 
-       SysTryReturn(NID_LCL, pLanguageMap, null, E_OUT_OF_MEMORY,"[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
+       xmlNodePtr cur = null;
+       std::unique_ptr< xmlDoc, FreeXmlDoc > pDoc(xmlParseFile(LANGUAGE_LIST_FILE_PATH));
+       SysTryReturn(NID_LCL, pDoc != null, null, E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] It is failed to get the langlist from the resource.");
 
-       pLanguageMap->Construct();
+       cur = xmlDocGetRootElement(pDoc.get());
+       SysTryReturn(NID_LCL, cur != null, null, E_EMPTY_BODY, "[E_EMPTY_BODY] It is empty document.");
+       SysTryReturn(NID_LCL, xmlStrcmp(cur->name, (const xmlChar *) "langlist") == 0, null, E_INVALID_CONTENT, "[E_INVALID_CONTENT] The document is wrong type");
 
-       for (int i = 0; i < pLocaleList->GetCount() ; i++)
-       {
-               Locale* pLocale = (Locale*)pLocaleList->GetAt(i);
-               std::unique_ptr<String> pLanguageCode(new (std::nothrow) String(pLocale->GetLanguageCodeString()));
-               SysTryReturn(NID_LCL, pLanguageCode, null, E_OUT_OF_MEMORY,"[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
-
-               if (!pLanguageMap->ContainsKey(*pLanguageCode))
-               {
-                       std::unique_ptr<String> pDummyValue(new (std::nothrow) String());
-                       SysTryReturn(NID_LCL, pDummyValue, null, E_OUT_OF_MEMORY,"[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
+       cur = cur->xmlChildrenNode;
 
-                       result r = pLanguageMap->Add(*(pLanguageCode.get()), *(pDummyValue.get()));
+       pAvailableLanguageList->Construct();
 
-                       if (IsFailed(r))
+       for (xmlNodePtr cur_node = cur; cur_node; cur_node = cur_node->next)
+       {
+               if (cur_node->type == XML_ELEMENT_NODE)
+               {
+                       std::unique_ptr< char, FreeCharPtr> pLocId((char*)xmlGetProp(cur_node, (const xmlChar *)"id"));
+                       Locale loc = _LocaleImpl(pLocId.get()).GetOspLocale();
+                       if (_LocaleImpl::IsSupported(loc))
                        {
-                               SetLastResult(E_SYSTEM);
-                               return null;
+                               std::unique_ptr< Locale > pLocale(new (std::nothrow) Locale(loc));
+                               SysTryReturn(NID_LCL, pLocale, null, E_OUT_OF_MEMORY,
+                                       "[%s] Memory allocation failed",GetErrorMessage(E_OUT_OF_MEMORY));
+
+                               if (!pAvailableLanguageList->Contains(*(pLocale.get())))
+                               {
+                                       result r = pAvailableLanguageList->Add(pLocale.get());
+                                       SysTryReturn(NID_LCL, r == E_SUCCESS, null, E_SYSTEM,
+                                               "[%s] It is failed to add a locale string [%s].", GetErrorMessage(E_SYSTEM), pLocId.get());
+                                       pLocale.release();
+                               }
                        }
-                       pLanguageCode.release();
-                       pDummyValue.release();
                }
        }
 
-       IList* pAvailableLanguageList;
-       pAvailableLanguageList = pLanguageMap->GetKeysN();
        SetLastResult(E_SUCCESS);
-       pLanguageMap->RemoveAll();
-       return pAvailableLanguageList;
+       return pAvailableLanguageList.release();
 }
 
 
@@ -443,109 +303,146 @@ IMap*
 _LocaleManagerImpl::GetAvailableTimeZonesN(U_ICU_NAMESPACE::StringEnumeration* pIcuTZStrList)
 {
        SysTryReturn(NID_LCL, pIcuTZStrList, null, E_SYSTEM,
-                               "[%s] The method cannot proceed due to a severe system error.",GetErrorMessage(E_SYSTEM));
+               "[%s] The method cannot proceed due to a severe system error.",GetErrorMessage(E_SYSTEM));
 
-        std::unique_ptr<HashMap, AllElementsDeleter> pTimeZoneMap(new (std::nothrow) HashMap());
-
-        SysTryReturn(NID_LCL, pTimeZoneMap, null, E_OUT_OF_MEMORY,
-                        "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
+        std::unique_ptr<HashMap> pTimeZoneMap(new (std::nothrow) HashMap(SingleObjectDeleter));
+       SysTryReturn(NID_LCL, pTimeZoneMap, null, E_OUT_OF_MEMORY,
+               "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
         pTimeZoneMap->Construct();
+
        result r = E_SUCCESS;
        int resultLength = -1;
        UErrorCode ec = U_ZERO_ERROR;
        const char* pIcuTZStr = pIcuTZStrList->next(&resultLength, ec);
-       IMap* pTZMap = GetAvailableTimeZonesN();
-
+       std::unique_ptr<IMap> pTZMap(GetAvailableTimeZonesN());
        r = GetLastResult();
        SysTryReturn(NID_LCL, pTZMap, null, r, "[%s] Fail to get available time zone list", GetErrorMessage(r));
 
        while (pIcuTZStr != null)
        {
-               String* pTimeZone = new (std::nothrow) String(pIcuTZStr);
+               std::unique_ptr< String > pTimeZone(new (std::nothrow) String(pIcuTZStr));
                SysTryReturn(NID_LCL, pTimeZone, null, E_OUT_OF_MEMORY,
                                        "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-               if (!pTimeZoneMap->ContainsKey(*pTimeZone) && pTZMap->ContainsKey(*pTimeZone))
+               if (!pTimeZoneMap->ContainsKey(*(pTimeZone.get())) && pTZMap->ContainsKey(*(pTimeZone.get())))
                {
-                       String* pDummyValue = new  (std::nothrow) String();
-                        r = pTimeZoneMap->Add(*pTimeZone, *pDummyValue);
-                       if (IsFailed(r))
-                       {
-                               delete pTimeZone;
-                                delete pDummyValue;
-                               pTZMap->RemoveAll();
-                               SetLastResult(E_SYSTEM);
-                               return null;
-                       }
+                       std::unique_ptr< String > pDummyValue(new  (std::nothrow) String());
+                       SysTryReturn(NID_LCL, pDummyValue, null, E_OUT_OF_MEMORY,"[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+                        r = pTimeZoneMap->Add(pTimeZone.get(), pDummyValue.get());
+                       SysTryReturn(NID_LCL, !IsFailed(r), null, E_SYSTEM, "[E_SYSTEM] It is failed to add a TZ into Map.");
+                       pTimeZone.release();
+                       pDummyValue.release();
                }
 
                pIcuTZStr = pIcuTZStrList->next(&resultLength, ec);
        }
        SetLastResult(E_SUCCESS);
-       pTZMap->RemoveAll();
        return pTimeZoneMap.release();
 }
 
+
 IMap*
 _LocaleManagerImpl::GetAvailableTimeZonesN(void)
 {
-       std::unique_ptr<HashMap, AllElementsDeleter> pTimeZoneMap(new (std::nothrow) HashMap());
+       File file;
+       String tzFilePath(TIMEZONE_LIST_FILE_PATH);
+       result r = E_SUCCESS;
 
+       std::unique_ptr<HashMap> pTimeZoneMap(new (std::nothrow) HashMap(SingleObjectDeleter));
        SysTryReturn(NID_LCL, pTimeZoneMap, null, E_OUT_OF_MEMORY,
                        "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
-
-       result r = E_SUCCESS;
-       int index = 0;
+       r = file.Construct(tzFilePath, "r");
+       SysTryReturn(NID_LCL, r == E_SUCCESS, null, E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] It is failed to get the tzlist from the ini file.");
 
        pTimeZoneMap->Construct();
 
        do
        {
-               String* pTimeZone = new (std::nothrow) String(TimeZoneList[index++]);
+               std::unique_ptr<String> pTimeZone(new (std::nothrow) String());
                SysTryReturn(NID_LCL, pTimeZone, null, E_OUT_OF_MEMORY,
                                "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+               r = file.Read(*(pTimeZone.get()));
+               if ( r == E_END_OF_FILE)
+               {
+                       break;
+               }
+               SysTryReturn(NID_LCL, r == E_SUCCESS, null, r, "[%s] It is failed to read the tzlist.", GetErrorMessage(r));
+               pTimeZone->Replace(L"\n", L"\0");
 
-               if (!pTimeZoneMap->ContainsKey(*pTimeZone))
+               if (!pTimeZoneMap->ContainsKey(*(pTimeZone.get())))
                {
-                       String* pDummyValue = new  (std::nothrow) String();
+                       std::unique_ptr<String> pDummyValue(new (std::nothrow) String());
+                       SysTryReturn(NID_LCL, pDummyValue, null, E_OUT_OF_MEMORY,
+                                       "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
-                       r = pTimeZoneMap->Add(*pTimeZone, *pDummyValue);
-                       if (IsFailed(r))
-                       {
-                               delete pTimeZone;
-                               delete pDummyValue;
-                               SetLastResult(E_SYSTEM);
-                               return null;
-                       }
+                       r = pTimeZoneMap->Add(pTimeZone.get(), pDummyValue.get());
+                       SysTryReturn(NID_LCL, r == E_SUCCESS, null, r,"[%s] It is failed to make the tz list.", GetErrorMessage(r));
+                       pTimeZone.release();
+                       pDummyValue.release();
                }
-       }while (index < TIMEZONE_MAX);
+       }while (1);
 
        SetLastResult(E_SUCCESS);
        return pTimeZoneMap.release();
 }
 
+
 IMap*
 _LocaleManagerImpl::GetAvailableTimeZonesN(int rawOffset)
 {
-       return GetAvailableTimeZonesN(U_ICU_NAMESPACE::TimeZone::createEnumeration(rawOffset * _TimeZoneImpl::ONE_MIN_IN_MILLISEC));
+       std::unique_ptr<U_ICU_NAMESPACE::StringEnumeration> pIcuTzList(U_ICU_NAMESPACE::TimeZone::createEnumeration(rawOffset * _TimeZoneImpl::ONE_MIN_IN_MILLISEC));
+       SysTryReturn(NID_LCL, pIcuTzList, null, E_SYSTEM, "[E_SYSTEM] It is failed to get Icu TZ list.");
+       IMap* pTzList =  GetAvailableTimeZonesN(pIcuTzList.get());
+       return pTzList;
 }
 
 
 TimeZone
 _LocaleManagerImpl::GetSystemTimeZone(void)
 {
-       char tz[PATH_MAX + 1];
-       int len = readlink("/opt/etc/localtime", tz, PATH_MAX);
+       char* pTZPath = null;
+       char* pTZID = null;
+       TimeZone timeZone;
+        DateTime utcTime;
+        struct tm gmTime;
+        struct tm*  pGmTime = null;
+        time_t currTime = time(null);
+       result r = E_SUCCESS;
+       ssize_t nLen = -1;
 
-       SysTryReturn(NID_LCL, len > 0, TimeZone(-1, ""), E_SYSTEM, "It is failed to get System Time Zone");
-       tz[len] = '\0';
-       SysTryReturn(NID_LCL, len > 20, TimeZone(-1, ""), E_SYSTEM, "It is failed to get System Time Zone");
+       pTZPath = (char*)malloc(sizeof(char) * 256);
+       SysTryCatch(NID_LCL, pTZPath, , E_OUT_OF_MEMORY, "It is not enough memory.");
 
-       String tzId(tz + 20);
-       SysLog(NID_LCL, "System TimeZone id [%ls]", tzId.GetPointer());
-       TimeZone timeZone;
-       result r = Tizen::Locales::TimeZone::GetTimeZone(tzId, timeZone);
-       SysTryReturn(NID_LCL, r == E_SUCCESS, TimeZone(-1, ""), r, "[%s] error occurs.", GetErrorMessage(r));
+       nLen = readlink("/opt/etc/localtime", pTZPath, 255);
+
+       if (nLen > 20)
+       {
+               pTZPath[nLen] = '\0';
+               pTZID = pTZPath + 20;
+       }
+       else
+       {
+               pTZID = vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_ID);
+               SysTryCatch(NID_LCL, pTZID, , E_SYSTEM, "It is failed to get System Time Zone.");
+               free(pTZPath);
+               pTZPath = pTZID;
+       }
+
+       pGmTime = gmtime_r(&currTime, &gmTime);
+       SysTryCatch(NID_LCL, pGmTime, , E_SYSTEM, "It is failed to convert the time value to UTC time.");
+
+       utcTime.SetValue(gmTime.tm_year + 1900, gmTime.tm_mon + 1, gmTime.tm_mday, gmTime.tm_hour, gmTime.tm_min, gmTime.tm_sec);
+
+       r = Tizen::Locales::TimeZone::GetTimeZone(String(pTZID), utcTime, timeZone);
+       SysTryCatch(NID_LCL, r == E_SUCCESS, , r, "[%s] error occurs.", GetErrorMessage(r));
+       free(pTZPath);
        return timeZone;
+
+CATCH:
+       if (pTZPath)
+       {
+               free(pTZPath);
+       }
+       return TimeZone(-1, "");
 }
 
 result