|
1 /* |
|
2 * Copyright (c) 2002-2006 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: Class implements XML DOM fragment using libxml2 classes |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 // INCLUDE FILES |
|
26 #include "SenDomFragmentBase.h" |
|
27 #include <xmlengserializationoptions.h> // needed for TSerializationOptions |
|
28 |
|
29 |
|
30 EXPORT_C CSenDomFragmentBase* CSenDomFragmentBase::NewL() |
|
31 { |
|
32 CSenDomFragmentBase* pNew = new (ELeave) CSenDomFragmentBase; |
|
33 CleanupStack::PushL(pNew); |
|
34 pNew->BaseConstructL(); |
|
35 CleanupStack::Pop(); // Pop pNew |
|
36 return pNew; |
|
37 } |
|
38 |
|
39 EXPORT_C CSenDomFragmentBase* CSenDomFragmentBase::NewL(const TXmlEngElement& aElement) |
|
40 { |
|
41 CSenDomFragmentBase* pNew = new (ELeave) CSenDomFragmentBase; |
|
42 CleanupStack::PushL(pNew); |
|
43 pNew->BaseConstructL(aElement); |
|
44 CleanupStack::Pop(); // Pop pNew |
|
45 return pNew; |
|
46 } |
|
47 |
|
48 EXPORT_C CSenDomFragmentBase* CSenDomFragmentBase::NewL(const TDesC8& aLocalName) |
|
49 { |
|
50 CSenDomFragmentBase* pNew = new (ELeave) CSenDomFragmentBase; |
|
51 CleanupStack::PushL(pNew); |
|
52 pNew->BaseConstructL(aLocalName); |
|
53 CleanupStack::Pop(); // Pop pNew |
|
54 return pNew; |
|
55 } |
|
56 |
|
57 EXPORT_C CSenDomFragmentBase* CSenDomFragmentBase::NewL( |
|
58 const TDesC8& aNsUri, |
|
59 const TDesC8& aLocalName |
|
60 ) |
|
61 { |
|
62 CSenDomFragmentBase* pNew = new (ELeave) CSenDomFragmentBase; |
|
63 CleanupStack::PushL(pNew); |
|
64 pNew->BaseConstructL(aNsUri, aLocalName); |
|
65 CleanupStack::Pop(); // Pop pNew |
|
66 return pNew; |
|
67 } |
|
68 |
|
69 EXPORT_C CSenDomFragmentBase* CSenDomFragmentBase::NewL( |
|
70 const TDesC8& aNsUri, |
|
71 const TDesC8& aLocalName, |
|
72 const TDesC8& aPrefix, |
|
73 const RAttributeArray& aAttrs |
|
74 ) |
|
75 { |
|
76 CSenDomFragmentBase* pNew = new (ELeave) CSenDomFragmentBase; |
|
77 CleanupStack::PushL(pNew); |
|
78 pNew->BaseConstructL(aNsUri, aLocalName, aPrefix, aAttrs); |
|
79 CleanupStack::Pop(); // Pop pNew |
|
80 return pNew; |
|
81 } |
|
82 |
|
83 EXPORT_C CSenDomFragmentBase* CSenDomFragmentBase::NewL( |
|
84 const TDesC8& aNsUri, |
|
85 const TDesC8& aLocalName, |
|
86 const TDesC8& aPrefix, |
|
87 const RAttributeArray& aAttrs, |
|
88 TXmlEngElement& aParent |
|
89 ) |
|
90 { |
|
91 CSenDomFragmentBase* pNew = new (ELeave) CSenDomFragmentBase; |
|
92 CleanupStack::PushL(pNew); |
|
93 pNew->BaseConstructL(aNsUri, aLocalName, aPrefix, aAttrs, aParent); |
|
94 CleanupStack::Pop(); // delete pNew; |
|
95 return pNew; |
|
96 } |
|
97 |
|
98 EXPORT_C CSenDomFragmentBase* CSenDomFragmentBase::NewL( |
|
99 const TDesC8& aNsUri, |
|
100 const TDesC8& aLocalName, |
|
101 const TDesC8& aPrefix, |
|
102 const RAttributeArray& aAttrs, |
|
103 TXmlEngElement& aParent, |
|
104 RSenDocument& aOwnerDocument |
|
105 ) |
|
106 { |
|
107 CSenDomFragmentBase* pNew = new (ELeave) CSenDomFragmentBase; |
|
108 CleanupStack::PushL(pNew); |
|
109 pNew->BaseConstructL(aNsUri, aLocalName, aPrefix, aAttrs, aParent, |
|
110 aOwnerDocument); |
|
111 CleanupStack::Pop(); // delete pNew; |
|
112 return pNew; |
|
113 } |
|
114 |
|
115 EXPORT_C CSenDomFragmentBase* CSenDomFragmentBase::NewL( |
|
116 const TDesC8& aNsUri, |
|
117 const TDesC8& aLocalName, |
|
118 const TDesC8& aPrefix |
|
119 ) |
|
120 { |
|
121 CSenDomFragmentBase* pNew = new (ELeave) CSenDomFragmentBase; |
|
122 CleanupStack::PushL(pNew); |
|
123 pNew->BaseConstructL(aNsUri, aLocalName, aPrefix); |
|
124 CleanupStack::Pop(); // delete pNew; |
|
125 return pNew; |
|
126 } |
|
127 |
|
128 EXPORT_C CSenDomFragmentBase::~CSenDomFragmentBase() |
|
129 { |
|
130 if ( ipDomDelegate ) |
|
131 { |
|
132 // We do not own the element, so remove it from the fragment. |
|
133 //ipDomDelegate->ExtractElement(); |
|
134 delete ipDomDelegate; |
|
135 ipDomDelegate = NULL; |
|
136 } |
|
137 } |
|
138 |
|
139 EXPORT_C CSenDomFragmentBase::CSenDomFragmentBase() |
|
140 : ipDomDelegate(NULL) |
|
141 { |
|
142 } |
|
143 |
|
144 EXPORT_C void CSenDomFragmentBase::BaseConstructL() |
|
145 { |
|
146 iDocument = RSenDocument::NewL(); |
|
147 } |
|
148 |
|
149 EXPORT_C void CSenDomFragmentBase::BaseConstructL(const TXmlEngElement& aElement) |
|
150 { |
|
151 CSenFragmentBase::BaseConstructL(aElement); |
|
152 } |
|
153 |
|
154 EXPORT_C void CSenDomFragmentBase::BaseConstructL(const TDesC8& aLocalName) |
|
155 { |
|
156 CSenFragmentBase::BaseConstructL(aLocalName); |
|
157 } |
|
158 |
|
159 EXPORT_C void CSenDomFragmentBase::BaseConstructL( |
|
160 const TDesC8& aNsUri, |
|
161 const TDesC8& aLocalName |
|
162 ) |
|
163 { |
|
164 CSenFragmentBase::BaseConstructL(aNsUri, aLocalName); |
|
165 } |
|
166 |
|
167 EXPORT_C void CSenDomFragmentBase::BaseConstructL( |
|
168 const TDesC8& aNsUri, |
|
169 const TDesC8& aLocalName, |
|
170 const TDesC8& aPrefix, |
|
171 const RAttributeArray& aAttrs |
|
172 ) |
|
173 { |
|
174 CSenFragmentBase::BaseConstructL(aNsUri, aLocalName, aPrefix, aAttrs); |
|
175 } |
|
176 |
|
177 EXPORT_C void CSenDomFragmentBase::BaseConstructL( |
|
178 const TDesC8& aNsUri, |
|
179 const TDesC8& aLocalName, |
|
180 const TDesC8& aPrefix, |
|
181 const RAttributeArray& aAttrs, |
|
182 TXmlEngElement& aParent |
|
183 ) |
|
184 { |
|
185 CSenFragmentBase::BaseConstructL( aNsUri, |
|
186 aLocalName, |
|
187 aPrefix, |
|
188 aAttrs, |
|
189 aParent); |
|
190 } |
|
191 |
|
192 EXPORT_C void CSenDomFragmentBase::BaseConstructL( |
|
193 const TDesC8& aNsUri, |
|
194 const TDesC8& aLocalName, |
|
195 const TDesC8& aPrefix, |
|
196 const RAttributeArray& aAttrs, |
|
197 TXmlEngElement& aParent, |
|
198 RSenDocument& aOwnerDocument |
|
199 ) |
|
200 { |
|
201 CSenFragmentBase::BaseConstructL( aNsUri, |
|
202 aLocalName, |
|
203 aPrefix, |
|
204 aAttrs, |
|
205 aParent, |
|
206 aOwnerDocument); |
|
207 } |
|
208 |
|
209 EXPORT_C void CSenDomFragmentBase::BaseConstructL( |
|
210 const TDesC8& aNsUri, |
|
211 const TDesC8& aLocalName, |
|
212 const TDesC8& aPrefix |
|
213 ) |
|
214 { |
|
215 CSenFragmentBase::BaseConstructL(aNsUri, aLocalName, aPrefix); |
|
216 } |
|
217 |
|
218 EXPORT_C void CSenDomFragmentBase::OnStartElementL(const RTagInfo& aElement, |
|
219 const RAttributeArray& aAttributes, |
|
220 TInt aErrorCode) |
|
221 { |
|
222 const TPtrC8 saxLocalName = aElement.LocalName().DesC(); |
|
223 const TPtrC8 saxNsUri = aElement.Uri().DesC(); |
|
224 const TPtrC8 saxPrefix = aElement.Prefix().DesC(); |
|
225 |
|
226 |
|
227 if ( iElement.IsNull() ) |
|
228 { |
|
229 if ( saxNsUri == KNullDesC8 && saxPrefix == KNullDesC8 ) |
|
230 { |
|
231 iDocument.CreateDocumentElementL(saxLocalName); |
|
232 } |
|
233 else |
|
234 { |
|
235 if ( saxPrefix == KNullDesC8 ) |
|
236 { |
|
237 iDocument.CreateDocumentElementL(saxLocalName, |
|
238 saxNsUri, |
|
239 KNullDesC8); |
|
240 } |
|
241 else |
|
242 { |
|
243 iDocument.CreateDocumentElementL(saxLocalName, |
|
244 saxNsUri, |
|
245 saxPrefix); |
|
246 } |
|
247 } |
|
248 iElement = iDocument.DocumentElement(); |
|
249 } |
|
250 |
|
251 TXmlEngElement element = AsElementL(); |
|
252 |
|
253 TPtrC8 localName = element.Name(); |
|
254 TPtrC8 nsUri(KNullDesC8); |
|
255 if ( element.NamespaceUri() != KNullDesC8 ) |
|
256 { |
|
257 nsUri.Set(element.NamespaceUri()); |
|
258 } |
|
259 |
|
260 if(iState == KSenStateIgnore) |
|
261 { |
|
262 if(localName == saxLocalName && nsUri == saxNsUri) |
|
263 { |
|
264 iState = KSenStateSave; |
|
265 AddNamespacesL(); |
|
266 AddAttributesL(aAttributes); |
|
267 } |
|
268 else |
|
269 { |
|
270 if ( ipNamespaceArray ) |
|
271 { |
|
272 ipNamespaceArray->ResetAndDestroy(); |
|
273 } |
|
274 } |
|
275 } |
|
276 else if((iState & KSenStateSave) == KSenStateSave) |
|
277 { |
|
278 ExpandL(aElement, aAttributes, aErrorCode); |
|
279 } |
|
280 } |
|
281 |
|
282 EXPORT_C void CSenDomFragmentBase::OnContentL(const TDesC8& aBytes, |
|
283 TInt /*aErrorCode*/) |
|
284 { |
|
285 if((iState & KSenStateSave) == KSenStateSave) |
|
286 { |
|
287 TXmlEngElement element = AsElementL(); |
|
288 element.AddTextL(aBytes); |
|
289 } |
|
290 } |
|
291 |
|
292 EXPORT_C void CSenDomFragmentBase::ExpandL(const RTagInfo& aElement, |
|
293 const RAttributeArray& aAttributes, |
|
294 TInt /*aErrorCode*/) |
|
295 { |
|
296 if ( ipDomDelegate ) |
|
297 { |
|
298 // We do not own the element, so remove it from the fragment. |
|
299 //ipDomDelegate->ExtractElement(); |
|
300 delete ipDomDelegate; |
|
301 ipDomDelegate = NULL; |
|
302 } |
|
303 |
|
304 const TPtrC8 saxLocalName = aElement.LocalName().DesC(); |
|
305 const TPtrC8 saxNsUri = aElement.Uri().DesC(); |
|
306 const TPtrC8 saxPrefix = aElement.Prefix().DesC(); |
|
307 |
|
308 TXmlEngElement element = AsElementL(); |
|
309 RSenDocument document = AsDocumentL(); |
|
310 |
|
311 // delegate parsing to a new DOMFragment, |
|
312 // until we encounter the end of an element with the given qualified name |
|
313 ipDomDelegate = CSenDomFragmentBase::NewL( saxNsUri, |
|
314 saxLocalName, |
|
315 saxPrefix, |
|
316 aAttributes, |
|
317 element, |
|
318 document ); |
|
319 |
|
320 ipDomDelegate->iState = KSenStateDelegate; |
|
321 |
|
322 OnDelegateParsingL(*ipDomDelegate); // note that the parsing is actually |
|
323 // performed AFTER the StartElement() |
|
324 // method, which called this ExpandL() |
|
325 // has been fully executed (this is an |
|
326 // async signal send to the _same_ |
|
327 // parser(!) |
|
328 } |
|
329 |
|
330 |
|
331 EXPORT_C void CSenDomFragmentBase::OnWriteStartElementL( |
|
332 const RTagInfo& /*aElement*/, |
|
333 const RAttributeArray& /*aAttributes*/) |
|
334 { |
|
335 // in DOM fragment: do nothing |
|
336 } |
|
337 |
|
338 EXPORT_C void CSenDomFragmentBase::OnWriteEndElementL( |
|
339 const RTagInfo& /*aElement*/) |
|
340 { |
|
341 // in DOM fragment: do nothing |
|
342 } |
|
343 |
|
344 |
|
345 // Overridden from CSenBaseFragment to be much more simple |
|
346 EXPORT_C void CSenDomFragmentBase::OnResumeParsingFromL( |
|
347 const RTagInfo& /*aElement*/, |
|
348 TInt /*aErrorCode*/) |
|
349 { |
|
350 SetContentHandler(*this); |
|
351 |
|
352 if ( ipDomDelegate ) |
|
353 { |
|
354 delete ipDomDelegate; |
|
355 ipDomDelegate = NULL; |
|
356 } |
|
357 } |
|
358 |
|
359 EXPORT_C HBufC8* CSenDomFragmentBase::AsXmlL() |
|
360 { |
|
361 return CSenFragmentBase::AsXmlL(); |
|
362 } |
|
363 |
|
364 EXPORT_C void CSenDomFragmentBase::AddNamespacesL() |
|
365 { |
|
366 CSenFragmentBase::AddNamespacesL(); |
|
367 } |
|
368 |
|
369 EXPORT_C void CSenDomFragmentBase::AddAttributesL(const RAttributeArray& aAttrs) |
|
370 { |
|
371 CSenFragmentBase::AddAttributesL(aAttrs); |
|
372 } |
|
373 |
|
374 EXPORT_C void CSenDomFragmentBase::OnEndElementL(const RTagInfo& aElement, TInt aErrorCode) |
|
375 { |
|
376 CSenFragmentBase::OnEndElementL(aElement, aErrorCode); |
|
377 } |
|
378 |
|
379 EXPORT_C void CSenDomFragmentBase::OnStartDocumentL(const RDocumentParameters& /*aDocParam*/, TInt /*aErrorCode*/) |
|
380 { |
|
381 // in DOM fragment: do nothing |
|
382 } |
|
383 |
|
384 EXPORT_C void CSenDomFragmentBase::OnEndDocumentL(TInt /*aErrorCode*/) |
|
385 { |
|
386 // in DOM fragment: do nothing |
|
387 } |
|
388 |
|
389 EXPORT_C void CSenDomFragmentBase::OnStartPrefixMappingL(const RString& aPrefix, const RString& aUri, TInt aErrorCode) |
|
390 { |
|
391 CSenFragmentBase::OnStartPrefixMappingL(aPrefix, aUri, aErrorCode); |
|
392 } |
|
393 |
|
394 EXPORT_C void CSenDomFragmentBase::OnEndPrefixMappingL(const RString& aPrefix, TInt aErrorCode) |
|
395 { |
|
396 CSenFragmentBase::OnEndPrefixMappingL(aPrefix, aErrorCode); |
|
397 } |
|
398 |
|
399 EXPORT_C void CSenDomFragmentBase::OnIgnorableWhiteSpaceL(const TDesC8& aBytes, TInt ErrorCode) |
|
400 { |
|
401 CSenFragmentBase::OnIgnorableWhiteSpaceL(aBytes, ErrorCode); |
|
402 } |
|
403 |
|
404 EXPORT_C void CSenDomFragmentBase::OnSkippedEntityL(const RString& aName, TInt aErrorCode) |
|
405 { |
|
406 CSenFragmentBase::OnSkippedEntityL(aName, aErrorCode); |
|
407 } |
|
408 |
|
409 EXPORT_C void CSenDomFragmentBase::OnProcessingInstructionL(const TDesC8& aTarget, const TDesC8& aData, TInt aErrorCode) |
|
410 { |
|
411 CSenFragmentBase::OnProcessingInstructionL(aTarget, aData, aErrorCode); |
|
412 } |
|
413 |
|
414 EXPORT_C void CSenDomFragmentBase::OnError(TInt aErrorCode) |
|
415 { |
|
416 CSenFragmentBase::OnError(aErrorCode); |
|
417 } |
|
418 |
|
419 EXPORT_C TAny* CSenDomFragmentBase::GetExtendedInterface(const TInt32 aUid) |
|
420 { |
|
421 return CSenFragmentBase::GetExtendedInterface(aUid); |
|
422 } |
|
423 |
|
424 EXPORT_C TPtrC8 CSenDomFragmentBase::ContentL() |
|
425 { |
|
426 return CSenFragmentBase::ContentL(); |
|
427 } |
|
428 |
|
429 EXPORT_C TXmlEngNamespace CSenDomFragmentBase::Namespace(const TDesC8& aPrefix) |
|
430 { |
|
431 return CSenFragmentBase::Namespace(aPrefix); |
|
432 } |
|
433 |
|
434 //EXPORT_C void CSenDomFragmentBase::DetachL() |
|
435 // { |
|
436 // CSenFragmentBase::DetachL(); |
|
437 // } |
|
438 |
|
439 EXPORT_C void CSenDomFragmentBase::ResetContentL() |
|
440 { |
|
441 CSenFragmentBase::ResetContentL(); |
|
442 } |
|
443 |
|
444 EXPORT_C TPtrC8 CSenDomFragmentBase::LocalName() const |
|
445 { |
|
446 return CSenFragmentBase::LocalName(); |
|
447 } |
|
448 |
|
449 EXPORT_C TPtrC8 CSenDomFragmentBase::NsUri() const |
|
450 { |
|
451 return CSenFragmentBase::NsUri(); |
|
452 } |
|
453 |
|
454 EXPORT_C TPtrC8 CSenDomFragmentBase::NsPrefix() const |
|
455 { |
|
456 return CSenFragmentBase::NsPrefix(); |
|
457 } |
|
458 |
|
459 EXPORT_C TXmlEngElement CSenDomFragmentBase::AsElementL() |
|
460 { |
|
461 return CSenFragmentBase::AsElementL(); |
|
462 } |
|
463 |
|
464 EXPORT_C RSenDocument& CSenDomFragmentBase::AsDocumentL() |
|
465 { |
|
466 return CSenFragmentBase::AsDocumentL(); |
|
467 } |
|
468 |
|
469 EXPORT_C TXmlEngElement CSenDomFragmentBase::ExtractElement() |
|
470 { |
|
471 return CSenFragmentBase::ExtractElement(); |
|
472 } |
|
473 |
|
474 EXPORT_C void CSenDomFragmentBase::OnDelegateParsingL(CSenFragmentBase& aDelegate) |
|
475 { |
|
476 CSenFragmentBase::OnDelegateParsingL(aDelegate); |
|
477 } |
|
478 |
|
479 EXPORT_C void CSenDomFragmentBase::OnDelegateParsingL(const RTagInfo& aElement, |
|
480 const RAttributeArray& aAttributes, |
|
481 TInt aErrorCode) |
|
482 { |
|
483 CSenFragmentBase::OnDelegateParsingL(aElement, aAttributes, aErrorCode); |
|
484 } |
|
485 |
|
486 EXPORT_C void CSenDomFragmentBase::SetOwner(CSenFragmentBase& aFragment) |
|
487 { |
|
488 CSenFragmentBase::SetOwner(aFragment); |
|
489 } |
|
490 |
|
491 EXPORT_C HBufC* CSenDomFragmentBase::AsXmlUnicodeL() |
|
492 { |
|
493 return CSenFragmentBase::AsXmlUnicodeL(); |
|
494 } |
|
495 |
|
496 EXPORT_C void CSenDomFragmentBase::WriteAsXMLToL(RWriteStream& aWs) |
|
497 { |
|
498 CSenFragmentBase::WriteAsXMLToL(aWs); |
|
499 } |
|
500 |
|
501 EXPORT_C TBool CSenDomFragmentBase::ConsistsOfL(CSenFragmentBase& aCandidate) |
|
502 { |
|
503 return CSenFragmentBase::ConsistsOfL(aCandidate); |
|
504 } |
|
505 |
|
506 EXPORT_C void CSenDomFragmentBase::SetContentHandler(CSenFragmentBase& aContentHandler) |
|
507 { |
|
508 CSenFragmentBase::SetContentHandler(aContentHandler); |
|
509 } |
|
510 |
|
511 void CSenDomFragmentBase::RenameL(const TDesC8& aLocalName, const TDesC8& aPrefix, const TDesC8& aNamespace) |
|
512 { |
|
513 CSenFragmentBase::RenameL(aLocalName, aPrefix, aNamespace); |
|
514 } |
|
515 |
|
516 void CSenDomFragmentBase::RenameL(const TDesC8& aLocalName, const TDesC8& aNamespace) |
|
517 { |
|
518 CSenFragmentBase::RenameL(aLocalName, aNamespace); |
|
519 } |
|
520 |
|
521 void CSenDomFragmentBase::RenameLocalNameL(const TDesC8& aLocalName) |
|
522 { |
|
523 CSenFragmentBase::RenameLocalNameL(aLocalName); |
|
524 } |
|
525 |
|
526 void CSenDomFragmentBase::RenameNamespaceL(const TDesC8& aNamespace) |
|
527 { |
|
528 CSenFragmentBase::RenameNamespaceL(aNamespace); |
|
529 } |
|
530 |
|
531 void CSenDomFragmentBase::RenamePrefixL(const TDesC8& aPrefix) |
|
532 { |
|
533 CSenFragmentBase::RenamePrefixL(aPrefix); |
|
534 } |
|
535 |
|
536 void CSenDomFragmentBase::RenameNamespaceL(const TDesC8& aPrefix, const TDesC8& aNamespace) |
|
537 { |
|
538 CSenFragmentBase::RenameNamespaceL(aPrefix, aNamespace); |
|
539 } |
|
540 |
|
541 EXPORT_C TXmlEngElement CSenDomFragmentBase::SetContentOfL(const TDesC8& aLocalName, |
|
542 const TDesC8& aContent) |
|
543 { |
|
544 return CSenFragmentBase::SetContentOfL(aLocalName, aContent); |
|
545 } |
|
546 |
|
547 EXPORT_C TPtrC8 CSenDomFragmentBase::ContentOf(const TDesC8& aLocalName) |
|
548 { |
|
549 return CSenFragmentBase::ContentOf(aLocalName); |
|
550 } |
|
551 |
|
552 EXPORT_C TBool CSenDomFragmentBase::ConsistsOfL(TXmlEngElement& aElement, |
|
553 TXmlEngElement& aCandidate) |
|
554 { |
|
555 return CSenFragmentBase::ConsistsOfL(aElement, aCandidate); |
|
556 } |
|
557 |
|
558 |
|
559 // End of File |
|
560 |