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