menufw/hierarchynavigator/hnutilities/src/hnmdbasekey.cpp
branchv5backport
changeset 14 1abc632eb502
parent 13 6205fd287e8a
child 20 636d517f67e6
equal deleted inserted replaced
13:6205fd287e8a 14:1abc632eb502
     1 /*
       
     2 * Copyright (c) 2007-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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <liwservicehandler.h>
       
    20 
       
    21 #include "hnmdkeyfactory.h"
       
    22 #include "hnconvutils.h"
       
    23 #include "hnliwutils.h"
       
    24 #include "hnglobals.h"
       
    25 #include "hnmdbasekey.h"
       
    26 
       
    27 // ======== MEMBER FUNCTIONS ========
       
    28    
       
    29 // ---------------------------------------------------------------------------
       
    30 // 
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 void CHnMdBaseKey::SetKeyOrNameL( const TXmlEngElement& aElement )
       
    34     {
       
    35     // set key or name
       
    36     if ( !aElement.Name().Compare( KKeyElementItem8 ) )
       
    37         {
       
    38         if ( aElement.HasAttributeL( KKeyAttrName8 ) )
       
    39             {
       
    40             // key
       
    41             SetKeyNameL( aElement.AttributeNodeL( KKeyAttrName8 ) );
       
    42             }
       
    43         else if ( aElement.HasAttributeL( KNameAttrName8 ) )
       
    44             {
       
    45             // name
       
    46             SetKeyNameL( aElement.AttributeNodeL( KNameAttrName8 ) );
       
    47             }
       
    48         }
       
    49     }
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // 
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 const RPointerArray<CHnMdBaseKey>& CHnMdBaseKey::SubKeys() const
       
    56     {
       
    57     return iSubKeys;
       
    58     }
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // 
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 void CHnMdBaseKey::BaseConstructL( const CHnMdBaseKey* aKey )
       
    65     {
       
    66     iKeyName.CreateL( aKey->KeyName() );
       
    67     iContent.CreateL( aKey->KeyContent() );
       
    68     SetSubKeysL( aKey );
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // 
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 void CHnMdBaseKey::BaseConstructL( TXmlEngElement aElement )
       
    76     {
       
    77     ASSERT( !aElement.Name().Compare( KKeyElementItem8 )
       
    78         || !aElement.Name().Compare( KContentTypeElementItem8 ) );
       
    79 
       
    80     SetKeyOrNameL( aElement );
       
    81     SetValueL( aElement );
       
    82 
       
    83     if ( aElement.HasChildNodes() )
       
    84         {
       
    85         SetSubKeysL( aElement  );
       
    86         }
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // 
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 void CHnMdBaseKey::SetValueL( const TXmlEngElement& aElement )
       
    94     {
       
    95     if ( aElement.HasAttributeL( KValueAttrName8 ) )
       
    96         {
       
    97         SetKeyContentL( aElement.AttributeNodeL( KValueAttrName8 ) );
       
    98         }
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // 
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 void CHnMdBaseKey::SetValueL( const TDesC8& aValue )
       
   106     {
       
   107     iContent.Close();
       
   108     iContent.CreateL( aValue.Length() );
       
   109     iContent.Copy( aValue );
       
   110     }
       
   111 
       
   112 // ---------------------------------------------------------------------------
       
   113 // 
       
   114 // ---------------------------------------------------------------------------
       
   115 //
       
   116 void CHnMdBaseKey::SetValueL( const TDesC& aValue )
       
   117     {
       
   118     iContent.Close();
       
   119     iContent.CreateL( aValue );
       
   120     }	
       
   121 	
       
   122 // ---------------------------------------------------------------------------
       
   123 // 
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 CHnMdBaseKey::CHnMdBaseKey()
       
   127     {
       
   128     }
       
   129 
       
   130 // ---------------------------------------------------------------------------
       
   131 // 
       
   132 // ---------------------------------------------------------------------------
       
   133 //
       
   134 CHnMdBaseKey::~CHnMdBaseKey()
       
   135     {
       
   136     iKeyName.Close();
       
   137     iContent.Close();
       
   138     iSubKeys.ResetAndDestroy();
       
   139     }
       
   140   
       
   141 // ---------------------------------------------------------------------------
       
   142 // 
       
   143 // ---------------------------------------------------------------------------
       
   144 //  
       
   145 const TDesC8& CHnMdBaseKey::KeyName() const
       
   146     {  
       
   147     return iKeyName;
       
   148     } 
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // 
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 const TDesC& CHnMdBaseKey::KeyContent() const
       
   155     {
       
   156     return iContent;
       
   157     }
       
   158     
       
   159 // ---------------------------------------------------------------------------
       
   160 // 
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 void CHnMdBaseKey::GetKeyContent( TInt& /* aKeyContent */ ) const
       
   164     {
       
   165     }
       
   166 
       
   167 // ---------------------------------------------------------------------------
       
   168 // 
       
   169 // ---------------------------------------------------------------------------
       
   170 //
       
   171 void CHnMdBaseKey::GetKeyContent( TInt64& /* aKeyContent */ ) const
       
   172     {
       
   173     }
       
   174 
       
   175 // ---------------------------------------------------------------------------
       
   176 //
       
   177 // ---------------------------------------------------------------------------
       
   178 //
       
   179 void CHnMdBaseKey::SetKeyNameL( const TXmlEngAttr& aName )
       
   180     {
       
   181     iKeyName.Close();
       
   182     iKeyName.CreateL( aName.Value() );
       
   183     }
       
   184 
       
   185 // ---------------------------------------------------------------------------
       
   186 //
       
   187 // ---------------------------------------------------------------------------
       
   188 //
       
   189 void CHnMdBaseKey::SetKeyNameL( const TDesC8& aName )
       
   190     {
       
   191     iKeyName.Close();
       
   192     iKeyName.CreateL( aName );
       
   193     }
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 // 
       
   197 // ---------------------------------------------------------------------------
       
   198 //
       
   199 void CHnMdBaseKey::SetSubKeysL( const TXmlEngElement& aElement )
       
   200     {    
       
   201     RXmlEngNodeList< TXmlEngElement > subkeys;
       
   202     CleanupClosePushL( subkeys );
       
   203     aElement.GetChildElements( subkeys );
       
   204     
       
   205     TInt subkeysAmount( subkeys.Count() );
       
   206     
       
   207     for ( TInt j( 0 ); j < subkeysAmount; j++ )
       
   208         {
       
   209         TXmlEngElement subkeyElement( subkeys.Next() );
       
   210         
       
   211         if ( !subkeyElement.Name().Compare( KKeyElementItem8 ) )
       
   212             {
       
   213             CHnMdBaseKey *subkey = HnMdKeyFactory::CreateL( subkeyElement );
       
   214             CleanupStack::PushL( subkey );
       
   215             AddSubKeyL( subkey );
       
   216             CleanupStack::Pop( subkey );
       
   217             }
       
   218         }
       
   219     CleanupStack::PopAndDestroy( &subkeys );
       
   220     }
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // 
       
   224 // ---------------------------------------------------------------------------
       
   225 //
       
   226 void CHnMdBaseKey::SetSubKeysL( const CHnMdBaseKey* aKey )
       
   227     {
       
   228     const RPointerArray<CHnMdBaseKey>& subKeys = aKey->SubKeys();
       
   229     TInt count = subKeys.Count();
       
   230     for( TInt i( 0 ); i < count ; i++ )
       
   231         {
       
   232         CHnMdBaseKey* subKey = subKeys[ i ]->CopyLC();
       
   233         AddSubKeyL( subKey );
       
   234         CleanupStack::Pop( subKey );
       
   235         }
       
   236     }
       
   237 
       
   238 // ---------------------------------------------------------------------------
       
   239 // 
       
   240 // ---------------------------------------------------------------------------
       
   241 //
       
   242 EXPORT_C void CHnMdBaseKey::AddSubKeyL( CHnMdBaseKey* aKey )
       
   243     {
       
   244     iSubKeys.AppendL( aKey );
       
   245     }
       
   246 
       
   247 // ---------------------------------------------------------------------------
       
   248 // 
       
   249 // ---------------------------------------------------------------------------
       
   250 //
       
   251 void CHnMdBaseKey::SetKeyContentL( const TXmlEngAttr& aContent )
       
   252     {
       
   253     HBufC* value = HnConvUtils::Str8ToStrLC( aContent.Value() );
       
   254     iContent.Close();
       
   255     iContent.Assign( value );
       
   256     // clean up
       
   257     CleanupStack::Pop( value );
       
   258     }
       
   259 
       
   260 // ---------------------------------------------------------------------------
       
   261 // 
       
   262 // ---------------------------------------------------------------------------
       
   263 //
       
   264 EXPORT_C CHnMdBaseKey* CHnMdBaseKey::EvaluateLC(
       
   265     const CLiwGenericParamList& aParamList,
       
   266     TInt aPos )
       
   267     {
       
   268     CHnMdBaseKey* copy = CopyLC();
       
   269     copy->DoEvaluateL(  aParamList, aPos );
       
   270     return copy;
       
   271     }
       
   272 
       
   273 // ---------------------------------------------------------------------------
       
   274 // 
       
   275 // ---------------------------------------------------------------------------
       
   276 //
       
   277 void CHnMdBaseKey::DoEvaluateL(
       
   278     const CLiwGenericParamList& aParamList,
       
   279     TInt aPos )
       
   280     {
       
   281     EvaluateKeyValueL( aParamList, aPos );
       
   282     // evaluate subkeys
       
   283     TInt count( iSubKeys.Count() );
       
   284     for( TInt i( 0 ); i < count; i++ )
       
   285         {
       
   286         CHnMdBaseKey* key = iSubKeys[ i ];
       
   287         key->DoEvaluateL( aParamList, aPos );
       
   288         }
       
   289     }
       
   290 
       
   291 // ---------------------------------------------------------------------------
       
   292 // 
       
   293 // ---------------------------------------------------------------------------
       
   294 //
       
   295 void CHnMdBaseKey::EvaluateKeyValueL(
       
   296     const CLiwGenericParamList& aParamList,
       
   297     TInt aPos )
       
   298     {
       
   299     HBufC8* tempContent = HnConvUtils::StrToStr8LC( iContent );
       
   300     RBuf tempResult;
       
   301     CleanupClosePushL( tempResult );
       
   302     if ( HnLiwUtils::GetStringL( aParamList, *tempContent, aPos, tempResult ) 
       
   303         != KErrBadDescriptor )
       
   304         {
       
   305         iContent.Swap( tempResult );
       
   306         }
       
   307     CleanupStack::PopAndDestroy( &tempResult );
       
   308     CleanupStack::PopAndDestroy( tempContent );
       
   309     }
       
   310 
       
   311 // ---------------------------------------------------------------------------
       
   312 // 
       
   313 // ---------------------------------------------------------------------------
       
   314 //
       
   315 
       
   316 EXPORT_C void CHnMdBaseKey::ToVariantL( TLiwVariant& /* aRet */ ) const
       
   317     {
       
   318     
       
   319     }
       
   320  
       
   321 // ---------------------------------------------------------------------------
       
   322 // 
       
   323 // ---------------------------------------------------------------------------
       
   324 //
       
   325 EXPORT_C void CHnMdBaseKey::ToGenericParamListL( CLiwGenericParamList & aRet ) const
       
   326     {
       
   327 
       
   328     // for each key
       
   329     for ( TInt i( 0 ); i < iSubKeys.Count(); i++ )
       
   330         {
       
   331         CHnMdBaseKey* key = iSubKeys[i];
       
   332         const TDesC8& keyName = key->KeyName();
       
   333         TLiwVariant value;
       
   334         value.PushL();
       
   335         key->ToVariantL( value );
       
   336         aRet.AppendL( TLiwGenericParam( keyName, value ) );      
       
   337         CleanupStack::PopAndDestroy( &value );
       
   338         }
       
   339     }