Merge "Fixed a defect of GsmEncoding" into tizen_2.1
[platform/framework/native/appfw.git] / src / app / inc / FAppPkg_PackageParser.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        FAppPkg_PackageParser.h
20  * @brief       This is the header file for the _PackageParser class.
21 */
22
23 #ifndef _FAPP_PKG_INTERNAL_PACKAGE_PARSER_H_
24 #define _FAPP_PKG_INTERNAL_PACKAGE_PARSER_H_
25
26 #include <libxml/xmlstring.h>
27
28 namespace Tizen { namespace App { namespace Package
29 {
30
31 class _PackageInfoImpl;
32 class _PackageAppInfoImpl;
33
34 class _PackageXmlAttribute
35 {
36 public:
37         _PackageXmlAttribute(void);
38         virtual ~_PackageXmlAttribute(void);
39
40         bool Construct(const char* pName, const char* pValue);
41
42         char* Find(const char* pName);
43         bool Add(const char* pName, const char* pValue);
44
45 private:
46         _PackageXmlAttribute(const _PackageXmlAttribute& value);
47         _PackageXmlAttribute& operator =(const _PackageXmlAttribute& source);
48
49         char* __pName;
50         char* __pValue;
51         _PackageXmlAttribute* __pNext;
52
53 }; // _PackageXmlAttribute
54
55
56 class _PackageXmlHandler
57 {
58 public:
59         _PackageXmlHandler(void);
60         virtual ~_PackageXmlHandler(void);
61
62         virtual bool OnStartDocument(void);
63         virtual bool OnEndDocument(void);
64         virtual bool OnStartElement(const char* pName);
65         virtual bool OnEndElement(const char* pName);
66         virtual bool OnCharacters(const char* pCharacters);
67
68         void SetError(void);
69         bool GetError(void);
70
71         char* GetElementName(void);
72         _PackageXmlAttribute* GetAttribute(void);
73         Tizen::Base::Collection::IEnumerator* GetElementEnumeratorN(void);
74         int GetElementCount(void);
75
76 protected:
77         bool ParseNormalizedDocument(const char* pFilepath);
78         int Normalize(const char* pBuf, int size, char* pNormalizedBuf);
79
80         bool SetElementName(const char* pElementName);
81         void DeleteElement(void);
82
83         bool SetCharacters(const char* pCharacter);
84         char* GetCharacters(void);
85         void DeleteCharacters(void);
86
87         void SetAttribute(_PackageXmlAttribute* pAttr);
88         void DeleteAttribute(void);
89
90 private:
91         _PackageXmlHandler(const _PackageXmlHandler& value);
92         _PackageXmlHandler& operator =(const _PackageXmlHandler& source);
93
94         static void StartDocument(void* pCtx);
95         static void EndDocument(void* pCtx);
96
97         static void StartElement(void* pCtx, const xmlChar* pName, const xmlChar** ppAtts);
98         static void EndElement(void* pCtx, const xmlChar* pName);
99         static void Characters(void* pCtx, const xmlChar* pCh, int len);
100
101         _PackageXmlAttribute* __pAttr;
102         char* __pElementName;
103         char* __pCharacters;
104         bool __error;
105
106         Tizen::Base::Collection::Stack __elementStack;
107
108 }; // _PackageXmlHandler
109
110
111 class _PackageParser
112         : public _PackageXmlHandler
113 {
114 public:
115         _PackageParser(void);
116         virtual ~_PackageParser(void);
117
118         bool Construct(PackageInfo* pPackageInfo);
119         bool Parse(const Tizen::Base::String& packagepath);
120
121 private:
122         _PackageParser(const _PackageParser& value);
123         _PackageParser& operator =(const _PackageParser& source);
124
125         virtual bool OnStartElement(const char* pName);
126         virtual bool OnEndElement(const char* pName);
127         virtual bool OnCharacters(const char* pCharacters);
128
129         bool OnUiAppStartElement(void);
130         bool OnServiceAppStartElement(void);
131         bool OnIconsStartElement(void);
132
133         bool OnUiAppEndElement(void);
134         bool OnServiceAppEndElement(void);
135         bool OnDisplayNamesEndElement(void);
136
137         bool OnIdValue(const char* pCharacters);
138         bool OnVersionValue(const char* pCharacters);
139         bool OnAuthorValue(const char* pCharacters);
140         bool OnUrlValue(const char* pCharacters);
141         bool OnPrivilegeValue(const char* pCharacters);
142         bool OnIconValue(const char* pCharacters);
143         bool OnDisplayNameValue(const char* pCharacters);
144         bool OnDescriptionValue(const char* pCharacters);
145         bool OnCategoryValue(const char* pCharacters);
146
147         bool ParseAppAttribute(_PackageXmlAttribute* pAttr, bool isUiApp);
148
149 private:
150         _PackageInfoImpl* __pPackageInfoImpl;
151         PackageAppInfo* __pAppInfo;
152
153         Tizen::Base::String __packagePath;
154
155         char* __pDefaultIconType;
156         bool __isDefaultName;
157 }; // _PackageParser
158
159 } } } // Tizen::App::Package
160
161 #endif // _FAPP_PKG_INTERNAL_PACKAGE_PARSER_H_