homescreenpluginsrv/hspsdom/src/hspsdomdocument.cpp
changeset 0 79c6a41cd166
child 12 502e5d91ad42
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     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:  Represents the entire xmluiml specific xml and css data. 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "hspsdomdocument.h"
       
    22 #include    "hspsdomnode.h"
       
    23 #include    "hspsdomlist.h"
       
    24 #include    "hspsdomstringpool.h"
       
    25 #include    <s32mem.h>
       
    26 
       
    27     
       
    28 // ============================ MEMBER FUNCTIONS ===============================    
       
    29 // -----------------------------------------------------------------------------
       
    30 // ChspsDomDocument::CloneL()
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 EXPORT_C ChspsDomDocument* ChspsDomDocument::CloneL()
       
    34     {
       
    35     ChspsDomDocument* clone = new (ELeave) ChspsDomDocument;
       
    36     CleanupStack::PushL( clone );
       
    37     
       
    38     clone->iDomStringPool = iDomStringPool->CloneL();
       
    39     if ( iRootNode )
       
    40         {
       
    41         clone->iRootNode = iRootNode->CloneL( *clone->iDomStringPool );
       
    42         }
       
    43     
       
    44     CleanupStack::Pop( clone );
       
    45     return clone;
       
    46     }
       
    47     
       
    48 // -----------------------------------------------------------------------------
       
    49 // ChspsDomDocument::CreateElementNSL
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 EXPORT_C ChspsDomNode* ChspsDomDocument::CreateElementNSL( 
       
    53     const TDesC8& aName, 
       
    54     const TDesC8& aNamespace )
       
    55     {
       
    56     return ChspsDomNode::NewL( aName, aNamespace, *iDomStringPool );
       
    57     }
       
    58 // -----------------------------------------------------------------------------
       
    59 // ChspsDomDocument::ChspsDomDocument
       
    60 // C++ default constructor can NOT contain any code, that
       
    61 // might leave.
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 ChspsDomDocument::ChspsDomDocument()
       
    65     {
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // ChspsDomDocument::ConstructL
       
    70 // Symbian 2nd phase constructor can leave.
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 void ChspsDomDocument::ConstructL()
       
    74     {
       
    75     iDomStringPool = ChspsDomStringPool::NewL();
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // ChspsDomDocument::NewL
       
    80 // Two-phased constructor.
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 EXPORT_C ChspsDomDocument* ChspsDomDocument::NewL()
       
    84     {
       
    85     ChspsDomDocument* self = new( ELeave ) ChspsDomDocument;
       
    86     
       
    87     CleanupStack::PushL( self );
       
    88     self->ConstructL();
       
    89     CleanupStack::Pop(self);
       
    90 
       
    91     return self;
       
    92     }
       
    93 // -----------------------------------------------------------------------------
       
    94 // ChspsDomDocument::NewL
       
    95 // Two-phased constructor.
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 EXPORT_C ChspsDomDocument* ChspsDomDocument::NewL( 
       
    99     RReadStream& aStream )
       
   100     {
       
   101     ChspsDomDocument* self = new( ELeave ) ChspsDomDocument;
       
   102     
       
   103     CleanupStack::PushL( self );
       
   104     aStream >> *self;
       
   105     CleanupStack::Pop(self);
       
   106 
       
   107     return self;
       
   108     }
       
   109 // -----------------------------------------------------------------------------
       
   110 // ChspsDomDocument::NewL
       
   111 // Constructs ChspsDomDocument from streamed HBufC8.
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 EXPORT_C ChspsDomDocument* ChspsDomDocument::NewL( 
       
   115     const HBufC8* aBufStream )
       
   116     {
       
   117     RDesReadStream readStream( *aBufStream );
       
   118     CleanupClosePushL( readStream );
       
   119     ChspsDomDocument* self = ChspsDomDocument::NewL( readStream );
       
   120     CleanupStack::PopAndDestroy( &readStream );
       
   121     return self;   
       
   122     }
       
   123 
       
   124 // Destructor
       
   125 EXPORT_C ChspsDomDocument::~ChspsDomDocument()
       
   126     {
       
   127     if ( iRootNode )
       
   128         {
       
   129         delete iRootNode;
       
   130         }
       
   131     
       
   132     if ( iDomStringPool )
       
   133         {
       
   134         delete iDomStringPool;
       
   135         }
       
   136     }
       
   137 
       
   138 // -----------------------------------------------------------------------------
       
   139 // ChspsDomDocument::DomNodeCount
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 EXPORT_C TInt ChspsDomDocument::DomNodeCount() const
       
   143     {
       
   144     TInt count( 0 );
       
   145     if ( iRootNode )
       
   146         {
       
   147         count = iRootNode->DescendantCount();
       
   148         }
       
   149     return count;
       
   150     }
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 // ChspsDomDocument::ExternalizeL
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 EXPORT_C void ChspsDomDocument::ExternalizeL( RWriteStream& aStream ) const
       
   157     {
       
   158     aStream << *iDomStringPool;
       
   159         
       
   160     if ( iRootNode )
       
   161         {
       
   162         aStream.WriteInt8L( ETrue );    //Root node exist
       
   163         aStream << *iRootNode;
       
   164         }
       
   165     else
       
   166         {
       
   167         aStream.WriteInt8L( EFalse );
       
   168         }    
       
   169     }
       
   170     
       
   171 // -----------------------------------------------------------------------------
       
   172 // ChspsDomDocument::InternalizeL
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 EXPORT_C void ChspsDomDocument::InternalizeL( RReadStream& aStream )
       
   176     {
       
   177     if(iDomStringPool)
       
   178         {
       
   179         delete iDomStringPool;
       
   180         iDomStringPool = NULL;    
       
   181         }
       
   182     iDomStringPool = ChspsDomStringPool::NewL( aStream );
       
   183         
       
   184     if ( iRootNode )
       
   185         {
       
   186         delete iRootNode;
       
   187         iRootNode = NULL;
       
   188         }
       
   189     
       
   190     TBool rootNodeExist( aStream.ReadInt8L() );
       
   191     if ( rootNodeExist )
       
   192         {    
       
   193         iRootNode = ChspsDomNode::NewL( aStream, *iDomStringPool );
       
   194         }
       
   195     }          
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // ChspsDomDocument::SetRootNode
       
   199 // -----------------------------------------------------------------------------
       
   200 //
       
   201 EXPORT_C void ChspsDomDocument::SetRootNode( ChspsDomNode* aRootNode )
       
   202     {
       
   203     iRootNode = aRootNode;
       
   204     iRootNode->SetParent( NULL );
       
   205     }          
       
   206 
       
   207 // -----------------------------------------------------------------------------
       
   208 // ChspsDomDocument::RootNode
       
   209 // -----------------------------------------------------------------------------
       
   210 //
       
   211 EXPORT_C ChspsDomNode* ChspsDomDocument::RootNode() const
       
   212     {
       
   213     return iRootNode;
       
   214     }          
       
   215 
       
   216 // -----------------------------------------------------------------------------
       
   217 // ChspsDomDocument::LastNode
       
   218 // -----------------------------------------------------------------------------
       
   219 //
       
   220 EXPORT_C ChspsDomNode* ChspsDomDocument::LastNode() const
       
   221     {
       
   222     ChspsDomNode* last = NULL;
       
   223     if ( iRootNode )
       
   224         {
       
   225         last = iRootNode;
       
   226         ChspsDomNode* tmp = iRootNode;
       
   227         while( tmp )
       
   228             {
       
   229             last = tmp;
       
   230             tmp = static_cast<ChspsDomNode*>( last->ChildNodes().Last() );
       
   231             }
       
   232         }
       
   233     return last;
       
   234     }          
       
   235 
       
   236 // -----------------------------------------------------------------------------
       
   237 // ChspsDomDocument::Size
       
   238 // -----------------------------------------------------------------------------
       
   239 //
       
   240 EXPORT_C TInt ChspsDomDocument::Size() const
       
   241     {
       
   242    	TInt size( 1 ); //Root node information takes one byte
       
   243     size += iDomStringPool->Size();
       
   244         
       
   245     if ( iRootNode )
       
   246         {
       
   247         
       
   248         size += iRootNode->Size();
       
   249         }
       
   250     
       
   251     return size;
       
   252     }
       
   253 
       
   254 // -----------------------------------------------------------------------------
       
   255 // ChspsDomDocument::MarshallL
       
   256 // -----------------------------------------------------------------------------
       
   257 //
       
   258 EXPORT_C HBufC8* ChspsDomDocument::MarshallL()
       
   259     {
       
   260     TInt dataLength = Size();
       
   261     HBufC8* writeBuf = HBufC8::NewLC( dataLength );
       
   262     TPtr8 p( writeBuf->Des() );
       
   263     RDesWriteStream writeStream( p );     //stream over the buffer
       
   264     CleanupClosePushL( writeStream );
       
   265     writeStream << *this; //Stream object
       
   266     CleanupStack::PopAndDestroy( &writeStream );
       
   267     CleanupStack::Pop( writeBuf );
       
   268     return writeBuf;
       
   269     }
       
   270 
       
   271 // -----------------------------------------------------------------------------
       
   272 // ChspsDomDocument::StringPool
       
   273 // -----------------------------------------------------------------------------
       
   274 //
       
   275 EXPORT_C ChspsDomStringPool& ChspsDomDocument::StringPool() const
       
   276     {
       
   277     return *iDomStringPool;
       
   278     }
       
   279 
       
   280 //  End of File