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