|
1 /* |
|
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * CScrXmlParser - Used to retrieve details from xml files for creating database and |
|
16 * Software environment updates. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 /** |
|
22 @file |
|
23 @released |
|
24 @internalTechnology |
|
25 */ |
|
26 |
|
27 #ifndef XMLPARSER_H |
|
28 #define XMLPARSER_H |
|
29 #pragma warning(disable: 4786) |
|
30 #pragma warning(disable: 4291) |
|
31 |
|
32 #include <vector> |
|
33 #include <string> |
|
34 |
|
35 #include <xercesc/parsers/XercesDOMParser.hpp> |
|
36 #include <xercesc/sax/ErrorHandler.hpp> |
|
37 #include <xercesc/dom/DOM.hpp> |
|
38 |
|
39 #include "toolsconf.h" |
|
40 |
|
41 /** |
|
42 * This template is used to cleanup memory by calling a function as pointed |
|
43 * by the first parameter as a function parameter. It can be used only used |
|
44 * with functions which take a pointer to a pointer as an argument. This is |
|
45 * currently a limitation as the xerces library takes the same to release |
|
46 * its own memory. |
|
47 */ |
|
48 |
|
49 template <typename tFnPtr, typename tPtr> class fn_auto_ptr |
|
50 { |
|
51 public: |
|
52 explicit fn_auto_ptr(tFnPtr aFnPtr, tPtr* aPtr) |
|
53 : iFnPtr(aFnPtr), |
|
54 iPtr(aPtr) |
|
55 {} |
|
56 |
|
57 ~fn_auto_ptr() { iFnPtr(&iPtr); } |
|
58 |
|
59 tPtr *get() const throw() |
|
60 { |
|
61 return (iPtr); |
|
62 } |
|
63 |
|
64 private: |
|
65 tFnPtr iFnPtr; |
|
66 tPtr* iPtr; |
|
67 }; |
|
68 |
|
69 |
|
70 template <typename tFnPtr, typename tPtr> class mem_fn_auto_ptr |
|
71 { |
|
72 public: |
|
73 |
|
74 explicit mem_fn_auto_ptr(tFnPtr aFnPtr, tPtr aPtr) |
|
75 : iFnPtr(aFnPtr), |
|
76 iPtr(aPtr) |
|
77 {} |
|
78 |
|
79 ~mem_fn_auto_ptr() { (iPtr->*iFnPtr)(); } |
|
80 |
|
81 tPtr operator->() const throw() |
|
82 { |
|
83 return (get()); |
|
84 } |
|
85 |
|
86 tPtr get() const throw() |
|
87 { |
|
88 return (iPtr); |
|
89 } |
|
90 |
|
91 private: |
|
92 tFnPtr iFnPtr; |
|
93 tPtr iPtr; |
|
94 }; |
|
95 |
|
96 template <typename tFnPtr> class static_fn_auto_ptr |
|
97 { |
|
98 public: |
|
99 |
|
100 explicit static_fn_auto_ptr(tFnPtr aFnPtr) |
|
101 : iFnPtr(aFnPtr) |
|
102 {} |
|
103 |
|
104 ~static_fn_auto_ptr() { &iFnPtr; } |
|
105 |
|
106 private: |
|
107 tFnPtr iFnPtr; |
|
108 }; |
|
109 |
|
110 namespace XmlDetails |
|
111 { |
|
112 struct TScrEnvironmentDetails |
|
113 { |
|
114 public: |
|
115 TScrEnvironmentDetails() |
|
116 :iSifPluginUid(0), |
|
117 iInstallerSid(0), |
|
118 iExecutionLayerSid(0) |
|
119 {} |
|
120 |
|
121 class TLocalizedSoftwareTypeName |
|
122 { |
|
123 public: |
|
124 TLocalizedSoftwareTypeName() |
|
125 :iLocale(0) |
|
126 {} |
|
127 |
|
128 int iLocale; |
|
129 std::wstring iName; |
|
130 }; |
|
131 |
|
132 std::wstring iUniqueSoftwareTypeName; |
|
133 std::vector<TLocalizedSoftwareTypeName> iLocalizedSoftwareTypeNames; |
|
134 int iSifPluginUid; |
|
135 int iInstallerSid; |
|
136 int iExecutionLayerSid; |
|
137 std::vector<std::wstring> iMIMEDetails; |
|
138 }; |
|
139 |
|
140 |
|
141 class TScrPreProvisionDetail |
|
142 { |
|
143 public: |
|
144 TScrPreProvisionDetail() |
|
145 {} |
|
146 |
|
147 class TComponentLocalizable |
|
148 { |
|
149 |
|
150 public: |
|
151 TComponentLocalizable() |
|
152 :iLocale(0) |
|
153 {} |
|
154 |
|
155 int iLocale; |
|
156 std::wstring iName; |
|
157 std::wstring iVendor; |
|
158 }; |
|
159 |
|
160 class TComponentProperty |
|
161 { |
|
162 |
|
163 public: |
|
164 TComponentProperty() |
|
165 :iLocale(0), |
|
166 iIsIntValue(false), |
|
167 iIsStr8Bit(false) |
|
168 {} |
|
169 |
|
170 public: |
|
171 std::wstring iName; |
|
172 int iLocale; |
|
173 std::wstring iValue; |
|
174 bool iIsIntValue; |
|
175 int iIsStr8Bit; |
|
176 }; |
|
177 |
|
178 class TComponentDependency |
|
179 { |
|
180 public: |
|
181 class TComponentDependencyDetail |
|
182 { |
|
183 public: |
|
184 std::wstring iSupplierId; |
|
185 std::wstring iFromVersion; |
|
186 std::wstring iToVersion; |
|
187 }; |
|
188 |
|
189 public: |
|
190 std::wstring iDependentId; |
|
191 std::vector<TComponentDependencyDetail> iComponentDependencyList; |
|
192 }; |
|
193 |
|
194 class TComponentFile |
|
195 { |
|
196 public: |
|
197 TComponentFile() |
|
198 {} |
|
199 |
|
200 struct TFileProperty |
|
201 { |
|
202 public: |
|
203 TFileProperty() |
|
204 :iIsIntValue(false) |
|
205 {} |
|
206 std::wstring iName; |
|
207 std::wstring iValue; |
|
208 bool iIsIntValue; |
|
209 }; |
|
210 |
|
211 std::wstring iLocation; |
|
212 std::vector<TFileProperty> iFileProperties; |
|
213 |
|
214 }; |
|
215 |
|
216 class TComponentDetails |
|
217 { |
|
218 public: |
|
219 TComponentDetails() |
|
220 |
|
221 :iIsRemovable(1), |
|
222 iSize(0), |
|
223 iScomoState(1), |
|
224 iOriginVerified(1), |
|
225 iIsHidden(0) |
|
226 {} |
|
227 |
|
228 class TVersion |
|
229 { |
|
230 public: |
|
231 |
|
232 TVersion() |
|
233 {} |
|
234 |
|
235 public: |
|
236 std::wstring iMajor; |
|
237 std::wstring iMinor; |
|
238 std::wstring iBuild; |
|
239 }; |
|
240 |
|
241 int iIsRemovable; |
|
242 __int64 iSize; |
|
243 int iScomoState; |
|
244 std::wstring iGlobalId; |
|
245 TVersion iVersion; |
|
246 int iOriginVerified; |
|
247 int iIsHidden; |
|
248 }; |
|
249 |
|
250 class TComponent |
|
251 { |
|
252 public: |
|
253 TComponent() |
|
254 :iComponentDetails() |
|
255 {} |
|
256 |
|
257 std::vector<TComponentLocalizable> iComponentLocalizables; |
|
258 std::vector<TComponentProperty> iComponentProperties; |
|
259 std::vector<TComponentFile> iComponentFiles; |
|
260 TComponentDependency iComponentDependency; |
|
261 TComponentDetails iComponentDetails; |
|
262 }; |
|
263 |
|
264 std::wstring iSoftwareTypeName; |
|
265 std::vector<TComponent> iComponents; |
|
266 |
|
267 }; |
|
268 } |
|
269 |
|
270 class CScrXmlParser |
|
271 { |
|
272 |
|
273 public: |
|
274 |
|
275 /** |
|
276 * Initializes the xml parser and logging feature based on supplied logging parameters. |
|
277 */ |
|
278 DllExport CScrXmlParser(); |
|
279 |
|
280 /** |
|
281 * Frees allocated memory. |
|
282 */ |
|
283 DllExport ~CScrXmlParser(); |
|
284 |
|
285 /** |
|
286 * Retrieves the database schema for database creation, from the supplied database file. |
|
287 */ |
|
288 DllExport std::vector<std::string>* ParseDbSchema(const std::string& aDbFile); |
|
289 |
|
290 /** |
|
291 * Retrieves software environment details, from the supplied xml file. |
|
292 */ |
|
293 DllExport std::vector<XmlDetails::TScrEnvironmentDetails>* GetEnvironmentDetails(const std::string aEnvDetailFile ); |
|
294 |
|
295 XmlDetails::TScrPreProvisionDetail GetPreProvisionDetails( const std::string aPreProvisionFile ); |
|
296 |
|
297 private: |
|
298 |
|
299 /** |
|
300 * Called while retrieving s/w environment details. |
|
301 */ |
|
302 |
|
303 XmlDetails::TScrEnvironmentDetails GetEnvironmentData( const XERCES_CPP_NAMESPACE::DOMElement* aDOMElement); |
|
304 |
|
305 XmlDetails::TScrPreProvisionDetail::TComponent GetPreProvisionData( const XERCES_CPP_NAMESPACE::DOMElement* aDOMElement); |
|
306 |
|
307 XmlDetails::TScrPreProvisionDetail::TComponentLocalizable GetComponentLocalizable( const XERCES_CPP_NAMESPACE::DOMElement* aDOMElement); |
|
308 |
|
309 XmlDetails::TScrPreProvisionDetail::TComponentProperty GetComponentProperty( const XERCES_CPP_NAMESPACE::DOMElement* aDOMElement); |
|
310 |
|
311 XmlDetails::TScrPreProvisionDetail::TComponentFile GetComponentFile( const XERCES_CPP_NAMESPACE::DOMElement* aDOMElement); |
|
312 |
|
313 XmlDetails::TScrPreProvisionDetail::TComponentDependency GetComponentDependency( const XERCES_CPP_NAMESPACE::DOMElement* aDOMElement); |
|
314 |
|
315 XmlDetails::TScrPreProvisionDetail::TComponentFile::TFileProperty GetFileProperty( const XERCES_CPP_NAMESPACE::DOMElement* aDOMElement); |
|
316 |
|
317 XmlDetails::TScrPreProvisionDetail::TComponentDetails GetComponentDetails( const XERCES_CPP_NAMESPACE::DOMElement* aDOMElement); |
|
318 |
|
319 XmlDetails::TScrEnvironmentDetails::TLocalizedSoftwareTypeName GetLocalizedSoftwareTypeName( const XERCES_CPP_NAMESPACE::DOMElement* aDOMElement); |
|
320 |
|
321 void ConfigDomParser(xercesc::XercesDOMParser& aDomParser); |
|
322 }; |
|
323 |
|
324 |
|
325 XERCES_CPP_NAMESPACE_BEGIN |
|
326 |
|
327 /** |
|
328 * |
|
329 * SchemaErrorHandler - Implementation of the error handler for xml schema validation. |
|
330 * The parser used, implements this customized error handling interface. |
|
331 * This has been registered with the xml parser in the constructor. The parser |
|
332 * reports all errors and warnings through this interface. |
|
333 */ |
|
334 |
|
335 class SchemaErrorHandler : public ErrorHandler |
|
336 { |
|
337 public: |
|
338 /** |
|
339 * Handles all warnings received while xml parsing. |
|
340 */ |
|
341 void warning (const SAXParseException &exc); |
|
342 |
|
343 /** |
|
344 * Handles all errors received while xml parsing. |
|
345 */ |
|
346 void error (const SAXParseException &exc); |
|
347 |
|
348 /** |
|
349 * Handles all fatal errors received while xml parsing. |
|
350 */ |
|
351 void fatalError (const SAXParseException &exc); |
|
352 |
|
353 /** |
|
354 * Called if an error occurs while reintializing the current xml handler. |
|
355 */ |
|
356 void resetErrors (); |
|
357 }; |
|
358 |
|
359 XERCES_CPP_NAMESPACE_END |
|
360 |
|
361 #endif // _XMLPARSER_H |