22 #include "xndomlist.h" |
22 #include "xndomlist.h" |
23 #include "xndomstringpool.h" |
23 #include "xndomstringpool.h" |
24 |
24 |
25 // LOCAL CONSTANTS AND MACROS |
25 // LOCAL CONSTANTS AND MACROS |
26 const TInt KNotDefined = -1; |
26 const TInt KNotDefined = -1; |
27 _LIT8( KIdAttr, "id" ); |
|
28 _LIT8( KRefAttr, "ref" ); |
|
29 const TInt KPropertyListGranularity = 8; |
27 const TInt KPropertyListGranularity = 8; |
30 // ============================ MEMBER FUNCTIONS =============================== |
28 // ============================ MEMBER FUNCTIONS =============================== |
31 |
29 |
32 // ----------------------------------------------------------------------------- |
30 // ----------------------------------------------------------------------------- |
33 // CXnDomNode::CXnDomNode |
31 // CXnDomNode::CXnDomNode |
34 // C++ default constructor can NOT contain any code, that |
32 // C++ default constructor can NOT contain any code, that |
35 // might leave. |
33 // might leave. |
36 // ----------------------------------------------------------------------------- |
34 // ----------------------------------------------------------------------------- |
37 // |
35 // |
38 CXnDomNode::CXnDomNode(CXnDomStringPool& aStringPool) : |
36 CXnDomNode::CXnDomNode(CXnDomStringPool* aStringPool) : |
39 iStringPool(aStringPool), iNodeId(KNotDefined) |
37 iNameRef( KNotDefined ), |
|
38 iNSRef( KNotDefined ), |
|
39 iStringPool( aStringPool ), |
|
40 iNodeId( KNotDefined ) |
40 { |
41 { |
41 } |
42 } |
42 |
43 |
43 // ----------------------------------------------------------------------------- |
44 // ----------------------------------------------------------------------------- |
44 // CXnDomNode::ConstructL |
45 // CXnDomNode::ConstructL |
45 // Symbian 2nd phase constructor can leave. |
46 // Symbian 2nd phase constructor can leave. |
46 // ----------------------------------------------------------------------------- |
47 // ----------------------------------------------------------------------------- |
47 // |
48 // |
48 void CXnDomNode::ConstructL(const TDesC8& aName, const TDesC8& aNS) |
49 void CXnDomNode::ConstructL(const TDesC8& aName, const TDesC8& aNS) |
49 { |
50 { |
50 iNameRef = iStringPool.AddStringL(aName); |
51 iNameRef = iStringPool->AddStringL(aName); |
51 iNSRef = iStringPool.AddStringL(aNS); |
52 iNSRef = iStringPool->AddStringL(aNS); |
52 |
53 |
53 iChildList = CXnDomList::NewL(CXnDomList::ENodeList, iStringPool); |
54 iChildList = CXnDomList::NewL(CXnDomList::ENodeList, iStringPool); |
54 iAttributeList |
55 iAttributeList |
55 = CXnDomList::NewL(CXnDomList::EAttributeList, iStringPool); |
56 = CXnDomList::NewL(CXnDomList::EAttributeList, iStringPool); |
56 iPropertyList = CXnDomList::NewL(CXnDomList::EPropertyList, iStringPool, |
57 iPropertyList = CXnDomList::NewL(CXnDomList::EPropertyList, iStringPool, |
62 // CXnDomNode::NewL |
63 // CXnDomNode::NewL |
63 // Two-phased constructor. |
64 // Two-phased constructor. |
64 // ----------------------------------------------------------------------------- |
65 // ----------------------------------------------------------------------------- |
65 // |
66 // |
66 CXnDomNode* CXnDomNode::NewL(const TDesC8& aName, const TDesC8& aNS, |
67 CXnDomNode* CXnDomNode::NewL(const TDesC8& aName, const TDesC8& aNS, |
67 CXnDomStringPool& aStringPool) |
68 CXnDomStringPool* aStringPool) |
68 { |
69 { |
69 CXnDomNode* self = new (ELeave) CXnDomNode(aStringPool); |
70 CXnDomNode* self = new (ELeave) CXnDomNode(aStringPool); |
70 |
71 |
71 CleanupStack::PushL(self); |
72 CleanupStack::PushL(self); |
72 self->ConstructL(aName, aNS); |
73 self->ConstructL(aName, aNS); |
101 delete iPropertyList; |
102 delete iPropertyList; |
102 |
103 |
103 delete iPCData; |
104 delete iPCData; |
104 } |
105 } |
105 |
106 |
106 // ----------------------------------------------------------------------------- |
107 // --------------------------------------------------------------------- |
107 // CXnDomNode::CloneL |
108 // CXnDomNode::CloneL |
108 // Clones this node and it's child nodes. This is a recursive function. |
109 // Clones this node and it's child nodes. This is a recursive function. |
109 // ----------------------------------------------------------------------------- |
110 // ----------------------------------------------------------------------------- |
110 // |
111 // |
111 EXPORT_C CXnDomNode* CXnDomNode::CloneL(CXnDomStringPool& aStringPool) |
112 EXPORT_C CXnDomNode* CXnDomNode::CloneL(CXnDomStringPool& aStringPool) |
112 { |
113 { |
113 const TDesC8& name = iStringPool.String(iNameRef); |
114 const TDesC8& name = iStringPool->String(iNameRef); |
114 const TDesC8& ns = iStringPool.String(iNSRef); |
115 const TDesC8& ns = iStringPool->String(iNSRef); |
115 |
116 |
116 CXnDomNode* clone = CXnDomNode::NewL(name, ns, aStringPool); |
117 CXnDomNode* clone = CXnDomNode::NewL(name, ns, &aStringPool); |
117 CleanupStack::PushL(clone); |
118 CleanupStack::PushL(clone); |
118 if (iPCData) |
119 if (iPCData) |
119 { |
120 { |
120 clone->AppendPCDataL(*iPCData); |
121 clone->AppendPCDataL(*iPCData); |
121 } |
122 } |
122 clone->iNodeId = iNodeId; |
123 clone->iNodeId = iNodeId; |
123 clone->iRefNode = iRefNode; |
|
124 |
124 |
125 TInt childCount(iChildList->Length()); |
125 TInt childCount(iChildList->Length()); |
126 |
126 |
127 for (TInt i = 0; i < childCount; i++) |
127 for (TInt i = 0; i < childCount; i++) |
128 { |
128 { |
161 CleanupStack::Pop(clone); |
161 CleanupStack::Pop(clone); |
162 return clone; |
162 return clone; |
163 } |
163 } |
164 |
164 |
165 // ----------------------------------------------------------------------------- |
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 |
166 // CXnDomNode::Name |
273 // ----------------------------------------------------------------------------- |
167 // ----------------------------------------------------------------------------- |
274 // |
168 // |
275 EXPORT_C const TDesC8& CXnDomNode::Name() |
169 EXPORT_C const TDesC8& CXnDomNode::Name() |
276 { |
170 { |
277 return iStringPool.String(iNameRef); |
171 if( iNameRef == KNotDefined ) |
|
172 { |
|
173 return KNullDesC8(); |
|
174 } |
|
175 else |
|
176 { |
|
177 return iStringPool->String( iNameRef ); |
|
178 } |
278 } |
179 } |
279 |
180 |
280 // ----------------------------------------------------------------------------- |
181 // ----------------------------------------------------------------------------- |
281 // CXnDomNode::Namespace |
182 // CXnDomNode::Namespace |
282 // ----------------------------------------------------------------------------- |
183 // ----------------------------------------------------------------------------- |
283 // |
184 // |
284 EXPORT_C const TDesC8& CXnDomNode::Namespace() |
185 EXPORT_C const TDesC8& CXnDomNode::Namespace() |
285 { |
186 { |
286 return iStringPool.String(iNSRef); |
187 if( iNSRef == KNotDefined ) |
|
188 { |
|
189 return KNullDesC8(); |
|
190 } |
|
191 else |
|
192 { |
|
193 return iStringPool->String( iNSRef ); |
|
194 } |
287 } |
195 } |
288 |
196 |
289 // ----------------------------------------------------------------------------- |
197 // ----------------------------------------------------------------------------- |
290 // CXnDomNode::AttributeList |
198 // CXnDomNode::AttributeList |
291 // ----------------------------------------------------------------------------- |
199 // ----------------------------------------------------------------------------- |
467 |
375 |
468 // ----------------------------------------------------------------------------- |
376 // ----------------------------------------------------------------------------- |
469 // CXnDomNode::StringPool |
377 // CXnDomNode::StringPool |
470 // ----------------------------------------------------------------------------- |
378 // ----------------------------------------------------------------------------- |
471 // |
379 // |
472 EXPORT_C CXnDomStringPool& CXnDomNode::StringPool() const |
380 EXPORT_C CXnDomStringPool* CXnDomNode::StringPool() const |
473 { |
381 { |
474 return iStringPool; |
382 return iStringPool; |
475 } |
383 } |
476 |
384 |
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 // ----------------------------------------------------------------------------- |
385 // ----------------------------------------------------------------------------- |
495 // CXnDomNode::Size |
386 // CXnDomNode::Size |
496 // ----------------------------------------------------------------------------- |
387 // ----------------------------------------------------------------------------- |
497 // |
388 // |
498 TInt CXnDomNode::Size() const |
389 TInt CXnDomNode::Size() const |
553 |
443 |
554 // ----------------------------------------------------------------------------- |
444 // ----------------------------------------------------------------------------- |
555 // CXnDomNode::InternalizeL |
445 // CXnDomNode::InternalizeL |
556 // ----------------------------------------------------------------------------- |
446 // ----------------------------------------------------------------------------- |
557 // |
447 // |
558 void CXnDomNode::InternalizeL(RReadStream& aStream) |
448 void CXnDomNode::InternalizeL( RReadStream& aStream ) |
559 { |
449 { |
560 iNameRef = aStream.ReadInt16L() + iStringPool.Offset(); |
450 iNameRef = aStream.ReadInt16L(); |
561 iNSRef = aStream.ReadInt16L() + iStringPool.Offset(); |
451 |
562 iRefNode = aStream.ReadInt8L(); |
452 iNSRef = KNotDefined; // This is set later by call to setnamespace, |
|
453 aStream.ReadInt16L(); // so only consume legacy data from stream. |
|
454 |
|
455 aStream.ReadInt8L(); // Consume legacy ref node parameter. |
563 |
456 |
564 TInt len(0); |
457 TInt len(0); |
565 TBool exist(aStream.ReadInt8L()); |
458 TBool exist(aStream.ReadInt8L()); |
566 if (exist) |
459 if (exist) |
567 { |
460 { |
587 User::Leave(KErrArgument); |
480 User::Leave(KErrArgument); |
588 } |
481 } |
589 } |
482 } |
590 |
483 |
591 iAttributeList = CXnDomList::NewL(aStream, iStringPool); |
484 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); |
485 iPropertyList = CXnDomList::NewL(aStream, iStringPool); |
636 } |
486 } |
637 |
487 |
638 // ----------------------------------------------------------------------------- |
488 // ----------------------------------------------------------------------------- |
639 // CXnDomNode::DescendantCount |
489 // CXnDomNode::DescendantCount |
710 // CXnDomNode::SetNamespaceL |
560 // CXnDomNode::SetNamespaceL |
711 // ----------------------------------------------------------------------------- |
561 // ----------------------------------------------------------------------------- |
712 // |
562 // |
713 EXPORT_C void CXnDomNode::SetNamespaceL(const TDesC8& aNS) |
563 EXPORT_C void CXnDomNode::SetNamespaceL(const TDesC8& aNS) |
714 { |
564 { |
715 iNSRef = iStringPool.AddStringL(aNS); |
565 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 } |
566 } |
777 |
567 |
778 // ----------------------------------------------------------------------------- |
568 // ----------------------------------------------------------------------------- |
779 // CXnDomNode::SetOwnershipL |
569 // CXnDomNode::SetOwnershipL |
780 // Clones this node and it's child nodes and sets new namespace. This is a |
570 // Clones this node and it's child nodes and sets new namespace. This is a |
791 CXnDomNode* child = static_cast<CXnDomNode*> (iChildList->Item(i)); |
581 CXnDomNode* child = static_cast<CXnDomNode*> (iChildList->Item(i)); |
792 child->SetOwnershipL(aNS); |
582 child->SetOwnershipL(aNS); |
793 } |
583 } |
794 } |
584 } |
795 |
585 |
|
586 // ----------------------------------------------------------------------------- |
|
587 // CXnDomNode::SwapStringPoolL |
|
588 // ----------------------------------------------------------------------------- |
|
589 // |
|
590 EXPORT_C void CXnDomNode::SwapStringPoolL( CXnDomStringPool* aStringPool ) |
|
591 { |
|
592 if( !aStringPool ) |
|
593 { |
|
594 User::Leave( KErrArgument ); |
|
595 } |
|
596 |
|
597 if( iNameRef != KNotDefined ) |
|
598 { |
|
599 iNameRef = aStringPool->AddStringL( iStringPool->String( iNameRef ) ); |
|
600 } |
|
601 |
|
602 if( iNSRef != KNotDefined ) |
|
603 { |
|
604 iNSRef = aStringPool->AddStringL( iStringPool->String( iNSRef ) ); |
|
605 } |
|
606 |
|
607 iChildList->SwapStringPoolL( aStringPool ); |
|
608 TInt count = iChildList->Length(); |
|
609 for( TInt i = 0; i < count; i++ ) |
|
610 { |
|
611 CXnDomNode* obj = |
|
612 static_cast<CXnDomNode*> ( iChildList->Item( i ) ); |
|
613 obj->SwapStringPoolL( aStringPool ); |
|
614 } |
|
615 |
|
616 iAttributeList->SwapStringPoolL( aStringPool ); |
|
617 count = iAttributeList->Length(); |
|
618 for( TInt i = 0; i < count; i++ ) |
|
619 { |
|
620 CXnDomAttribute* obj = |
|
621 static_cast<CXnDomAttribute*> ( iAttributeList->Item( i ) ); |
|
622 obj->SwapStringPoolL( aStringPool ); |
|
623 } |
|
624 |
|
625 count = iPropertyList->Length(); |
|
626 iPropertyList->SwapStringPoolL( aStringPool ); |
|
627 for( TInt i = 0; i < count; i++ ) |
|
628 { |
|
629 CXnDomProperty* obj = |
|
630 static_cast<CXnDomProperty*> ( iPropertyList->Item( i ) ); |
|
631 obj->SwapStringPoolL( aStringPool ); |
|
632 } |
|
633 |
|
634 iStringPool = aStringPool; |
|
635 } |
|
636 |
796 // End of File |
637 // End of File |