Change systeminfo api
[platform/framework/native/appfw.git] / src / app / package / FAppPkg_PackageParser.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  * @file        FAppPkg_PackageParser.cpp
18  * @brief       This is the implementation for the _PackageParser class.
19  */
20
21 #include <libxml/parserInternals.h>
22 #include <system_info.h>
23
24 #include <FAppPkgPackageAppInfo.h>
25 #include <FBaseSysLog.h>
26 #include <FIoFile.h>
27 #include <FIoDirectory.h>
28 #include <FAppPkg_PackageAppInfoImpl.h>
29 #include <FAppPkg_PackageInfoImpl.h>
30 #include <FAppPkg_PackageParser.h>
31 #include <FBase_StringConverter.h>
32
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
35 using namespace Tizen::Base::Utility;
36 using namespace Tizen::App;
37 using namespace Tizen::Io;
38 using namespace Tizen::System;
39
40 namespace Tizen { namespace App { namespace Package
41 {
42
43 _PackageXmlAttribute::_PackageXmlAttribute(void)
44 :__pName(null)
45 ,__pValue(null)
46 ,__pNext(null)
47 {
48 }
49
50 _PackageXmlAttribute::~_PackageXmlAttribute(void)
51 {
52         delete[] __pName;
53         delete[] __pValue;
54         delete __pNext;
55 }
56
57 bool
58 _PackageXmlAttribute::Construct(const char* pName, const char* pValue)
59 {
60         if (pName == 0 || pValue == 0)
61         {
62                 return true;
63         }
64
65         __pName = new (std::nothrow) char[strlen(pName)+1];
66         SysTryReturn(NID_APP, __pName, false, E_OUT_OF_MEMORY, "__pName is null");
67         strcpy(__pName, pName);
68
69         __pValue = new (std::nothrow) char[strlen(pValue)+1];
70         SysTryReturn(NID_APP, __pValue, false, E_OUT_OF_MEMORY, "__pValue is null");
71         strcpy(__pValue, pValue);
72
73         return true;
74 }
75
76 char*
77 _PackageXmlAttribute::Find(const char* pName)
78 {
79         if (pName == 0)
80         {
81                 return null;
82         }
83
84         if (__pName == 0 || __pValue == 0)
85         {
86                 return null;
87         }
88
89         if (strcasecmp(pName, __pName) == 0)
90         {
91                 return __pValue;
92         }
93
94         if (__pNext)
95         {
96                 return __pNext->Find(pName);
97         }
98
99         return null;
100 }
101
102 bool
103 _PackageXmlAttribute::Add(const char* pName, const char* pValue)
104 {
105         if (pName == 0 || pValue == 0)
106         {
107                 return true;
108         }
109
110         if (__pNext)
111         {
112                 _PackageXmlAttribute* pNext = __pNext;
113                 while (pNext->__pNext)
114                 {
115                         pNext = pNext->__pNext;
116                 }
117
118                 return pNext->Add(pName, pValue);
119         }
120         else
121         {
122                 __pNext = new (std::nothrow) _PackageXmlAttribute();
123                 SysTryReturn(NID_APP, __pNext, false, E_OUT_OF_MEMORY, "__pNext is null");
124
125                 __pNext->Construct(pName, pValue);
126         }
127
128         return true;
129 }
130
131
132 _PackageXmlHandler::_PackageXmlHandler(void)
133 :__pAttr(null)
134 ,__pElementName(null)
135 ,__pCharacters(null)
136 ,__error(false)
137 {
138 }
139
140 _PackageXmlHandler::~_PackageXmlHandler(void)
141 {
142         delete __pAttr;
143         __pAttr = null;
144
145         delete[] __pElementName;
146         __pElementName = null;
147 }
148
149 bool
150 _PackageXmlHandler::OnStartDocument(void)
151 {
152         return true;
153 }
154
155 bool
156 _PackageXmlHandler::OnEndDocument(void)
157 {
158         return true;
159 }
160
161 bool
162 _PackageXmlHandler::OnStartElement(const char* pName)
163 {
164         return true;
165 }
166
167 bool
168 _PackageXmlHandler::OnEndElement(const char* pName)
169 {
170         return true;
171 }
172
173 bool
174 _PackageXmlHandler::OnCharacters(const char* pCharacters)
175 {
176         return true;
177 }
178
179 void
180 _PackageXmlHandler::StartElement(void* pCtx, const xmlChar* pName, const xmlChar** ppAtts)
181 {
182         if (pName == 0)
183         {
184                 return;
185         }
186
187         _PackageXmlHandler* pHandler = null;
188         pHandler = (_PackageXmlHandler*) pCtx;
189         bool xmlResult = false;
190
191         pHandler->SetElementName((const char *) pName);
192
193         if (ppAtts)
194         {
195                 _PackageXmlAttribute* pAttr = 0;
196
197                 if (ppAtts[0] != null && ppAtts[1] != null)
198                 {
199                         pAttr = new (std::nothrow) _PackageXmlAttribute();
200                         SysTryReturnVoidResult(NID_APP, pAttr, E_OUT_OF_MEMORY, "pAttr is null.");
201
202                         pAttr->Construct((const char *)ppAtts[0], (const char *)ppAtts[1]);
203                         ppAtts = &ppAtts[2];
204                 }
205
206                 while (ppAtts != null && ppAtts[0] != null && ppAtts[1] != null)
207                 {
208                         pAttr->Add((const char *)ppAtts[0], (const char *)ppAtts[1]);
209                         ppAtts = &ppAtts[2];
210                 }
211
212                 pHandler->SetAttribute(pAttr);
213         }
214
215         xmlResult = pHandler->OnStartElement((const char *)pName);
216         if (xmlResult == false)
217         {
218                 pHandler->SetError();
219         }
220 }
221
222 void
223 _PackageXmlHandler::EndElement(void* pCtx, const xmlChar* pName)
224 {
225         _PackageXmlHandler* pHandler = null;
226         pHandler = (_PackageXmlHandler*) pCtx;
227         bool xmlResult = false;
228         char* pCharacters = pHandler->GetCharacters();
229
230         if (pCharacters && (strlen(pCharacters) > 0))
231         {
232                 xmlResult = pHandler->OnCharacters(pCharacters);
233                 if (xmlResult == false)
234                 {
235                         pHandler->SetError();
236                 }
237         }
238
239         xmlResult = pHandler->OnEndElement((const char *)pName);
240         if (xmlResult == false)
241         {
242                 pHandler->SetError();
243         }
244
245         pHandler->DeleteElement();
246         pHandler->DeleteAttribute();
247         pHandler->DeleteCharacters();
248 }
249
250 void
251 _PackageXmlHandler::Characters(void* pCtx, const xmlChar* pCh, int len)
252 {
253         SysTryReturnVoidResult(NID_APP, pCh, E_SYSTEM, "pCh is null.");
254
255         _PackageXmlHandler* pHandler = null;
256         pHandler = (_PackageXmlHandler*) pCtx;
257         char* pCharacters = null;
258
259         if (pCh[0] == 0x20 || pCh[0] == 0x09 || pCh[0] == 0x0D || pCh[0] == 0x0A)
260         {
261                 return;
262         }
263
264         pCharacters = new (std::nothrow) char[len+1];
265         SysTryReturnVoidResult(NID_APP, pCharacters, E_OUT_OF_MEMORY, "pCharacters is null.");
266
267         strncpy(pCharacters, (const char *)pCh, len);
268         pCharacters[len] = 0;
269
270         pHandler->SetCharacters(pCharacters);
271
272         delete[] pCharacters;
273 }
274
275 bool
276 _PackageXmlHandler::ParseNormalizedDocument(const char* pFilepath)
277 {
278         xmlSAXHandler* pSAXHandler = null;
279         xmlParserCtxtPtr ctxt = 0;
280         bool ret = true;
281         File file;
282         FileAttributes attr;
283         result r = E_SUCCESS;
284         char* pBuf = null;
285         char* pNormalizedBuf = null;
286         int size = 0;
287         int normalizedSize = 0;
288         int readSize = 0;
289
290         r = file.Construct(pFilepath, L"r");
291         TryCatch(r == E_SUCCESS, ret = false, "file.Construct is failed. [%s]", pFilepath);
292
293         r = file.GetAttributes(pFilepath, attr);
294         TryCatch(IsFailed(r) == false, ret = false, "file.GetAttributes is failed. [%s]", pFilepath);
295
296         size = (int)attr.GetFileSize();
297         TryCatch(size > 0, ret = false, "size is invalid. [%s]", pFilepath);
298
299         pBuf = new (std::nothrow) char[size+1];
300         TryCatch(pBuf, ret = false, "pBuf is null");
301
302         pNormalizedBuf = new (std::nothrow) char[size+1];
303         TryCatch(pNormalizedBuf, ret = false, "pNormalizedBuf is null");
304
305         memset(pBuf, 0, size+1);
306         memset(pNormalizedBuf, 0, size+1);
307
308         readSize = file.Read(pBuf, size);
309         TryCatch(readSize > 0, ret = false, "file.Read is failed. [%s][%d]", pFilepath, readSize);
310
311         normalizedSize = Normalize(pBuf, size, pNormalizedBuf);
312         TryCatch(normalizedSize > 0, ret = false, "normalizedSize [%d]", readSize);
313
314         ctxt = xmlCreateMemoryParserCtxt(pNormalizedBuf, normalizedSize);
315         TryCatch(ctxt, ret = false, "invalid xml file, %s", pFilepath);
316
317         pSAXHandler = new (std::nothrow) xmlSAXHandler;
318         TryCatch(pSAXHandler, ret = false, "pSAXHandler is null");
319         memset(pSAXHandler, 0, sizeof(xmlSAXHandler));
320
321         ctxt->userData = (void *)this;
322
323         pSAXHandler->startElement = _PackageXmlHandler::StartElement;
324         pSAXHandler->endElement = _PackageXmlHandler::EndElement;
325         pSAXHandler->characters = _PackageXmlHandler::Characters;
326
327         ctxt->sax = pSAXHandler;
328
329         xmlParseDocument(ctxt);
330         xmlFreeParserCtxt(ctxt);
331
332         TryCatch(GetError() != true, ret = false, "xml parsing error is occurred.");
333
334 CATCH:
335         delete[] pBuf;
336         delete[] pNormalizedBuf;
337
338         return ret;
339 }
340
341 int
342 _PackageXmlHandler::Normalize(const char* pBuf, int size, char* pNormalizedBuf)
343 {
344         int idx = 0;
345         int normalizedIdx = 0;
346
347         while (pBuf[idx] && idx < size)
348         {
349                 if (pBuf[idx] == 0x0D)
350                 {
351                         if (pBuf[idx + 1] == 0x0A)
352                         {
353                                 idx++;
354                         }
355                         pNormalizedBuf[normalizedIdx] = 0x0A;
356                         normalizedIdx++;
357                 }
358                 else if((pBuf[idx] == 0X0A) && (pBuf[idx + 1] == 0x4d) && (pBuf[idx - 1] == 0x3E))
359                 {
360                         idx++;
361                         pNormalizedBuf[normalizedIdx] = pBuf[idx];
362                         normalizedIdx++;
363                 }
364                 else
365                 {
366                         pNormalizedBuf[normalizedIdx] = pBuf[idx];
367                         normalizedIdx++;
368                 }
369
370                 idx++;
371         }
372
373         return normalizedIdx;
374 }
375
376 bool
377 _PackageXmlHandler::SetElementName(const char* pElementName)
378 {
379         SysTryReturn(NID_APP, pElementName, false, E_SYSTEM, "pElementName is null");
380
381         if (__pElementName)
382         {
383                 delete[] __pElementName;
384                 __pElementName = null;
385         }
386
387         __pElementName = new (std::nothrow) char[strlen(pElementName)+1];
388         SysTryReturn(NID_APP, __pElementName, false, E_OUT_OF_MEMORY, "__pElementName is null");
389         strcpy(__pElementName, pElementName);
390
391         __elementStack.Push(*new (std::nothrow) String(pElementName));
392
393         return true;
394 }
395
396 char*
397 _PackageXmlHandler::GetElementName(void)
398 {
399         return __pElementName;
400 }
401
402 void
403 _PackageXmlHandler::DeleteElement(void)
404 {
405         delete[]__pElementName;
406         __pElementName = 0;
407
408         __elementStack.Pop();
409 }
410
411 bool
412 _PackageXmlHandler::SetCharacters(const char* pCharacter)
413 {
414         SysTryReturn(NID_APP, pCharacter, false, E_SYSTEM, "pCharacter is null");
415
416         if (__pCharacters == null)
417         {
418                 __pCharacters = new (std::nothrow) char[4096];
419                 SysTryReturn(NID_APP, __pCharacters, false, E_OUT_OF_MEMORY, "__pCharacters is null");
420
421                 memset(__pCharacters, 0, 4096);
422         }
423
424         strncat(__pCharacters, pCharacter, strlen(pCharacter));
425
426         return true;
427 }
428
429 char*
430 _PackageXmlHandler::GetCharacters(void)
431 {
432         return __pCharacters;
433 }
434
435 void
436 _PackageXmlHandler::DeleteCharacters(void)
437 {
438         delete[] __pCharacters;
439         __pCharacters = null;
440 }
441
442 void
443 _PackageXmlHandler::SetAttribute(_PackageXmlAttribute* pAttr)
444 {
445         __pAttr = pAttr;
446 }
447
448 _PackageXmlAttribute*
449 _PackageXmlHandler::GetAttribute(void)
450 {
451         return __pAttr;
452 }
453
454 void
455 _PackageXmlHandler::DeleteAttribute(void)
456 {
457         delete __pAttr;
458         __pAttr = null;
459 }
460
461 IEnumerator*
462 _PackageXmlHandler::GetElementEnumeratorN(void)
463 {
464         return __elementStack.GetEnumeratorN();
465 }
466
467 int
468 _PackageXmlHandler::GetElementCount(void)
469 {
470         return __elementStack.GetCount();
471 }
472
473 void
474 _PackageXmlHandler::SetError(void)
475 {
476         __error = true;
477 }
478
479 bool
480 _PackageXmlHandler::GetError(void)
481 {
482         return __error;
483 }
484
485
486 _PackageParser::_PackageParser(void)
487 :__pPackageInfoImpl(null)
488 ,__pAppInfo(null)
489 ,__pDefaultIconType(null)
490 ,__isDefaultName(false)
491 {
492 }
493
494 _PackageParser::~_PackageParser(void)
495 {
496         delete[] __pDefaultIconType;
497         __pDefaultIconType = null;
498 }
499
500 bool
501 _PackageParser::Construct(PackageInfo* pPackageInfo)
502 {
503         SysTryReturn(NID_APP, pPackageInfo, false, E_INVALID_ARG, "pPackageInfo is null.");
504
505         _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo);
506         SysTryReturn(NID_APP, pPackageInfoImpl, false, E_SYSTEM, "pPackageInfoImpl is null.");
507
508         __pPackageInfoImpl = pPackageInfoImpl;
509         return true;
510 }
511
512 bool
513 _PackageParser::Parse(const String& packagepath)
514 {
515         __packagePath = packagepath;
516
517         bool res = true;
518         FileUnzipper unzipper;
519
520         Directory::Remove("/tmp/__manifest/", true);
521         Directory::Create("/tmp/__manifest/", false);
522
523         result r = unzipper.Construct(packagepath);
524         SysTryReturn(NID_APP, !IsFailed(r), false, E_SYSTEM, "unzipper.Construct() failed.");
525
526         r = unzipper.UnzipTo(L"/tmp/__manifest", L"info/manifest.xml");
527         SysTryReturn(NID_APP, !IsFailed(r), false, E_SYSTEM, "unzipper.UnzipTo() failed.");
528
529         res = ParseNormalizedDocument("/tmp/__manifest/info/manifest.xml");
530
531         Directory::Remove("/tmp/__manifest/", true);
532
533         return res;
534 }
535
536 bool
537 _PackageParser::OnStartElement(const char* pName)
538 {
539         SysTryReturn(NID_APP, pName, true, E_SYSTEM, "pName is null.");
540
541         bool status = true;
542
543         if (strcasecmp(pName, "UiApp") == 0)
544         {
545                 status = OnUiAppStartElement();
546         }
547         else if (strcasecmp(pName, "ServiceApp") == 0)
548         {
549                 status = OnServiceAppStartElement();
550         }
551         else if (strcasecmp(pName, "Icons") == 0)
552         {
553                 status = OnIconsStartElement();
554         }
555
556         if (!status)
557         {
558                 return false;
559         }
560
561         return true;
562 }
563
564 bool
565 _PackageParser::OnEndElement(const char* pName)
566 {
567         SysTryReturn(NID_APP, pName, true, E_SYSTEM, "pName is null.");
568
569         bool status = true;
570
571         if (strcasecmp(pName, "UiApp") == 0)
572         {
573                 status = OnUiAppEndElement();
574         }
575         else if (strcasecmp(pName, "ServiceApp") == 0)
576         {
577                 status = OnServiceAppEndElement();
578         }
579         else if (strcasecmp(pName, "DisplayNames") == 0)
580         {
581                 status = OnDisplayNamesEndElement();
582         }
583
584         if (!status)
585         {
586                 return false;
587         }
588
589         return true;
590 }
591
592 bool
593 _PackageParser::OnCharacters(const char* pCharacters)
594 {
595         bool status = true;
596
597         char* pName = GetElementName();
598         SysTryReturn(NID_APP, pName, false, E_SYSTEM, "pName is null.");
599
600         if (strcasecmp(pName, "Id") == 0)
601         {
602                 status = OnIdValue(pCharacters);
603         }
604         else if (strcasecmp(pName, "Version") == 0)
605         {
606                 status = OnVersionValue(pCharacters);
607         }
608         else if (strcasecmp(pName, "Url") == 0)
609         {
610                 status = OnUrlValue(pCharacters);
611         }
612         else if (strcasecmp(pName, "Privilege") == 0)
613         {
614                 status = OnPrivilegeValue(pCharacters);
615         }
616         else if (strcasecmp(pName, "DisplayName") == 0)
617         {
618                 status = OnDisplayNameValue(pCharacters);
619         }
620         else if (strcasecmp(pName, "Author") == 0)
621         {
622                 status = OnAuthorValue(pCharacters);
623         }
624         else if (strcasecmp(pName, "Description") == 0)
625         {
626                 status = OnDescriptionValue(pCharacters);
627         }
628         else if (strcasecmp(pName, "Icon") == 0)
629         {
630                 status = OnIconValue(pCharacters);
631         }
632         else if (strcasecmp(pName, "Category") == 0)
633         {
634                 status = OnCategoryValue(pCharacters);
635         }
636
637         if (!status)
638         {
639                 return false;
640         }
641
642         return true;
643 }
644
645 bool
646 _PackageParser::OnUiAppStartElement(void)
647 {
648         __pAppInfo = new (std::nothrow) PackageAppInfo;
649         SysTryReturn(NID_APP, __pAppInfo, false, E_OUT_OF_MEMORY, "__pAppInfo is null.");
650
651         _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(__pAppInfo);
652         SysTryReturn(NID_APP, pPackageAppInfoImpl, false, E_SYSTEM, "pPackageAppInfoImpl is null.");
653
654         _PackageXmlAttribute* pAttr = GetAttribute();
655         SysTryReturn(NID_APP, pAttr, true, E_SYSTEM, "pAttr is null");
656
657         ParseAppAttribute(pAttr, true);
658
659         return true;
660 }
661
662 bool
663 _PackageParser::OnServiceAppStartElement(void)
664 {
665         __pAppInfo = new (std::nothrow) PackageAppInfo;
666         SysTryReturn(NID_APP, __pAppInfo, false, E_OUT_OF_MEMORY, "__pAppInfo is null.");
667
668         _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(__pAppInfo);
669         SysTryReturn(NID_APP, pPackageAppInfoImpl, false, E_SYSTEM, "pPackageAppInfoImpl is null.");
670
671         _PackageXmlAttribute* pAttr = GetAttribute();
672         SysTryReturn(NID_APP, pAttr, true, E_SYSTEM, "pAttr is null");
673
674         ParseAppAttribute(pAttr, false);
675
676         return true;
677 }
678
679 bool
680 _PackageParser::OnIconsStartElement(void)
681 {
682         int res = 0;
683         int width = 0;
684         String defaultIconType;
685
686         res = system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_WIDTH, &width);
687         if (res != SYSTEM_INFO_ERROR_NONE)
688         {
689                 SysLog(NID_APP, "system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_WIDTH) failed. res = [%d]", res);
690                 defaultIconType = L"Xhigh";
691         }
692         else
693         {
694                 if (width == 480)
695                 {
696                         defaultIconType = L"High";
697                 }
698                 else
699                 {
700                         defaultIconType = L"Xhigh";
701                 }
702         }
703
704         __pDefaultIconType = _StringConverter::CopyToCharArrayN(defaultIconType);
705         SysTryReturn(NID_APP, __pDefaultIconType, false, E_OUT_OF_MEMORY, "__pDefaultIconType is null.");
706
707         SysLog(NID_APP, "ScreenWidth = [%d], DefaultIconType = [%s]", width, __pDefaultIconType);
708
709         return true;
710 }
711
712 bool
713 _PackageParser::OnUiAppEndElement(void)
714 {
715         __pPackageInfoImpl->AddPackageAppInfo(*__pAppInfo);
716         __pAppInfo = null;
717
718         __isDefaultName = false;
719
720         return true;
721 }
722
723 bool
724 _PackageParser::OnServiceAppEndElement(void)
725 {
726         __pPackageInfoImpl->AddPackageAppInfo(*__pAppInfo);
727         __pAppInfo = null;
728
729         __isDefaultName = false;
730
731         return true;
732 }
733
734 bool
735 _PackageParser::OnDisplayNamesEndElement(void)
736 {
737         // fall-back
738
739         return true;
740 }
741
742 bool
743 _PackageParser::OnIdValue(const char* pCharacters)
744 {
745         SysLog(NID_APP, "Id = [%s]", pCharacters);
746         __pPackageInfoImpl->SetId(pCharacters);
747
748         return true;
749 }
750
751 bool
752 _PackageParser::OnVersionValue(const char* pCharacters)
753 {
754         SysLog(NID_APP, "Version = [%s]", pCharacters);
755         __pPackageInfoImpl->SetVersion(pCharacters);
756
757         return true;
758 }
759
760 bool
761 _PackageParser::OnAuthorValue(const char* pCharacters)
762 {
763         SysLog(NID_APP, "Author = [%s]", pCharacters);
764         __pPackageInfoImpl->SetAuthor(pCharacters);
765
766         return true;
767 }
768
769 bool
770 _PackageParser::OnUrlValue(const char* pCharacters)
771 {
772         SysLog(NID_APP, "Url = [%s]", pCharacters);
773         __pPackageInfoImpl->SetUrl(pCharacters);
774
775         return true;
776 }
777
778 bool
779 _PackageParser::OnPrivilegeValue(const char* pCharacters)
780 {
781         SysLog(NID_APP, "Privilege = [%s]", pCharacters);
782         __pPackageInfoImpl->AddPrivilege(*new (std::nothrow) String(pCharacters));
783
784         return true;
785 }
786
787 bool
788 _PackageParser::OnIconValue(const char* pCharacters)
789 {
790         SysTryReturn(NID_APP, __pDefaultIconType, false, E_SYSTEM, "__pDefaultIconType is null");
791
792         _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(__pAppInfo);
793         SysTryReturn(NID_APP, pPackageAppInfoImpl, false, E_SYSTEM, "pPackageAppInfoImpl is null.");
794
795         _PackageXmlAttribute* pAttr = GetAttribute();
796         SysTryReturn(NID_APP, pAttr, true, E_SYSTEM, "pAttr is null");
797
798         char* pSection = pAttr->Find("Section");
799         SysTryReturn(NID_APP, pSection, true, E_SYSTEM, "pSection is null");
800
801         String iconRelPath;
802         String tempIconPath;
803
804         if (strcasecmp(__pDefaultIconType, "Xhigh") == 0)
805         {
806                 iconRelPath.Format(1024, L"shared/res/screen-density-xhigh/%s", pCharacters);
807         }
808         else if (strcasecmp(__pDefaultIconType, "High") == 0)
809         {
810                 iconRelPath.Format(1024, L"shared/res/screen-density-high/%s", pCharacters);
811         }
812         else
813         {
814                 SysTryReturn(NID_APP, 0, false, E_SYSTEM, "Invalid __pDefaultIconType [%s]", __pDefaultIconType);
815         }
816
817         if (strcasecmp(pSection, "MainMenu") == 0)
818         {
819                 FileUnzipper unzipper;
820                 String tmp(L"/tmp/__icon/");
821                 Directory::Remove(tmp, true);
822                 Directory::Create(tmp, false);
823
824                 result r = unzipper.Construct(__packagePath);
825                 SysTryReturn(NID_APP, !IsFailed(r), false, E_SYSTEM, "unzipper.Construct() failed.");
826
827                 r = unzipper.UnzipTo(tmp, iconRelPath);
828                 if (!IsFailed(r))
829                 {
830                         tempIconPath = tmp + iconRelPath;
831                         pPackageAppInfoImpl->SetAppTempIconPath(tempIconPath);
832                 }
833                 else
834                 {
835                         SysLog(NID_APP, "UnzipTo() is failed.");
836                 }
837         }
838
839         SysLog(NID_APP, "Section = [%s], Icon = [%ls], TempIcon = [%ls]", pSection, iconRelPath.GetPointer(), tempIconPath.GetPointer());
840
841         return true;
842 }
843
844 bool
845 _PackageParser::OnDisplayNameValue(const char* pCharacters)
846 {
847         _PackageXmlAttribute* pAttr = 0;
848         char* pAttrValue = 0;
849
850         _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(__pAppInfo);
851         SysTryReturn(NID_APP, pPackageAppInfoImpl, false, E_SYSTEM, "pPackageAppInfoImpl is null.");
852
853         pAttr = GetAttribute();
854         SysTryReturn(NID_APP, pAttr, true, E_SYSTEM, "pAttr is null");
855
856         pAttrValue = pAttr->Find("Locale");
857         SysTryReturn(NID_APP, pAttrValue, true, E_SYSTEM, "pAttrValue is null");
858
859         if (strcasecmp(pAttrValue, "eng-GB") == 0 || strcasecmp(pAttrValue, "eng-US") == 0)
860         {
861                 pPackageAppInfoImpl->SetAppDisplayName(pCharacters);
862
863                 if (__isDefaultName == true)
864                 {
865                         __pPackageInfoImpl->SetDisplayName(pCharacters);
866                 }
867         }
868
869         String* pValue = new (std::nothrow) String;
870         StringUtil::Utf8ToString(pCharacters, *pValue);
871
872         pPackageAppInfoImpl->AddName(*(new (std::nothrow) String(pAttrValue)), *pValue);
873
874         SysLog(NID_APP, "DisplayName Locale = [%s][%s]", pAttrValue, pCharacters);
875
876         return true;
877 }
878
879 bool
880 _PackageParser::OnDescriptionValue(const char* pCharacters)
881 {
882         _PackageXmlAttribute *pAttr = 0;
883         char *pAttrValue = 0;
884
885         pAttr = GetAttribute();
886         SysTryReturn(NID_APP, pAttr, true, E_SYSTEM, "pAttr is null");
887
888         pAttrValue = pAttr->Find("Locale");
889         SysTryReturn(NID_APP, pAttrValue, true, E_SYSTEM, "pAttrValue is null");
890
891         if (strcasecmp(pAttrValue, "eng-GB") == 0 || strcasecmp(pAttrValue, "eng-US") == 0)
892         {
893                 __pPackageInfoImpl->SetDescription(pCharacters);
894         }
895
896         SysLog(NID_APP, "Description Locale =[%s][%s]", pAttrValue, pCharacters);
897
898         return true;
899 }
900
901 bool
902 _PackageParser::OnCategoryValue(const char* pCharacters)
903 {
904         _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(__pAppInfo);
905         SysTryReturn(NID_APP, pPackageAppInfoImpl, false, E_SYSTEM, "pPackageAppInfoImpl is null.");
906
907         pPackageAppInfoImpl->AddCategory(new (std::nothrow) String(pCharacters));
908
909         SysLog(NID_APP, "Category = [%s]", pCharacters);
910
911         return true;
912 }
913
914 bool
915 _PackageParser::ParseAppAttribute(_PackageXmlAttribute* pAttr, bool isUiApp)
916 {
917         _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(__pAppInfo);
918         SysTryReturn(NID_APP, pPackageAppInfoImpl, false, E_SYSTEM, "pPackageAppInfoImpl is null.");
919
920         char* pName = pAttr->Find("Name");
921         SysTryReturn(NID_APP, pName, true, E_SYSTEM, "pName is null");
922
923         SysLog(NID_APP, "Name = [%s]", pName);
924         pPackageAppInfoImpl->SetAppName(pName);
925
926         AppId appId = __pPackageInfoImpl->GetId() + L"." + pName;
927         pPackageAppInfoImpl->SetAppId(appId);
928
929         char* pMain = pAttr->Find("Main");
930         if (pMain)
931         {
932                 SysLog(NID_APP, "Main = [%s]", pMain);
933                 if (strcasecmp(pMain, "True") == 0)
934                 {
935                         __isDefaultName = true;
936                         __pPackageInfoImpl->SetMainAppId(appId);
937                         pPackageAppInfoImpl->SetMainApp(true);
938                 }
939         }
940
941         if (isUiApp == true)
942         {
943                 char* pMenuIconVisible = pAttr->Find("MenuIconVisible");
944                 if (pMenuIconVisible)
945                 {
946                         if (strcasecmp(pMenuIconVisible, "True") == 0)
947                         {
948                                 pPackageAppInfoImpl->SetMenuIconVisible(true);
949                         }
950                         else
951                         {
952                                 pPackageAppInfoImpl->SetMenuIconVisible(false);
953                         }
954
955                         SysLog(NID_APP, "MenuIconVisible = [%s]", pMenuIconVisible);
956                 }
957         }
958         else
959         {
960                 pPackageAppInfoImpl->SetMenuIconVisible(false);
961         }
962
963         return true;
964 }
965
966 } } } // Tizen::App::Package