|
1 /* |
|
2 * Copyright (c) 2005,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: Primary datatype for the entire Document Object Model. |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "xndomnode.h" |
|
20 #include "xndomattribute.h" |
|
21 #include "xndomproperty.h" |
|
22 #include "xndomlist.h" |
|
23 #include "xndomstringpool.h" |
|
24 |
|
25 // LOCAL CONSTANTS AND MACROS |
|
26 const TInt KNotDefined = -1; |
|
27 _LIT8( KIdAttr, "id" ); |
|
28 _LIT8( KRefAttr, "ref" ); |
|
29 const TInt KPropertyListGranularity = 8; |
|
30 // ============================ MEMBER FUNCTIONS =============================== |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // CXnDomNode::CXnDomNode |
|
34 // C++ default constructor can NOT contain any code, that |
|
35 // might leave. |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 CXnDomNode::CXnDomNode(CXnDomStringPool& aStringPool) : |
|
39 iStringPool(aStringPool), iNodeId(KNotDefined) |
|
40 { |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // CXnDomNode::ConstructL |
|
45 // Symbian 2nd phase constructor can leave. |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 void CXnDomNode::ConstructL(const TDesC8& aName, const TDesC8& aNS) |
|
49 { |
|
50 iNameRef = iStringPool.AddStringL(aName); |
|
51 iNSRef = iStringPool.AddStringL(aNS); |
|
52 |
|
53 iChildList = CXnDomList::NewL(CXnDomList::ENodeList, iStringPool); |
|
54 iAttributeList |
|
55 = CXnDomList::NewL(CXnDomList::EAttributeList, iStringPool); |
|
56 iPropertyList = CXnDomList::NewL(CXnDomList::EPropertyList, iStringPool, |
|
57 KPropertyListGranularity); |
|
58 |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CXnDomNode::NewL |
|
63 // Two-phased constructor. |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 CXnDomNode* CXnDomNode::NewL(const TDesC8& aName, const TDesC8& aNS, |
|
67 CXnDomStringPool& aStringPool) |
|
68 { |
|
69 CXnDomNode* self = new (ELeave) CXnDomNode(aStringPool); |
|
70 |
|
71 CleanupStack::PushL(self); |
|
72 self->ConstructL(aName, aNS); |
|
73 CleanupStack::Pop(self); |
|
74 |
|
75 return self; |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CXnDomNode::NewL |
|
80 // Two-phased stream constructor. |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 CXnDomNode* CXnDomNode::NewL(RReadStream& aStream, |
|
84 CXnDomStringPool& aStringPool) |
|
85 { |
|
86 CXnDomNode* self = new (ELeave) CXnDomNode(aStringPool); |
|
87 |
|
88 CleanupStack::PushL(self); |
|
89 |
|
90 aStream >> *self; |
|
91 CleanupStack::Pop(self); |
|
92 |
|
93 return self; |
|
94 } |
|
95 |
|
96 // Destructor |
|
97 CXnDomNode::~CXnDomNode() |
|
98 { |
|
99 delete iChildList; |
|
100 delete iAttributeList; |
|
101 delete iPropertyList; |
|
102 |
|
103 delete iPCData; |
|
104 } |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // CXnDomNode::CloneL |
|
108 // Clones this node and it's child nodes. This is a recursive function. |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 EXPORT_C CXnDomNode* CXnDomNode::CloneL(CXnDomStringPool& aStringPool) |
|
112 { |
|
113 const TDesC8& name = iStringPool.String(iNameRef); |
|
114 const TDesC8& ns = iStringPool.String(iNSRef); |
|
115 |
|
116 CXnDomNode* clone = CXnDomNode::NewL(name, ns, aStringPool); |
|
117 CleanupStack::PushL(clone); |
|
118 if (iPCData) |
|
119 { |
|
120 clone->AppendPCDataL(*iPCData); |
|
121 } |
|
122 clone->iNodeId = iNodeId; |
|
123 clone->iRefNode = iRefNode; |
|
124 |
|
125 TInt childCount(iChildList->Length()); |
|
126 |
|
127 for (TInt i = 0; i < childCount; i++) |
|
128 { |
|
129 CXnDomNode* childClone = |
|
130 static_cast<CXnDomNode*> (iChildList->Item(i))->CloneL( |
|
131 aStringPool); |
|
132 CleanupStack::PushL(childClone); |
|
133 childClone->iParentNode = clone; |
|
134 clone->iChildList->AddItemL(childClone); |
|
135 CleanupStack::Pop(childClone); |
|
136 } |
|
137 |
|
138 TInt attrCount(iAttributeList->Length()); |
|
139 for (TInt j = 0; j < attrCount; j++) |
|
140 { |
|
141 CXnDomAttribute |
|
142 * attrClone = |
|
143 static_cast<CXnDomAttribute*> (iAttributeList->Item(j))->CloneL( |
|
144 aStringPool); |
|
145 CleanupStack::PushL(attrClone); |
|
146 clone->iAttributeList->AddItemL(attrClone); |
|
147 CleanupStack::Pop(attrClone); |
|
148 } |
|
149 |
|
150 TInt propertyCount(iPropertyList->Length()); |
|
151 for (TInt k = 0; k < propertyCount; k++) |
|
152 { |
|
153 CXnDomProperty |
|
154 * propClone = |
|
155 static_cast<CXnDomProperty*> (iPropertyList->Item(k))->CloneL( |
|
156 aStringPool); |
|
157 CleanupStack::PushL(propClone); |
|
158 clone->iPropertyList->AddItemL(propClone); |
|
159 CleanupStack::Pop(propClone); |
|
160 } |
|
161 CleanupStack::Pop(clone); |
|
162 return clone; |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // CXnDomNode::CloneWithoutKidsL |
|
167 // Clones only this node. This is a recursive function. |
|
168 // ----------------------------------------------------------------------------- |
|
169 // |
|
170 EXPORT_C CXnDomNode* CXnDomNode::CloneWithoutKidsL( |
|
171 CXnDomStringPool& aStringPool) |
|
172 { |
|
173 const TDesC8& name = iStringPool.String(iNameRef); |
|
174 const TDesC8& ns = iStringPool.String(iNSRef); |
|
175 |
|
176 CXnDomNode* clone = CXnDomNode::NewL(name, ns, aStringPool); |
|
177 CleanupStack::PushL(clone); |
|
178 if (iPCData) |
|
179 { |
|
180 clone->AppendPCDataL(*iPCData); |
|
181 } |
|
182 clone->iNodeId = iNodeId; |
|
183 clone->iRefNode = iRefNode; |
|
184 |
|
185 TInt attrCount(iAttributeList->Length()); |
|
186 for (TInt j = 0; j < attrCount; j++) |
|
187 { |
|
188 CXnDomAttribute |
|
189 * attrClone = |
|
190 static_cast<CXnDomAttribute*> (iAttributeList->Item(j))->CloneL( |
|
191 aStringPool); |
|
192 CleanupStack::PushL(attrClone); |
|
193 clone->iAttributeList->AddItemL(attrClone); |
|
194 CleanupStack::Pop(attrClone); |
|
195 } |
|
196 |
|
197 TInt propertyCount(iPropertyList->Length()); |
|
198 for (TInt k = 0; k < propertyCount; k++) |
|
199 { |
|
200 CXnDomProperty |
|
201 * propClone = |
|
202 static_cast<CXnDomProperty*> (iPropertyList->Item(k))->CloneL( |
|
203 aStringPool); |
|
204 CleanupStack::PushL(propClone); |
|
205 clone->iPropertyList->AddItemL(propClone); |
|
206 CleanupStack::Pop(propClone); |
|
207 } |
|
208 CleanupStack::Pop(clone); |
|
209 return clone; |
|
210 } |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // CXnDomNode::CreateRefNodeL |
|
214 // Recursive function to create referer nodes. |
|
215 // ----------------------------------------------------------------------------- |
|
216 // |
|
217 EXPORT_C CXnDomNode* CXnDomNode::CreateRefNodeL() |
|
218 { |
|
219 const TDesC8& name = iStringPool.String(iNameRef); |
|
220 const TDesC8& ns = iStringPool.String(iNSRef); |
|
221 |
|
222 CXnDomNode* ref = CXnDomNode::NewL(name, ns, iStringPool); |
|
223 CleanupStack::PushL(ref); |
|
224 |
|
225 ref->iRefNode = ETrue; |
|
226 |
|
227 TInt childCount(iChildList->Length()); |
|
228 |
|
229 for (TInt i = 0; i < childCount; i++) |
|
230 { |
|
231 CXnDomNode |
|
232 * childRef = |
|
233 static_cast<CXnDomNode*> (iChildList->Item(i))->CreateRefNodeL(); |
|
234 CleanupStack::PushL(childRef); |
|
235 childRef->iParentNode = ref; |
|
236 ref->iChildList->AddItemL(childRef); |
|
237 CleanupStack::Pop(childRef); |
|
238 } |
|
239 |
|
240 CXnDomAttribute* attr = NULL; |
|
241 if (!iRefNode) |
|
242 { |
|
243 attr = static_cast<CXnDomAttribute*> (iAttributeList->FindByName( |
|
244 KIdAttr)); |
|
245 } |
|
246 else |
|
247 { |
|
248 attr = static_cast<CXnDomAttribute*> (iAttributeList->FindByName( |
|
249 KRefAttr)); |
|
250 } |
|
251 |
|
252 if (attr) |
|
253 { |
|
254 CXnDomAttribute* newAttr = CXnDomAttribute::NewL(KRefAttr, |
|
255 iStringPool); |
|
256 CleanupStack::PushL(newAttr); |
|
257 newAttr->SetValueL(attr->Value()); |
|
258 ref->iAttributeList->AddItemL(newAttr); |
|
259 CleanupStack::Pop(newAttr); |
|
260 } |
|
261 else |
|
262 { |
|
263 //referred node don't have an id or ref, thats not ok. |
|
264 User::Leave(KErrArgument); |
|
265 } |
|
266 |
|
267 CleanupStack::Pop(ref); |
|
268 return ref; |
|
269 } |
|
270 |
|
271 // ----------------------------------------------------------------------------- |
|
272 // CXnDomNode::Name |
|
273 // ----------------------------------------------------------------------------- |
|
274 // |
|
275 EXPORT_C const TDesC8& CXnDomNode::Name() |
|
276 { |
|
277 return iStringPool.String(iNameRef); |
|
278 } |
|
279 |
|
280 // ----------------------------------------------------------------------------- |
|
281 // CXnDomNode::Namespace |
|
282 // ----------------------------------------------------------------------------- |
|
283 // |
|
284 EXPORT_C const TDesC8& CXnDomNode::Namespace() |
|
285 { |
|
286 return iStringPool.String(iNSRef); |
|
287 } |
|
288 |
|
289 // ----------------------------------------------------------------------------- |
|
290 // CXnDomNode::AttributeList |
|
291 // ----------------------------------------------------------------------------- |
|
292 // |
|
293 EXPORT_C CXnDomList& CXnDomNode::AttributeList() const |
|
294 { |
|
295 return *iAttributeList; |
|
296 } |
|
297 // ----------------------------------------------------------------------------- |
|
298 // CXnDomNode::PropertyList |
|
299 // ----------------------------------------------------------------------------- |
|
300 // |
|
301 EXPORT_C CXnDomList& CXnDomNode::PropertyList() |
|
302 { |
|
303 return *iPropertyList; |
|
304 } |
|
305 // ----------------------------------------------------------------------------- |
|
306 // CXnDomNode::SetParent |
|
307 // ----------------------------------------------------------------------------- |
|
308 // |
|
309 EXPORT_C void CXnDomNode::SetParent(CXnDomNode* aParent) |
|
310 { |
|
311 iParentNode = aParent; |
|
312 } |
|
313 // ----------------------------------------------------------------------------- |
|
314 // CXnDomNode::Parent |
|
315 // ----------------------------------------------------------------------------- |
|
316 // |
|
317 EXPORT_C CXnDomNode* CXnDomNode::Parent() const |
|
318 { |
|
319 return iParentNode; |
|
320 } |
|
321 // ----------------------------------------------------------------------------- |
|
322 // CXnDomNode::AddChildL |
|
323 // ----------------------------------------------------------------------------- |
|
324 // |
|
325 EXPORT_C void CXnDomNode::AddChildL(CXnDomNode* aNode) |
|
326 { |
|
327 aNode->SetParent(this); |
|
328 iChildList->AddItemL(aNode); |
|
329 } |
|
330 |
|
331 // ----------------------------------------------------------------------------- |
|
332 // CXnDomNode::AddChildL |
|
333 // ----------------------------------------------------------------------------- |
|
334 // |
|
335 EXPORT_C void CXnDomNode::AddChildL(CXnDomNode* aNode, TInt aIndex) |
|
336 { |
|
337 aNode->SetParent(this); |
|
338 iChildList->AddItemL(aNode, aIndex); |
|
339 } |
|
340 |
|
341 // ----------------------------------------------------------------------------- |
|
342 // CXnDomNode::DeleteChild |
|
343 // ----------------------------------------------------------------------------- |
|
344 // |
|
345 EXPORT_C void CXnDomNode::DeleteChild(CXnDomNode* aNode) |
|
346 { |
|
347 iChildList->DeleteItem(aNode); |
|
348 } |
|
349 |
|
350 // ----------------------------------------------------------------------------- |
|
351 // CXnDomNode::ReplaceChildL |
|
352 // ----------------------------------------------------------------------------- |
|
353 // |
|
354 EXPORT_C void CXnDomNode::ReplaceChildL(CXnDomNode* aNode, |
|
355 CXnDomNode* aNewNode) |
|
356 { |
|
357 CXnDomNode* swapChild = NULL; |
|
358 CXnDomList& childList = aNode->ChildNodes(); |
|
359 TInt childCount(childList.Length()); |
|
360 for (TInt i = 0; i < childCount; i++) |
|
361 { |
|
362 swapChild = static_cast<CXnDomNode*> (childList.Item(i)); |
|
363 aNewNode->AddChildL(swapChild); //Let the new node adopt the child |
|
364 childList.RemoveItem(swapChild); //Remove it from the orginal parent |
|
365 } |
|
366 iChildList->DeleteItem(aNode); // Delete the old child |
|
367 |
|
368 aNewNode->SetParent(this); //Set new child |
|
369 iChildList->AddItemL(aNewNode); |
|
370 } |
|
371 |
|
372 // ----------------------------------------------------------------------------- |
|
373 // CXnDomNode::ChildNodes |
|
374 // ----------------------------------------------------------------------------- |
|
375 // |
|
376 EXPORT_C CXnDomList& CXnDomNode::ChildNodes() |
|
377 { |
|
378 return *iChildList; |
|
379 } |
|
380 // ----------------------------------------------------------------------------- |
|
381 // CXnDomNode::SetNodeId |
|
382 // ----------------------------------------------------------------------------- |
|
383 // |
|
384 EXPORT_C void CXnDomNode::SetNodeId(const TInt aNodeId) |
|
385 { |
|
386 iNodeId = aNodeId; |
|
387 } |
|
388 // ----------------------------------------------------------------------------- |
|
389 // CXnDomNode::NodeId |
|
390 // ----------------------------------------------------------------------------- |
|
391 // |
|
392 EXPORT_C TInt CXnDomNode::NodeId() const |
|
393 { |
|
394 return iNodeId; |
|
395 } |
|
396 |
|
397 // ----------------------------------------------------------------------------- |
|
398 // CXnDomNode::ItemIndex |
|
399 // ----------------------------------------------------------------------------- |
|
400 // |
|
401 EXPORT_C TInt CXnDomNode::ItemIndex(const MXnDomListItem& aItem) const |
|
402 { |
|
403 return iChildList->ItemIndex(aItem); |
|
404 } |
|
405 |
|
406 // ----------------------------------------------------------------------------- |
|
407 // CXnDomNode::AppendPCDataL |
|
408 // ----------------------------------------------------------------------------- |
|
409 // |
|
410 EXPORT_C void CXnDomNode::AppendPCDataL(const TDesC8& aPCData) |
|
411 { |
|
412 if (iPCData) |
|
413 { |
|
414 iPCData = iPCData->ReAllocL(iPCData->Length() + aPCData.Length()); |
|
415 iPCData->Des().Append(aPCData); |
|
416 } |
|
417 else |
|
418 { |
|
419 iPCData = aPCData.AllocL(); |
|
420 } |
|
421 } |
|
422 |
|
423 // ----------------------------------------------------------------------------- |
|
424 // CXnDomNode::PCData |
|
425 // ----------------------------------------------------------------------------- |
|
426 // |
|
427 EXPORT_C const TDesC8& CXnDomNode::PCData() |
|
428 { |
|
429 if (iPCData) |
|
430 { |
|
431 return *iPCData; |
|
432 } |
|
433 return KNullDesC8; |
|
434 } |
|
435 |
|
436 // ----------------------------------------------------------------------------- |
|
437 // CXnDomNode::SetPCDataL |
|
438 // ----------------------------------------------------------------------------- |
|
439 // |
|
440 EXPORT_C void CXnDomNode::SetPCDataL(const TDesC8& aPCData) |
|
441 { |
|
442 if (iPCData) |
|
443 { |
|
444 delete iPCData; |
|
445 iPCData = NULL; |
|
446 } |
|
447 iPCData = aPCData.AllocL(); |
|
448 } |
|
449 |
|
450 // ----------------------------------------------------------------------------- |
|
451 // CXnDomNode::ContentType |
|
452 // ----------------------------------------------------------------------------- |
|
453 // |
|
454 EXPORT_C const TContentType& CXnDomNode::ContentType() |
|
455 { |
|
456 return iContentType; |
|
457 } |
|
458 |
|
459 // ----------------------------------------------------------------------------- |
|
460 // CXnDomNode::SetContentType |
|
461 // ----------------------------------------------------------------------------- |
|
462 // |
|
463 EXPORT_C void CXnDomNode::SetContentType(const TContentType& aContentType) |
|
464 { |
|
465 iContentType = aContentType; |
|
466 } |
|
467 |
|
468 // ----------------------------------------------------------------------------- |
|
469 // CXnDomNode::StringPool |
|
470 // ----------------------------------------------------------------------------- |
|
471 // |
|
472 EXPORT_C CXnDomStringPool& CXnDomNode::StringPool() const |
|
473 { |
|
474 return iStringPool; |
|
475 } |
|
476 |
|
477 // ----------------------------------------------------------------------------- |
|
478 // CXnDomNode::SetRefNode |
|
479 // ----------------------------------------------------------------------------- |
|
480 // |
|
481 EXPORT_C void CXnDomNode::SetRefNode(TBool aRefNode) |
|
482 { |
|
483 iRefNode = aRefNode; |
|
484 } |
|
485 |
|
486 // ----------------------------------------------------------------------------- |
|
487 // CXnDomNode::IsRefNode |
|
488 // ----------------------------------------------------------------------------- |
|
489 // |
|
490 EXPORT_C TBool CXnDomNode::IsRefNode() const |
|
491 { |
|
492 return iRefNode; |
|
493 } |
|
494 // ----------------------------------------------------------------------------- |
|
495 // CXnDomNode::Size |
|
496 // ----------------------------------------------------------------------------- |
|
497 // |
|
498 TInt CXnDomNode::Size() const |
|
499 { |
|
500 TInt size(0); |
|
501 |
|
502 size += sizeof(TInt16); //iNameRef |
|
503 size += sizeof(TInt16); //iNSRef |
|
504 size += sizeof(TBool); //iRefNode |
|
505 if (iPCData) |
|
506 { |
|
507 size += sizeof(TInt8); |
|
508 size += sizeof(TInt16); |
|
509 size += iPCData->Size(); |
|
510 size++; |
|
511 } |
|
512 else |
|
513 { |
|
514 size += sizeof(TInt8); |
|
515 } |
|
516 |
|
517 size += sizeof(TInt32); //For nodeId |
|
518 size += iAttributeList->Size(); |
|
519 size += iPropertyList->Size(); |
|
520 |
|
521 size += iChildList->Size(); |
|
522 |
|
523 return size; |
|
524 } |
|
525 // ----------------------------------------------------------------------------- |
|
526 // CXnDomNode::ExternalizeL |
|
527 // NOTE: This function is not implemented yet! |
|
528 // ----------------------------------------------------------------------------- |
|
529 // |
|
530 void CXnDomNode::ExternalizeL(RWriteStream& aStream) const |
|
531 { |
|
532 |
|
533 aStream.WriteInt16L(iNameRef); |
|
534 aStream.WriteInt16L(iNSRef); |
|
535 aStream.WriteInt8L(iRefNode); |
|
536 |
|
537 if (iPCData) |
|
538 { |
|
539 aStream.WriteInt8L(ETrue); |
|
540 aStream.WriteInt16L(iPCData->Length()); |
|
541 aStream << *iPCData; |
|
542 } |
|
543 else |
|
544 { |
|
545 aStream.WriteInt8L(EFalse); |
|
546 } |
|
547 |
|
548 aStream.WriteInt32L(iNodeId); |
|
549 aStream << *iChildList; |
|
550 aStream << *iAttributeList; |
|
551 aStream << *iPropertyList; |
|
552 } |
|
553 |
|
554 // ----------------------------------------------------------------------------- |
|
555 // CXnDomNode::InternalizeL |
|
556 // ----------------------------------------------------------------------------- |
|
557 // |
|
558 void CXnDomNode::InternalizeL(RReadStream& aStream) |
|
559 { |
|
560 iNameRef = aStream.ReadInt16L() + iStringPool.Offset(); |
|
561 iNSRef = aStream.ReadInt16L() + iStringPool.Offset(); |
|
562 iRefNode = aStream.ReadInt8L(); |
|
563 |
|
564 TInt len(0); |
|
565 TBool exist(aStream.ReadInt8L()); |
|
566 if (exist) |
|
567 { |
|
568 len = aStream.ReadInt16L(); |
|
569 delete iPCData; |
|
570 iPCData = NULL; |
|
571 iPCData = HBufC8::NewL(aStream, len); |
|
572 } |
|
573 |
|
574 iNodeId = aStream.ReadInt32L(); |
|
575 |
|
576 iChildList = CXnDomList::NewL(aStream, iStringPool); |
|
577 TInt count(iChildList->Length()); |
|
578 for (TInt i = 0; i < count; i++) |
|
579 { |
|
580 CXnDomNode* node = static_cast<CXnDomNode*> (iChildList->Item(i)); |
|
581 if (node) |
|
582 { |
|
583 node->SetParent(this); |
|
584 } |
|
585 else |
|
586 { |
|
587 User::Leave(KErrArgument); |
|
588 } |
|
589 } |
|
590 |
|
591 iAttributeList = CXnDomList::NewL(aStream, iStringPool); |
|
592 |
|
593 iPropertyList = CXnDomList::NewL(aStream, iStringPool); |
|
594 } |
|
595 |
|
596 // ----------------------------------------------------------------------------- |
|
597 // CXnDomNode::ReadL |
|
598 // ----------------------------------------------------------------------------- |
|
599 // |
|
600 void CXnDomNode::ReadL(RReadStream& aStream) |
|
601 { |
|
602 iNameRef = aStream.ReadInt16L(); |
|
603 iNSRef = aStream.ReadInt16L(); |
|
604 iRefNode = aStream.ReadInt8L(); |
|
605 |
|
606 TBool exist(aStream.ReadInt8L()); |
|
607 if (exist) |
|
608 { |
|
609 TInt len(0); |
|
610 len = aStream.ReadInt16L(); |
|
611 delete iPCData; |
|
612 iPCData = NULL; |
|
613 iPCData = HBufC8::NewL(aStream, len); |
|
614 } |
|
615 |
|
616 iNodeId = aStream.ReadInt32L(); |
|
617 |
|
618 iChildList = CXnDomList::NewL(aStream, iStringPool); |
|
619 TInt count(iChildList->Length()); |
|
620 for (TInt i = 0; i < count; i++) |
|
621 { |
|
622 CXnDomNode* node = static_cast<CXnDomNode*> (iChildList->Item(i)); |
|
623 if (node) |
|
624 { |
|
625 node->SetParent(this); |
|
626 } |
|
627 else |
|
628 { |
|
629 User::Leave(KErrArgument); |
|
630 } |
|
631 } |
|
632 |
|
633 iAttributeList = CXnDomList::NewL(aStream, iStringPool); |
|
634 |
|
635 iPropertyList = CXnDomList::NewL(aStream, iStringPool); |
|
636 } |
|
637 |
|
638 // ----------------------------------------------------------------------------- |
|
639 // CXnDomNode::DescendantCount |
|
640 // Recursive counting function |
|
641 // ----------------------------------------------------------------------------- |
|
642 // |
|
643 EXPORT_C TInt CXnDomNode::DescendantCount() const |
|
644 { |
|
645 TInt count(1); //Node itself |
|
646 |
|
647 TInt length(iChildList->Length()); |
|
648 for (TInt i = 0; i < length; i++) |
|
649 { |
|
650 count |
|
651 += static_cast<CXnDomNode*> (iChildList->Item(i))->DescendantCount(); |
|
652 } |
|
653 |
|
654 return count; |
|
655 } |
|
656 |
|
657 // ----------------------------------------------------------------------------- |
|
658 // CXnDomNode::DeleteAttributeList |
|
659 // Deletes the attribute list |
|
660 // ----------------------------------------------------------------------------- |
|
661 // |
|
662 EXPORT_C void CXnDomNode::DeleteAttributeList() |
|
663 { |
|
664 delete iAttributeList; |
|
665 iAttributeList = NULL; |
|
666 |
|
667 } |
|
668 |
|
669 // ----------------------------------------------------------------------------- |
|
670 // CXnDomNode::AttributeValue |
|
671 // Returns value of "name" attribute |
|
672 // ----------------------------------------------------------------------------- |
|
673 // |
|
674 EXPORT_C const TDesC8& CXnDomNode::AttributeValue(const TDesC8& aAttribute) const |
|
675 { |
|
676 CXnDomAttribute* attribute = |
|
677 static_cast<CXnDomAttribute*> (iAttributeList->FindByName( |
|
678 aAttribute)); |
|
679 if (attribute) |
|
680 { |
|
681 return attribute->Value(); |
|
682 } |
|
683 else |
|
684 { |
|
685 return KNullDesC8; |
|
686 } |
|
687 } |
|
688 |
|
689 // ----------------------------------------------------------------------------- |
|
690 // CXnDomNode::SetLayoutNode |
|
691 // Sets pointer to associated layout node |
|
692 // ----------------------------------------------------------------------------- |
|
693 // |
|
694 EXPORT_C void CXnDomNode::SetLayoutNode(CXnNode* aNode) |
|
695 { |
|
696 iLayoutNode = aNode; |
|
697 } |
|
698 |
|
699 // ----------------------------------------------------------------------------- |
|
700 // CXnDomNode::LayoutNode |
|
701 // Gets pointer to associated layout node |
|
702 // ----------------------------------------------------------------------------- |
|
703 // |
|
704 EXPORT_C CXnNode* CXnDomNode::LayoutNode() |
|
705 { |
|
706 return iLayoutNode; |
|
707 } |
|
708 |
|
709 // ----------------------------------------------------------------------------- |
|
710 // CXnDomNode::SetNamespaceL |
|
711 // ----------------------------------------------------------------------------- |
|
712 // |
|
713 EXPORT_C void CXnDomNode::SetNamespaceL(const TDesC8& aNS) |
|
714 { |
|
715 iNSRef = iStringPool.AddStringL(aNS); |
|
716 } |
|
717 |
|
718 // ----------------------------------------------------------------------------- |
|
719 // CXnDomNode::CloneL |
|
720 // Clones this node and it's child nodes and sets new namespace. This is a |
|
721 // recursive function. |
|
722 // ----------------------------------------------------------------------------- |
|
723 // |
|
724 EXPORT_C CXnDomNode* CXnDomNode::CloneL(CXnDomStringPool& aStringPool, |
|
725 const TDesC8& aNS) |
|
726 { |
|
727 const TDesC8& name = iStringPool.String(iNameRef); |
|
728 |
|
729 CXnDomNode* clone = CXnDomNode::NewL(name, aNS, aStringPool); |
|
730 CleanupStack::PushL(clone); |
|
731 if (iPCData) |
|
732 { |
|
733 clone->AppendPCDataL(*iPCData); |
|
734 } |
|
735 clone->iNodeId = iNodeId; |
|
736 clone->iRefNode = iRefNode; |
|
737 |
|
738 TInt childCount(iChildList->Length()); |
|
739 |
|
740 for (TInt i = 0; i < childCount; i++) |
|
741 { |
|
742 CXnDomNode* childClone = |
|
743 static_cast<CXnDomNode*> (iChildList->Item(i))->CloneL( |
|
744 aStringPool, aNS); |
|
745 CleanupStack::PushL(childClone); |
|
746 childClone->iParentNode = clone; |
|
747 clone->iChildList->AddItemL(childClone); |
|
748 CleanupStack::Pop(childClone); |
|
749 } |
|
750 |
|
751 TInt attrCount(iAttributeList->Length()); |
|
752 for (TInt j = 0; j < attrCount; j++) |
|
753 { |
|
754 CXnDomAttribute |
|
755 * attrClone = |
|
756 static_cast<CXnDomAttribute*> (iAttributeList->Item(j))->CloneL( |
|
757 aStringPool); |
|
758 CleanupStack::PushL(attrClone); |
|
759 clone->iAttributeList->AddItemL(attrClone); |
|
760 CleanupStack::Pop(attrClone); |
|
761 } |
|
762 |
|
763 TInt propertyCount(iPropertyList->Length()); |
|
764 for (TInt k = 0; k < propertyCount; k++) |
|
765 { |
|
766 CXnDomProperty |
|
767 * propClone = |
|
768 static_cast<CXnDomProperty*> (iPropertyList->Item(k))->CloneL( |
|
769 aStringPool); |
|
770 CleanupStack::PushL(propClone); |
|
771 clone->iPropertyList->AddItemL(propClone); |
|
772 CleanupStack::Pop(propClone); |
|
773 } |
|
774 CleanupStack::Pop(clone); |
|
775 return clone; |
|
776 } |
|
777 |
|
778 // ----------------------------------------------------------------------------- |
|
779 // CXnDomNode::SetOwnershipL |
|
780 // Clones this node and it's child nodes and sets new namespace. This is a |
|
781 // recursive function. |
|
782 // ----------------------------------------------------------------------------- |
|
783 // |
|
784 EXPORT_C void CXnDomNode::SetOwnershipL(const TDesC8& aNS) |
|
785 { |
|
786 TInt childCount(iChildList->Length()); |
|
787 |
|
788 SetNamespaceL(aNS); |
|
789 for (TInt i = 0; i < childCount; i++) |
|
790 { |
|
791 CXnDomNode* child = static_cast<CXnDomNode*> (iChildList->Item(i)); |
|
792 child->SetOwnershipL(aNS); |
|
793 } |
|
794 } |
|
795 |
|
796 // End of File |