Get a available language list from xml.
authorHokwon Song <hokwon.song@samsung.com>
Fri, 12 Apr 2013 02:54:06 +0000 (11:54 +0900)
committerHokwon Song <hokwon.song@samsung.com>
Fri, 12 Apr 2013 02:57:50 +0000 (11:57 +0900)
Change-Id: I6c575d6cd65f3c1abd2aaae1c9192dbf09a002c9
Signed-off-by: Hokwon Song <hokwon.song@samsung.com>
src/locales/FLcl_LocaleManagerImpl.cpp
src/locales/inc/FLcl_LocaleManagerImpl.h

index ff97ee7..714aca0 100644 (file)
@@ -24,6 +24,8 @@
 #include <runtime_info.h>
 #include <unicode/calendar.h>
 #include <unicode/timezone.h>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
 
 #include <FBaseSysLog.h>
 #include <FBase_StringConverter.h>
@@ -39,7 +41,7 @@ using namespace Tizen::Base::Collection;
 
 namespace Tizen { namespace Locales
 {
-
+static const char* LANGLIST_FILE_PATH ="/opt/data/setting/langlist.xml";
 static const int TIMEZONE_MAX = 224;
 static const char* TimeZoneList[TIMEZONE_MAX] =
 {
@@ -344,11 +346,65 @@ _LocaleManagerImpl::GetSelectedLanguage(void)
 IList*
 _LocaleManagerImpl::GetAvailableLanguagesN(void)
 {
-       result r = E_SUCCESS;
+       xmlDocPtr doc;
+       xmlNodePtr cur;
+
+       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));
+
+       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.");
+
+       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 = cur->xmlChildrenNode;
+
+       pAvailableLanguageList->Construct();
+
+       for (xmlNodePtr cur_node = cur; cur_node; cur_node = cur_node->next)
+       {
+               if (cur_node->type == XML_ELEMENT_NODE)
+               {
+                       char* pLocId = (char*)xmlGetProp(cur_node, (const xmlChar *)"id");
+                       Locale loc = _LocaleImpl(pLocId).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));
+
+                       result r = pAvailableLanguageList->Add(pLanguageLocaleID.get());
+                       SysTryCatch(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();
+               }
+       }
+
+       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)
+{
        std::unique_ptr<IList, AllElementsDeleter> pLocaleList (GetAvailableLocalesN());
        std::unique_ptr<HashMap> pLanguageMap(new (std::nothrow) HashMap());
 
-        SysTryReturn(NID_LCL, pLanguageMap, 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));
 
        pLanguageMap->Construct();
 
@@ -363,11 +419,11 @@ _LocaleManagerImpl::GetAvailableLanguagesN(void)
                        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 = pLanguageMap->Add(*(pLanguageCode.get()), *(pDummyValue.get()));
+                       result r = pLanguageMap->Add(*(pLanguageCode.get()), *(pDummyValue.get()));
 
                        if (IsFailed(r))
                        {
-                               SetLastResult(E_UNSUPPORTED_OPERATION);
+                               SetLastResult(E_SYSTEM);
                                return null;
                        }
                        pLanguageCode.release();
index 1c8b5e4..ff0b3ec 100644 (file)
@@ -42,8 +42,11 @@ public:
 
        static Tizen::Locales::Locale GetSystemLocale(void);
        static Tizen::Base::Collection::IList* GetAvailableLocalesN(void);
+
        static Tizen::Base::String GetSelectedLanguage(void);
        static Tizen::Base::Collection::IList* GetAvailableLanguagesN(void);
+       static Tizen::Base::Collection::IList* GetAvailableLanguagesFallBackN(void);
+
        static Tizen::Base::Collection::IMap* GetAvailableTimeZonesN(void);
        static Tizen::Base::Collection::IMap* GetAvailableTimeZonesN(int rawOffset);