Fix the boiler plate codes
[platform/framework/native/appfw.git] / src / app / inc / FAppPkg_PackageParser.h
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        FAppPkg_PackageParser.h
19  * @brief       This is the header file for the _PackageParser class.
20 */
21
22 #ifndef _FAPP_PKG_INTERNAL_PACKAGE_PARSER_H_
23 #define _FAPP_PKG_INTERNAL_PACKAGE_PARSER_H_
24
25 #include <libxml/xmlstring.h>
26
27 namespace Tizen { namespace App { namespace Package
28 {
29
30 class _PackageInfoImpl;
31 class _PackageAppInfoImpl;
32
33 class _PackageXmlAttribute
34 {
35 public:
36         _PackageXmlAttribute(void);
37         virtual ~_PackageXmlAttribute(void);
38
39         bool Construct(const char* pName, const char* pValue);
40
41         char* Find(const char* pName);
42         bool Add(const char* pName, const char* pValue);
43
44 private:
45         _PackageXmlAttribute(const _PackageXmlAttribute& value);
46         _PackageXmlAttribute& operator =(const _PackageXmlAttribute& source);
47
48         char* __pName;
49         char* __pValue;
50         _PackageXmlAttribute* __pNext;
51
52 }; // _PackageXmlAttribute
53
54
55 class _PackageXmlHandler
56 {
57 public:
58         _PackageXmlHandler(void);
59         virtual ~_PackageXmlHandler(void);
60
61         virtual bool OnStartDocument(void);
62         virtual bool OnEndDocument(void);
63         virtual bool OnStartElement(const char* pName);
64         virtual bool OnEndElement(const char* pName);
65         virtual bool OnCharacters(const char* pCharacters);
66
67         void SetError(void);
68         bool GetError(void);
69
70         char* GetElementName(void);
71         _PackageXmlAttribute* GetAttribute(void);
72         Tizen::Base::Collection::IEnumerator* GetElementEnumeratorN(void);
73         int GetElementCount(void);
74
75 protected:
76         bool ParseNormalizedDocument(const char* pFilepath);
77         int Normalize(const char* pBuf, int size, char* pNormalizedBuf);
78
79         bool SetElementName(const char* pElementName);
80         void DeleteElement(void);
81
82         bool SetCharacters(const char* pCharacter);
83         char* GetCharacters(void);
84         void DeleteCharacters(void);
85
86         void SetAttribute(_PackageXmlAttribute* pAttr);
87         void DeleteAttribute(void);
88
89 private:
90         _PackageXmlHandler(const _PackageXmlHandler& value);
91         _PackageXmlHandler& operator =(const _PackageXmlHandler& source);
92
93         static void StartDocument(void* pCtx);
94         static void EndDocument(void* pCtx);
95
96         static void StartElement(void* pCtx, const xmlChar* pName, const xmlChar** ppAtts);
97         static void EndElement(void* pCtx, const xmlChar* pName);
98         static void Characters(void* pCtx, const xmlChar* pCh, int len);
99
100         _PackageXmlAttribute* __pAttr;
101         char* __pElementName;
102         char* __pCharacters;
103         bool __error;
104
105         Tizen::Base::Collection::Stack __elementStack;
106
107 }; // _PackageXmlHandler
108
109
110 class _PackageParser
111         : public _PackageXmlHandler
112 {
113 public:
114         _PackageParser(void);
115         virtual ~_PackageParser(void);
116
117         bool Construct(PackageInfo* pPackageInfo);
118         bool Parse(const Tizen::Base::String& packagepath);
119
120 private:
121         _PackageParser(const _PackageParser& value);
122         _PackageParser& operator =(const _PackageParser& source);
123
124         virtual bool OnStartElement(const char* pName);
125         virtual bool OnEndElement(const char* pName);
126         virtual bool OnCharacters(const char* pCharacters);
127
128         bool OnUiAppStartElement(void);
129         bool OnServiceAppStartElement(void);
130         bool OnIconsStartElement(void);
131
132         bool OnUiAppEndElement(void);
133         bool OnServiceAppEndElement(void);
134         bool OnDisplayNamesEndElement(void);
135
136         bool OnIdValue(const char* pCharacters);
137         bool OnVersionValue(const char* pCharacters);
138         bool OnAuthorValue(const char* pCharacters);
139         bool OnUrlValue(const char* pCharacters);
140         bool OnPrivilegeValue(const char* pCharacters);
141         bool OnIconValue(const char* pCharacters);
142         bool OnDisplayNameValue(const char* pCharacters);
143         bool OnDescriptionValue(const char* pCharacters);
144         bool OnCategoryValue(const char* pCharacters);
145
146         bool ParseAppAttribute(_PackageXmlAttribute* pAttr, bool isUiApp);
147
148 private:
149         _PackageInfoImpl* __pPackageInfoImpl;
150         PackageAppInfo* __pAppInfo;
151
152         Tizen::Base::String __packagePath;
153
154         char* __pDefaultIconType;
155         bool __isDefaultName;
156 }; // _PackageParser
157
158 } } } // Tizen::App::Package
159
160 #endif // _FAPP_PKG_INTERNAL_PACKAGE_PARSER_H_