|
1 /* |
|
2 * Copyright (c) 2008 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 "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: factory settings for content harvester |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <xcfwtree.h> |
|
21 #include <xcfwengine.h> |
|
22 #include <gecoobjectbase.h> |
|
23 #include <gecodefaultobject.h> |
|
24 #include <e32const.h> |
|
25 #include <liwservicehandler.h> |
|
26 |
|
27 #include "chfactorysettingsparser.h" |
|
28 #include "chfactorysettingsglobals.h" |
|
29 #include "chfactsetutils.h" |
|
30 #include "cpdebug.h" |
|
31 |
|
32 _LIT8( KType, "type" ); |
|
33 _LIT8( KItem, "item" ); |
|
34 _LIT8( KData, "data" ); |
|
35 _LIT8( KAdd, "Add" ); |
|
36 _LIT8( KDelete, "Delete" ); |
|
37 _LIT( KCpData, "cp_data" ); |
|
38 _LIT( KPublisher, "publisher" ); |
|
39 |
|
40 // ============================ MEMBER FUNCTIONS =============================== |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CCHFactorySettingsParser::CCHFactorySettingsParser |
|
44 // C++ default constructor can NOT contain any code, that |
|
45 // might leave. |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 CCHFactorySettingsParser::CCHFactorySettingsParser() |
|
49 { |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CCHFactorySettingsParser::ConstructL |
|
54 // Symbian 2nd phase constructor can leave. |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 void CCHFactorySettingsParser::ConstructL( MLiwInterface* aInterface ) |
|
58 { |
|
59 iActiveScheduler = new ( ELeave ) CActiveSchedulerWait(); |
|
60 |
|
61 iContentEngine = CXCFWEngine::NewL( this ); |
|
62 iCPSInterface = aInterface; |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CCHFactorySettingsParser::NewL |
|
67 // Two-phased constructor. |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 CCHFactorySettingsParser* CCHFactorySettingsParser::NewL( |
|
71 MLiwInterface* aInterface ) |
|
72 { |
|
73 CCHFactorySettingsParser* self = NewLC( aInterface ); |
|
74 CleanupStack::Pop( self ); |
|
75 return self; |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CCHFactorySettingsParser::NewLC |
|
80 // Two-phased constructor. |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 CCHFactorySettingsParser* CCHFactorySettingsParser::NewLC( |
|
84 MLiwInterface* aInterface ) |
|
85 { |
|
86 CCHFactorySettingsParser* self = new( ELeave ) CCHFactorySettingsParser(); |
|
87 CleanupStack::PushL( self ); |
|
88 self->ConstructL( aInterface ); |
|
89 return self; |
|
90 } |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 // Destructor |
|
94 // ----------------------------------------------------------------------------- |
|
95 // |
|
96 CCHFactorySettingsParser::~CCHFactorySettingsParser() |
|
97 { |
|
98 delete iContentTree; |
|
99 delete iContentEngine; |
|
100 delete iActiveScheduler; |
|
101 } |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // CCHFactorySettingsParser::RestoreL |
|
105 // (other items were commented in a header). |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 TInt CCHFactorySettingsParser::RestoreL( const TDesC& aStr, TBool aUnInstall ) |
|
109 { |
|
110 CP_DEBUG(_L8("CCHFactorySettingsParser::RestoreL" )); |
|
111 TInt err; |
|
112 iContentTree = CXCFWTree::NewL( ); |
|
113 |
|
114 iContentEngine->LoadL( *iContentTree, aStr ); |
|
115 |
|
116 iActiveScheduler->Start( ); |
|
117 |
|
118 if ( iCompletionStatus == MADatFactorySettingsObserver::ECompleted ) |
|
119 { |
|
120 //this trap ensures stoping the ActiveSheduler |
|
121 //in case a leave occurs when updating data |
|
122 TRAP( err, HandleEntriesL( aUnInstall ) ); |
|
123 } |
|
124 |
|
125 delete iContentTree; |
|
126 iContentTree = NULL; |
|
127 return err; |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CCHFactorySettingsParser::HandleCompletionL |
|
132 // (other items were commented in a header). |
|
133 // ----------------------------------------------------------------------------- |
|
134 // |
|
135 void CCHFactorySettingsParser::HandleCompletionL( |
|
136 TADatFactorySettingsStatus aStatus ) |
|
137 { |
|
138 CP_DEBUG(_L8("CCHFactorySettingsParser::HandleCompletionL" )); |
|
139 iCompletionStatus = aStatus; |
|
140 iActiveScheduler->AsyncStop( ); |
|
141 } |
|
142 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // CCHFactorySettingsParser::HandleEngineEventL |
|
145 // (other items were commented in a header). |
|
146 // ----------------------------------------------------------------------------- |
|
147 // |
|
148 void CCHFactorySettingsParser::HandleEngineEventL( TXCFWEngineEvent aEvent ) |
|
149 { |
|
150 CP_DEBUG(_L8("CCHFactorySettingsParser::HandleEngineEventL" )); |
|
151 // handle completion |
|
152 if ( aEvent == EEvtParsingComplete ) |
|
153 { |
|
154 TADatFactorySettingsStatus status = |
|
155 MADatFactorySettingsObserver::ECompleted; |
|
156 HandleCompletionL( status ); |
|
157 } |
|
158 |
|
159 // else => ignore |
|
160 } |
|
161 |
|
162 // ----------------------------------------------------------------------------- |
|
163 // CCHFactorySettingsParser::HandleEngineErrorL |
|
164 // (other items were commented in a header). |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 void CCHFactorySettingsParser::HandleEngineErrorL( TInt /*aErrorCode*/) |
|
168 { |
|
169 HandleCompletionL( MADatFactorySettingsObserver::EFailed ); |
|
170 } |
|
171 |
|
172 // ----------------------------------------------------------------------------- |
|
173 // CCHFactorySettingsParser::HandleEntriesL |
|
174 // (other items were commented in a header). |
|
175 // ----------------------------------------------------------------------------- |
|
176 // |
|
177 void CCHFactorySettingsParser::HandleEntriesL( TBool aUnInstall ) |
|
178 { |
|
179 CP_DEBUG(_L8("CCHFactorySettingsParser::HandleEntriesL" )); |
|
180 MXCFWNode* root = iContentTree->Root( ); |
|
181 // get children |
|
182 RNodeArray entries; |
|
183 CleanupClosePushL( entries ); |
|
184 iContentTree->GetChildNodesL( root, entries ); |
|
185 for ( TInt i = 0; i < entries.Count( ); i++ ) |
|
186 { |
|
187 TPtrC typeIdentifier(entries[i]->Data()->TypeIdentifier( )); |
|
188 |
|
189 if ( ( typeIdentifier == KMainDataItem ) |
|
190 || ( typeIdentifier == KMainPublisherItem ) ) |
|
191 { |
|
192 CLiwGenericParamList* inparam = CLiwGenericParamList::NewLC( ); |
|
193 CLiwGenericParamList* outparam = CLiwGenericParamList::NewLC( ); |
|
194 CLiwDefaultMap* map = CLiwDefaultMap::NewLC( ); |
|
195 if ( typeIdentifier == KMainDataItem ) |
|
196 { |
|
197 TLiwGenericParam item_type( KType, TLiwVariant( KCpData )); |
|
198 inparam->AppendL( item_type ); |
|
199 } |
|
200 else |
|
201 { |
|
202 TLiwGenericParam item_type( KType, TLiwVariant( KPublisher )); |
|
203 inparam->AppendL( item_type ); |
|
204 } |
|
205 |
|
206 if ( aUnInstall ) |
|
207 { |
|
208 RemoveItemL( entries[i], map ); |
|
209 TLiwGenericParam item( KData, TLiwVariant( map )); |
|
210 inparam->AppendL( item ); |
|
211 iCPSInterface->ExecuteCmdL( KDelete, *inparam, *outparam ); |
|
212 } |
|
213 else |
|
214 { |
|
215 AddItemL( entries[i], map, EMap ); |
|
216 TLiwGenericParam item( KItem, TLiwVariant( map )); |
|
217 inparam->AppendL( item ); |
|
218 iCPSInterface->ExecuteCmdL( KAdd, *inparam, *outparam ); |
|
219 } |
|
220 CleanupStack::PopAndDestroy( map ); |
|
221 CleanupStack::PopAndDestroy( outparam ); |
|
222 CleanupStack::PopAndDestroy( inparam ); |
|
223 } |
|
224 |
|
225 } |
|
226 // clean up |
|
227 CleanupStack::PopAndDestroy( &entries ); |
|
228 } |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // CCHFactorySettingsParser::AddMapL |
|
232 // (other items were commented in a header). |
|
233 // ----------------------------------------------------------------------------- |
|
234 // |
|
235 void CCHFactorySettingsParser::AddItemL( MXCFWNode* aItem, |
|
236 CLiwContainer* aContainer, TTypes aType ) |
|
237 { |
|
238 CP_DEBUG(_L8("CCHFactorySettingsParser::AddItemL" )); |
|
239 RNodeArray children; |
|
240 CleanupClosePushL( children ); |
|
241 iContentTree->GetChildNodesL( aItem, children ); |
|
242 for ( TInt i = 0; i < children.Count( ); i++ ) |
|
243 { |
|
244 if ( children[i]->Data()->TypeIdentifier( ) == KDataItem ) |
|
245 { |
|
246 switch ( aType ) |
|
247 { |
|
248 case EMap: |
|
249 ExtractAttributesAndAddL( children[i], |
|
250 static_cast<CLiwDefaultMap*>(aContainer) ); |
|
251 break; |
|
252 case EList: |
|
253 ExtractAttributesAndAddL( children[i], |
|
254 static_cast<CLiwDefaultList*>(aContainer ) ); |
|
255 break; |
|
256 default: |
|
257 { |
|
258 User::Panic( _L("Wrong Type" ),1 ); |
|
259 } |
|
260 } |
|
261 |
|
262 } |
|
263 } |
|
264 CleanupStack::PopAndDestroy( &children ); |
|
265 } |
|
266 |
|
267 // ----------------------------------------------------------------------------- |
|
268 // CCHFactorySettingsParser::RemoveItemL |
|
269 // (other items were commented in a header). |
|
270 // ----------------------------------------------------------------------------- |
|
271 // |
|
272 void CCHFactorySettingsParser::RemoveItemL( MXCFWNode* aItem, |
|
273 CLiwDefaultMap* aMap ) |
|
274 { |
|
275 CP_DEBUG(_L8("CCHFactorySettingsParser::RemoveItemL" )); |
|
276 RNodeArray children; |
|
277 CleanupClosePushL( children ); |
|
278 iContentTree->GetChildNodesL( aItem, children ); |
|
279 for ( TInt i = 0; i < children.Count( ); i++ ) |
|
280 { |
|
281 if ( children[i]->Data()->TypeIdentifier( ) == KDataItem ) |
|
282 { |
|
283 ExtractDeleteAttributesL( children[i], aMap ); |
|
284 } |
|
285 } |
|
286 CleanupStack::PopAndDestroy( &children ); |
|
287 } |
|
288 |
|
289 // ----------------------------------------------------------------------------- |
|
290 // |
|
291 // ----------------------------------------------------------------------------- |
|
292 // |
|
293 void CCHFactorySettingsParser::ExtractAttributesAndAddL( MXCFWNode* aItem, |
|
294 CLiwDefaultList* aList ) |
|
295 { |
|
296 CP_DEBUG(_L8("CCHFactorySettingsParser::ExtractAttributesAndAddL" )); |
|
297 TPtrC type; |
|
298 CGECODefaultObject* node= |
|
299 static_cast<CGECODefaultObject*>(aItem->Data( )); |
|
300 if ( !node->GetAttribute( KAttributeType, type ) ) |
|
301 { |
|
302 HBufC8* bufV= NULL; |
|
303 CLiwDefaultMap* nestedMap= NULL; |
|
304 CLiwDefaultList* nestedList= NULL; |
|
305 TPtrC value; |
|
306 TBool valueExist(node->GetAttribute( KAttributeValue, value ) ); |
|
307 TTypes typeCheck = ConvertToType( type ); |
|
308 //check if value exist |
|
309 //it is not needed in case of Map and List |
|
310 if ( valueExist==KErrNone || typeCheck==EMap || typeCheck==EList ) |
|
311 { |
|
312 switch ( typeCheck ) |
|
313 { |
|
314 case EInteger: |
|
315 aList->AppendL( FactSetCHUtils::Str2Int32( value ) ); |
|
316 break; |
|
317 case EUInteger: |
|
318 aList->AppendL( FactSetCHUtils::Str2Uint( value ) ); |
|
319 break; |
|
320 case EDescriptor8: |
|
321 bufV = FactSetCHUtils::Str2Str8LC( value ); |
|
322 aList->AppendL( *bufV ); |
|
323 CleanupStack::PopAndDestroy( bufV ); |
|
324 break; |
|
325 case EDescriptor16: |
|
326 aList->AppendL( value ); |
|
327 break; |
|
328 case EMap: |
|
329 nestedMap = CLiwDefaultMap::NewLC( ); |
|
330 AddItemL( aItem, nestedMap, EMap ); |
|
331 aList->AppendL( nestedMap ); |
|
332 CleanupStack::PopAndDestroy( nestedMap ); |
|
333 break; |
|
334 case EList: |
|
335 nestedList = CLiwDefaultList::NewLC( ); |
|
336 AddItemL( aItem, nestedList, EList ); |
|
337 aList->AppendL( nestedList ); |
|
338 CleanupStack::PopAndDestroy( nestedList ); |
|
339 break; |
|
340 case EBool: |
|
341 aList->AppendL( FactSetCHUtils::Str2Bool( value ) ); |
|
342 break; |
|
343 case EReal: |
|
344 aList->AppendL( FactSetCHUtils::Str2Real( value ) ); |
|
345 case EUid: |
|
346 aList->AppendL( FactSetCHUtils::Str2Uid( value ) ); |
|
347 break; |
|
348 default: |
|
349 { |
|
350 //wrong type - ignore |
|
351 } |
|
352 } |
|
353 } |
|
354 } |
|
355 } |
|
356 |
|
357 // ----------------------------------------------------------------------------- |
|
358 // |
|
359 // ----------------------------------------------------------------------------- |
|
360 // |
|
361 void CCHFactorySettingsParser::ExtractAttributesAndAddL( MXCFWNode* aItem, |
|
362 CLiwDefaultMap* aMap ) |
|
363 { |
|
364 CP_DEBUG(_L8("CCHFactorySettingsParser::ExtractAttributesAndAddL" )); |
|
365 TPtrC key; |
|
366 TPtrC type; |
|
367 CGECODefaultObject* node= |
|
368 static_cast<CGECODefaultObject*>(aItem->Data( )); |
|
369 if ( !node->GetAttribute( KAttributeType, type ) |
|
370 && !node->GetAttribute( KAttributeKey, key ) ) |
|
371 { |
|
372 HBufC8* bufV= NULL; |
|
373 CLiwDefaultMap* nestedMap= NULL; |
|
374 HBufC8* buf = FactSetCHUtils::Str2Str8LC( key ); |
|
375 TPtrC value; |
|
376 CLiwDefaultList* nestedList= NULL; |
|
377 TBool valueExist(node->GetAttribute( KAttributeValue, value ) ); |
|
378 TTypes typeCheck = ConvertToType( type ); |
|
379 //check if value exist |
|
380 //it is not needed in case of Map and List |
|
381 if ( valueExist==KErrNone || typeCheck==EMap || typeCheck==EList ) |
|
382 { |
|
383 switch ( typeCheck ) |
|
384 { |
|
385 case EInteger: |
|
386 aMap->InsertL( *buf, FactSetCHUtils::Str2Int32( value ) ); |
|
387 break; |
|
388 case EUInteger: |
|
389 aMap->InsertL( *buf, FactSetCHUtils::Str2Uint( value ) ); |
|
390 break; |
|
391 case EDescriptor8: |
|
392 bufV = FactSetCHUtils::Str2Str8LC( value ); |
|
393 aMap->InsertL( *buf, *bufV ); |
|
394 CleanupStack::PopAndDestroy( bufV ); |
|
395 break; |
|
396 case EDescriptor16: |
|
397 aMap->InsertL( *buf, value ); |
|
398 break; |
|
399 case EMap: |
|
400 nestedMap = CLiwDefaultMap::NewL( ); |
|
401 AddItemL( aItem, nestedMap, EMap ); |
|
402 aMap->InsertL( *buf, nestedMap ); |
|
403 nestedMap->DecRef( ); |
|
404 break; |
|
405 case EList: |
|
406 nestedList = CLiwDefaultList::NewL( ); |
|
407 AddItemL( aItem, nestedList, EList ); |
|
408 aMap->InsertL( *buf, nestedList ); |
|
409 nestedList->DecRef( ); |
|
410 break; |
|
411 case EBool: |
|
412 aMap->InsertL( *buf, FactSetCHUtils::Str2Bool( value ) ); |
|
413 break; |
|
414 case EReal: |
|
415 aMap->InsertL( *buf, FactSetCHUtils::Str2Real( value ) ); |
|
416 break; |
|
417 case EUid: |
|
418 aMap->InsertL( *buf, FactSetCHUtils::Str2Uid( value ) ); |
|
419 break; |
|
420 default: |
|
421 { |
|
422 //wrong type - ignore |
|
423 } |
|
424 } |
|
425 } |
|
426 CleanupStack::PopAndDestroy( buf ); |
|
427 } |
|
428 } |
|
429 // ----------------------------------------------------------------------------- |
|
430 // |
|
431 // ----------------------------------------------------------------------------- |
|
432 // |
|
433 void CCHFactorySettingsParser::ExtractDeleteAttributesL( MXCFWNode* aItem, |
|
434 CLiwDefaultMap* aMap ) |
|
435 { |
|
436 CP_DEBUG(_L8("CCHFactorySettingsParser::ExtractDeleteAttributesL" )); |
|
437 TPtrC key; |
|
438 TPtrC type; |
|
439 CGECODefaultObject* node= |
|
440 static_cast<CGECODefaultObject*>(aItem->Data( )); |
|
441 if ( !node->GetAttribute( KAttributeType, type ) |
|
442 && !node->GetAttribute( KAttributeKey, key ) ) |
|
443 { |
|
444 HBufC8* bufV= NULL; |
|
445 HBufC8* buf = FactSetCHUtils::Str2Str8LC( key ); |
|
446 TPtrC value; |
|
447 TBool valueExist(node->GetAttribute( KAttributeValue, value ) ); |
|
448 TTypes typeCheck = ConvertToType( type ); |
|
449 //check if value exist |
|
450 if ( valueExist==KErrNone ) |
|
451 { |
|
452 switch ( typeCheck ) |
|
453 { |
|
454 case EDescriptor8: |
|
455 bufV = FactSetCHUtils::Str2Str8LC( value ); |
|
456 aMap->InsertL( *buf, *bufV ); |
|
457 CleanupStack::PopAndDestroy( bufV ); |
|
458 break; |
|
459 case EDescriptor16: |
|
460 aMap->InsertL( *buf, value ); |
|
461 break; |
|
462 |
|
463 default: |
|
464 { |
|
465 //wrong type - ignore |
|
466 } |
|
467 } |
|
468 } |
|
469 CleanupStack::PopAndDestroy( buf ); |
|
470 } |
|
471 } |
|
472 |
|
473 // ----------------------------------------------------------------------------- |
|
474 // |
|
475 // ----------------------------------------------------------------------------- |
|
476 // |
|
477 CCHFactorySettingsParser::TTypes CCHFactorySettingsParser::ConvertToType( |
|
478 const TDesC& aType ) |
|
479 { |
|
480 CP_DEBUG(_L8("CCHFactorySettingsParser::ConvertToType" )); |
|
481 if ( !aType.Compare( KInteger ) ) |
|
482 return EInteger; |
|
483 if ( !aType.Compare( KUInteger ) ) |
|
484 return EUInteger; |
|
485 if ( !aType.Compare( KDescriptor8 ) ) |
|
486 return EDescriptor8; |
|
487 if ( !aType.Compare( KDescriptor16 ) ) |
|
488 return EDescriptor16; |
|
489 if ( !aType.Compare( KMap ) ) |
|
490 return EMap; |
|
491 if ( !aType.Compare( KList ) ) |
|
492 return EList; |
|
493 if ( !aType.Compare( KBool ) ) |
|
494 return EBool; |
|
495 if ( !aType.Compare( KReal ) ) |
|
496 return EReal; |
|
497 if ( !aType.Compare( KUid ) ) |
|
498 return EUid; |
|
499 return EUndefined; |
|
500 } |
|
501 |
|
502 // End of File |