|
1 /* |
|
2 * Copyright (c) 2007-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: Implements CAcpXmlHandler methods |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <escapeutils.h> |
|
20 #include "acpprovider.h" |
|
21 #include "acpxmlhandler.h" |
|
22 #include "accountcreationpluginlogger.h" |
|
23 #include "macpxmlhandlerobserver.h" |
|
24 #include "accountcreationengineconstants.h" |
|
25 |
|
26 |
|
27 // --------------------------------------------------------------------------- |
|
28 // CAcpXmlHandler::CAcpXmlHandler |
|
29 // --------------------------------------------------------------------------- |
|
30 // |
|
31 CAcpXmlHandler::CAcpXmlHandler( MAcpXmlHandlerObserver& aObserver ) |
|
32 : CActive( EPriorityStandard ), |
|
33 iObserver( aObserver ) |
|
34 { |
|
35 // Add active scheduler. |
|
36 CActiveScheduler::Add( this ); |
|
37 } |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // CAcpXmlHandler::ConstructL |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 void CAcpXmlHandler::ConstructL() |
|
44 { |
|
45 ACPLOG( "CAcpXmlHandler::ConstructL begin" ); |
|
46 // Create XML parser |
|
47 iParser = CParser::NewL( KXmlMimeType, *this ); |
|
48 ACPLOG( "CAcpXmlHandler::ConstructL end" ); |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // CAcpXmlHandler::NewL |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 CAcpXmlHandler* CAcpXmlHandler::NewL( MAcpXmlHandlerObserver& aObserver ) |
|
56 { |
|
57 CAcpXmlHandler* self = CAcpXmlHandler::NewLC( aObserver ); |
|
58 CleanupStack::Pop( self ); |
|
59 return self; |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // CAcpXmlHandler::NewLC |
|
64 // --------------------------------------------------------------------------- |
|
65 // |
|
66 CAcpXmlHandler* CAcpXmlHandler::NewLC( MAcpXmlHandlerObserver& aObserver ) |
|
67 { |
|
68 CAcpXmlHandler* self = new ( ELeave ) CAcpXmlHandler( aObserver ); |
|
69 CleanupStack::PushL( self ); |
|
70 self->ConstructL(); |
|
71 return self; |
|
72 } |
|
73 |
|
74 // --------------------------------------------------------------------------- |
|
75 // CAcpXmlHandler::~CAcpXmlHandler |
|
76 // --------------------------------------------------------------------------- |
|
77 // |
|
78 CAcpXmlHandler::~CAcpXmlHandler() |
|
79 { |
|
80 ACPLOG( "CAcpXmlHandler::~CAcpXmlHandler begin" ); |
|
81 |
|
82 Cancel(); // Ensures that the parsing is stopped |
|
83 delete iParser; |
|
84 delete iBuffer; |
|
85 delete iOngoingAttr; |
|
86 delete iProvider; |
|
87 |
|
88 ACPLOG( "CAcpXmlHandler::~CAcpXmlHandler end" ); |
|
89 } |
|
90 |
|
91 // --------------------------------------------------------------------------- |
|
92 // CAcpXmlHandler::StartParsingL |
|
93 // Starts parsing xml with given filename. |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 void CAcpXmlHandler::StartParsingL( const TFileName& aFilename ) |
|
97 { |
|
98 ACPLOG( "CAcpXmlHandler::StartParsingL begin" ); |
|
99 |
|
100 // Save the filename because of deleting file later on. |
|
101 iFilename.Append( aFilename ); |
|
102 |
|
103 // Leave if parsing is active. |
|
104 if ( IsActive() ) |
|
105 { |
|
106 User::Leave( KErrInUse ); |
|
107 } |
|
108 |
|
109 // Connect to fileserver and open xml file to be parsed. |
|
110 User::LeaveIfError( iFileServer.Connect() ); |
|
111 User::LeaveIfError( iFile.Open( iFileServer, aFilename, EFileRead ) ); |
|
112 |
|
113 delete iBuffer; |
|
114 iBuffer = NULL; |
|
115 |
|
116 TEntry entry; |
|
117 |
|
118 // Get size of file. |
|
119 User::LeaveIfError( iFileServer.Entry( aFilename, entry ) ); |
|
120 |
|
121 TInt fileSize = entry.iSize; |
|
122 |
|
123 // Create buffer for file reading and start process. |
|
124 iBuffer = HBufC8::NewL( fileSize ); |
|
125 |
|
126 TPtr8 ptr( iBuffer->Des() ); |
|
127 ptr.Zero(); |
|
128 |
|
129 iFile.Read( ptr, fileSize, iStatus ); |
|
130 SetActive(); |
|
131 |
|
132 iParser->ParseBeginL(); |
|
133 |
|
134 ACPLOG( "CAcpXmlHandler::StartParsingL end" ); |
|
135 } |
|
136 |
|
137 // --------------------------------------------------------------------------- |
|
138 // CAcpXmlHandler::HandleFinishedProviderL |
|
139 // Handles finished provider and notifies observer. |
|
140 // --------------------------------------------------------------------------- |
|
141 // |
|
142 void CAcpXmlHandler::HandleFinishedProviderL() |
|
143 { |
|
144 ACPLOG( "CAcpXmlHandler::HandleFinishedProviderL" ); |
|
145 |
|
146 // Provider exists, save it by calling observer. |
|
147 if ( iProvider ) |
|
148 { |
|
149 iObserver.NotifyParsedProviderL( *iProvider ); |
|
150 delete iProvider; |
|
151 iProvider = NULL; |
|
152 } |
|
153 |
|
154 // Start new provider by creating instance from CAcpProvider. |
|
155 iProvider = CAcpProvider::NewL(); |
|
156 } |
|
157 |
|
158 // --------------------------------------------------------------------------- |
|
159 // CAcpXmlHandler::DoCancel |
|
160 // From CActive. |
|
161 // --------------------------------------------------------------------------- |
|
162 // |
|
163 void CAcpXmlHandler::DoCancel() |
|
164 { |
|
165 ACPLOG( "CAcpXmlHandler::DoCancel begin" ); |
|
166 |
|
167 ACPLOG( "CAcpXmlHandler::DoCancel - ReadCancel" ); |
|
168 iFile.ReadCancel(); |
|
169 |
|
170 TRAP_IGNORE( iParser->ParseEndL() ); |
|
171 |
|
172 iFileServer.Delete( iFilename ); // Delete old file |
|
173 |
|
174 iFile.Close(); |
|
175 iFileServer.Close(); |
|
176 |
|
177 delete iBuffer; |
|
178 iBuffer = NULL; |
|
179 |
|
180 delete iOngoingAttr; |
|
181 iOngoingAttr = NULL; |
|
182 |
|
183 ACPLOG( "CAcpXmlHandler::DoCancel end" ); |
|
184 } |
|
185 |
|
186 // --------------------------------------------------------------------------- |
|
187 // CAcpXmlHandler::RunL |
|
188 // From CActive. |
|
189 // --------------------------------------------------------------------------- |
|
190 // |
|
191 void CAcpXmlHandler::RunL() |
|
192 { |
|
193 ACPLOG( "CAcpXmlHandler::RunL begin" ); |
|
194 |
|
195 if ( KErrNone == iStatus.Int() ) |
|
196 { |
|
197 // When buffer length is zero, we have reached end of the document. |
|
198 if ( !iBuffer->Length() ) |
|
199 { |
|
200 ACPLOG( " - end of XML document reached" ); |
|
201 DoCancel(); |
|
202 } |
|
203 // Otherwise continue reading of Xml file. |
|
204 else |
|
205 { |
|
206 iParser->ParseL( *iBuffer ); |
|
207 TPtr8 ptr( iBuffer->Des() ); |
|
208 iFile.Read( ptr, iStatus ); |
|
209 SetActive(); |
|
210 ACPLOG( " - continuing reading XML document" ); |
|
211 } |
|
212 } |
|
213 else |
|
214 { |
|
215 iObserver.NotifyParsingCompleted( iStatus.Int() ); |
|
216 } |
|
217 |
|
218 ACPLOG( "CAcpXmlHandler::RunL end" ); |
|
219 } |
|
220 |
|
221 |
|
222 // --------------------------------------------------------------------------- |
|
223 // CAcpXmlHandler::OnStartDocumentL |
|
224 // From MContentHandler. |
|
225 // --------------------------------------------------------------------------- |
|
226 // |
|
227 void CAcpXmlHandler::OnStartDocumentL( |
|
228 const RDocumentParameters& /*aDocParam*/, |
|
229 TInt aErrorCode ) |
|
230 { |
|
231 if ( KErrNone != aErrorCode ) |
|
232 { |
|
233 ACPLOG2( "CAcpXmlHandler::OnStartDocumentL: error=%d", aErrorCode ); |
|
234 iObserver.NotifyParsingCompleted( aErrorCode ); |
|
235 } |
|
236 } |
|
237 |
|
238 // --------------------------------------------------------------------------- |
|
239 // CAcpXmlHandler::OnEndDocumentL |
|
240 // From MContentHandler. |
|
241 // --------------------------------------------------------------------------- |
|
242 // |
|
243 void CAcpXmlHandler::OnEndDocumentL( TInt aErrorCode ) |
|
244 { |
|
245 ACPLOG2( "CAcpXmlHandler::OnEndDocumentL begin: error=%d", aErrorCode ); |
|
246 |
|
247 if ( KErrNone == aErrorCode ) |
|
248 { |
|
249 // Save last one. |
|
250 HandleFinishedProviderL(); |
|
251 delete iProvider; |
|
252 iProvider = NULL; |
|
253 } |
|
254 |
|
255 iObserver.NotifyParsingCompleted( aErrorCode ); |
|
256 |
|
257 ACPLOG( "CAcpXmlHandler::OnEndDocumentL end" ); |
|
258 } |
|
259 |
|
260 // --------------------------------------------------------------------------- |
|
261 // CAcpXmlHandler::OnStartElementL |
|
262 // From MContentHandler. |
|
263 // --------------------------------------------------------------------------- |
|
264 // |
|
265 void CAcpXmlHandler::OnStartElementL( |
|
266 const RTagInfo& aElement, |
|
267 const RAttributeArray& , |
|
268 TInt aErrorCode ) |
|
269 { |
|
270 TBuf<KMaxElementLength>element; |
|
271 element.Copy(aElement.LocalName().DesC()); |
|
272 |
|
273 ACPLOG2( "CAcpXmlHandler::OnStartElementL: element=%S", &element ); |
|
274 ACPLOG2( "CAcpXmlHandler::OnStartElementL: error=%d", aErrorCode ); |
|
275 |
|
276 if ( KErrNone == aErrorCode ) |
|
277 { |
|
278 // No need to go through attributes since they're not used. |
|
279 // Parsing has reached to some of supported elements. |
|
280 // Save element value to member data for further actions. |
|
281 TPtrC8 ptr = aElement.LocalName().DesC(); |
|
282 |
|
283 if ( !ptr.Compare( KServiceProvider ) || |
|
284 !ptr.Compare( KProviderName ) || |
|
285 !ptr.Compare( KIconUrl ) || |
|
286 !ptr.Compare( KSisUrl ) || |
|
287 !ptr.Compare( KCreateUrl ) || |
|
288 !ptr.Compare( KActivateUrl ) || |
|
289 !ptr.Compare( KProviderDescription ) || |
|
290 !ptr.Compare( KProviderType ) || |
|
291 !ptr.Compare( KReportUrl ) ) |
|
292 { |
|
293 iOngoingAttr = HBufC8::NewL( ptr.Length() ); |
|
294 iOngoingAttr->Des().Copy( ptr ); |
|
295 iGetContentNow = ETrue; |
|
296 // just for creating provider |
|
297 if ( !ptr.Compare( KServiceProvider ) ) |
|
298 { |
|
299 iGetContentNow = EFalse; |
|
300 } |
|
301 } |
|
302 |
|
303 if ( iOngoingAttr ) |
|
304 { |
|
305 // Parsing of provider has been started. |
|
306 // This means that old provider is ready for saving |
|
307 // if it's not first one. In that case, new provider is started. |
|
308 if ( !iOngoingAttr->Compare( KServiceProvider ) ) |
|
309 { |
|
310 HandleFinishedProviderL(); |
|
311 delete iOngoingAttr; |
|
312 iOngoingAttr = NULL; |
|
313 } |
|
314 } |
|
315 } |
|
316 else |
|
317 { |
|
318 ACPLOG2( "CAcpXmlHandler::OnStartElementL: error=%d", aErrorCode ); |
|
319 iObserver.NotifyParsingCompleted( aErrorCode ); |
|
320 } |
|
321 } |
|
322 |
|
323 // --------------------------------------------------------------------------- |
|
324 // CAcpXmlHandler::OnEndElementL |
|
325 // From MContentHandler. |
|
326 // --------------------------------------------------------------------------- |
|
327 // |
|
328 void CAcpXmlHandler::OnEndElementL( const RTagInfo& /*aElement*/, |
|
329 TInt aErrorCode ) |
|
330 { |
|
331 if ( KErrNone == aErrorCode ) |
|
332 { |
|
333 // Reset member variables. |
|
334 iGetContentNow = EFalse; |
|
335 |
|
336 delete iOngoingAttr; |
|
337 iOngoingAttr = NULL; |
|
338 } |
|
339 else |
|
340 { |
|
341 ACPLOG2( "CAcpXmlHandler::OnEndElementL: error=%d", aErrorCode ); |
|
342 iObserver.NotifyParsingCompleted( aErrorCode ); |
|
343 } |
|
344 } |
|
345 |
|
346 // --------------------------------------------------------------------------- |
|
347 // CAcpXmlHandler::OnContentL |
|
348 // From MContentHandler. |
|
349 // --------------------------------------------------------------------------- |
|
350 // |
|
351 void CAcpXmlHandler::OnContentL( const TDesC8& aBytes, TInt aErrorCode ) |
|
352 { |
|
353 if ( KErrNone == aErrorCode ) |
|
354 { |
|
355 ACPLOG( "CAcpXmlHandler::OnContentL" ); |
|
356 // We need to save content data if iGetContentNow is set. |
|
357 if ( iGetContentNow ) |
|
358 { |
|
359 // Convert unicode data to 16-bit descriptor. |
|
360 HBufC* bytes = EscapeUtils::ConvertToUnicodeFromUtf8L( aBytes ); |
|
361 |
|
362 // On the cleanup stack |
|
363 CleanupStack::PushL( bytes ); |
|
364 |
|
365 ACPLOG2( "CAcpXmlHandler::OnContentL: aBytes=%S", bytes ); |
|
366 |
|
367 // Provider name. |
|
368 if ( !iOngoingAttr->Compare( KProviderName ) ) |
|
369 { |
|
370 ACPLOG( "CAcpXmlHandler::SetProviderNameL" ); |
|
371 iProvider->SetProviderNameL( *bytes ); |
|
372 } |
|
373 // Location of icons package. |
|
374 else if ( !iOngoingAttr->Compare( KIconUrl ) ) |
|
375 { |
|
376 ACPLOG( "CAcpXmlHandler::SetIconUrlL" ); |
|
377 iProvider->SetIconUrlL( aBytes ); |
|
378 } |
|
379 // Location of sis package. |
|
380 else if ( !iOngoingAttr->Compare( KSisUrl ) ) |
|
381 { |
|
382 ACPLOG( "CAcpXmlHandler::SetSisUrlL" ); |
|
383 iProvider->SetSisUrlL( aBytes ); |
|
384 } |
|
385 // Location to create settings. |
|
386 else if ( !iOngoingAttr->Compare( KCreateUrl ) ) |
|
387 { |
|
388 ACPLOG( "CAcpXmlHandler::SetCreationUrlL" ); |
|
389 iProvider->SetCreationUrlL( aBytes ); |
|
390 } |
|
391 // Location to activate settings. |
|
392 else if ( !iOngoingAttr->Compare( KActivateUrl ) ) |
|
393 { |
|
394 ACPLOG( "CAcpXmlHandler::SetActivationUrlL" ); |
|
395 iProvider->SetActivationUrlL( aBytes ); |
|
396 } |
|
397 // Provider description. |
|
398 else if ( !iOngoingAttr->Compare( KProviderDescription ) ) |
|
399 { |
|
400 ACPLOG( "CAcpXmlHandler::SetProviderDescription" ); |
|
401 iProvider->SetProviderDescriptionL( *bytes ); |
|
402 } |
|
403 // Provider type. |
|
404 else if ( !iOngoingAttr->Compare( KProviderType ) ) |
|
405 { |
|
406 ACPLOG( "CAcpXmlHandler::SetProviderType" ); |
|
407 iProvider->SetProviderTypeL( *bytes ); |
|
408 } |
|
409 // Location to activate settings. |
|
410 else if ( !iOngoingAttr->Compare( KReportUrl ) ) |
|
411 { |
|
412 ACPLOG( " - Provider report url ignored" ); |
|
413 } |
|
414 // Should never happen. |
|
415 else |
|
416 { |
|
417 User::Leave( KErrNotSupported ); |
|
418 } |
|
419 CleanupStack::PopAndDestroy( bytes ); |
|
420 } |
|
421 } |
|
422 else |
|
423 { |
|
424 ACPLOG2( "CAcpXmlHandler::OnContentL: error=%d", aErrorCode ); |
|
425 iObserver.NotifyParsingCompleted( aErrorCode ); |
|
426 } |
|
427 } |
|
428 |
|
429 // --------------------------------------------------------------------------- |
|
430 // CAcpXmlHandler::OnStartPrefixMappingL |
|
431 // From MContentHandler. |
|
432 // --------------------------------------------------------------------------- |
|
433 // |
|
434 void CAcpXmlHandler::OnStartPrefixMappingL( |
|
435 const RString& /*aPrefix*/, |
|
436 const RString& /*aUri*/, |
|
437 TInt /*aErrorCode*/ ) |
|
438 { |
|
439 } |
|
440 |
|
441 // --------------------------------------------------------------------------- |
|
442 // CAcpXmlHandler::OnEndPrefixMappingL |
|
443 // From MContentHandler. |
|
444 // --------------------------------------------------------------------------- |
|
445 // |
|
446 void CAcpXmlHandler::OnEndPrefixMappingL( |
|
447 const RString& /*aPrefix*/, |
|
448 TInt /*aErrorCode*/ ) |
|
449 { |
|
450 } |
|
451 |
|
452 // --------------------------------------------------------------------------- |
|
453 // CAcpXmlHandler::OnIgnorableWhiteSpaceL |
|
454 // From MContentHandler. |
|
455 // --------------------------------------------------------------------------- |
|
456 // |
|
457 void CAcpXmlHandler::OnIgnorableWhiteSpaceL( |
|
458 const TDesC8& /*aBytes*/, |
|
459 TInt /*aErrorCode*/ ) |
|
460 { |
|
461 } |
|
462 |
|
463 // --------------------------------------------------------------------------- |
|
464 // CAcpXmlHandler::OnSkippedEntityL |
|
465 // From MContentHandler. |
|
466 // --------------------------------------------------------------------------- |
|
467 // |
|
468 void CAcpXmlHandler::OnSkippedEntityL( |
|
469 const RString& /*aName*/, |
|
470 TInt /*aErrorCode*/ ) |
|
471 { |
|
472 } |
|
473 |
|
474 // --------------------------------------------------------------------------- |
|
475 // CAcpXmlHandler::OnProcessingInstructionL |
|
476 // From MContentHandler. |
|
477 // --------------------------------------------------------------------------- |
|
478 // |
|
479 void CAcpXmlHandler::OnProcessingInstructionL( |
|
480 const TDesC8& /*aTarget*/, |
|
481 const TDesC8& /*aData*/, |
|
482 TInt /*aErrorCode*/ ) |
|
483 { |
|
484 } |
|
485 |
|
486 // --------------------------------------------------------------------------- |
|
487 // CAcpXmlHandler::OnError |
|
488 // From MContentHandler. |
|
489 // --------------------------------------------------------------------------- |
|
490 // |
|
491 void CAcpXmlHandler::OnError( TInt aErrorCode ) |
|
492 { |
|
493 ACPLOG2( "CAcpXmlHandler::OnError: error=%d", aErrorCode ); |
|
494 |
|
495 // Send a notification that the parsing stopped because of error. |
|
496 iObserver.NotifyParsingCompleted( aErrorCode ); |
|
497 } |
|
498 |
|
499 // --------------------------------------------------------------------------- |
|
500 // CAcpXmlHandler::GetExtendedInterface |
|
501 // From MContentHandler. |
|
502 // --------------------------------------------------------------------------- |
|
503 // |
|
504 TAny* CAcpXmlHandler::GetExtendedInterface( const TInt32 /*aUid*/ ) |
|
505 { |
|
506 return NULL; |
|
507 } |
|
508 |
|
509 // End of file. |