homescreenpluginsrv/hspsmanager/src/hspsserverutil.cpp
changeset 0 79c6a41cd166
child 1 844b978f8d5e
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:  Utility for common code.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "hspsthememanagement.h"
       
    20 #include "hspsserverutil.h"
       
    21 #include "hspsodt.h"
       
    22 #include "hspsdomdepthiterator.h"
       
    23 #include "hspsdomnode.h"
       
    24 #include "hspsdomdocument.h"
       
    25 #include "hspsconfiguration.h"
       
    26 #include "hspsdomlist.h"
       
    27 #include "hspsresource.h"
       
    28 #include "hspsdomattribute.h"
       
    29 #include "hspsmanifest.h"
       
    30 #include "bautils.h" 
       
    31 #include "sysutil.h"
       
    32 
       
    33 
       
    34 _LIT(KHspsFolder, "\\200159c0\\themes\\" );
       
    35 _LIT(KSourcesFolder, "\\sources\\");
       
    36 _LIT( KThemesFolder, "\\themes\\" );
       
    37 _LIT( KDoubleBackSlash, "\\" );
       
    38 _LIT8( KHexPrefix8, "0x" );
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // hspsServerUtil::GenerateConfigurationAttributesL
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 void hspsServerUtil::GenerateConfigurationAttributesL( ChspsODT& aOdt )
       
    45     {
       
    46     ChspsDomDocument& dom = aOdt.DomDocument();
       
    47     ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( *dom.RootNode() );   
       
    48     CleanupStack::PushL( iter );
       
    49                         
       
    50     ChspsDomNode* prevNode = NULL;
       
    51     ChspsDomNode* node = iter->First();
       
    52     while( node && prevNode != node )
       
    53         {           
       
    54         const TDesC8& name = node->Name();
       
    55         
       
    56         // Configuration element 
       
    57         if ( name == KConfigurationElement )
       
    58             {                                                   
       
    59             // Add attributes for the configuration node        
       
    60             // NOTE! ID attribute is not set here           
       
    61             TPtrC8 ptr = KManifestTypeApp().Ptr();
       
    62             switch ( aOdt.ConfigurationType() )
       
    63                 {
       
    64                 case EhspsViewConfiguration:
       
    65                     {
       
    66                     ptr.Set( KManifestTypeView );
       
    67                     }
       
    68                     break;
       
    69                 case EhspsWidgetConfiguration:
       
    70                     {
       
    71                     ptr.Set( KManifestTypeWidget );
       
    72                     }
       
    73                     break;
       
    74                 case EhspsTemplateConfiguration:
       
    75                     {
       
    76                     ptr.Set( KManifestTypeTemplate );
       
    77                     }
       
    78                     break;
       
    79                 default:
       
    80                     {                   
       
    81                     }
       
    82                 }
       
    83                     
       
    84             AddAttributeDescL( *node, KConfigurationAttrType, ptr );
       
    85             
       
    86             AddAttributeNumericL( *node, KConfigurationAttrInterface, aOdt.RootUid(), EHex );
       
    87             
       
    88             AddAttributeNumericL( *node, KConfigurationAttrUid, aOdt.ThemeUid(), EHex );
       
    89             
       
    90             // Create "name" and "_name" attributes, of which latter holds the entity reference 
       
    91             // (logical key for finding localizad strings)
       
    92             HBufC8* nameBuf = HBufC8::NewLC( aOdt.ThemeFullName().Length() );
       
    93             TPtr8 namePtr( nameBuf->Des() );
       
    94             namePtr.Copy( aOdt.ThemeFullName() );
       
    95             AddAttributeDescL( *node, KConfigurationAttrName, namePtr ); // will be updated when localized
       
    96             AddAttributeDescL( *node, KConfigurationAttrNameEntity, namePtr ); // logical id
       
    97             CleanupStack::PopAndDestroy( nameBuf );                        
       
    98 
       
    99             // Create theme version attribute
       
   100             HBufC8* tv = HBufC8::NewLC( aOdt.ThemeVersion().Length() );
       
   101             TPtr8 tvPtr( tv->Des() );
       
   102             tvPtr.Copy( aOdt.ThemeVersion() );
       
   103             AddAttributeDescL( *node, KConfigurationAttrVersion, tvPtr );
       
   104             CleanupStack::PopAndDestroy( tv );
       
   105             
       
   106             AddAttributeNumericL ( *node, KConfigurationAttrMultiInstance,
       
   107                 aOdt.MultiInstance(), EDecimal );
       
   108 
       
   109             AddAttributeDescL( *node, KConfigurationAttrState, KConfStateNotConfirmed );
       
   110             
       
   111             const TInt descLength = aOdt.Description().Length();
       
   112             if ( descLength )
       
   113                 {
       
   114                 // Add description of the widget (16 > 8bit conversion) 
       
   115                 HBufC8* buf = HBufC8::NewLC( descLength );
       
   116                 TPtr8 bufPtr( buf->Des() );
       
   117                 bufPtr.Copy( aOdt.Description() );
       
   118                 AddAttributeDescL( *node, KConfigurationAttrDesc, bufPtr ); // will be updated when localized
       
   119                 AddAttributeDescL( *node, KConfigurationAttrDescEntity, bufPtr ); // logical id
       
   120                 CleanupStack::PopAndDestroy( buf );
       
   121                 }
       
   122             else
       
   123                 {
       
   124                 AddAttributeDescL( *node, KConfigurationAttrDesc, KNullDesC8 );
       
   125                 }
       
   126             
       
   127             }       
       
   128         
       
   129         prevNode = node;    
       
   130         node = iter->NextL();
       
   131         }
       
   132     CleanupStack::PopAndDestroy( iter );
       
   133     }
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // ChspsInstallationHandler::GenerateObjectAttributesL()
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 void hspsServerUtil::GenerateObjectAttributesL( ChspsODT& aOdt )
       
   140     {
       
   141     // Find the configuration node
       
   142     ChspsDomDocument& dom = aOdt.DomDocument();     
       
   143     ChspsDomNode* configurationNode = dom.RootNode();
       
   144     if ( !configurationNode )
       
   145         {
       
   146 #ifdef _hsps_DEBUG_       
       
   147         RDebug::Print( _L("hspsServerUtil::GenerateObjectAttributesL(): - invalid ODT!") );
       
   148 #endif      
       
   149         User::Leave( KErrGeneral );
       
   150         }
       
   151     
       
   152     // Find resources node from the XML definition (child of the configuration node)
       
   153     ChspsDomList& childsList = configurationNode->ChildNodes(); 
       
   154     ChspsDomNode* resourcesNode = (ChspsDomNode *)childsList.FindByName( KResourcesElement );
       
   155     TInt popResources = EFalse;
       
   156     if ( !resourcesNode )
       
   157         {
       
   158         // Create a node and add it into the configuration node
       
   159         resourcesNode = dom.CreateElementNSL( 
       
   160             KResourcesElement,      
       
   161             configurationNode->Namespace()          
       
   162             );                              
       
   163         CleanupStack::PushL( resourcesNode );
       
   164         popResources = ETrue;
       
   165         configurationNode->AddChildL( resourcesNode );
       
   166         resourcesNode->SetParent( configurationNode );
       
   167         }    
       
   168                               
       
   169     // Loop ODT's resources (parsed ealier from the manifest file)
       
   170     const TInt resourceCount = aOdt.ResourceCount();
       
   171     TBool addResource = EFalse;
       
   172     for( TInt resourceIndex=0; resourceIndex < resourceCount; resourceIndex++ )
       
   173         {                
       
   174         ChspsResource& resource = aOdt.ResourceL( resourceIndex );                                
       
   175         
       
   176         addResource = EFalse;
       
   177         
       
   178         // If resource is located under the sources folder
       
   179         if ( resource.FileName().FindF( KSourcesFolder ) > 0 )        
       
   180             {                        
       
   181             // If resource is for the active device language or it's a locale independent resource
       
   182             addResource = ( resource.Language() == aOdt.OdtLanguage() || resource.Language() == ELangNone );                                     
       
   183             }
       
   184                 
       
   185         if ( addResource )        	
       
   186         	{          	
       
   187 	         // Create an object node and add the object into the resources list                    
       
   188 	        ChspsDomNode* objectNode = dom.CreateElementNSL( 
       
   189 	            KObjectElement,         
       
   190 	            resourcesNode->Namespace()          
       
   191 	            );                              
       
   192 	        CleanupStack::PushL( objectNode );
       
   193 	        resourcesNode->AddChildL( objectNode );
       
   194 	        objectNode->SetParent( resourcesNode );
       
   195 	        
       
   196 	        // Name (16->8bit conversion)
       
   197 	        HBufC8* nameBuf = HBufC8::NewLC( resource.ResourceId().Length() );
       
   198 	        TPtr8 namePtr( nameBuf->Des() );
       
   199 	        namePtr.Copy( GetFixedOdtName( resource.ResourceId() ) );            
       
   200 	        
       
   201 	        AddAttributeDescL( *objectNode, KObjectAttrFilename, namePtr );
       
   202 	        CleanupStack::PopAndDestroy( nameBuf );
       
   203 	        
       
   204 	        // Media type
       
   205 	        TPtrC8 mimePtr( resource.MimeType().Des8() );           
       
   206 	        if ( mimePtr.Length() )
       
   207 	            {
       
   208 	            AddAttributeDescL( *objectNode, KObjectAttrMediatype, mimePtr );
       
   209 	            }
       
   210 	        
       
   211 	        // Tag
       
   212             TPtrC tagPtr( resource.Tags() );           
       
   213             if ( tagPtr.Length() )
       
   214                 {
       
   215                 // (16->8bit conversion)
       
   216                 HBufC8* buf = HBufC8::NewLC( tagPtr.Length() );
       
   217                 TPtr8 bufPtr( buf->Des() );
       
   218                 bufPtr.Copy( tagPtr );
       
   219                 AddAttributeDescL( *objectNode, KObjectAttrTag, bufPtr );
       
   220                 CleanupStack::PopAndDestroy( buf );
       
   221                 }
       
   222 	                
       
   223 	        // Path 
       
   224 	        TInt pos = resource.FileName().FindF( KHspsFolder );
       
   225 	        if ( pos > 0 )
       
   226 	            {
       
   227 	            // Remove filename and extension from the path
       
   228 	            TParsePtrC parserPtr( resource.FileName() );
       
   229 	            TFileName path( parserPtr.DriveAndPath() );
       
   230 	            	            
       
   231 	            // Remove path to the Definition repository 
       
   232 	            path.Copy( path.Mid( pos + KHspsFolder().Length() ) );
       
   233 	            
       
   234 	            // Fix path references for localized resources
       
   235 	            GetLocaleIndependentResourcePath( resource.Language(), path );	            	            
       
   236 	            
       
   237 	            // 16->8bit conversion	            
       
   238 	            HBufC8 *pathBuf = HBufC8::NewLC( path.Length() );                  	            
       
   239 	            pathBuf->Des().Copy( path );
       
   240 	            	            	            
       
   241 	            AddAttributeDescL( *objectNode, KObjectAttrPath, pathBuf->Des() );
       
   242 	            CleanupStack::PopAndDestroy( pathBuf );
       
   243 	            }
       
   244 	        
       
   245 	        // Now the document has an ownership of the objectnode
       
   246 	        CleanupStack::Pop( objectNode );
       
   247 	        
       
   248         	}
       
   249         
       
   250         } // for loop
       
   251 
       
   252     if ( popResources )
       
   253         {
       
   254         // Now the document has an ownership of the resourcesNode
       
   255         CleanupStack::Pop( resourcesNode );
       
   256         }
       
   257     }
       
   258 
       
   259 
       
   260 TFileName hspsServerUtil::GetFixedOdtName( 
       
   261         const TDesC& aNameAndExtension )
       
   262     {        
       
   263     TParsePtrC parsePtr( aNameAndExtension );                      
       
   264     TPtrC fileExtension = parsePtr.Ext();
       
   265     if ( fileExtension.Length() > 2 && fileExtension.Left(2).CompareF( _L(".o") ) == 0 )
       
   266         {            
       
   267         // Strip the first letter            
       
   268         TInt odtIndex(0);                  
       
   269         TLex lex( fileExtension.Mid(3) );
       
   270         if ( lex.Val( odtIndex ) == KErrNone && odtIndex >= 0 )
       
   271             {                
       
   272             fileExtension.Set( _L(".o0000") );
       
   273             }
       
   274         }
       
   275     
       
   276     TFileName fileName( parsePtr.Name() );
       
   277     fileName.Append( fileExtension );
       
   278     return fileName;
       
   279     }
       
   280 
       
   281 // -----------------------------------------------------------------------------
       
   282 // hspsServerUtil::GetLocaleIndependentResourcePath
       
   283 // -----------------------------------------------------------------------------
       
   284 //
       
   285 void hspsServerUtil::GetLocaleIndependentResourcePath(
       
   286 		const TLanguage& aResourceLanguage,		 
       
   287 		TFileName& aPath )
       
   288 	{
       
   289 	TBool isLocaleSpecificResource = ( aResourceLanguage != ELangNone );		
       
   290 	
       
   291 	// If locale specific resource
       
   292     if ( isLocaleSpecificResource )
       
   293     	{
       
   294     	// Remove locale specific subfolder from the path
       
   295     	TInt pos = aPath.FindF( KSourcesFolder );
       
   296     	if ( pos )
       
   297     		{    		    		    		    	
       
   298     		aPath.Copy( aPath.Left( pos + KSourcesFolder().Length() ) );
       
   299     		}
       
   300     	}    
       
   301 	}
       
   302 
       
   303 // -----------------------------------------------------------------------------
       
   304 // hspsServerUtil::GetRelativeResourcePath
       
   305 // -----------------------------------------------------------------------------
       
   306 //
       
   307 void hspsServerUtil::GetRelativeResourcePath(
       
   308         const TFileName& aSourceFile,
       
   309         TPath& aRelativePath )
       
   310     {    
       
   311     // find last part (structure after "/themes/") 
       
   312     TInt pos = aSourceFile.FindF( KThemesFolder );
       
   313     if( pos != KErrNotFound )
       
   314         {
       
   315         pos += KThemesFolder().Length();        
       
   316         TInt len( aSourceFile.Length() - pos );               
       
   317         aRelativePath.Copy( aSourceFile.Right( len ) );                     
       
   318         }    
       
   319     }
       
   320 
       
   321 // -----------------------------------------------------------------------------
       
   322 // hspsServerUtil::AddAttributeNumericL
       
   323 // -----------------------------------------------------------------------------
       
   324 //
       
   325 TInt hspsServerUtil::AddAttributeNumericL(
       
   326         ChspsDomNode& aNode,
       
   327         const TDesC8& aAttrName, 
       
   328         const TInt aValue,
       
   329         const TRadix aFormat )
       
   330     {
       
   331     // Format change
       
   332     // Value string, 10 -> Max decimal 4294967295 , max hexadecimal 0xXXXXXXXX
       
   333     const TInt KMaxLength = 10;
       
   334     TBuf8<KMaxLength> attValueDes8; 
       
   335     
       
   336     if ( aFormat == EHex )
       
   337         {
       
   338         _LIT8( KFormat8, "%X" );
       
   339         _LIT8( KHexPrefix, "0x" );
       
   340         attValueDes8.Append( KHexPrefix );
       
   341         attValueDes8.AppendFormat( KFormat8, aValue );
       
   342         }
       
   343     else // EDecimal
       
   344         {
       
   345         _LIT8( KFormat8, "%d" );
       
   346         attValueDes8.AppendFormat( KFormat8, aValue );
       
   347         }
       
   348     
       
   349     ChspsDomList& attrList = aNode.AttributeList();
       
   350     ChspsDomAttribute* attr = static_cast<ChspsDomAttribute*>( attrList.FindByName(aAttrName) );
       
   351     if ( attr )
       
   352         {               
       
   353         // Replace value of the attribute
       
   354         attr->SetValueL( attValueDes8 );
       
   355         }
       
   356     else
       
   357         {              
       
   358         // Add an attribute
       
   359         ChspsDomAttribute* attr = ChspsDomAttribute::NewL( aAttrName, aNode.StringPool() );    
       
   360         CleanupStack::PushL( attr );            
       
   361         attr->SetValueL( attValueDes8 );
       
   362         ChspsDomList& attrList = aNode.AttributeList();
       
   363         attrList.AddItemL( attr );    //takes ownership
       
   364         CleanupStack::Pop( attr );
       
   365         }
       
   366     
       
   367     return KErrNone;
       
   368     }
       
   369 
       
   370 // -----------------------------------------------------------------------------
       
   371 // hspsServerUtil::AddAttributeDescL
       
   372 // -----------------------------------------------------------------------------
       
   373 //
       
   374 void hspsServerUtil::AddAttributeDescL(
       
   375         ChspsDomNode& aNode,
       
   376         const TDesC8& aAttrName, 
       
   377         const TDesC8& aValue )
       
   378     {
       
   379     ChspsDomList& attrList = aNode.AttributeList();
       
   380     ChspsDomAttribute* attr = static_cast<ChspsDomAttribute*>( attrList.FindByName(aAttrName) );
       
   381     if ( attr )
       
   382         {               
       
   383         // Replace value of the attribute
       
   384         attr->SetValueL( aValue );
       
   385         }
       
   386     else
       
   387         {              
       
   388         // Add an attribute
       
   389         ChspsDomAttribute* attr = ChspsDomAttribute::NewL( aAttrName, aNode.StringPool() );    
       
   390         CleanupStack::PushL( attr );            
       
   391         attr->SetValueL( aValue );
       
   392         ChspsDomList& attrList = aNode.AttributeList();
       
   393         attrList.AddItemL( attr );    //takes ownership
       
   394         CleanupStack::Pop( attr );
       
   395         }        
       
   396     }
       
   397 
       
   398 
       
   399 // -----------------------------------------------------------------------------
       
   400 // Finds a configuration node with the provided id attribute
       
   401 // -----------------------------------------------------------------------------
       
   402 //
       
   403 ChspsDomNode* hspsServerUtil::FindConfigurationNodeL(
       
   404 		ChspsODT& aOdt,		
       
   405 		const TInt aConfigurationId )
       
   406 	{
       
   407 	__UHEAP_MARK;
       
   408 	
       
   409     ChspsDomNode *configurationNode = NULL;
       
   410     
       
   411     ChspsDomDocument& dom = aOdt.DomDocument();
       
   412     ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( *dom.RootNode() );
       
   413     CleanupStack::PushL( iter );
       
   414 
       
   415     // Find a configuration node with an id attribute that matches the provided id
       
   416     ChspsDomNode* node = iter->First();
       
   417     ChspsDomNode* prevNode = NULL;
       
   418     TBool jobDone = EFalse;
       
   419     while( node && !jobDone && prevNode != node )    
       
   420         {                
       
   421         const TDesC8& name = node->Name();
       
   422         
       
   423         // An element was found 
       
   424         if ( name == KConfigurationElement )
       
   425             {           
       
   426             ChspsDomList& attrList = node->AttributeList();                    
       
   427             ChspsDomAttribute* idAttr = static_cast<ChspsDomAttribute*>( attrList.FindByName(KConfigurationAttrId) );            
       
   428             if ( !idAttr )
       
   429                 {
       
   430                 // Return with NULL
       
   431                 jobDone = ETrue;                                                 
       
   432                 }
       
   433             else
       
   434                 {            
       
   435                 TInt id(0);            
       
   436                 const TDesC8& idValue = idAttr->Value();                        
       
   437                 TLex8 lex( idValue );                        
       
   438                 lex.Val( id );            
       
   439                 if ( aConfigurationId == id )
       
   440                     {
       
   441                     configurationNode = node;        
       
   442                     jobDone = ETrue;
       
   443                     }
       
   444                 }
       
   445             }
       
   446         
       
   447         prevNode = node;        
       
   448         node = iter->NextL();
       
   449         }
       
   450     CleanupStack::PopAndDestroy( iter );
       
   451 
       
   452 #ifdef _hsps_DEBUG_
       
   453     if ( !configurationNode )
       
   454         {
       
   455         RDebug::Print( _L("hspsServerUtil::FindConfigurationNodeL(): failed to find the configuration node") );
       
   456         }
       
   457 #endif
       
   458     
       
   459     __UHEAP_MARKEND;
       
   460     
       
   461     return configurationNode;
       
   462     }
       
   463 
       
   464 // -----------------------------------------------------------------------------
       
   465 // Finds a plugin node with the provided id
       
   466 // -----------------------------------------------------------------------------
       
   467 //
       
   468 ChspsDomNode* hspsServerUtil::FindPluginNodeL(
       
   469         ChspsODT& aOdt,        
       
   470         const TInt aPluginId )
       
   471     {            
       
   472     __UHEAP_MARK;
       
   473     
       
   474     ChspsDomNode* pluginNode = NULL;
       
   475     
       
   476     ChspsDomDocument& dom = aOdt.DomDocument();
       
   477     ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( *dom.RootNode() );
       
   478     CleanupStack::PushL( iter );
       
   479 
       
   480     // Find a plugin node with the provided id attribute
       
   481     ChspsDomNode* node = iter->First();
       
   482     ChspsDomNode* prevNode = NULL;
       
   483     TBool jobDone = EFalse;
       
   484     while( node && !jobDone && prevNode != node )
       
   485         {                
       
   486         const TDesC8& name = node->Name();
       
   487         
       
   488         // Plugin element was found 
       
   489         if ( name == KPluginElement )
       
   490             {           
       
   491             ChspsDomList& attrList = node->AttributeList();                    
       
   492             ChspsDomAttribute* idAttr = static_cast<ChspsDomAttribute*>( attrList.FindByName(KPluginAttrId) );            
       
   493             if ( !idAttr )
       
   494                 {
       
   495                 // Mandatory information is missing for some reason (should be set at installation handler)!
       
   496                 // Exit with NULL
       
   497                 jobDone = ETrue;                
       
   498                 }
       
   499             else
       
   500                 {            
       
   501                 TInt id(0);            
       
   502                 const TDesC8& idValue = idAttr->Value();                        
       
   503                 TLex8 lex( idValue );                        
       
   504                 lex.Val( id );            
       
   505                 if ( aPluginId == id )
       
   506                     {
       
   507                     pluginNode = node;
       
   508                     jobDone = ETrue;
       
   509                     }
       
   510                 }
       
   511             }
       
   512         
       
   513         prevNode = node;        
       
   514         node = iter->NextL();        
       
   515         }
       
   516     CleanupStack::PopAndDestroy( iter );
       
   517 
       
   518 #ifdef _hsps_DEBUG_
       
   519     if ( !pluginNode )
       
   520         {
       
   521         RDebug::Print( _L("hspsServerUtil::FindPluginNodeL(): failed to find the plugin node") );
       
   522         }
       
   523 #endif
       
   524     
       
   525     __UHEAP_MARKEND;
       
   526     
       
   527     return pluginNode;
       
   528     }
       
   529 
       
   530 // -----------------------------------------------------------------------------
       
   531 // hspsServerUtil::GetConfigurationNameFromDomL
       
   532 // -----------------------------------------------------------------------------
       
   533 //
       
   534 TPtrC8 hspsServerUtil::FindConfigurationAttrL( 
       
   535     const ChspsODT& aOdt,
       
   536     const TDesC8& aAttr )
       
   537     {
       
   538     TPtrC8 ptr;
       
   539     
       
   540     // Get ODT's DOM and find the 1st configuration node
       
   541     ChspsDomNode* confNode = aOdt.DomDocument().RootNode();
       
   542     if( !confNode || confNode->Name().CompareF( KConfigurationElement) != 0 )
       
   543         {            
       
   544         User::Leave( KErrGeneral );            
       
   545         }                
       
   546         
       
   547     // Find the name attribute and return it's value
       
   548     ChspsDomList& attrList = confNode->AttributeList();
       
   549     ChspsDomAttribute* attr = static_cast<ChspsDomAttribute*>( attrList.FindByName(aAttr) );                
       
   550     if ( !attr )
       
   551         {
       
   552         User::Leave( KErrGeneral );
       
   553         }            
       
   554     ptr.Set( attr->Value() );
       
   555             
       
   556     return ptr;
       
   557     }    
       
   558 
       
   559 // -----------------------------------------------------------------------------
       
   560 // hspsServerUtil::CopyResourceFileL
       
   561 // -----------------------------------------------------------------------------
       
   562 //
       
   563 TInt hspsServerUtil::CopyResourceFileL(
       
   564         RFs& aFs,
       
   565         CFileMan& aFilemanager,
       
   566         const TPath& aTargetPath,
       
   567         const TFileName& aSourceFile )
       
   568     {
       
   569     // Make target folder
       
   570     TInt error = aFs.MkDirAll( aTargetPath );            
       
   571     if( error == KErrAlreadyExists )
       
   572         {
       
   573         // lets ignore error if directory already exists                
       
   574         error = KErrNone;
       
   575         }       
       
   576     if( !error )
       
   577         {
       
   578         // Default to 'copying was not neccessary'
       
   579         error = KErrAlreadyExists;
       
   580         
       
   581         // Check whether the resource needs to be copied
       
   582         if ( hspsServerUtil::ResourceCopyIsRelevantL( 
       
   583                 aSourceFile,
       
   584                 aTargetPath,
       
   585                 aFs ) 
       
   586             )
       
   587             {        
       
   588             // Slowish operation
       
   589             error = aFilemanager.Copy( 
       
   590                     aSourceFile, 
       
   591                     aTargetPath );
       
   592             if( !error )
       
   593                 {
       
   594                 // Clear readonly file attribs that might be inherited from the source file                
       
   595                 aFilemanager.Attribs( 
       
   596                     aTargetPath,
       
   597                     0,
       
   598                     KEntryAttReadOnly,
       
   599                     TTime( 0 ) ); // TTime(0) = preserve original time stamp.                                                                      
       
   600                 }
       
   601             
       
   602             } // copy op        
       
   603         }
       
   604     
       
   605     return error;
       
   606     }
       
   607 
       
   608 // -----------------------------------------------------------------------------
       
   609 // hspsServerUtil::ResourceCopyIsRelevant
       
   610 // -----------------------------------------------------------------------------
       
   611 //
       
   612 TBool hspsServerUtil::ResourceCopyIsRelevantL( 
       
   613     const TDesC& aSource,
       
   614     const TDesC& aTarget,
       
   615     RFs& aFs )
       
   616     {
       
   617     // Basic sanity check.
       
   618     if( aSource.Length() == 0 || aTarget.Length() == 0 )
       
   619         {
       
   620         return EFalse;
       
   621         }
       
   622 
       
   623     // Collect data from files.
       
   624     
       
   625     TEntry sourceEntry;
       
   626     TInt entryError = aFs.Entry( aSource, sourceEntry ); 
       
   627     if( entryError != KErrNone )
       
   628         {
       
   629         // Problem. Do not copy.
       
   630         return EFalse;
       
   631         }            
       
   632 
       
   633     TEntry targetEntry;
       
   634     entryError = aFs.Entry( aTarget, targetEntry ); 
       
   635     if( entryError == KErrNotFound )
       
   636         {
       
   637         // Target does not exist. Copy needed.
       
   638         return ETrue;
       
   639         }           
       
   640     else if( entryError != KErrNone ) 
       
   641         {
       
   642         // All other errors handled here. Better not to copy.
       
   643         return EFalse;
       
   644         }
       
   645     
       
   646     TParse sourceParser;
       
   647     sourceParser.Set( aSource, NULL, NULL );
       
   648     
       
   649     TParse targetParser;
       
   650     targetParser.Set( aTarget, NULL, NULL );
       
   651             
       
   652     // We have tdesc of target drive but SysUtils need TDriveNumber instead
       
   653     // so extract it from tdesc. default to C.
       
   654     TInt targetDriveNumber = EDriveC;
       
   655         
       
   656     // Sanity checks before accessing descriptor (prevent "out of bounds" panic).
       
   657     if( targetParser.DrivePresent() &&
       
   658         targetParser.Drive().Length() > 0 )
       
   659         {
       
   660         // Use tmp variable so that CharToDrive does not mess our fallback
       
   661         // value. (it should not do that in case of error... but better
       
   662         // to do fool-proof.)
       
   663         TInt tmpDriveNumber = EDriveC;
       
   664         
       
   665         // Convert from TDesC to enumeration of drives.
       
   666         if( RFs::CharToDrive( targetParser.Drive()[0], tmpDriveNumber ) == KErrNone )
       
   667             {
       
   668             targetDriveNumber = tmpDriveNumber;
       
   669             }        
       
   670         }   
       
   671 
       
   672     const TInt KTargetExists = BaflUtils::FileExists( aFs, aTarget ); 
       
   673            
       
   674     // Target exists + size and time stamp identical?
       
   675     if( KTargetExists &&
       
   676         sourceEntry.iSize == targetEntry.iSize &&
       
   677         sourceEntry.iModified == targetEntry.iModified )
       
   678         {
       
   679         return EFalse;
       
   680         }    
       
   681     
       
   682     // Check required disk space.
       
   683     TInt requiredDiskSpace = 0;
       
   684     
       
   685     if( KTargetExists && sourceEntry.iSize > targetEntry.iSize )
       
   686         {
       
   687         requiredDiskSpace = sourceEntry.iSize - targetEntry.iSize; 
       
   688         }
       
   689     else if( !KTargetExists )
       
   690         {
       
   691         requiredDiskSpace = sourceEntry.iSize;
       
   692         }
       
   693     
       
   694     if( requiredDiskSpace != 0 )
       
   695         {
       
   696         if( SysUtil::DiskSpaceBelowCriticalLevelL( &aFs, requiredDiskSpace, targetDriveNumber ) )
       
   697             {
       
   698             return EFalse;
       
   699             }
       
   700         }
       
   701         
       
   702     // All tests passed.
       
   703     return ETrue;
       
   704     }
       
   705 
       
   706 // -----------------------------------------------------------------------------
       
   707 // hspsServerUtil::UpdateConfigurationStateL
       
   708 // -----------------------------------------------------------------------------
       
   709 //
       
   710 void hspsServerUtil::UpdateConfigurationStateL( 
       
   711     ChspsODT& aOdt,
       
   712     TDesC8& aConfState,
       
   713     TDesC8& aNextConfState,
       
   714     TBool& aOdtUpdated )
       
   715     {
       
   716     aOdtUpdated = EFalse;
       
   717     ChspsDomDocument& dom = aOdt.DomDocument();
       
   718     ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( *dom.RootNode() );   
       
   719     CleanupStack::PushL( iter );                  
       
   720     ChspsDomNode* prevNode = NULL;
       
   721     ChspsDomNode* node = iter->First();
       
   722     
       
   723     while( node && prevNode != node )
       
   724         {           
       
   725         const TDesC8& name = node->Name();
       
   726         
       
   727         // Configuration element 
       
   728         if ( name == KConfigurationElement )
       
   729             {
       
   730             ChspsDomList& attrList = node->AttributeList();
       
   731             ChspsDomAttribute* attr = static_cast<ChspsDomAttribute*>( 
       
   732                 attrList.FindByName( KConfigurationAttrState ) );               
       
   733             if ( attr && attr->Value().CompareF( aConfState ) == 0 )
       
   734                 {
       
   735                 attr->SetValueL( aNextConfState );
       
   736                 aOdtUpdated = ETrue;
       
   737                 }           
       
   738             }       
       
   739         
       
   740         prevNode = node;    
       
   741         node = iter->NextL();
       
   742         }
       
   743 
       
   744     CleanupStack::PopAndDestroy( iter );
       
   745     
       
   746     }
       
   747 
       
   748 // -----------------------------------------------------------------------------
       
   749 // hspsServerUtil::UpdateAppConfigurationStateL
       
   750 // -----------------------------------------------------------------------------
       
   751 //
       
   752 void hspsServerUtil::UpdateAppConfigurationStateL( 
       
   753         ChspsODT& aAppOdt,
       
   754         const TDesC8& aConfState,
       
   755         const TDesC8& aNextConfState )
       
   756     {
       
   757     __ASSERT_DEBUG( aConfState.Length() > 0, User::Leave( KErrArgument) );
       
   758     __ASSERT_DEBUG( aNextConfState.Length() > 0, User::Leave( KErrArgument) );
       
   759         
       
   760     // Update application configuration state
       
   761     ChspsDomNode* appConfNode = hspsServerUtil::FindNodeByAttributeL(
       
   762         aAppOdt,
       
   763         KConfigurationElement,
       
   764         KConfigurationAttrType,
       
   765         KConfTypeApp );
       
   766     ChspsDomList& attrList = appConfNode->AttributeList();
       
   767     ChspsDomAttribute* attr = static_cast<ChspsDomAttribute*>( 
       
   768         attrList.FindByName( KConfigurationAttrState ) );               
       
   769     if ( attr && attr->Value().CompareF( aConfState ) == 0 )
       
   770         {
       
   771         attr->SetValueL( aNextConfState );
       
   772         }
       
   773     }
       
   774 
       
   775 // -----------------------------------------------------------------------------
       
   776 // hspsServerUtil::FindNodeByAttributeL
       
   777 // -----------------------------------------------------------------------------
       
   778 //
       
   779 ChspsDomNode* hspsServerUtil::FindNodeByAttributeL( 
       
   780     ChspsODT& aOdt,
       
   781     const TDesC8& aNodeName,
       
   782     const TDesC8& aAttrName, 
       
   783     const TDesC8& aAttrValue)
       
   784     {
       
   785     __UHEAP_MARK;
       
   786     
       
   787     ChspsDomDocument& dom = aOdt.DomDocument();
       
   788     ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( *dom.RootNode() );   
       
   789     CleanupStack::PushL( iter );
       
   790                         
       
   791     ChspsDomNode* foundNode( NULL );
       
   792     ChspsDomNode* prevNode( NULL );
       
   793     ChspsDomNode* node = iter->First();
       
   794     while( node && 
       
   795            prevNode != node &&
       
   796            foundNode == NULL )
       
   797         {           
       
   798         const TDesC8& name = node->Name();        
       
   799         if ( name.CompareF( aNodeName ) == 0 )
       
   800             {
       
   801             // Node name match
       
   802             ChspsDomList& attrList = node->AttributeList();
       
   803             ChspsDomAttribute* attr = static_cast<ChspsDomAttribute*>( 
       
   804                 attrList.FindByName( aAttrName ) );               
       
   805             if ( attr && attr->Value().CompareF( aAttrValue ) == 0 )
       
   806                 {
       
   807                 // Attribute name and value match
       
   808                 foundNode = node;
       
   809                 }           
       
   810             }       
       
   811         // Get next node
       
   812         prevNode = node;    
       
   813         node = iter->NextL();
       
   814         }
       
   815 
       
   816     CleanupStack::PopAndDestroy( iter );
       
   817     
       
   818     __UHEAP_MARKEND;
       
   819     
       
   820     return foundNode;
       
   821     }
       
   822 
       
   823 // -----------------------------------------------------------------------------
       
   824 // hspsServerUtil::FindUniquePluginsL
       
   825 // -----------------------------------------------------------------------------
       
   826 //
       
   827 void hspsServerUtil::FindUniquePluginsL( 
       
   828         ChspsODT& aOdt, 
       
   829         RArray<TInt>& aPluginArray )
       
   830     {    
       
   831     aPluginArray.Reset();          
       
   832     ChspsDomDocument& dom = aOdt.DomDocument();
       
   833     ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( *dom.RootNode() );
       
   834     CleanupStack::PushL( iter );
       
   835     
       
   836     ChspsDomNode* node = iter->First();
       
   837     ChspsDomNode* prevNode = NULL;
       
   838     while( node && prevNode != node )
       
   839        {                
       
   840        const TDesC8& name = node->Name();
       
   841        
       
   842        // Plugin element was found 
       
   843        if ( name == KPluginElement )
       
   844            {           
       
   845            ChspsDomList& attrList = node->AttributeList();                    
       
   846            ChspsDomAttribute* uidAttr = static_cast<ChspsDomAttribute*>( attrList.FindByName(KPluginAttrUid) );            
       
   847            if ( uidAttr )
       
   848                {     
       
   849                // Convert from hex to int
       
   850                const TUid pluginUid = ConvertDescIntoUid( uidAttr->Value() );               
       
   851                if ( pluginUid.iUid > 0 )
       
   852                    {
       
   853                    TBool isUnique = ETrue;
       
   854                    for( TInt i=0; isUnique && i<aPluginArray.Count();i++ )
       
   855                        {
       
   856                        if ( aPluginArray[i] == pluginUid.iUid )
       
   857                            {
       
   858                            isUnique=EFalse;
       
   859                            }
       
   860                        }
       
   861                    if ( isUnique )
       
   862                        {
       
   863                        aPluginArray.Append( pluginUid.iUid );
       
   864                        }
       
   865                    }               
       
   866                }
       
   867            }
       
   868            
       
   869            prevNode = node;        
       
   870            node = iter->NextL();        
       
   871            }
       
   872    CleanupStack::PopAndDestroy( iter );      
       
   873 }
       
   874 
       
   875 //----------------------------------------------------------------------------
       
   876 // CHspsServiceUtilities::HexString2Uint
       
   877 // ----------------------------------------------------------------------------
       
   878 //
       
   879 TInt hspsServerUtil::HexString2Uint(
       
   880     const TDesC8& aStr,
       
   881     TUint& aTrg )
       
   882     {
       
   883     // Assign to lexer.
       
   884     TLex8 lex( aStr );
       
   885     
       
   886     // Ignore preceding "0x" if it exists. TLex does not know how to handle that
       
   887     // and returns just zero.
       
   888     if( aStr.Length() >= KHexPrefix8().Length() &&
       
   889         aStr.FindF( KHexPrefix8() ) == 0 )
       
   890         {
       
   891         lex.Inc( KHexPrefix8().Length() );
       
   892         }
       
   893     
       
   894     // Actual conversion.
       
   895     TInt status = KErrNone;
       
   896     TUint val = 0;
       
   897     status = lex.Val( val, EHex );
       
   898     
       
   899     // Error check.
       
   900     if( status == KErrNone )
       
   901         {
       
   902         aTrg = val;
       
   903         }
       
   904     
       
   905     return status;
       
   906     }
       
   907 
       
   908 //----------------------------------------------------------------------------
       
   909 // CHspsServiceUtilities::DecString2Int
       
   910 // ----------------------------------------------------------------------------
       
   911 //
       
   912 TInt hspsServerUtil::DecString2Int(
       
   913     const TDesC8& aStr )
       
   914     {
       
   915     TLex8 lex( aStr );
       
   916     TUint value;
       
   917     lex.Mark();
       
   918     
       
   919     while ( lex.Peek().IsDigit() )
       
   920         {
       
   921         lex.Inc();
       
   922         }
       
   923     TPtrC8 uidToken = lex.MarkedToken();
       
   924     TLex8 uidLex( uidToken );
       
   925     TInt err = uidLex.Val( value, EDecimal );
       
   926     
       
   927     return value;
       
   928     }
       
   929 // -----------------------------------------------------------------------------
       
   930 // Returns a count of plugin instances.
       
   931 // -----------------------------------------------------------------------------
       
   932 //
       
   933 void hspsServerUtil::PluginInstanceCountL(
       
   934         const ChspsODT& aAppODT,        
       
   935         const TInt aPluginUid,
       
   936         TInt& aInstanceCount )              
       
   937     {       
       
   938     aInstanceCount = 0;
       
   939     
       
   940     ChspsDomDocument& dom = aAppODT.DomDocument();
       
   941     ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( *dom.RootNode() );
       
   942     CleanupStack::PushL( iter );
       
   943 
       
   944     // Find a plugin node with the provided id attribute
       
   945     ChspsDomNode* node = iter->First();
       
   946     ChspsDomNode* prevNode = NULL;
       
   947     TBool jobDone = EFalse;
       
   948     while( node && !jobDone && prevNode != node )
       
   949         {               
       
   950         const TDesC8& name = node->Name();
       
   951         
       
   952         // Plugin element was found 
       
   953         if ( name == KPluginElement )
       
   954             {           
       
   955             ChspsDomList& attrList = node->AttributeList();                 
       
   956             ChspsDomAttribute* attr = static_cast<ChspsDomAttribute*>( attrList.FindByName(KPluginAttrUid) );           
       
   957             if ( !attr )
       
   958                 {
       
   959                 // Mandatory information is missing for some reason (should be set at installation handler)!
       
   960                 // Exit with NULL
       
   961                 jobDone = ETrue;                
       
   962                 }
       
   963             else
       
   964                 {
       
   965                 // Convert from (hex?) string into TUid presentation
       
   966                 const TUid uid = ConvertDescIntoUid( attr->Value() );                          
       
   967                 if ( aPluginUid == uid.iUid )
       
   968                     {
       
   969                     aInstanceCount++;
       
   970                     }
       
   971                 }
       
   972             }
       
   973         
       
   974         prevNode = node;        
       
   975         node = iter->NextL();       
       
   976         }
       
   977     CleanupStack::PopAndDestroy( iter );    
       
   978     }
       
   979 // -----------------------------------------------------------------------------
       
   980 // hspsServerUtil::ConvertDescIntoUid()
       
   981 //----------------------------------------------------------------------------
       
   982 //
       
   983 TUid hspsServerUtil::ConvertDescIntoUid(
       
   984         const TDesC8& aStr )
       
   985     {
       
   986     TLex8 lex(aStr);
       
   987     TUint pluginUid;
       
   988     lex.Mark();
       
   989     
       
   990     if(lex.Peek() == '0')
       
   991         {
       
   992         lex.Inc();
       
   993         }
       
   994     if(lex.Peek() == 'x')
       
   995         {
       
   996         lex.Inc();
       
   997         }
       
   998     lex.Mark();
       
   999     while (lex.Peek().IsHexDigit())
       
  1000         {
       
  1001         lex.Inc();
       
  1002         }
       
  1003     TPtrC8 uidToken = lex.MarkedToken();
       
  1004     TLex8 uidLex(uidToken);
       
  1005     TInt err = uidLex.Val(pluginUid,EHex);
       
  1006     
       
  1007     return TUid::Uid(pluginUid);
       
  1008     }
       
  1009 //----------------------------------------------------------------------------
       
  1010 // hspsServerUtil::FindChildNodeByTagL()
       
  1011 // ----------------------------------------------------------------------------
       
  1012 //
       
  1013 ChspsDomNode* hspsServerUtil::FindChildNodeByTagL(
       
  1014     const TDesC8& aNodeTag, 
       
  1015     ChspsDomNode& aParentNode,
       
  1016     TInt& aIndex )
       
  1017     {
       
  1018     ChspsDomNode* node( NULL );
       
  1019     ChspsDomList& items = aParentNode.ChildNodes();
       
  1020     TInt length = items.Length();
       
  1021     node = NULL;
       
  1022     for ( TInt i = aIndex; i < length && node == NULL; i++ )
       
  1023         {
       
  1024         node = static_cast<ChspsDomNode*>( items.Item( i ) );
       
  1025         const TDesC8& name = node->Name();
       
  1026         if( name.Compare( aNodeTag ) != 0 )
       
  1027             {
       
  1028             node = NULL;
       
  1029             }
       
  1030         else
       
  1031             {
       
  1032             aIndex = i;
       
  1033             }
       
  1034         }
       
  1035     
       
  1036     return node;
       
  1037     }
       
  1038 
       
  1039 //----------------------------------------------------------------------------
       
  1040 // hspsServerUtil::FindFilesL()
       
  1041 // ----------------------------------------------------------------------------
       
  1042 //
       
  1043 void hspsServerUtil::FindFilesL(
       
  1044     const TDesC& aDirName, 
       
  1045     const TDesC& aFileName,
       
  1046     RArray <TFileName>& aFiles )
       
  1047     {
       
  1048     RFs fs;
       
  1049     CleanupClosePushL( fs );
       
  1050     User::LeaveIfError( fs.Connect() );
       
  1051     
       
  1052     // Find files from root directory
       
  1053     hspsServerUtil::FindFilesFromDirL( 
       
  1054             aDirName, 
       
  1055             aFileName, 
       
  1056             aFiles );
       
  1057     
       
  1058     // Directory scanner to browse directory structure
       
  1059     CDirScan* dirScan = CDirScan::NewL( fs );
       
  1060     CleanupStack::PushL( dirScan );
       
  1061     dirScan->SetScanDataL( 
       
  1062         aDirName, 
       
  1063         ( KEntryAttDir | KEntryAttMatchExclusive ), 
       
  1064         ESortNone );
       
  1065     
       
  1066     // Directory path where installation files are searched
       
  1067     TFileName dirName;
       
  1068 
       
  1069     // Get first directory list
       
  1070     CDir* dirList( NULL );
       
  1071     dirScan->NextL( dirList );
       
  1072     // Find files from root directories
       
  1073     while ( dirList )
       
  1074         {
       
  1075         CleanupStack::PushL( dirList );
       
  1076         for ( TInt i = 0; i < dirList->Count(); i++ )
       
  1077             {
       
  1078             // Get directory path
       
  1079             dirName = dirScan->FullPath();
       
  1080             // Append directory entry
       
  1081             const TEntry& dirEntry = ( *dirList )[ i ];
       
  1082             dirName.Append( dirEntry.iName );
       
  1083             dirName.Append( KDoubleBackSlash );
       
  1084             hspsServerUtil::FindFilesFromDirL( 
       
  1085                 dirName, 
       
  1086                 aFileName, 
       
  1087                 aFiles );
       
  1088             }
       
  1089         // Get next directory list
       
  1090         CleanupStack::PopAndDestroy( dirList );
       
  1091         dirScan->NextL( dirList );
       
  1092         }
       
  1093     
       
  1094     CleanupStack::PopAndDestroy( dirScan );
       
  1095 
       
  1096     CleanupStack::PopAndDestroy(); // fs
       
  1097     
       
  1098     }
       
  1099 
       
  1100 //----------------------------------------------------------------------------
       
  1101 // hspsServerUtil::FindFilesFromDirL()
       
  1102 // ----------------------------------------------------------------------------
       
  1103 //
       
  1104 void hspsServerUtil::FindFilesFromDirL(
       
  1105     const TDesC& aDirName, 
       
  1106     const TDesC& aFileName,
       
  1107     RArray <TFileName>& aFiles )
       
  1108     {
       
  1109     RFs fs;
       
  1110     CleanupClosePushL( fs );
       
  1111     User::LeaveIfError( fs.Connect() );
       
  1112     
       
  1113     // File finder to search files from a directory
       
  1114     TFindFile fileFinder( fs );
       
  1115     
       
  1116     // Define drives where files are searched
       
  1117     TInt driveNumber;
       
  1118     TParse dirParser;
       
  1119     dirParser.Set( aDirName, NULL, NULL );
       
  1120     // Default drives C: and Z:
       
  1121     TInt findMask( 
       
  1122             KDriveAttExclude |
       
  1123             KDriveAttRemovable |
       
  1124             KDriveAttRemote );
       
  1125     if( RFs::CharToDrive( dirParser.Drive()[0], driveNumber ) == KErrNone )
       
  1126         {
       
  1127         if ( driveNumber == EDriveC )
       
  1128             {
       
  1129             // Search from C: drive
       
  1130             findMask = ( 
       
  1131                 KDriveAttExclude | 
       
  1132                 KDriveAttRemovable | 
       
  1133                 KDriveAttRemote | 
       
  1134                 KDriveAttRom );
       
  1135             }
       
  1136         else if ( driveNumber == EDriveZ )
       
  1137             {
       
  1138             // Search from Z: drive
       
  1139             findMask = KDriveAttRom;
       
  1140             }
       
  1141         }            
       
  1142     fileFinder.SetFindMask( findMask ); 
       
  1143     
       
  1144     // Find files from the directory entry
       
  1145     CDir* fileList( NULL );
       
  1146     fileFinder.FindWildByDir( aFileName, aDirName, fileList );
       
  1147     CleanupStack::PushL( fileList );
       
  1148     for ( TInt k = 0; fileList && k < fileList->Count(); k++ )
       
  1149         {
       
  1150         // Add found file with full path to file array
       
  1151         const TEntry& fileEntry = (*fileList)[k];
       
  1152         TFileName file;
       
  1153         file.Append( aDirName );
       
  1154         file.Append( fileEntry.iName );
       
  1155         aFiles.Append( file );
       
  1156         }
       
  1157     CleanupStack::PopAndDestroy( fileList );
       
  1158 
       
  1159     CleanupStack::PopAndDestroy(); // fs
       
  1160     }
       
  1161 
       
  1162 // -----------------------------------------------------------------------------
       
  1163 // hspsServerUtil::SetAttributeValueL
       
  1164 // -----------------------------------------------------------------------------
       
  1165 //
       
  1166 void hspsServerUtil::SetAttributeValueL( 
       
  1167     const ChspsODT& aOdt,
       
  1168     const TDesC8& aNodeName,
       
  1169     const TDesC8& aAttrName, 
       
  1170     const TDesC8& aAttrValue,
       
  1171     const TDesC8& aSetAttrName,
       
  1172     const TDesC8& aSetAttrValue )
       
  1173     {
       
  1174     
       
  1175     ChspsDomDocument& dom = aOdt.DomDocument();
       
  1176     ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( *dom.RootNode() );   
       
  1177     CleanupStack::PushL( iter );
       
  1178                         
       
  1179     TBool nodeFound( EFalse );
       
  1180     ChspsDomNode* prevNode( NULL );
       
  1181     ChspsDomNode* node = iter->First();
       
  1182     while( node && 
       
  1183            prevNode != node )
       
  1184         {           
       
  1185         const TDesC8& name = node->Name();        
       
  1186         if ( name.CompareF( aNodeName ) == 0 )
       
  1187             {
       
  1188             // Node name match
       
  1189             ChspsDomList& attrList = node->AttributeList();
       
  1190             ChspsDomAttribute* attr = static_cast<ChspsDomAttribute*>( 
       
  1191                 attrList.FindByName( aAttrName ) );               
       
  1192             if ( attr && attr->Value().CompareF( aAttrValue ) == 0 )
       
  1193                 {
       
  1194                 // Attribute name and value match - Defined node found
       
  1195                 attr = static_cast<ChspsDomAttribute*>( 
       
  1196                     attrList.FindByName( aSetAttrName ) );
       
  1197                 if ( attr )
       
  1198                     {
       
  1199                     // Updated attribute found - Update attribute value
       
  1200                     attr->SetValueL( aSetAttrValue );
       
  1201                     }
       
  1202                 else
       
  1203                     {
       
  1204                     // Add new attribute
       
  1205                     AddAttributeDescL( *node, aSetAttrName, aSetAttrValue );
       
  1206                     }
       
  1207                 nodeFound = ETrue;
       
  1208                 }
       
  1209             }       
       
  1210         // Get next node
       
  1211         prevNode = node;    
       
  1212         node = iter->NextL();
       
  1213         }
       
  1214 
       
  1215     if ( !nodeFound )
       
  1216         {
       
  1217         User::Leave( KErrNotFound );
       
  1218         }
       
  1219     
       
  1220     CleanupStack::PopAndDestroy( iter );
       
  1221         
       
  1222     }
       
  1223 
       
  1224 // -----------------------------------------------------------------------------
       
  1225 // hspsServerUtil::GetAttributeValueL
       
  1226 // -----------------------------------------------------------------------------
       
  1227 //
       
  1228 void hspsServerUtil::GetAttributeValueL( 
       
  1229     const ChspsODT& aOdt,
       
  1230     const TDesC8& aNodeName,
       
  1231     const TDesC8& aAttrName, 
       
  1232     const TDesC8& aAttrValue,
       
  1233     const TDesC8& aGetAttrName,
       
  1234     TPtrC8& aGetAttrValue )
       
  1235     {
       
  1236     __UHEAP_MARK;
       
  1237     
       
  1238     ChspsDomDocument& dom = aOdt.DomDocument();
       
  1239     ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( *dom.RootNode() );   
       
  1240     CleanupStack::PushL( iter );
       
  1241                         
       
  1242     TBool nodeFound( EFalse );
       
  1243     ChspsDomNode* prevNode( NULL );
       
  1244     ChspsDomNode* node = iter->First();
       
  1245     while( node && 
       
  1246            prevNode != node &&
       
  1247            !nodeFound )
       
  1248         {           
       
  1249         const TDesC8& name = node->Name();        
       
  1250         if ( name.CompareF( aNodeName ) == 0 )
       
  1251             {
       
  1252             // Node name match
       
  1253             ChspsDomList& attrList = node->AttributeList();
       
  1254             ChspsDomAttribute* attr = static_cast<ChspsDomAttribute*>( 
       
  1255                 attrList.FindByName( aAttrName ) );               
       
  1256             if ( attr && attr->Value().CompareF( aAttrValue ) == 0 )
       
  1257                 {
       
  1258                 // Attribute name and value match - Defined node found
       
  1259                 attr = static_cast<ChspsDomAttribute*>( 
       
  1260                     attrList.FindByName( aGetAttrName ) );
       
  1261                 if ( attr )
       
  1262                     {
       
  1263                     // Updated 
       
  1264                     aGetAttrValue.Set( attr->Value() );
       
  1265                     nodeFound = ETrue;
       
  1266                     }
       
  1267                 }
       
  1268             }       
       
  1269         // Get next node
       
  1270         prevNode = node;    
       
  1271         node = iter->NextL();
       
  1272         }
       
  1273 
       
  1274     if ( !nodeFound )
       
  1275         {
       
  1276         User::Leave( KErrNotFound );
       
  1277         }
       
  1278     
       
  1279     CleanupStack::PopAndDestroy( iter );
       
  1280     
       
  1281     __UHEAP_MARKEND;
       
  1282     
       
  1283     }
       
  1284 
       
  1285 // -----------------------------------------------------------------------------
       
  1286 // hspsServerUtil::CheckResourceFilesL
       
  1287 // -----------------------------------------------------------------------------
       
  1288 //
       
  1289 void hspsServerUtil::CheckResourceFilesL( 
       
  1290     const ChspsODT& aOdt,
       
  1291     const TInt aConfUid )
       
  1292     {
       
  1293     __UHEAP_MARK;
       
  1294 
       
  1295     // Convert configuration UID to decimal string
       
  1296     TBuf<10> confUid; 
       
  1297     _LIT( KFormat, "%D" );
       
  1298     confUid.AppendFormat( KFormat, aConfUid );
       
  1299 
       
  1300     RFs fs;
       
  1301     CleanupClosePushL( fs );
       
  1302     User::LeaveIfError( fs.Connect() );
       
  1303     
       
  1304     TInt resCount = aOdt.ResourceCount();
       
  1305     for ( TInt i = 0; i < resCount; i++ )
       
  1306         {
       
  1307         // Check if resource file belongs to defined configuration
       
  1308         // (file path contains configuration UID string)
       
  1309         ChspsResource& res = aOdt.ResourceL( i );
       
  1310         TPtrC resFile = res.FileName();
       
  1311         if ( resFile.FindC( confUid ) != KErrNotFound )
       
  1312             {
       
  1313             // Check that resource files exists
       
  1314             if ( !BaflUtils::FileExists( fs, resFile ) )
       
  1315                 {
       
  1316                 User::Leave( KErrNotFound );
       
  1317                 }
       
  1318             }
       
  1319         }
       
  1320     
       
  1321     CleanupStack::PopAndDestroy(); // fs
       
  1322     
       
  1323     __UHEAP_MARKEND;
       
  1324     
       
  1325     }
       
  1326 
       
  1327 // -----------------------------------------------------------------------------
       
  1328 // hspsServerUtil::GetConfigurationVersionL
       
  1329 // -----------------------------------------------------------------------------
       
  1330 //
       
  1331 void hspsServerUtil::CheckConfigurationVersionL( 
       
  1332     ChspsODT& aOdt,
       
  1333     const TInt aConfUid,
       
  1334     const TDesC& aVersion )
       
  1335     {
       
  1336     __UHEAP_MARK;
       
  1337 
       
  1338     // Create configuration UID string
       
  1339     TBuf8<10> confUid;    
       
  1340     _LIT8( KFormat8, "%X" );
       
  1341     _LIT8( KHexPrefix, "0x" );
       
  1342     confUid.Append( KHexPrefix );
       
  1343     confUid.AppendFormat( KFormat8, aConfUid );
       
  1344 
       
  1345     // Find configuration node
       
  1346     ChspsDomNode* confNode = hspsServerUtil::FindNodeByAttributeL(
       
  1347         aOdt,
       
  1348         KConfigurationElement,
       
  1349         KConfigurationAttrUid,
       
  1350         confUid );
       
  1351     
       
  1352     if ( confNode )
       
  1353         {
       
  1354         ChspsDomList& attrList = confNode->AttributeList();
       
  1355         ChspsDomAttribute* attr = static_cast<ChspsDomAttribute*>( 
       
  1356             attrList.FindByName( KConfigurationAttrVersion ) );               
       
  1357         if ( attr )
       
  1358             {
       
  1359             HBufC8* tv = HBufC8::NewLC( aVersion.Length() );
       
  1360             TPtr8 tvPtr( tv->Des() );
       
  1361             tvPtr.Copy( aVersion );
       
  1362             // Check configuration version
       
  1363             if ( attr->Value().Compare( tvPtr ) != 0 )
       
  1364                 {
       
  1365                 // Configuration not supported
       
  1366                 User::Leave( KErrNotSupported );
       
  1367                 }
       
  1368             CleanupStack::PopAndDestroy( tv );
       
  1369             }
       
  1370         else
       
  1371             {
       
  1372             // Invalid configuration
       
  1373             User::Leave( KErrGeneral );
       
  1374             }
       
  1375         }
       
  1376     else
       
  1377         {
       
  1378         // Configuration not found
       
  1379         User::Leave( KErrNotFound );
       
  1380         }
       
  1381     
       
  1382     __UHEAP_MARKEND;
       
  1383     }
       
  1384 
       
  1385 // -----------------------------------------------------------------------------
       
  1386 // hspsServerUtil::EditPluginNodeActivityL
       
  1387 // -----------------------------------------------------------------------------
       
  1388 //
       
  1389 void hspsServerUtil::EditPluginNodeActivityL( ChspsDomNode* aRootNode,
       
  1390                                               const TNodeEditMode aEditMode,
       
  1391                                               TInt aDepth  )
       
  1392     {
       
  1393     // This wrapper exists to prevent modification of original aDepth
       
  1394     // (_EditPluginNodeActivityL uses TInt reference for depth count and
       
  1395     // modifies it).
       
  1396     hspsServerUtil::_EditPluginNodeActivityL( aRootNode, aEditMode, aDepth );
       
  1397     }
       
  1398 
       
  1399 // -----------------------------------------------------------------------------
       
  1400 // hspsServerUtil::_EditPluginNodeActivityL
       
  1401 // -----------------------------------------------------------------------------
       
  1402 //
       
  1403 void hspsServerUtil::_EditPluginNodeActivityL( ChspsDomNode* aRootNode,      
       
  1404                                                const TNodeEditMode aEditMode,
       
  1405                                                TInt& aDepth )
       
  1406     {
       
  1407     // Sanity check.
       
  1408     if( !aRootNode )
       
  1409         {
       
  1410         return;
       
  1411         }
       
  1412 
       
  1413     // Recursion depth logic.
       
  1414     if( aDepth == RECURSION_DEPTH_INFINITE )
       
  1415         {
       
  1416         // Work as normal. Recurse as far as object tree exists.
       
  1417         }
       
  1418     else if( aDepth > 0 )
       
  1419         {
       
  1420         // Depth was defined. Decrement by one.
       
  1421         aDepth--;
       
  1422         }
       
  1423     else if( aDepth == 0 )
       
  1424         {
       
  1425         // No more recursion.
       
  1426         return;
       
  1427         }
       
  1428     
       
  1429     // Iterate childs    
       
  1430     ChspsDomList& childs = aRootNode->ChildNodes();    
       
  1431     for( int i = 0; i < childs.Length(); i++ )
       
  1432         {
       
  1433         ChspsDomNode* child = static_cast<ChspsDomNode*>( childs.Item( i ) );         
       
  1434         
       
  1435         // Modify node activity based on selected edit mode.
       
  1436         if( child->Name().CompareF( KPluginElement ) == 0 )
       
  1437             {
       
  1438             if( aEditMode == EActivateFirst && i == 0 )
       
  1439                 {
       
  1440                 hspsServerUtil::AddAttributeDescL( *child,
       
  1441                                                    KPluginAttrActive,
       
  1442                                                    KPluginActiveStateActive );                
       
  1443                 }
       
  1444             else 
       
  1445                 {
       
  1446                 hspsServerUtil::AddAttributeDescL( *child,
       
  1447                                                    KPluginAttrActive,
       
  1448                                                    KPluginActiveStateNotActive );                
       
  1449                 }
       
  1450             }
       
  1451 
       
  1452         // Recurse.
       
  1453         _EditPluginNodeActivityL( child,
       
  1454                                   aEditMode,
       
  1455                                   aDepth );
       
  1456         }    
       
  1457     }
       
  1458 
       
  1459 // -----------------------------------------------------------------------------
       
  1460 // hspsServerUtil::GetActivePluginNode
       
  1461 // -----------------------------------------------------------------------------
       
  1462 //
       
  1463 ChspsDomNode* hspsServerUtil::GetActivePluginNode( ChspsDomNode* aParentNode )
       
  1464     {
       
  1465     // Sanity check.
       
  1466     if( !aParentNode )
       
  1467         {
       
  1468         return NULL;
       
  1469         }
       
  1470 
       
  1471     // Return structure.
       
  1472     ChspsDomNode* activeNode = NULL;
       
  1473     
       
  1474     // Iterate childs    
       
  1475     ChspsDomList& childs = aParentNode->ChildNodes();    
       
  1476     for( int i = 0; i < childs.Length(); i++ )
       
  1477         {
       
  1478         ChspsDomNode* child = static_cast<ChspsDomNode*>( childs.Item( i ) );         
       
  1479         
       
  1480         // Only for plugin elements.
       
  1481         if( child->Name().CompareF( KPluginElement ) == 0 )
       
  1482             {
       
  1483             // 1. Check if has activity attribute.            
       
  1484             ChspsDomList& attrList = child->AttributeList();            
       
  1485             ChspsDomAttribute* pluginActivityAttr = 
       
  1486                 static_cast<ChspsDomAttribute*>( attrList.FindByName( KPluginAttrActive ) );                
       
  1487             if( pluginActivityAttr )
       
  1488                 {
       
  1489                 // 2. Check whether node is active.
       
  1490                 if( pluginActivityAttr->Value().CompareF( KPluginActiveStateActive ) == 0 )
       
  1491                     {
       
  1492                     // 3. Active node found. assign and break.
       
  1493                     activeNode = child;
       
  1494                     break;
       
  1495                     }
       
  1496                 }                
       
  1497             }
       
  1498         }
       
  1499     
       
  1500     return activeNode;
       
  1501     }
       
  1502 
       
  1503 // -----------------------------------------------------------------------------
       
  1504 // hspsServerUtil::GetPluginId
       
  1505 // -----------------------------------------------------------------------------
       
  1506 //
       
  1507 TInt hspsServerUtil::GetPluginId( ChspsDomNode* aNode )
       
  1508     {
       
  1509     // Sanity check.
       
  1510     if( !aNode )
       
  1511         {
       
  1512         return KErrArgument;
       
  1513         }
       
  1514     
       
  1515     // Return value.
       
  1516     TInt pluginId = KErrNotFound;
       
  1517 
       
  1518     // Find out plugin id.
       
  1519     ChspsDomList& attrList = aNode->AttributeList();                                                                                                      
       
  1520     ChspsDomAttribute* pluginIdAttr = 
       
  1521         static_cast<ChspsDomAttribute*> ( attrList.FindByName( KPluginAttrId ) );        
       
  1522     if( pluginIdAttr )
       
  1523         {
       
  1524         // Found.
       
  1525         const TDesC8& pluginIdValue = pluginIdAttr->Value();
       
  1526         pluginId = DecString2Int( pluginIdValue );  
       
  1527         }
       
  1528     
       
  1529     return pluginId;
       
  1530     }
       
  1531 
       
  1532 // -----------------------------------------------------------------------------
       
  1533 // hspsServerUtil::GetPluginUid
       
  1534 // -----------------------------------------------------------------------------
       
  1535 //
       
  1536 TUid hspsServerUtil::GetPluginUid( ChspsDomNode* aNode )
       
  1537     {
       
  1538     // Sanity check.
       
  1539     if( !aNode )
       
  1540         {
       
  1541         return KNullUid;
       
  1542         }
       
  1543     
       
  1544     // Read Uid from attribute list.
       
  1545     ChspsDomList& attrList = aNode->AttributeList();
       
  1546     ChspsDomAttribute* pluginUidAttr = 
       
  1547         static_cast<ChspsDomAttribute*> ( attrList.FindByName( KPluginAttrUid ) );                                                            
       
  1548 
       
  1549     // Sanity check.
       
  1550     if( !pluginUidAttr )
       
  1551         {
       
  1552         return KNullUid;
       
  1553         }
       
  1554     
       
  1555     // Convert uids from string to numeric format
       
  1556     const TDesC8& pluginUidValue = pluginUidAttr->Value();                    
       
  1557     const TUid pluginUid = hspsServerUtil::ConvertDescIntoUid(pluginUidValue);    
       
  1558     
       
  1559     // Return result.
       
  1560     return pluginUid;
       
  1561     }
       
  1562 
       
  1563 // -----------------------------------------------------------------------------
       
  1564 // hspsServerUtil::GetPluginIdsByUidL
       
  1565 // -----------------------------------------------------------------------------
       
  1566 //
       
  1567 void hspsServerUtil::GetPluginIdsByUidL(
       
  1568         const ChspsODT& aAppODT,        
       
  1569         const TUid aPluginUid,
       
  1570         RArray<TInt>& aPluginIds )       
       
  1571     {       
       
  1572     ChspsDomDocument& dom = aAppODT.DomDocument();
       
  1573     ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( *dom.RootNode() );
       
  1574     CleanupStack::PushL( iter );
       
  1575 
       
  1576     // Find a plugin node with the provided id attribute
       
  1577     ChspsDomNode* node = iter->First();
       
  1578     ChspsDomNode* prevNode = NULL;
       
  1579     TBool jobDone = EFalse;
       
  1580     while( node && !jobDone && prevNode != node )
       
  1581         {               
       
  1582         const TDesC8& name = node->Name();
       
  1583         
       
  1584         // Plugin element was found 
       
  1585         if ( name == KPluginElement )
       
  1586             {           
       
  1587             ChspsDomList& attrList = node->AttributeList();                 
       
  1588             ChspsDomAttribute* attr = static_cast<ChspsDomAttribute*>( attrList.FindByName(KPluginAttrUid) );           
       
  1589             if ( !attr )
       
  1590                 {
       
  1591                 // Mandatory information is missing for some reason (should be set at installation handler)!
       
  1592                 // Exit with NULL
       
  1593                 jobDone = ETrue;                
       
  1594                 }
       
  1595             else
       
  1596                 {
       
  1597                 // Convert from (hex?) string into TUid presentation
       
  1598                 const TUid uid = ConvertDescIntoUid( attr->Value() );                          
       
  1599                 if ( aPluginUid == uid )
       
  1600                     {
       
  1601                     const TDesC8& strPluginId = node->AttributeValue(KPluginAttrId);
       
  1602                     TInt pluginId = DecString2Int( strPluginId );           
       
  1603                     aPluginIds.AppendL( pluginId );                    
       
  1604                     }
       
  1605                 }
       
  1606             }
       
  1607         
       
  1608         prevNode = node;        
       
  1609         node = iter->NextL();       
       
  1610         }
       
  1611     
       
  1612     CleanupStack::PopAndDestroy( iter );    
       
  1613     }
       
  1614 
       
  1615 // -----------------------------------------------------------------------------
       
  1616 // hspsServerUtil::GetParentNode
       
  1617 // -----------------------------------------------------------------------------
       
  1618 //
       
  1619 ChspsDomNode* hspsServerUtil::GetParentNode(
       
  1620     const ChspsDomNode& aNode,
       
  1621     const TDesC8& aNodeName,
       
  1622     const TDesC8& aAttrName,
       
  1623     const TDesC8& aAttrValue )       
       
  1624     {
       
  1625     ChspsDomNode* parent = aNode.Parent();
       
  1626     TBool found( EFalse );
       
  1627     while ( parent && !found )
       
  1628         {
       
  1629         if ( parent->Name().CompareF( aNodeName ) == 0 )
       
  1630             {
       
  1631             ChspsDomList& attrList = parent->AttributeList();                 
       
  1632             ChspsDomAttribute* attr = static_cast<ChspsDomAttribute*>( attrList.FindByName( aAttrName ) );
       
  1633             if ( attr->Value().CompareF( aAttrValue ) == 0 )
       
  1634                 {
       
  1635                 found = ETrue;
       
  1636                 }
       
  1637             }
       
  1638         if ( !found )
       
  1639             {
       
  1640             // Get next level parent node
       
  1641             parent = parent->Parent();
       
  1642             }
       
  1643         }
       
  1644     
       
  1645     return parent;
       
  1646     }
       
  1647 
       
  1648 // -----------------------------------------------------------------------------
       
  1649 // hspsServerUtil::IsFile
       
  1650 // -----------------------------------------------------------------------------
       
  1651 //
       
  1652 TBool hspsServerUtil::IsFile(
       
  1653         const TDesC& aFileDeclaration,
       
  1654         TFileName& aFilename )        
       
  1655     {
       
  1656     _LIT(KDeclarationSkin, "SKIN(");        // prefixes for filelogo/filepreview values 
       
  1657     _LIT(KDeclarationMif, "MIF(");
       
  1658     _LIT(KDeclarationUid, "UID(");
       
  1659         
       
  1660     aFilename = KNullDesC();
       
  1661     if ( aFileDeclaration.FindF( KDeclarationSkin ) >= 0  
       
  1662             || aFileDeclaration.FindF( KDeclarationMif ) >= 0             
       
  1663             || aFileDeclaration.FindF( KDeclarationUid ) >= 0 )
       
  1664         {                
       
  1665         // pick filename from the mif declaration if it's available (e.g. "skin(<id> <id>):mif(<path> <id> <id>)")
       
  1666         TInt mifOffset = aFileDeclaration.FindF( KDeclarationMif );
       
  1667         if ( mifOffset >= 0 )            
       
  1668             {              
       
  1669             aFilename = aFileDeclaration.Mid( mifOffset + KDeclarationMif().Length() );
       
  1670             aFilename.TrimAll();                
       
  1671                         
       
  1672             // drop everything before the first bitmap index
       
  1673             TInt endPos = aFilename.Locate( ' ' );
       
  1674             if ( endPos > 1 )
       
  1675                 {
       
  1676                 aFilename = aFilename.Left( endPos );                                
       
  1677                 }                                                      
       
  1678             }                                       
       
  1679         }
       
  1680     else
       
  1681         {
       
  1682         // store possible icon path
       
  1683         aFilename.Copy( aFileDeclaration );
       
  1684         }
       
  1685     
       
  1686     return ( aFilename.Length() > 0 );
       
  1687     }
       
  1688 
       
  1689 // -----------------------------------------------------------------------------
       
  1690 // hspsServerUtil::GetValidResourcesL
       
  1691 // -----------------------------------------------------------------------------
       
  1692 void hspsServerUtil::GetValidResourcesL(
       
  1693         ChspsODT& aODT,        
       
  1694         const TInt aConfUid,
       
  1695         const TLanguage aActiveLanguage,
       
  1696         RPointerArray<ChspsResource>& aWidgetResources )
       
  1697     {    
       
  1698     const TInt resourceCount = aODT.ResourceCount();
       
  1699             
       
  1700     // pick resources with the active language       
       
  1701     for( TInt resourceIndex = 0; resourceIndex < resourceCount; resourceIndex++ )
       
  1702         {
       
  1703         ChspsResource& resource = aODT.ResourceL( resourceIndex );        
       
  1704         if ( resource.ConfigurationUid() == aConfUid &&
       
  1705              resource.FileName().FindF( KSourcesFolder ) > 0 &&
       
  1706              resource.Language() == aActiveLanguage )                
       
  1707             {                                
       
  1708             aWidgetResources.Append( &resource );
       
  1709             }
       
  1710         }        
       
  1711     
       
  1712     // Resources for language none or language test.    
       
  1713     for( TInt resourceIndex = 0; resourceIndex < resourceCount; resourceIndex++ )
       
  1714         {
       
  1715         ChspsResource& resource = aODT.ResourceL( resourceIndex );
       
  1716         if ( resource.ConfigurationUid() == aConfUid &&
       
  1717              resource.FileName().FindF( KSourcesFolder ) > 0 )
       
  1718             {
       
  1719             if( resource.Language() == ELangTest || resource.Language() == ELangNone )
       
  1720                 {
       
  1721                 // Checking also that not going to overwrite existing localized resource.                
       
  1722                 TBool localizedVersionAvailable = EFalse;
       
  1723                 for( TInt checkIndex = 0; checkIndex < aWidgetResources.Count(); checkIndex++ )
       
  1724                     {
       
  1725                     ChspsResource* checkResource = aWidgetResources[ checkIndex ];
       
  1726                     if( !checkResource )
       
  1727                         {
       
  1728                         continue;
       
  1729                         }
       
  1730                     
       
  1731                     TParsePtrC resource1FullPath( resource.FileName() );
       
  1732                     TParsePtrC resource2FullPath( checkResource->FileName() );
       
  1733                     
       
  1734                     if( resource1FullPath.NameAndExt().CompareF( resource2FullPath.NameAndExt() ) == 0 )                 
       
  1735                         {
       
  1736                         localizedVersionAvailable = ETrue;
       
  1737                         break;
       
  1738                         }
       
  1739                     }
       
  1740             
       
  1741                 if( !localizedVersionAvailable )
       
  1742                     {
       
  1743                     aWidgetResources.Append( &resource );
       
  1744                     }
       
  1745                 }
       
  1746             }
       
  1747         }           
       
  1748     }
       
  1749 
       
  1750 // -----------------------------------------------------------------------------
       
  1751 // hspsServerUtil::EnoughDiskSpaceAvailable
       
  1752 // -----------------------------------------------------------------------------
       
  1753 TInt hspsServerUtil::EnoughDiskSpaceAvailableL(
       
  1754         ChspsODT& aODT,        
       
  1755         const TLanguage aActiveLanguage,
       
  1756         RFs& aFs,
       
  1757         const TDriveNumber aDriveNumber,
       
  1758         const TInt aAdditionalDiskSpace )
       
  1759     {        
       
  1760     __UHEAP_MARK;
       
  1761     
       
  1762     TInt err = KErrNone;   
       
  1763     
       
  1764     // Retrieve data for needed resource files.
       
  1765     RPointerArray<ChspsResource> widgetResources; // Objects are not owned.
       
  1766     CleanupClosePushL( widgetResources );
       
  1767     
       
  1768     GetValidResourcesL( aODT,
       
  1769         aODT.ThemeUid(),
       
  1770         aActiveLanguage,
       
  1771         widgetResources );
       
  1772     
       
  1773     TInt requiredDiskSpace = aAdditionalDiskSpace;
       
  1774     
       
  1775     // Calculate disk space required for resources.
       
  1776     for( TInt i = 0; i < widgetResources.Count() && !err; i++ )
       
  1777         {      
       
  1778         ChspsResource* resource = widgetResources[i];
       
  1779         if( !resource )
       
  1780             {
       
  1781             continue;
       
  1782             }
       
  1783                          
       
  1784         TEntry entryData;
       
  1785         err = aFs.Entry( resource->FileName(), entryData );        
       
  1786         requiredDiskSpace += entryData.iSize;  
       
  1787         }
       
  1788     
       
  1789     widgetResources.Reset();
       
  1790     CleanupStack::PopAndDestroy( 1, &widgetResources );    
       
  1791     
       
  1792     // Check if calculated space is available.
       
  1793     if( !err &&
       
  1794         SysUtil::DiskSpaceBelowCriticalLevelL( &aFs,
       
  1795                 requiredDiskSpace,
       
  1796                 aDriveNumber ) )
       
  1797         {
       
  1798         err = KErrDiskFull;
       
  1799         }
       
  1800         
       
  1801     __UHEAP_MARKEND;
       
  1802     
       
  1803     return err;
       
  1804     }
       
  1805 // -----------------------------------------------------------------------------
       
  1806 // Finds a node from a dom document.
       
  1807 // Looks for the next node tag.
       
  1808 // -----------------------------------------------------------------------------
       
  1809 ChspsDomNode* hspsServerUtil::FindNodeByTagL( 
       
  1810         const TDesC8& aNodeTag,
       
  1811         ChspsDomNode& aDomNode )
       
  1812     {
       
  1813     ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( aDomNode );
       
  1814     CleanupStack::PushL( iter );
       
  1815     ChspsDomNode* targetNode( NULL );
       
  1816     ChspsDomNode* node = iter->First();
       
  1817     TBool found = EFalse;
       
  1818     while( !found && node )
       
  1819         {
       
  1820         const TDesC8& name = node->Name();
       
  1821         if ( name.Compare( aNodeTag ) == 0 )
       
  1822             {  
       
  1823             found = ETrue;
       
  1824             targetNode = node;
       
  1825             }
       
  1826         node = iter->NextL();
       
  1827         }   
       
  1828     CleanupStack::PopAndDestroy( iter );
       
  1829     return targetNode;
       
  1830     } 
       
  1831 // -----------------------------------------------------------------------------
       
  1832 // hspsServerUtil::hspsServerUtil
       
  1833 // -----------------------------------------------------------------------------
       
  1834 //
       
  1835 hspsServerUtil::hspsServerUtil() 
       
  1836     {
       
  1837     // Empty. Should never be called.
       
  1838     }            
       
  1839     
       
  1840 // end of file