|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Callback methods for SAX libxml2 parser |
|
15 // |
|
16 |
|
17 #include <stdapis/libxml2/libxml2_modules.h> |
|
18 #include <stdapis/libxml2/libxml2_globals.h> |
|
19 #include "xmlengsaxplugin.h" |
|
20 #include "xmlengsaxpluginerror.h" |
|
21 |
|
22 _LIT8(KEmptyString, ""); |
|
23 |
|
24 LOCAL_C const TInt KAttribPrefixOffset = 1; |
|
25 LOCAL_C const TInt KAttribURIOffset = 2; |
|
26 LOCAL_C const TInt KAttribValueWithEndOffset = 3; |
|
27 LOCAL_C const TInt KAttribEndOffset = 4; |
|
28 LOCAL_C const TInt KAttributeNextOffset = 5; |
|
29 |
|
30 /** |
|
31 * GetLengthString: |
|
32 * @param aString the string |
|
33 * |
|
34 * Return length of string. |
|
35 */ |
|
36 TInt GetLengthString(const xmlChar* aString) |
|
37 { |
|
38 const xmlChar* ptr = aString; |
|
39 if(!ptr) |
|
40 { |
|
41 return 0; |
|
42 } |
|
43 while (*ptr) |
|
44 { |
|
45 ++ptr; |
|
46 } |
|
47 |
|
48 return ptr - aString; |
|
49 } |
|
50 |
|
51 /** |
|
52 * AttributeArrayDelete: |
|
53 * @param aPtr the argument required by TCleanupItem object |
|
54 * |
|
55 * Operation which pop and closed RAttributeArray object. |
|
56 */ |
|
57 LOCAL_C void AttributeArrayDelete(TAny *aPtr) |
|
58 { |
|
59 RAttributeArray& attributes = *(RAttributeArray*)aPtr; |
|
60 |
|
61 TInt nAttributes = attributes.Count(); |
|
62 |
|
63 for(TInt i=0; i<nAttributes; i++) |
|
64 { |
|
65 attributes[i].Close(); |
|
66 } |
|
67 |
|
68 attributes.Close(); |
|
69 } |
|
70 |
|
71 /** |
|
72 * EntityDeclL: |
|
73 * @param aUserData the user data (XML parser context) |
|
74 * @param aName the entity name |
|
75 * @param aType the entity type |
|
76 * @param aPublicId The public ID of the entity |
|
77 * @param aSystemId The system ID of the entity |
|
78 * @param aContent the entity value (without processing). |
|
79 * |
|
80 * An entity definition has been parsed. |
|
81 */ |
|
82 void EntityDeclaration(void *aUserData, |
|
83 const xmlChar *aName, |
|
84 int aType, |
|
85 const xmlChar *aPublicId, |
|
86 const xmlChar *aSystemId, |
|
87 xmlChar *aContent) |
|
88 { |
|
89 CXMLEngineSAXPlugin* wrapper = reinterpret_cast<CXMLEngineSAXPlugin*>(aUserData); |
|
90 |
|
91 //reset of recoverable error |
|
92 wrapper->SetErrorStatus(EFalse); |
|
93 |
|
94 //because condition in parser.c file |
|
95 if (aType == XML_EXTERNAL_GENERAL_PARSED_ENTITY) |
|
96 { |
|
97 wrapper->getParserContext()->replaceEntities = 1; |
|
98 } |
|
99 else |
|
100 { |
|
101 wrapper->getParserContext()->replaceEntities = 0; |
|
102 } |
|
103 xmlSAX2EntityDecl(wrapper->getParserContext(), aName, aType, aPublicId, aSystemId, aContent); |
|
104 } |
|
105 |
|
106 /** |
|
107 * ExternalSubset: |
|
108 * @param aUserData the user data (XML parser context) |
|
109 * @param aName the root element name |
|
110 * @param aExternalID the external ID |
|
111 * @param aSystemID the SYSTEM ID (e.g. filename or URL) |
|
112 * |
|
113 * Callback on external subset declaration. |
|
114 */ |
|
115 void ExternalSubset(void *aUserData, |
|
116 const xmlChar *aName, |
|
117 const xmlChar *aExternalID, |
|
118 const xmlChar *aSystemID) |
|
119 |
|
120 { |
|
121 CXMLEngineSAXPlugin* wrapper = reinterpret_cast<CXMLEngineSAXPlugin*>(aUserData); |
|
122 //reset of recoverable error |
|
123 wrapper->SetErrorStatus(EFalse); |
|
124 |
|
125 xmlSAX2ExternalSubset(wrapper->getParserContext(), aName, aExternalID, aSystemID); |
|
126 } |
|
127 |
|
128 /** |
|
129 * ResolveEntity: |
|
130 * @param aUserData the user data (XML parser context) |
|
131 * @param aPublicId The public ID of the entity |
|
132 * @param aSystemId The system ID of the entity |
|
133 * |
|
134 * Callback on resolve entity. |
|
135 */ |
|
136 xmlParserInputPtr ResolveEntity(void *aUserData, |
|
137 const xmlChar *aPublicId, |
|
138 const xmlChar *aSystemId) |
|
139 { |
|
140 CXMLEngineSAXPlugin* wrapper = reinterpret_cast<CXMLEngineSAXPlugin*>(aUserData); |
|
141 //reset of recoverable error |
|
142 wrapper->SetErrorStatus(EFalse); |
|
143 |
|
144 return xmlSAX2ResolveEntity(wrapper->getParserContext(), aPublicId, aSystemId); |
|
145 } |
|
146 |
|
147 /** |
|
148 * GetEntityL: |
|
149 * @param aUserData the user data (XML parser context) |
|
150 * @param aName The entity name |
|
151 * |
|
152 * Get an entity by name. |
|
153 * |
|
154 * Returns the xmlEntityPtr if found. |
|
155 */ |
|
156 xmlEntityPtr GetEntityL(void *aUserData, |
|
157 const xmlChar *aName) |
|
158 { |
|
159 CXMLEngineSAXPlugin* wrapper = reinterpret_cast<CXMLEngineSAXPlugin*>(aUserData); |
|
160 wrapper->getParserContext()->replaceEntities = 0; |
|
161 |
|
162 //reset of recoverable error |
|
163 wrapper->SetErrorStatus(EFalse); |
|
164 |
|
165 xmlEntityPtr entity; |
|
166 entity = xmlSAX2GetEntity(wrapper->getParserContext(), aName); |
|
167 |
|
168 //predefined, internal and external entity |
|
169 if (entity) |
|
170 { |
|
171 //entity in attribute |
|
172 if (wrapper->getParserContext()->instate == XML_PARSER_ATTRIBUTE_VALUE) |
|
173 { |
|
174 wrapper->getParserContext()->replaceEntities = 1; |
|
175 } |
|
176 //entity in content |
|
177 else |
|
178 { |
|
179 |
|
180 //internal and predefined - nothing |
|
181 |
|
182 //external entity |
|
183 if (entity->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY) |
|
184 { |
|
185 TPtrC8 skipString(aName); |
|
186 RString ref = wrapper->StringPool().OpenStringL(skipString); |
|
187 |
|
188 CleanupClosePushL(ref); |
|
189 wrapper->getContentHandler()->OnSkippedEntityL(ref, KErrNone); |
|
190 CleanupStack::PopAndDestroy(&ref); |
|
191 } |
|
192 } |
|
193 |
|
194 return entity; |
|
195 } |
|
196 |
|
197 //external subset |
|
198 if (wrapper->getParserContext()->hasExternalSubset) |
|
199 { |
|
200 |
|
201 wrapper->GetEntity().name = aName; |
|
202 wrapper->GetEntity().type = XML_ENTITY_DECL; |
|
203 wrapper->GetEntity().etype = XML_INTERNAL_GENERAL_ENTITY; |
|
204 wrapper->GetEntity().orig = BAD_CAST ""; |
|
205 wrapper->GetEntity().content = BAD_CAST ""; |
|
206 |
|
207 if (wrapper->getParserContext()->instate == XML_PARSER_ATTRIBUTE_VALUE |
|
208 && !wrapper->IsFeatureEnabled(EReplaceIntEntityFromExtSubsetByRef)) |
|
209 { |
|
210 wrapper->getParserContext()->replaceEntities = 1; |
|
211 return &(wrapper->GetEntity()); |
|
212 } |
|
213 |
|
214 TPtrC8 skipString(aName); |
|
215 RString ref = wrapper->StringPool().OpenStringL(skipString); |
|
216 |
|
217 CleanupClosePushL(ref); |
|
218 wrapper->getContentHandler()->OnSkippedEntityL(ref, KErrNone); |
|
219 CleanupStack::PopAndDestroy(&ref); |
|
220 |
|
221 return &(wrapper->GetEntity()); |
|
222 |
|
223 } |
|
224 |
|
225 return NULL; |
|
226 } |
|
227 |
|
228 /** |
|
229 * GetEntityCal: |
|
230 * @param aUserData the user data (XML parser context) |
|
231 * @param aName The entity name |
|
232 * |
|
233 * Get an entity by name. |
|
234 * |
|
235 * Returns the xmlEntityPtr if found. |
|
236 */ |
|
237 xmlEntityPtr GetEntityCal(void *aUserData, const xmlChar *aName) |
|
238 { |
|
239 xmlEntityPtr tmp = NULL; |
|
240 TRAPD(error,tmp = GetEntityL(aUserData,aName)); |
|
241 if(error != KErrNone) |
|
242 { |
|
243 CXMLEngineSAXPlugin* wrapper = reinterpret_cast<CXMLEngineSAXPlugin*>(aUserData); |
|
244 wrapper->StopParsing(error); |
|
245 } |
|
246 return tmp; |
|
247 } |
|
248 |
|
249 /** |
|
250 * GetParameterEntity: |
|
251 * @param aUserData the user data (XML parser context) |
|
252 * @param aName The entity name |
|
253 * |
|
254 * Get a parameter entity by name. |
|
255 * |
|
256 * Returns the xmlEntityPtr if found. |
|
257 */ |
|
258 xmlEntityPtr GetParameterEntity(void *aUserData, |
|
259 const xmlChar *aName) |
|
260 { |
|
261 CXMLEngineSAXPlugin* wrapper = reinterpret_cast<CXMLEngineSAXPlugin*>(aUserData); |
|
262 |
|
263 xmlEntityPtr entity; |
|
264 entity = xmlSAX2GetParameterEntity(wrapper->getParserContext(), aName); |
|
265 |
|
266 return entity; |
|
267 } |
|
268 |
|
269 /** |
|
270 * StructuredError: |
|
271 * @param aUserData user provided data for the error callback |
|
272 * @param aError the error being raised. |
|
273 * |
|
274 * Signature of the function to use when there is an error and |
|
275 * the module handles the new error reporting mechanism. |
|
276 */ |
|
277 void StructuredError(void *aUserData, |
|
278 xmlErrorPtr aError) |
|
279 { |
|
280 |
|
281 CXMLEngineSAXPlugin* wrapper = reinterpret_cast<CXMLEngineSAXPlugin*>(aUserData); |
|
282 TInt error = GetErrorNum(aError->code); |
|
283 |
|
284 // warning handling |
|
285 if (error == KErrNone) |
|
286 { |
|
287 return; |
|
288 } |
|
289 |
|
290 //because cascade of errors |
|
291 //first error is returned in case when any other event occurs between cascade of calling libxml2_StructuredError event |
|
292 if (!wrapper->IsErrorStatus()) |
|
293 { |
|
294 wrapper->getContentHandler()->OnError(error); |
|
295 wrapper->SetErrorStatus(ETrue); |
|
296 } |
|
297 } |
|
298 |
|
299 /** |
|
300 * StartDocumentL: |
|
301 * @param aUserData the user data (XML parser context) |
|
302 * |
|
303 * Called when the document start being processed. |
|
304 */ |
|
305 void StartDocumentL(void* aUserData) |
|
306 { |
|
307 |
|
308 CXMLEngineSAXPlugin* wrapper = reinterpret_cast<CXMLEngineSAXPlugin*>(aUserData); |
|
309 //reset of recoverable error |
|
310 wrapper->SetErrorStatus(EFalse); |
|
311 |
|
312 RDocumentParameters params; |
|
313 TPtrC8 enc(KEmptyString); |
|
314 |
|
315 if (wrapper->getParserContext()->encoding) |
|
316 { |
|
317 TPtrC8 tmpStr(wrapper->getParserContext()->encoding); |
|
318 enc.Set(tmpStr); |
|
319 } |
|
320 |
|
321 params.Open(wrapper->StringPool().OpenStringL(enc)); |
|
322 CleanupClosePushL(params); |
|
323 |
|
324 wrapper->getContentHandler()->OnStartDocumentL(params, KErrNone); |
|
325 CleanupStack::PopAndDestroy(¶ms); |
|
326 } |
|
327 |
|
328 /** |
|
329 * StartDocument: |
|
330 * @param aUserData the user data (XML parser context) |
|
331 * |
|
332 * Called when the document start being processed. |
|
333 */ |
|
334 void StartDocument(void* aUserData) |
|
335 { |
|
336 TRAPD(error,StartDocumentL(aUserData)); |
|
337 if(error != KErrNone) |
|
338 { |
|
339 CXMLEngineSAXPlugin* wrapper = reinterpret_cast<CXMLEngineSAXPlugin*>(aUserData); |
|
340 wrapper->StopParsing(error); |
|
341 } |
|
342 } |
|
343 |
|
344 /** |
|
345 * EndDocumentL: |
|
346 * @param aUserData the user data (XML parser context) |
|
347 * |
|
348 * Called when the document end has been detected. |
|
349 */ |
|
350 void EndDocument(void* aUserData) |
|
351 { |
|
352 |
|
353 CXMLEngineSAXPlugin* wrapper = reinterpret_cast<CXMLEngineSAXPlugin*>(aUserData); |
|
354 //reset of recoverable error |
|
355 wrapper->SetErrorStatus(EFalse); |
|
356 |
|
357 TRAPD(error,wrapper->getContentHandler()->OnEndDocumentL(KErrNone)); |
|
358 if(error) |
|
359 { |
|
360 wrapper->StopParsing(error); |
|
361 } |
|
362 } |
|
363 |
|
364 /** |
|
365 * Characters: |
|
366 * @param aUserData the user data (XML parser context) |
|
367 * @param aCharacter a xmlChar string |
|
368 * @param aLen the number of xmlChar |
|
369 * |
|
370 * Receiving some chars from the parser. |
|
371 */ |
|
372 void Characters(void* aUserData, const xmlChar* aCharacter, int aLen) |
|
373 { |
|
374 CXMLEngineSAXPlugin* wrapper = reinterpret_cast<CXMLEngineSAXPlugin*>(aUserData); |
|
375 |
|
376 //reset of recoverable error |
|
377 wrapper->SetErrorStatus(EFalse); |
|
378 |
|
379 TPtrC8 ptr(aCharacter, aLen); |
|
380 TRAPD(error,wrapper->getContentHandler()->OnContentL(ptr, KErrNone)); |
|
381 if(error) |
|
382 { |
|
383 wrapper->StopParsing(error); |
|
384 } |
|
385 } |
|
386 |
|
387 /** |
|
388 * IgnorableWhitespace: |
|
389 * @param aUserData the user data (XML parser context) |
|
390 * @param aCharacter a xmlChar string |
|
391 * @param aLen the number of xmlChar |
|
392 * |
|
393 * Receiving some ignorable whitespaces from the parser. |
|
394 * UNUSED: by default the DOM building will use characters. |
|
395 */ |
|
396 void IgnorableWhitespace(void *aUserData, const xmlChar* aCharacter, int aLen) |
|
397 { |
|
398 |
|
399 CXMLEngineSAXPlugin* wrapper = reinterpret_cast<CXMLEngineSAXPlugin*>(aUserData); |
|
400 //reset of recoverable error |
|
401 wrapper->SetErrorStatus(EFalse); |
|
402 |
|
403 TPtrC8 ptr(aCharacter, aLen); |
|
404 TRAPD(error,wrapper->getContentHandler()->OnIgnorableWhiteSpaceL(ptr, KErrNone)); |
|
405 if(error) |
|
406 { |
|
407 wrapper->StopParsing(error); |
|
408 } |
|
409 } |
|
410 |
|
411 /** |
|
412 * ProcessingInstruction: |
|
413 * @param aUserData the user data (XML parser context) |
|
414 * @param aTarget the target name |
|
415 * @param aData the PI data's |
|
416 * |
|
417 * A processing instruction has been parsed. |
|
418 */ |
|
419 void ProcessingInstruction(void *aUserData, const xmlChar* aTarget, const xmlChar* aData) |
|
420 { |
|
421 |
|
422 CXMLEngineSAXPlugin* wrapper = reinterpret_cast<CXMLEngineSAXPlugin*>(aUserData); |
|
423 //reset of recoverable error |
|
424 wrapper->SetErrorStatus(EFalse); |
|
425 |
|
426 TPtrC8 target(KEmptyString); |
|
427 TPtrC8 data(KEmptyString); |
|
428 |
|
429 if (aTarget) |
|
430 { |
|
431 TPtrC8 ptrTemp(aTarget); |
|
432 target.Set(ptrTemp); |
|
433 } |
|
434 |
|
435 if (aData) |
|
436 { |
|
437 TPtrC8 ptrTemp(aData); |
|
438 data.Set(ptrTemp); |
|
439 } |
|
440 |
|
441 TRAPD(error,wrapper->getContentHandler()->OnProcessingInstructionL(target, data, KErrNone)); |
|
442 if(error) |
|
443 { |
|
444 wrapper->StopParsing(error); |
|
445 } |
|
446 } |
|
447 |
|
448 /** |
|
449 * StartElementNsL: |
|
450 * @param aUserData the user data (XML parser context) |
|
451 * @param aLocalname the local name of the element |
|
452 * @param aPrefix the element namespace prefix if available |
|
453 * @param aURI the element namespace name if available |
|
454 * @param aNbNamespaces number of namespace definitions on that node |
|
455 * @param aNamespaces pointer to the array of prefix/URI pairs namespace definitions |
|
456 * @param aNbAttributes the number of attributes on that node |
|
457 * @param aNbDefaulted the number of defaulted attributes. The defaulted |
|
458 * ones are at the end of the array |
|
459 * @param aAttributes pointer to the array of (localname/prefix/URI/value/end) |
|
460 * attribute values. |
|
461 * |
|
462 * SAX2 callback when an element start has been detected by the parser. |
|
463 * It provides the namespace informations for the element, as well as |
|
464 * the new namespace declarations on the element. |
|
465 */ |
|
466 void StartElementNsL( |
|
467 void *aUserData, |
|
468 const xmlChar *aLocalName, |
|
469 const xmlChar *aPrefix, |
|
470 const xmlChar *aURI, |
|
471 int /*aNbNamespaces*/, |
|
472 const xmlChar **/*aNamespaces*/, |
|
473 int aNbAttributes, |
|
474 int /*aNbDefaulted*/, |
|
475 const xmlChar **aAttributes) |
|
476 { |
|
477 |
|
478 CXMLEngineSAXPlugin* wrapper = reinterpret_cast<CXMLEngineSAXPlugin*>(aUserData); |
|
479 |
|
480 //reset of recoverable error |
|
481 wrapper->SetErrorStatus(EFalse); |
|
482 |
|
483 TPtrC8 ptrName(aLocalName); |
|
484 TPtrC8 ptrPrefix; |
|
485 TPtrC8 ptrUri; |
|
486 HBufC8* buf = NULL; |
|
487 |
|
488 if(wrapper->IsFeatureEnabled(EConvertTagsToLowerCase)) |
|
489 { |
|
490 //remove buffer when any function in this method leave |
|
491 buf = HBufC8::NewLC(ptrName.Length()); |
|
492 buf->Des().Copy(ptrName); |
|
493 buf->Des().LowerCase(); |
|
494 ptrName.Set(buf->Des()); |
|
495 } |
|
496 |
|
497 if (aPrefix) |
|
498 ptrPrefix.Set(aPrefix); |
|
499 |
|
500 if (aURI) |
|
501 ptrUri.Set(aURI); |
|
502 |
|
503 RTagInfo nameTagInfo; |
|
504 RString strURI, strPrefix, strName; |
|
505 |
|
506 strURI = wrapper->StringPool().OpenStringL(ptrUri); |
|
507 CleanupClosePushL(strURI); |
|
508 |
|
509 strPrefix = wrapper->StringPool().OpenStringL(ptrPrefix); |
|
510 CleanupClosePushL(strPrefix); |
|
511 |
|
512 strName = wrapper->StringPool().OpenStringL(ptrName); |
|
513 |
|
514 CleanupStack::Pop(&strPrefix); |
|
515 CleanupStack::Pop(&strURI); |
|
516 |
|
517 nameTagInfo.Open(strURI, strPrefix, strName); |
|
518 CleanupClosePushL(nameTagInfo); |
|
519 |
|
520 const TUint8** ptr; |
|
521 ptr = aAttributes; |
|
522 |
|
523 RAttributeArray attributeArray; |
|
524 CleanupStack::PushL(TCleanupItem(AttributeArrayDelete, &attributeArray)); |
|
525 |
|
526 if (ptr) |
|
527 { |
|
528 for (TInt i=0; i<aNbAttributes; i++) |
|
529 { |
|
530 TPtrC8 attribName(*ptr); |
|
531 TPtrC8 attribPrefix; |
|
532 if (*(ptr+1)) |
|
533 { |
|
534 attribPrefix.Set(*(ptr + KAttribPrefixOffset)); |
|
535 } |
|
536 TPtrC8 attribURI; |
|
537 if (*(ptr + KAttribURIOffset)) |
|
538 { |
|
539 attribURI.Set(*(ptr + KAttribURIOffset)); |
|
540 } |
|
541 |
|
542 TPtrC8 attribValue(*(ptr + KAttribValueWithEndOffset), *(ptr+KAttribEndOffset) - *(ptr+KAttribValueWithEndOffset)); |
|
543 |
|
544 |
|
545 RString strAttribURI, strAttribPrefix, strAttribName, strAttribValue; |
|
546 |
|
547 strAttribURI = wrapper->StringPool().OpenStringL(attribURI); |
|
548 CleanupClosePushL(strAttribURI); |
|
549 |
|
550 strAttribPrefix = wrapper->StringPool().OpenStringL(attribPrefix); |
|
551 CleanupClosePushL(strAttribPrefix); |
|
552 |
|
553 strAttribName = wrapper->StringPool().OpenStringL(attribName); |
|
554 CleanupClosePushL(strAttribName); |
|
555 |
|
556 strAttribValue = wrapper->StringPool().OpenStringL(attribValue); |
|
557 |
|
558 CleanupStack::Pop(&strAttribName); |
|
559 CleanupStack::Pop(&strAttribPrefix); |
|
560 CleanupStack::Pop(&strAttribURI); |
|
561 |
|
562 RAttribute attrib; |
|
563 attrib.Open(strAttribURI, strAttribPrefix, strAttribName, strAttribValue); |
|
564 CleanupClosePushL(attrib); |
|
565 attributeArray.AppendL(attrib); |
|
566 CleanupStack::Pop(&attrib); |
|
567 |
|
568 ptr = ptr + KAttributeNextOffset; |
|
569 } |
|
570 } |
|
571 wrapper->getContentHandler()->OnStartElementL(nameTagInfo,attributeArray, KErrNone); |
|
572 CleanupStack::PopAndDestroy(&attributeArray); |
|
573 CleanupStack::PopAndDestroy(&nameTagInfo); |
|
574 |
|
575 if (buf) |
|
576 { |
|
577 CleanupStack::PopAndDestroy(buf); |
|
578 } |
|
579 } |
|
580 |
|
581 /** |
|
582 * StartElementNs: |
|
583 * @param aUserData the user data (XML parser context) |
|
584 * @param aLocalname the local name of the element |
|
585 * @param aPrefix the element namespace prefix if available |
|
586 * @param aURI the element namespace name if available |
|
587 * @param aNbNamespaces number of namespace definitions on that node |
|
588 * @param aNamespaces pointer to the array of prefix/URI pairs namespace definitions |
|
589 * @param aNbAttributes the number of attributes on that node |
|
590 * @param aNbDefaulted the number of defaulted attributes. The defaulted |
|
591 * ones are at the end of the array |
|
592 * @param aAttributes pointer to the array of (localname/prefix/URI/value/end) |
|
593 * attribute values. |
|
594 * |
|
595 * SAX2 callback when an element start has been detected by the parser. |
|
596 * It provides the namespace informations for the element, as well as |
|
597 * the new namespace declarations on the element. |
|
598 */ |
|
599 void StartElementNs( |
|
600 void *aUserData, |
|
601 const xmlChar *aLocalName, |
|
602 const xmlChar *aPrefix, |
|
603 const xmlChar *aURI, |
|
604 int aNbNamespaces, |
|
605 const xmlChar **aNamespaces, |
|
606 int aNbAttributes, |
|
607 int aNbDefaulted, |
|
608 const xmlChar **aAttributes) |
|
609 { |
|
610 TRAPD(error, StartElementNsL(aUserData,aLocalName,aPrefix,aURI, |
|
611 aNbNamespaces,aNamespaces,aNbAttributes,aNbDefaulted,aAttributes)); |
|
612 if(error != KErrNone) |
|
613 { |
|
614 CXMLEngineSAXPlugin* wrapper = reinterpret_cast<CXMLEngineSAXPlugin*>(aUserData); |
|
615 wrapper->StopParsing(error); |
|
616 } |
|
617 } |
|
618 |
|
619 /** |
|
620 * EndElementNsL: |
|
621 * @param aUserData the user data (XML parser context) |
|
622 * @param aLocalname the local name of the element |
|
623 * @param aPrefix the element namespace prefix if available |
|
624 * @param aURI the element namespace name if available |
|
625 * |
|
626 * SAX2 callback when an element end has been detected by the parser. |
|
627 * It provides the namespace informations for the element. |
|
628 */ |
|
629 void EndElementNsL( |
|
630 void *aUserData, |
|
631 const xmlChar *aLocalName, |
|
632 const xmlChar *aPrefix, |
|
633 const xmlChar *aURI) |
|
634 { |
|
635 |
|
636 CXMLEngineSAXPlugin* wrapper = reinterpret_cast<CXMLEngineSAXPlugin*>(aUserData); |
|
637 //reset of recoverable error |
|
638 wrapper->SetErrorStatus(EFalse); |
|
639 |
|
640 TPtrC8 ptrUri; |
|
641 TPtrC8 ptrPrefix; |
|
642 TPtrC8 ptrName(aLocalName); |
|
643 |
|
644 HBufC8* buf = NULL; |
|
645 |
|
646 if(wrapper->IsFeatureEnabled(EConvertTagsToLowerCase)) |
|
647 { |
|
648 //remove buffer when any function in this method leave |
|
649 buf = HBufC8::NewLC(ptrName.Length()); |
|
650 buf->Des().Copy(ptrName); |
|
651 buf->Des().LowerCase(); |
|
652 ptrName.Set(buf->Des()); |
|
653 } |
|
654 |
|
655 |
|
656 if (aPrefix) |
|
657 ptrPrefix.Set(aPrefix); |
|
658 |
|
659 if (aURI) |
|
660 ptrUri.Set(aURI); |
|
661 |
|
662 RTagInfo nameTagInfo; |
|
663 RString strURI, strPrefix, strName; |
|
664 |
|
665 strURI = wrapper->StringPool().OpenStringL(ptrUri); |
|
666 CleanupClosePushL(strURI); |
|
667 |
|
668 strPrefix = wrapper->StringPool().OpenStringL(ptrPrefix); |
|
669 CleanupClosePushL(strPrefix); |
|
670 |
|
671 strName = wrapper->StringPool().OpenStringL(ptrName); |
|
672 CleanupClosePushL(strName); |
|
673 |
|
674 nameTagInfo.Open(strURI, strPrefix, strName); |
|
675 wrapper->getContentHandler()->OnEndElementL(nameTagInfo, KErrNone); |
|
676 |
|
677 CleanupStack::PopAndDestroy(&strName); |
|
678 CleanupStack::PopAndDestroy(&strPrefix); |
|
679 CleanupStack::PopAndDestroy(&strURI); |
|
680 |
|
681 if (buf) |
|
682 { |
|
683 CleanupStack::PopAndDestroy(buf); |
|
684 } |
|
685 } |
|
686 |
|
687 /** |
|
688 * EndElementNs: |
|
689 * @param aUserData the user data (XML parser context) |
|
690 * @param aLocalname the local name of the element |
|
691 * @param aPrefix the element namespace prefix if available |
|
692 * @param aURI the element namespace name if available |
|
693 * |
|
694 * SAX2 callback when an element end has been detected by the parser. |
|
695 * It provides the namespace informations for the element. |
|
696 */ |
|
697 void EndElementNs( void *aUserData, |
|
698 const xmlChar *aLocalName, |
|
699 const xmlChar *aPrefix, |
|
700 const xmlChar *aURI) |
|
701 { |
|
702 TRAPD(error, EndElementNsL(aUserData,aLocalName,aPrefix,aURI)); |
|
703 if(error != KErrNone) |
|
704 { |
|
705 CXMLEngineSAXPlugin* wrapper = reinterpret_cast<CXMLEngineSAXPlugin*>(aUserData); |
|
706 wrapper->StopParsing(error); |
|
707 } |
|
708 } |
|
709 |
|
710 /** |
|
711 * StartPrefixMappingL: |
|
712 * @param aUserData the user data (XML parser context) |
|
713 * @param aPrefix the element namespace prefix if available, NULL if default namespace |
|
714 * @param aURI the element namespace name if available |
|
715 * |
|
716 * SAX2 callback when namespace prefix mapping is done. |
|
717 */ |
|
718 void StartPrefixMappingL( |
|
719 void* aUserData, |
|
720 const xmlChar* aPrefix, |
|
721 const xmlChar* aURI) |
|
722 { |
|
723 |
|
724 CXMLEngineSAXPlugin* wrapper = reinterpret_cast<CXMLEngineSAXPlugin*>(aUserData); |
|
725 //reset of recoverable error |
|
726 wrapper->SetErrorStatus(EFalse); |
|
727 |
|
728 if (wrapper->IsFeatureEnabled(EReportNamespaceMapping)) |
|
729 { |
|
730 TPtrC8 ptrPrefix; |
|
731 TPtrC8 ptrURI; |
|
732 |
|
733 if (aPrefix) |
|
734 { |
|
735 ptrPrefix.Set(aPrefix); |
|
736 } |
|
737 |
|
738 if (aURI) |
|
739 { |
|
740 ptrURI.Set(aURI); |
|
741 } |
|
742 |
|
743 |
|
744 RString strPrefix = wrapper->StringPool().OpenStringL(ptrPrefix); |
|
745 CleanupClosePushL(strPrefix); |
|
746 RString strURI = wrapper->StringPool().OpenStringL(ptrURI); |
|
747 CleanupClosePushL(strURI); |
|
748 wrapper->getContentHandler()->OnStartPrefixMappingL(strPrefix, strURI, KErrNone); |
|
749 CleanupStack::PopAndDestroy(&strURI); |
|
750 CleanupStack::PopAndDestroy(&strPrefix); |
|
751 } |
|
752 } |
|
753 |
|
754 /** |
|
755 * StartPrefixMapping: |
|
756 * @param aUserData the user data (XML parser context) |
|
757 * @param aPrefix the element namespace prefix if available, NULL if default namespace |
|
758 * @param aURI the element namespace name if available |
|
759 * |
|
760 * SAX2 callback when namespace prefix mapping is done. |
|
761 */ |
|
762 void StartPrefixMapping( |
|
763 void* aUserData, |
|
764 const xmlChar* aPrefix, |
|
765 const xmlChar* aURI) |
|
766 { |
|
767 TRAPD(error, StartPrefixMappingL(aUserData,aPrefix,aURI)); |
|
768 if(error != KErrNone) |
|
769 { |
|
770 CXMLEngineSAXPlugin* wrapper = reinterpret_cast<CXMLEngineSAXPlugin*>(aUserData); |
|
771 wrapper->StopParsing(error); |
|
772 } |
|
773 } |
|
774 |
|
775 /** |
|
776 * EndPrefixMappingL: |
|
777 * @param aUserData the user data (XML parser context) |
|
778 * @param aPrefix the element namespace prefix if available, NULL otherwise |
|
779 * |
|
780 * SAX2 callback when namespace prefix mapping is getting out of scope. |
|
781 */ |
|
782 void EndPrefixMappingL( |
|
783 void* aUserData, |
|
784 const xmlChar* aPrefix) |
|
785 { |
|
786 |
|
787 CXMLEngineSAXPlugin* wrapper = reinterpret_cast<CXMLEngineSAXPlugin*>(aUserData); |
|
788 //reset of recoverable error |
|
789 wrapper->SetErrorStatus(EFalse); |
|
790 |
|
791 if (wrapper->IsFeatureEnabled(EReportNamespaceMapping)) |
|
792 { |
|
793 TPtrC8 ptrPrefix; |
|
794 |
|
795 if (aPrefix) |
|
796 { |
|
797 ptrPrefix.Set(aPrefix); |
|
798 } |
|
799 |
|
800 RString strPrefix = wrapper->StringPool().OpenStringL(ptrPrefix); |
|
801 CleanupClosePushL(strPrefix); |
|
802 wrapper->getContentHandler()->OnEndPrefixMappingL(strPrefix, KErrNone); |
|
803 CleanupStack::PopAndDestroy(&strPrefix); |
|
804 } |
|
805 } |
|
806 |
|
807 /** |
|
808 * EndPrefixMapping: |
|
809 * @param aUserData the user data (XML parser context) |
|
810 * @param aPrefix the element namespace prefix if available, NULL otherwise |
|
811 * |
|
812 * SAX2 callback when namespace prefix mapping is getting out of scope. |
|
813 */ |
|
814 void EndPrefixMapping( |
|
815 void* aUserData, |
|
816 const xmlChar* aPrefix) |
|
817 { |
|
818 TRAPD(error, EndPrefixMappingL(aUserData,aPrefix)); |
|
819 if(error != KErrNone) |
|
820 { |
|
821 CXMLEngineSAXPlugin* wrapper = reinterpret_cast<CXMLEngineSAXPlugin*>(aUserData); |
|
822 wrapper->StopParsing(error); |
|
823 } |
|
824 } |