homescreenpluginsrv/hspstools/src/hspsodtdump.cpp
changeset 0 79c6a41cd166
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Implementation of ChspsOdtDump.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "hspsodtdump.h"
       
    20 #include "hspslogbus.h"
       
    21 #include <hspsodt.h>
       
    22 #include <hspsdomdocument.h>
       
    23 #include <hspsdomlist.h>
       
    24 #include <hspsdomdepthiterator.h>
       
    25 #include <hspsdomnode.h>
       
    26 #include <hspsdomattribute.h>
       
    27 #include <hspsresource.h>
       
    28 #include <utf.h>
       
    29 
       
    30 //----------------------------------------------------------------------------
       
    31 // ChspsOdtDump::Dump()
       
    32 // ----------------------------------------------------------------------------
       
    33 //
       
    34 #ifdef HSPS_BUILD_LOG_IMPLEMENTATION
       
    35 EXPORT_C void ChspsOdtDump::Dump( ChspsODT& aOdt, ChspsLogBus& aLogBus )
       
    36     {    
       
    37     TRAP_IGNORE( DumpL( aOdt, aLogBus ) );
       
    38     }
       
    39 #else
       
    40 EXPORT_C void ChspsOdtDump::Dump( ChspsODT& /*aOdt*/, ChspsLogBus& /*aLogBus*/ )
       
    41     {    
       
    42     }
       
    43 #endif
       
    44 
       
    45 //----------------------------------------------------------------------------
       
    46 // ChspsOdtDump::DumpL()
       
    47 // ----------------------------------------------------------------------------
       
    48 //
       
    49 #ifdef HSPS_BUILD_LOG_IMPLEMENTATION
       
    50 void ChspsOdtDump::DumpL( ChspsODT& aOdt, ChspsLogBus& aLogBus )
       
    51     {            
       
    52     __UHEAP_MARK;
       
    53         ChspsDomDocument& domDocument = aOdt.DomDocument();
       
    54     
       
    55         aLogBus.LogText( _L( "### DOM DUMP START ###" ) );
       
    56     
       
    57         TInt attrCount(0);
       
    58         // TInt propCount(0);
       
    59         
       
    60         ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( *domDocument.RootNode() );
       
    61         CleanupStack::PushL( iter );
       
    62         
       
    63         _LIT8(KDelim, "\t" );
       
    64         ChspsDomNode* nodeParent( NULL );
       
    65         ChspsDomNode* node = iter->First();
       
    66         while ( node )    
       
    67             {
       
    68             const TInt depth = GetNodeDepth( node );
       
    69                             
       
    70             HBufC8 *nameBuf = GetFixedTextLC( node->Name(), depth, KDelim, ETrue );
       
    71             CleanupStack::PushL( nameBuf );
       
    72             const TDesC8& name = nameBuf->Des();
       
    73             
       
    74             aLogBus.LogText( _L8("%S\n"), &name );              
       
    75             
       
    76             ChspsDomList& attrList = node->AttributeList();
       
    77             TInt length( attrList.Length() );
       
    78             attrCount += length;
       
    79             //_LOGTFRM1(_L8(" Attribute count: %d\n"), length );
       
    80             for( TInt i=0; i<length; i++ )
       
    81                 {
       
    82                 ChspsDomAttribute* attr = static_cast<ChspsDomAttribute*>( attrList.Item(i) );
       
    83                 
       
    84                 HBufC8 *attrBuf = GetFixedTextLC( attr->Name(), depth,  KDelim, EFalse );
       
    85                 CleanupStack::PushL( attrBuf );
       
    86                 const TDesC8& attrName = attrBuf->Des();
       
    87                 
       
    88                 const TDesC8& attrValue = attr->Value();
       
    89                                         
       
    90                 aLogBus.LogText( _L8("%S=%S\n"), &attrName, &attrValue );
       
    91                 
       
    92                 CleanupStack::PopAndDestroy( attrBuf );
       
    93                 }
       
    94             
       
    95             if ( node->Parent() )
       
    96                 {
       
    97                 nodeParent = node;
       
    98                 }
       
    99             if ( node != nodeParent )
       
   100                 {
       
   101                 
       
   102                 }
       
   103             node = iter->NextL();
       
   104             
       
   105             CleanupStack::PopAndDestroy( nameBuf );
       
   106             }
       
   107         CleanupStack::PopAndDestroy( iter );
       
   108 
       
   109        aLogBus.LogText( _L( "### DOM DUMP END ###" ) );        
       
   110 
       
   111        aLogBus.LogText( _L8("**** Resources: ") );
       
   112        
       
   113        for( TInt index=0; index < aOdt.ResourceCount(); index++ )
       
   114            {
       
   115            ChspsResource* r = &aOdt.ResourceL(index);     
       
   116            TBuf8<512> name;
       
   117            CnvUtfConverter::ConvertFromUnicodeToUtf8( name, r->FileName() );               
       
   118            aLogBus.LogText( _L8( "%D) %S\n" ), index, &name );
       
   119            }
       
   120        
       
   121        aLogBus.LogText( _L8("**** Resources END ") );        
       
   122        
       
   123     __UHEAP_MARKEND;    
       
   124     }
       
   125 #else
       
   126 void ChspsOdtDump::DumpL( ChspsODT& /*aOdt*/, ChspsLogBus& /*aLogBus*/ )
       
   127     {    
       
   128     }
       
   129 #endif
       
   130 
       
   131 //----------------------------------------------------------------------------
       
   132 // ChspsOdtDump::GetNodeDepth()
       
   133 // ----------------------------------------------------------------------------
       
   134 //
       
   135 #ifdef HSPS_BUILD_LOG_IMPLEMENTATION
       
   136 TInt ChspsOdtDump::GetNodeDepth( ChspsDomNode *aNode )
       
   137     {
       
   138     TInt depth = 0;
       
   139     ChspsDomNode* node( aNode );
       
   140     while( node )
       
   141         {
       
   142         node = node->Parent();
       
   143         if ( node )
       
   144             {
       
   145             depth++;
       
   146             }
       
   147         }
       
   148     return depth;
       
   149     }
       
   150 #else
       
   151 TInt ChspsOdtDump::GetNodeDepth( ChspsDomNode* /*aNode*/ )
       
   152     {
       
   153     return 0;
       
   154     }
       
   155 #endif
       
   156 
       
   157 //----------------------------------------------------------------------------
       
   158 // ChspsOdtDump::GetFixedTextLC()
       
   159 // ----------------------------------------------------------------------------
       
   160 //
       
   161 #ifdef HSPS_BUILD_LOG_IMPLEMENTATION
       
   162 HBufC8* ChspsOdtDump::GetFixedTextLC( const TDesC8& aText,
       
   163                                       const TInt aDepth,
       
   164                                       const TDesC8& aDelim,
       
   165                                       TBool aShowHighlight )
       
   166     {
       
   167     HBufC8 *buf = HBufC8::NewL( aDepth * aDelim.Length() + aText.Length() + 1 + 1 );    
       
   168     TInt i = 0;
       
   169     for( ; i < aDepth; i++ )
       
   170         {
       
   171         buf->Des().Append( aDelim );
       
   172         }
       
   173     if ( !aShowHighlight )
       
   174         {
       
   175         buf->Des().Append( _L("*") );
       
   176         }
       
   177     buf->Des().Append( aText );
       
   178     return buf;
       
   179     }
       
   180 #else
       
   181 HBufC8* ChspsOdtDump::GetFixedTextLC( const TDesC8& /*aText*/,
       
   182                                       const TInt /*aDepth*/,
       
   183                                       const TDesC8& /*aDelim*/,
       
   184                                       TBool /*aShowHighlight*/ )
       
   185     {
       
   186     return NULL;
       
   187     }
       
   188 #endif