homescreensrv_plat/sapi_homescreenplugin/src/hspsliwutilities.cpp
branchRCL_3
changeset 30 a5a39a295112
child 31 8baec10861af
equal deleted inserted replaced
29:0efa10d348c0 30:a5a39a295112
       
     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:  Build liw list from a DomDocument.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <s32mem.h>
       
    19 #include <hspsdomdepthiterator.h>
       
    20 #include <hspsdomnode.h>
       
    21 #include <hspsdomattribute.h>
       
    22 
       
    23 #include "hspsliwutilities.h"
       
    24 #include "hspsxmlelements.h"
       
    25 #include "hspsliwvocabulary.hrh"
       
    26 
       
    27 const TInt KMaxTextLength = 16 * 1024; // 16KB.
       
    28 
       
    29 _LIT8( KMaxChildDefault, "6" );
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // Constructor
       
    33 // -----------------------------------------------------------------------------  
       
    34 CHspsLiwUtilities::CHspsLiwUtilities()
       
    35 	{
       
    36 	
       
    37 	}
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // Destructor
       
    41 // -----------------------------------------------------------------------------  
       
    42 CHspsLiwUtilities::~CHspsLiwUtilities()
       
    43 	{
       
    44 
       
    45 	}
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 // -----------------------------------------------------------------------------  
       
    50 CHspsLiwUtilities* CHspsLiwUtilities::CHspsLiwUtilities::NewL()
       
    51 	{
       
    52 	CHspsLiwUtilities* self = CHspsLiwUtilities::NewLC();
       
    53 	CleanupStack::Pop( self ); //self
       
    54 	return self;
       
    55 	}
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // 
       
    59 // -----------------------------------------------------------------------------  
       
    60 CHspsLiwUtilities* CHspsLiwUtilities::CHspsLiwUtilities::NewLC()
       
    61 	{
       
    62 	CHspsLiwUtilities* self = new ( ELeave ) CHspsLiwUtilities();
       
    63 	CleanupStack::PushL( self );
       
    64 	self->ConstructL();
       
    65 	return self;	
       
    66 	}
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // 2nd stage constructor
       
    70 // -----------------------------------------------------------------------------  
       
    71 void CHspsLiwUtilities::ConstructL()
       
    72 	{	
       
    73 	}
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // Adds common status element to the output parameter list
       
    77 // ----------------------------------------------------------------------------- 
       
    78 void CHspsLiwUtilities::AppendStatusL( 
       
    79     TInt32 aStatus,
       
    80     CLiwGenericParamList& aOutParamList )
       
    81     {    
       
    82     TLiwGenericParam param;
       
    83     param.SetNameAndValueL( KHspsLiwStatus, TLiwVariant( aStatus ) );
       
    84     aOutParamList.AppendL( param );
       
    85 
       
    86     param.Reset();
       
    87     
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // Builds liw list from a dom document.
       
    92 // ----------------------------------------------------------------------------- 
       
    93 void CHspsLiwUtilities::GetConfigurationL( 
       
    94 	const TDesC8& aReturnName,
       
    95     const TDesC8& aPluginId,
       
    96     ChspsDomDocument& aDomDocument,
       
    97     CLiwGenericParamList& aOutParamList )
       
    98 	{
       
    99 	ChspsDomNode* node( NULL );
       
   100     TInt err = KErrNotFound;
       
   101 	//figure out what part of the dom is wanted.
       
   102 	//we have configuration id.
       
   103 	if( aPluginId.Length() > 0 )
       
   104 		{
       
   105 		//we have plugin id.
       
   106 		//get view/widget configuration.
       
   107 		//finds configuration node with plugin id.
       
   108 		node = &( FindRootNodeByIdentifierL( KPluginElement, aPluginId, *aDomDocument.RootNode() ));
       
   109 		if ( node )
       
   110 		    {
       
   111     		node = &( FindRootNodeByTagL( KConfigurationElement, 
       
   112                     *node ));
       
   113 		    }
       
   114 		}
       
   115 	else
       
   116 		{
       
   117 		//get application configuration
       
   118 		//finds first configuration node.
       
   119 		node = &( FindRootNodeByTagL( KConfigurationElement, 
       
   120 								  *aDomDocument.RootNode() ));
       
   121 		}
       
   122 
       
   123 	if( node )
       
   124 		{
       
   125 	    CLiwDefaultMap* rootMap = CLiwDefaultMap::NewL();
       
   126 	    CleanupStack::PushL( rootMap ); 
       
   127 
       
   128     	err = BuildConfigurationMapL( *node, *rootMap );
       
   129     	//put map into the iterable.
       
   130     	TLiwVariant rootMapVariant;
       
   131     	rootMapVariant.Set( rootMap );
       
   132     	//Put iterable into outParamList
       
   133     	TLiwGenericParam rootMapParam;
       
   134     	rootMapParam.SetNameAndValueL( aReturnName, rootMapVariant );
       
   135     	aOutParamList.AppendL( rootMapParam );
       
   136     	//Cleanup.
       
   137     	CleanupStack::Pop( rootMap );
       
   138     	rootMap->DecRef();
       
   139     	rootMapParam.Reset();
       
   140 	    }
       
   141 	
       
   142 	User::LeaveIfError( err );
       
   143 	}
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // Builds plugins list from plugin header list
       
   147 // ----------------------------------------------------------------------------- 
       
   148 void CHspsLiwUtilities::GetPluginsOutputL( 
       
   149     CArrayPtrFlat<ChspsODT>& aList,
       
   150     CLiwGenericParamList& aOutParamList )
       
   151     {
       
   152     CLiwDefaultList* pluginList = CLiwDefaultList::NewL();
       
   153     CleanupStack::PushL( pluginList );
       
   154     
       
   155     BuildPluginInfoListL( aList, *pluginList );
       
   156     
       
   157     TLiwVariant listVariant;
       
   158     listVariant.Set( pluginList );
       
   159     TLiwGenericParam param;
       
   160     param.SetNameAndValueL( KHspsLiwPlugins, listVariant );
       
   161     aOutParamList.AppendL( param );
       
   162     
       
   163     CleanupStack::Pop( pluginList );
       
   164     pluginList->DecRef();
       
   165     param.Reset();
       
   166     
       
   167     }
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // Builds plugins list from plugin node list
       
   171 // ----------------------------------------------------------------------------- 
       
   172 void CHspsLiwUtilities::GetPluginListOutputL( 
       
   173     ChspsDomNode& aRootNode,
       
   174     TDesC8& aType,
       
   175     TDesC8& aPluginId,
       
   176     CLiwGenericParamList& aOutParamList )
       
   177     {    
       
   178     CLiwDefaultList* pluginList = CLiwDefaultList::NewL();
       
   179     CleanupStack::PushL( pluginList );
       
   180 
       
   181     BuildPluginListL(
       
   182         aRootNode,
       
   183         aType,
       
   184         aPluginId,
       
   185         *pluginList );
       
   186 
       
   187     TLiwVariant listVariant;
       
   188     listVariant.Set( pluginList );
       
   189     TLiwGenericParam param;
       
   190     param.SetNameAndValueL( KHspsLiwPlugins, listVariant );
       
   191     aOutParamList.AppendL( param );
       
   192     
       
   193     CleanupStack::Pop( pluginList );
       
   194     pluginList->DecRef();
       
   195     param.Reset();
       
   196 
       
   197     }
       
   198 
       
   199 // -----------------------------------------------------------------------------
       
   200 // Creates output parmater list for AddPlugin method
       
   201 // ----------------------------------------------------------------------------- 
       
   202 void CHspsLiwUtilities::AddPluginOutputL( 
       
   203     TInt aPluginId,
       
   204     CLiwGenericParamList& aOutParamList )
       
   205     {    
       
   206     TBuf8<10>id;
       
   207     _LIT8(KFormat8, "%d");
       
   208     id.AppendFormat( KFormat8, aPluginId );
       
   209     
       
   210     TLiwGenericParam param;
       
   211     param.SetNameAndValueL( KPluginId, TLiwVariant( id ) );
       
   212     aOutParamList.AppendL( param );
       
   213     
       
   214     param.Reset();
       
   215     
       
   216     }
       
   217 // -----------------------------------------------------------------------------
       
   218 // Creates output parmater list for RemovePlugin method
       
   219 // ----------------------------------------------------------------------------- 
       
   220 void CHspsLiwUtilities::RemovePluginOutputL( 
       
   221     CLiwGenericParamList& aOutParamList )
       
   222     {
       
   223     
       
   224     AppendStatusL( KErrNone, aOutParamList );
       
   225 
       
   226     }
       
   227 
       
   228 // -----------------------------------------------------------------------------
       
   229 // Creates output parmater list for ReplacePlugin method
       
   230 // ----------------------------------------------------------------------------- 
       
   231 void CHspsLiwUtilities::ReplacePluginOutputL( 
       
   232     CLiwGenericParamList& aOutParamList )
       
   233     {    
       
   234     AppendStatusL( KErrNone, aOutParamList );
       
   235     }
       
   236 
       
   237 // -----------------------------------------------------------------------------
       
   238 // Builds settings Dom document from liw list
       
   239 // ----------------------------------------------------------------------------- 
       
   240 TInt CHspsLiwUtilities::SetPluginSettingsNodeL( 
       
   241      const CLiwList& aItemList,
       
   242      TDesC8& aPluginId,
       
   243      ChspsDomDocument& aDomDocument,
       
   244      ChspsDomDocument& aSettingsDom )
       
   245     {
       
   246     TInt error(KErrNone);
       
   247     ChspsDomNode* node( NULL );
       
   248     ChspsDomNode* settingsNode( NULL );
       
   249     ChspsDomNode* itemNode( NULL );
       
   250     
       
   251     if( aPluginId.Length() > 0 )
       
   252         {
       
   253         // get plugin node
       
   254         node = &( FindRootNodeByIdentifierL( KPluginElement, aPluginId, *aDomDocument.RootNode() ));
       
   255         if ( node )
       
   256             {
       
   257             // get control node of the plugin
       
   258             node = &( FindRootNodeByTagL( KControlElement, 
       
   259                                         *node ));
       
   260             if( node )
       
   261                 {
       
   262                 TInt index = 0;
       
   263                 // get settings node (child of control node)
       
   264                 settingsNode = FindChildNodeByTagL(
       
   265                          KSettingsElement,
       
   266                          *node,
       
   267                          index );
       
   268                 }
       
   269             }
       
   270         
       
   271         
       
   272         if ( node == NULL || settingsNode == NULL )
       
   273             {
       
   274             // pluginId Not Found
       
   275             error=KErrNotFound;
       
   276             } 
       
   277         
       
   278         TLiwVariant tempVariant;
       
   279         tempVariant.PushL();
       
   280         TInt itemsCount = aItemList.Count();
       
   281         if ( (KErrNone == error) &&
       
   282                      (itemsCount > 0) )
       
   283             {    
       
   284             // Find items for plugin settings
       
   285             for ( TInt i = 0; ( i < itemsCount && error == KErrNone ); i++ )
       
   286                 {
       
   287                 error = KErrNotFound;
       
   288                 aItemList.AtL( i, tempVariant );
       
   289                 const CLiwMap* item = tempVariant.AsMap();
       
   290                 if ( (item != NULL) &&
       
   291                       item->FindL( KHspsLiwItemId, tempVariant ) )
       
   292                     {
       
   293                     TPtrC8 itemId;
       
   294                     itemId.Set( tempVariant.AsData() );
       
   295                    
       
   296                     itemNode = &( FindRootNodeByIdentifierL( 
       
   297                             KItemElement, itemId, *settingsNode ));
       
   298                     if( itemNode )
       
   299                         {
       
   300                         item->FindL(KHspsLiwProperties, tempVariant );
       
   301                         const CLiwList* propertyList = tempVariant.AsList();
       
   302                         if(propertyList && propertyList->Count() > 0)
       
   303                             {
       
   304                             if ( SetPluginPropertyNodeL( *propertyList, *itemNode) == KErrNone )
       
   305                                 {
       
   306                                 error = KErrNone;                              
       
   307                                 }
       
   308                             }
       
   309                         }
       
   310                     }               
       
   311                 tempVariant.Reset();
       
   312                 }
       
   313             }
       
   314         else
       
   315             {
       
   316             error = KErrNotFound;
       
   317             }
       
   318 
       
   319         CleanupStack::Pop(&tempVariant);
       
   320         tempVariant.Reset();
       
   321         
       
   322         
       
   323         if( error == KErrNone )
       
   324             {
       
   325           
       
   326             // Making Settings Dom
       
   327             ChspsDomNode* clone = settingsNode->CloneL( aSettingsDom.StringPool() );
       
   328             CleanupStack::PushL( clone );
       
   329             aSettingsDom.SetRootNode( clone );
       
   330             CleanupStack::Pop( clone );
       
   331             }
       
   332             
       
   333         }
       
   334     
       
   335     return error;
       
   336     }
       
   337 
       
   338 // -----------------------------------------------------------------------------
       
   339 // Parse Properties from liw list
       
   340 // ----------------------------------------------------------------------------- 
       
   341 TInt CHspsLiwUtilities::SetPluginPropertyNodeL( const CLiwList& aPropertyList,
       
   342         ChspsDomNode& aNode  )
       
   343     {
       
   344     // Init used local variables.        
       
   345     TInt err = KErrNone;
       
   346     
       
   347     TLiwVariant mapVariant;
       
   348     mapVariant.PushL();
       
   349     
       
   350     TLiwVariant propertyNameVariant;
       
   351     propertyNameVariant.PushL();
       
   352 
       
   353     TLiwVariant propertyValueVariant;
       
   354     propertyValueVariant.PushL();            
       
   355     
       
   356     const TInt propertiesCount = aPropertyList.Count();
       
   357     
       
   358     // Loop all items in given list.
       
   359     for( TInt i = 0; ( i < propertiesCount && err == KErrNone ); i++ )
       
   360         {        
       
   361         // Extract map.
       
   362         aPropertyList.AtL( i, mapVariant );
       
   363         
       
   364         const CLiwMap* property = mapVariant.AsMap();
       
   365         if( property == NULL ) 
       
   366             {
       
   367             err = KErrCorrupt;
       
   368             }
       
   369                        
       
   370         // Extract property name.
       
   371         if( !err )
       
   372             {
       
   373             if( !property->FindL( KHspsLiwPropertyName, propertyNameVariant ) )
       
   374                 {
       
   375                 err = KErrNotFound;
       
   376                 }
       
   377             }
       
   378         
       
   379         TPtrC8 name;
       
   380         if( !err )
       
   381             {
       
   382             name.Set( propertyNameVariant.AsData() );
       
   383             if( name.Length() > KMaxTextLength )
       
   384                 {
       
   385                 err = KErrArgument;
       
   386                 }
       
   387             }
       
   388         
       
   389         // Extract property value.
       
   390         if( !err )
       
   391             {
       
   392             if( !property->FindL( KHspsLiwPropertyValue, propertyValueVariant ) )
       
   393                 {
       
   394                 err = KErrNotFound;
       
   395                 }
       
   396             }
       
   397         
       
   398         TPtrC8 value;
       
   399         if( !err )
       
   400             {        
       
   401             value.Set( propertyValueVariant.AsData() );
       
   402             if( value.Length() > KMaxTextLength )
       
   403                 {
       
   404                 err = KErrArgument;
       
   405                 }
       
   406             }
       
   407         
       
   408         // Set attribute.
       
   409         if( !err )
       
   410             {
       
   411             err = SetPropertyAttributesL( name, value, aNode );
       
   412             }
       
   413         
       
   414         mapVariant.Reset();
       
   415         propertyNameVariant.Reset();
       
   416         propertyValueVariant.Reset();        
       
   417         }
       
   418         
       
   419     // Cleanup.    
       
   420     CleanupStack::Pop( &propertyValueVariant );
       
   421     CleanupStack::Pop( &propertyNameVariant );
       
   422     CleanupStack::Pop( &mapVariant );
       
   423     
       
   424     return err;   
       
   425     }
       
   426 //-----------------------------------------------------------------------------
       
   427 // SetpropertyAttributeL replaces value of property attribute given in parameter 
       
   428 // -----------------------------------------------------------------------------
       
   429 //
       
   430 TInt CHspsLiwUtilities::SetPropertyAttributesL(
       
   431          TDesC8& aAttrName,
       
   432          TDesC8& aAttrValue,
       
   433         ChspsDomNode& aNode )
       
   434     {
       
   435    
       
   436    
       
   437     TInt error(KErrNotFound);
       
   438     ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( aNode );
       
   439     CleanupStack::PushL( iter );                                
       
   440     ChspsDomNode* node = iter->First();                              
       
   441     TBool replaced(EFalse);                     
       
   442     
       
   443     while( node && !replaced )
       
   444         {
       
   445         const TDesC8& nodeName = node->Name();
       
   446         if( nodeName == KPropertyElement )
       
   447             {
       
   448             ChspsDomList& attrList = node->AttributeList();
       
   449             ChspsDomAttribute* attr = static_cast<ChspsDomAttribute*>( attrList.FindByName(KPropertyAttrName) );     
       
   450             if ( attr )
       
   451                 {
       
   452                 const TDesC8& name = attr->Value(); 
       
   453                 if (aAttrName.Compare( name )== 0 ) 
       
   454                     {
       
   455                     ChspsDomAttribute* attr2 = static_cast<ChspsDomAttribute*>( attrList.FindByName(KPropertyAttrValue) );
       
   456                     if( attr2 )
       
   457                         {
       
   458                         attr2->SetValueL( aAttrValue );
       
   459                         replaced=ETrue;
       
   460                         error = KErrNone;
       
   461                         }
       
   462                     }
       
   463                 }
       
   464             }
       
   465         if( !replaced )
       
   466             {
       
   467             node = iter->NextL();
       
   468             }
       
   469         }
       
   470                 
       
   471     CleanupStack::PopAndDestroy( iter );
       
   472     
       
   473     return error;
       
   474    
       
   475     }  
       
   476 // -----------------------------------------------------------------------------
       
   477 // Creates output parmater list for SetPluginSettings method
       
   478 // ----------------------------------------------------------------------------- 
       
   479 void CHspsLiwUtilities::SetPluginSettingsOutputL( 
       
   480     CLiwGenericParamList& aOutParamList )
       
   481     {
       
   482     AppendStatusL( KErrNone, aOutParamList );
       
   483     }
       
   484 
       
   485 // -----------------------------------------------------------------------------
       
   486 // Creates output parmater list for GetPluginSettings method
       
   487 // ----------------------------------------------------------------------------- 
       
   488 
       
   489 void CHspsLiwUtilities::GetPluginSettingsOutputL( 
       
   490 		ChspsDomDocument& aDom, 
       
   491 		CLiwGenericParamList& aOutParamList )
       
   492 	{
       
   493 	TInt pos = 0;
       
   494     CLiwDefaultList* list = CLiwDefaultList::NewL();
       
   495     CleanupStack::PushL( list );
       
   496 	ChspsDomNode* node( NULL );
       
   497 
       
   498 	node = aDom.RootNode();
       
   499     if( !node )
       
   500     	{
       
   501     	User::Leave( KErrNotFound );
       
   502     	}
       
   503   
       
   504     // get ctrl node (child of control node)
       
   505     node = FindChildNodeByTagL(
       
   506     	KControlElement,
       
   507         *node,
       
   508         pos );
       
   509     
       
   510     if( !node )
       
   511     	{
       
   512     	User::Leave( KErrNotFound );
       
   513     	}
       
   514 
       
   515     // get settings node (child of control node)
       
   516     node = FindChildNodeByTagL(
       
   517     	KSettingsElement,
       
   518         *node,
       
   519         pos );
       
   520 	    
       
   521     if ( node )
       
   522         {
       
   523         // append item maps to settings list
       
   524         AppendItemsL( *node, *list );
       
   525         }
       
   526     else
       
   527         {
       
   528         User::Leave( KErrNotFound );
       
   529         }
       
   530     
       
   531 	TLiwVariant listVariant;
       
   532 	listVariant.Set( list );
       
   533 
       
   534     TLiwGenericParam param;
       
   535     param.SetNameAndValueL( KHspsLiwSettings, listVariant );
       
   536     aOutParamList.AppendL( param );
       
   537     
       
   538     CleanupStack::Pop( list );
       
   539     list->DecRef();
       
   540     param.Reset();
       
   541   	}
       
   542 
       
   543 
       
   544 // -----------------------------------------------------------------------------
       
   545 // Creates output parmater list for MovePlugins method
       
   546 // ----------------------------------------------------------------------------- 
       
   547 void CHspsLiwUtilities::MovePluginsOutputL( 
       
   548     CLiwGenericParamList& aOutParamList )
       
   549     {
       
   550     
       
   551     AppendStatusL( KErrNone, aOutParamList );
       
   552 
       
   553     }
       
   554 
       
   555 // -----------------------------------------------------------------------------
       
   556 // Gets list of plugin id's from plugins list
       
   557 // ----------------------------------------------------------------------------- 
       
   558 void CHspsLiwUtilities::GetPluginIdListL( 
       
   559     const CLiwList* aPluginsList,
       
   560     CArrayFixFlat<TInt>& aPluginIdList )
       
   561     {
       
   562     
       
   563     const TInt pluginsCount = aPluginsList->Count();
       
   564     TLiwVariant entry;
       
   565     entry.PushL();
       
   566     for( TInt i = 0; i < pluginsCount; i++ )
       
   567         {
       
   568         aPluginsList->AtL( i, entry );
       
   569         TInt id = 0;
       
   570         TPtrC8 pluginId = entry.AsData();
       
   571         TLex8 lex( pluginId );
       
   572         User::LeaveIfError( lex.Val( id ) );
       
   573         if ( id < 1 )
       
   574             {
       
   575             User::Leave( KErrArgument );
       
   576             }
       
   577 
       
   578         // Plugin id's must be unique
       
   579         const TInt pluginIdCount = aPluginIdList.Count();
       
   580         for ( TInt j = 0; j < pluginIdCount; j++ )
       
   581             {
       
   582             if ( id == aPluginIdList.At( j ) )
       
   583                 {
       
   584                 User::Leave( KErrArgument );
       
   585                 }
       
   586             }
       
   587         
       
   588         aPluginIdList.AppendL( id );
       
   589         entry.Reset();
       
   590         }
       
   591     CleanupStack::Pop( &entry );
       
   592 
       
   593     }
       
   594 
       
   595 // -----------------------------------------------------------------------------
       
   596 // Builds plugins list from plugin header list
       
   597 // ----------------------------------------------------------------------------- 
       
   598 void CHspsLiwUtilities::GetAppConfsOutputL( 
       
   599     CArrayPtrFlat<ChspsODT>& aList,
       
   600     CLiwGenericParamList& aOutParamList )
       
   601     {
       
   602     CLiwDefaultList* pluginList = CLiwDefaultList::NewL();
       
   603     CleanupStack::PushL( pluginList );
       
   604     
       
   605     BuildAppConfInfoListL( aList, *pluginList );
       
   606     
       
   607     TLiwVariant listVariant;
       
   608     listVariant.Set( pluginList );
       
   609     TLiwGenericParam param;
       
   610     param.SetNameAndValueL( KHspsLiwAppConfs, listVariant );
       
   611     aOutParamList.AppendL( param );
       
   612     
       
   613     CleanupStack::Pop( pluginList );
       
   614     pluginList->DecRef();
       
   615     param.Reset();
       
   616     
       
   617     }
       
   618 
       
   619 // -----------------------------------------------------------------------------
       
   620 // Creates output parmater list for SetActiveAppConf method
       
   621 // ----------------------------------------------------------------------------- 
       
   622 void CHspsLiwUtilities::SetActiveAppConfOutputL( 
       
   623     CLiwGenericParamList& aOutParamList )
       
   624     {
       
   625     
       
   626     AppendStatusL( KErrNone, aOutParamList );
       
   627 
       
   628     }
       
   629 
       
   630 // -----------------------------------------------------------------------------
       
   631 // Creates output parmater list for SetConfState method
       
   632 // ----------------------------------------------------------------------------- 
       
   633 void CHspsLiwUtilities::SetConfStateOutputL( 
       
   634     CLiwGenericParamList& aOutParamList )
       
   635     {
       
   636     
       
   637     AppendStatusL( KErrNone, aOutParamList );
       
   638 
       
   639     }
       
   640 
       
   641 // -----------------------------------------------------------------------------
       
   642 // Returns value of defined attribute
       
   643 // ----------------------------------------------------------------------------- 
       
   644 void CHspsLiwUtilities::GetAttributeValueL( 
       
   645     ChspsDomNode& aNode,
       
   646     const TDesC8& aAttrId,
       
   647     TPtrC8& aAttrValue )
       
   648     {
       
   649     
       
   650     // Get configutation node's ID attribute
       
   651     ChspsDomList& attrList = aNode.AttributeList();    
       
   652     ChspsDomAttribute* attr = static_cast<ChspsDomAttribute*>( 
       
   653                                   attrList.FindByName( aAttrId ) );
       
   654     if ( !attr )
       
   655         {
       
   656         User::Leave( KErrNotFound );
       
   657         }
       
   658 
       
   659     aAttrValue.Set( attr->Value() );
       
   660     
       
   661     }
       
   662 
       
   663 // -----------------------------------------------------------------------------
       
   664 // Finds a node from a dom document.
       
   665 // Looks for configuration elements and plugin elements by the identifier.
       
   666 // -----------------------------------------------------------------------------
       
   667 ChspsDomNode& CHspsLiwUtilities::FindRootNodeByIdentifierL( 
       
   668         const TDesC8& aNodeTag,
       
   669         const TDesC8& aNodeIdentifier,
       
   670 		ChspsDomNode& aNode )
       
   671 	{
       
   672 	ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( aNode );
       
   673 	CleanupStack::PushL( iter );
       
   674 	ChspsDomNode* targetNode( NULL );
       
   675 	ChspsDomNode* node = iter->First();
       
   676 	TBool found = EFalse;
       
   677 	while( !found && node )
       
   678 		{
       
   679 	    const TDesC8& name = node->Name();
       
   680 	    if ( name.Compare( aNodeTag ) == 0)
       
   681 	    	{
       
   682 	    	ChspsDomList& attrList = node->AttributeList();
       
   683 	    	
       
   684 	    	ChspsDomAttribute* attr = static_cast<ChspsDomAttribute*>( 
       
   685 	    							      attrList.FindByName( KAttrId ));
       
   686 	    	if ( attr )
       
   687 	    	    {
       
   688                 const TDesC8& value = attr->Value();
       
   689                 if( value.Compare( aNodeIdentifier ) == 0 )
       
   690                     {
       
   691                     found = ETrue;
       
   692                     targetNode = node;
       
   693                     }
       
   694 	    	    }
       
   695 	    	}
       
   696 	    node = iter->NextL();
       
   697 		}	
       
   698     CleanupStack::PopAndDestroy( iter );
       
   699 	return *targetNode;
       
   700 	}
       
   701 
       
   702 // -----------------------------------------------------------------------------
       
   703 // Finds a node from a dom document.
       
   704 // Looks for the next node tag.
       
   705 // -----------------------------------------------------------------------------
       
   706 ChspsDomNode& CHspsLiwUtilities::FindRootNodeByTagL( 
       
   707 		const TDesC8& aNodeTag,
       
   708 		 ChspsDomNode& aDomNode )
       
   709 	{
       
   710 	ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( aDomNode );
       
   711 	CleanupStack::PushL( iter );
       
   712 	ChspsDomNode* targetNode( NULL );
       
   713 	ChspsDomNode* node = iter->First();
       
   714 	TBool found = EFalse;
       
   715 	while( !found && node )
       
   716 		{
       
   717 	    const TDesC8& name = node->Name();
       
   718 	    if ( name.Compare( aNodeTag ) == 0 )
       
   719 	        {  
       
   720         	found = ETrue;
       
   721         	targetNode = node;
       
   722 	        }
       
   723 	    node = iter->NextL();
       
   724 		}	
       
   725     CleanupStack::PopAndDestroy( iter );
       
   726 	return *targetNode;
       
   727 	}
       
   728 
       
   729 // -----------------------------------------------------------------------------
       
   730 // Appends found attributes into the LIW map instance
       
   731 // -----------------------------------------------------------------------------
       
   732 //
       
   733 TInt CHspsLiwUtilities::AppendAttributeToMapL( CLiwDefaultMap& aMap, 
       
   734 		                              ChspsDomList& aAttrList, 
       
   735 		                              const TDesC8& aDomName,
       
   736 		                              const TDesC8& aLiwName,
       
   737 		                              const TDesC8& aDefaultValue )
       
   738 	{
       
   739 	TInt err = KErrNone;
       
   740 	ChspsDomAttribute* attr = static_cast<ChspsDomAttribute*>( 
       
   741 											aAttrList.FindByName(aDomName) );	            
       
   742 	if( attr )
       
   743         {
       
   744         const TDesC8& value = attr->Value(); 
       
   745         aMap.InsertL( aLiwName, TLiwVariant( value ) );                                  
       
   746         }   
       
   747     else
       
   748     	{
       
   749     	aMap.InsertL( aLiwName, TLiwVariant( aDefaultValue ) );
       
   750    	}
       
   751     return err;
       
   752 	}
       
   753 
       
   754 // -----------------------------------------------------------------------------
       
   755 // Builds a plugin map.
       
   756 // -----------------------------------------------------------------------------
       
   757 //
       
   758 TInt CHspsLiwUtilities::BuildConfigurationMapL( ChspsDomNode& aConfigurationNode, 
       
   759 		                                   CLiwDefaultMap& aMap )
       
   760 	{
       
   761 	TInt err = KErrNone;	
       
   762 	//Get plugin info.
       
   763 	const TDesC8& name = aConfigurationNode.Name();
       
   764     ChspsDomList& attrList = aConfigurationNode.AttributeList();
       
   765     if ( name == KConfigurationElement )
       
   766         {    
       
   767         //Add id
       
   768         AppendAttributeToMapL( aMap, attrList, KConfigurationAttrId, KHspsLiwId );
       
   769         //Add pluginUid
       
   770         AppendAttributeToMapL( aMap, attrList, KConfigurationAttrUid, KHspsLiwUid );
       
   771         //Add type
       
   772         AppendAttributeToMapL( aMap, attrList, KConfigurationAttrType, KHspsLiwType );
       
   773         //Add interface
       
   774         AppendAttributeToMapL( aMap, attrList, KConfigurationAttrInterface, 
       
   775         													KHspsLiwInterface );
       
   776         //Add name
       
   777         AppendAttributeToMapL( aMap, attrList, KConfigurationAttrName, KHspsLiwName );
       
   778 
       
   779         //Add multiinstance
       
   780         AppendAttributeToMapL( aMap, attrList, KConfigurationAttrMultiInstance,
       
   781             KHspsLiwMultiInstance );
       
   782         
       
   783         //Add desc
       
   784         AppendAttributeToMapL( aMap, attrList, KConfigurationAttrDescription,
       
   785                 KHspsLiwDescription );
       
   786 
       
   787         // Add state
       
   788         AppendAttributeToMapL( aMap, attrList, KConfigurationAttrState, KHspsLiwState );
       
   789 
       
   790         // Add max_child
       
   791         AppendAttributeToMapL( aMap,
       
   792                 attrList,
       
   793                 KConfigurationAttrMaxChild,
       
   794                 KHspsLiwMaxChild,
       
   795                 KMaxChildDefault );        
       
   796         
       
   797         //Add list of plugins.
       
   798        	//create list where maps are added.
       
   799       	AppendPluginsFlatL( aConfigurationNode, aMap );      	     	
       
   800         //Add list of settings.
       
   801         AppendSettingsL( aConfigurationNode, aMap );
       
   802         //Add list of resources.
       
   803         AppendResourcesL( aConfigurationNode, aMap );
       
   804         }
       
   805     else
       
   806     	{
       
   807     	//should be always configuration element.
       
   808     	}
       
   809 	return err;
       
   810 	}
       
   811 
       
   812 // -----------------------------------------------------------------------------
       
   813 // Builds and appends a plugins to a map. Plugins are appended without chidren 
       
   814 // plugins, settings or resources.
       
   815 // -----------------------------------------------------------------------------
       
   816 //
       
   817 TInt CHspsLiwUtilities::AppendPluginsFlatL( ChspsDomNode& aConfigurationNode, 
       
   818 						 CLiwDefaultMap& aMap )
       
   819 	{
       
   820 	TInt err = KErrNone;
       
   821 	//create a list for plugins.
       
   822 	CLiwDefaultList* list = CLiwDefaultList::NewL();
       
   823 	CleanupStack::PushL( list );
       
   824 	
       
   825 	ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( 
       
   826 														   aConfigurationNode );
       
   827 	CleanupStack::PushL( iter );
       
   828  	TBool found = EFalse;
       
   829  	ChspsDomNode* node = iter->First();
       
   830 
       
   831 	//find plugins element.
       
   832 	while( !found && node )
       
   833 		{
       
   834 		const TDesC8& name = node->Name();
       
   835 		if ( name.Compare( KPluginsElement ) == 0)
       
   836 			{
       
   837 	    	//iterate plugin information
       
   838 	    	ChspsDomList& children = node->ChildNodes();
       
   839 	    	TInt length = children.Length();
       
   840 	    	for( TInt i = 0; i < length; i++ )
       
   841 	    		{
       
   842 	    		ChspsDomNode* plugin;
       
   843 	    		plugin = static_cast<ChspsDomNode*>( children.Item( i ) );
       
   844 	    		//create a plugin map and add it to the list.
       
   845 	    		CLiwDefaultMap* map = CLiwDefaultMap::NewL();
       
   846 	    		CleanupStack::PushL( map );
       
   847 
       
   848                 TInt pluginMapItems = ( 
       
   849                     CHspsLiwUtilities::EPluginMapId +
       
   850                     CHspsLiwUtilities::EPluginMapUid +
       
   851                     CHspsLiwUtilities::EPluginMapActivationState +
       
   852                     CHspsLiwUtilities::EPluginMapLocked );
       
   853                 BuildPluginMapL( *plugin, *map, pluginMapItems );
       
   854                 
       
   855                 //append map to the list                
       
   856                 TLiwVariant mapVariant;
       
   857                 mapVariant.Set( map );
       
   858                 list->AppendL( mapVariant );
       
   859                 
       
   860                 CleanupStack::Pop( map );
       
   861                 map->DecRef();
       
   862                 }
       
   863             found = ETrue;
       
   864             }
       
   865         node = iter->NextL();
       
   866         }
       
   867      
       
   868     //append list to a map.
       
   869     TLiwVariant listVariant;
       
   870     listVariant.Set( list );
       
   871     aMap.InsertL( KHspsLiwPlugins, listVariant );
       
   872     
       
   873     CleanupStack::PopAndDestroy( iter );
       
   874     CleanupStack::Pop( list );
       
   875     list->DecRef();    
       
   876     
       
   877     return err; 
       
   878     }
       
   879 
       
   880 // -----------------------------------------------------------------------------
       
   881 // Builds and appends settings to a map.
       
   882 // -----------------------------------------------------------------------------
       
   883 //
       
   884 TInt CHspsLiwUtilities::AppendSettingsL( 
       
   885     ChspsDomNode& aConfigurationNode, 
       
   886     CLiwDefaultMap& aMap )
       
   887     {
       
   888     TInt err( KErrNone );
       
   889     TInt index( 0 );
       
   890     
       
   891     //create list
       
   892     CLiwDefaultList* list = CLiwDefaultList::NewL();
       
   893     CleanupStack::PushL( list );
       
   894     //get control (child of configuration node)
       
   895     ChspsDomNode* node( NULL );
       
   896     node = FindChildNodeByTagL( 
       
   897         KControlElement, 
       
   898         aConfigurationNode,
       
   899         index );
       
   900 
       
   901     if( node )
       
   902         {
       
   903         // get settings node (child of control node)
       
   904         node = FindChildNodeByTagL(
       
   905             KSettingsElement,
       
   906             *node,
       
   907             index );
       
   908         if ( node )
       
   909             {
       
   910             // append item maps to settings list
       
   911             AppendItemsL( *node, *list );
       
   912             }
       
   913         else
       
   914             {
       
   915             // there should always be a settings element
       
   916             err = KErrNotFound;
       
   917             }
       
   918         }
       
   919     else
       
   920         {
       
   921         //there should always be a control element.
       
   922         err = KErrNotFound;
       
   923         }
       
   924     
       
   925     User::LeaveIfError( err );
       
   926     
       
   927     //append list to a map.
       
   928     TLiwVariant listVariant;
       
   929     listVariant.Set( list );
       
   930     aMap.InsertL( KHspsLiwSettings, listVariant );
       
   931     //cleanup.
       
   932     CleanupStack::Pop( list );
       
   933     list->DecRef();    
       
   934     
       
   935     return err;
       
   936     }
       
   937 
       
   938 // -----------------------------------------------------------------------------
       
   939 // Builds and appends resources to a map.
       
   940 // -----------------------------------------------------------------------------
       
   941 //
       
   942 TInt CHspsLiwUtilities::AppendResourcesL( ChspsDomNode& aConfigurationNode, 
       
   943                                             CLiwDefaultMap& aMap )
       
   944     {    
       
   945     TInt err = KErrNone;
       
   946     //create list.
       
   947     CLiwDefaultList* list = CLiwDefaultList::NewL();
       
   948     CleanupStack::PushL( list );    
       
   949     //find resources.
       
   950     ChspsDomList& children = aConfigurationNode.ChildNodes();
       
   951     TInt length = children.Length();
       
   952     for( TInt i = 0; i < length; i++ )
       
   953         {
       
   954         ChspsDomNode* child;
       
   955         child = static_cast<ChspsDomNode*>( children.Item( i ) );
       
   956         const TDesC8& childName = child->Name();
       
   957         if( childName.Compare( KResourcesElement ) == 0)
       
   958             {
       
   959             ChspsDomList& objects = child->ChildNodes();
       
   960             TInt length = objects.Length();
       
   961             for( TInt i = 0; i < length; i++ )
       
   962                 {
       
   963                 //put object elements to the list.
       
   964                 ChspsDomNode* object;
       
   965                 object = static_cast<ChspsDomNode*>( objects.Item( i ) );
       
   966                 const TDesC8& objectName = object->Name();
       
   967                 if( objectName.Compare( KObjectElement ) == 0)
       
   968                     {
       
   969                     CLiwDefaultMap* map = CLiwDefaultMap::NewL();
       
   970                     CleanupStack::PushL( map );
       
   971                     
       
   972                     BuildObjectMapL( *object, *map );
       
   973                     
       
   974                     ///append object to the list                
       
   975                     TLiwVariant mapVariant;
       
   976                     mapVariant.Set( map );
       
   977                     list->AppendL( mapVariant );
       
   978                     
       
   979                     CleanupStack::Pop( map );
       
   980                     map->DecRef();
       
   981                     }                
       
   982                 }
       
   983             //There should be only one.
       
   984             break;
       
   985             }
       
   986         }
       
   987     //append list to a map.
       
   988     TLiwVariant listVariant;
       
   989     listVariant.Set( list );
       
   990     aMap.InsertL( KHspsLiwResources, listVariant );    
       
   991     //cleanup.
       
   992     CleanupStack::Pop( list );
       
   993     list->DecRef();    
       
   994     return err;
       
   995     }
       
   996 
       
   997 // -----------------------------------------------------------------------------
       
   998 // Builds plugin map without resources, settings or child plugins.
       
   999 // -----------------------------------------------------------------------------
       
  1000 //
       
  1001 TInt CHspsLiwUtilities::BuildPluginMapL( 
       
  1002     ChspsDomNode& aPluginNode, 
       
  1003     CLiwDefaultMap& aMap,
       
  1004     TInt aItemMask )
       
  1005     {
       
  1006     TInt err( KErrNotFound );
       
  1007 
       
  1008     // Get plugin info.
       
  1009     const TDesC8& name = aPluginNode.Name();
       
  1010     ChspsDomList& attrList = aPluginNode.AttributeList();
       
  1011     
       
  1012     if ( name == KPluginElement )
       
  1013         {
       
  1014         if ( aItemMask & CHspsLiwUtilities::EPluginMapId )
       
  1015             {
       
  1016             //Add plugin id
       
  1017             AppendAttributeToMapL( aMap, attrList, KPluginAttrId, KHspsLiwId );
       
  1018             }
       
  1019         if ( aItemMask & CHspsLiwUtilities::EPluginMapUid )
       
  1020             {
       
  1021             //Add plugin uid
       
  1022             AppendAttributeToMapL( aMap, attrList, KPluginAttrUid, KHspsLiwUid );
       
  1023             }
       
  1024         if ( aItemMask & CHspsLiwUtilities::EPluginMapType ||
       
  1025              aItemMask & CHspsLiwUtilities::EPluginMapName )
       
  1026             {
       
  1027             // Get plugin type and name from Configuration node attribute list
       
  1028             TInt index = 0;
       
  1029             ChspsDomNode* confNode = FindChildNodeByTagL( 
       
  1030                 KConfigurationElement,
       
  1031                 aPluginNode,
       
  1032                 index );
       
  1033             if ( confNode )
       
  1034                 {
       
  1035                 ChspsDomList&confNodeAttrList = confNode->AttributeList();
       
  1036                 if ( aItemMask & CHspsLiwUtilities::EPluginMapType )
       
  1037                     {
       
  1038                     // Add plugin type
       
  1039                     AppendAttributeToMapL( aMap, confNodeAttrList, KConfigurationAttrType, KHspsLiwType );
       
  1040                     }
       
  1041                 if ( aItemMask & CHspsLiwUtilities::EPluginMapName )
       
  1042                     {
       
  1043                     // Add plugin type
       
  1044                     AppendAttributeToMapL( aMap, confNodeAttrList, KConfigurationAttrName, KHspsLiwName );
       
  1045                     }
       
  1046                 }
       
  1047             }
       
  1048         if ( aItemMask & CHspsLiwUtilities::EPluginMapActivationState )
       
  1049             {
       
  1050             //Add plugin activation state
       
  1051             AppendAttributeToMapL( aMap, attrList, KPluginAttrActive, KHspsLiwActivationState );
       
  1052             }
       
  1053         if ( aItemMask & CHspsLiwUtilities::EPluginMapDesc )
       
  1054             {
       
  1055             //Add plugin description
       
  1056             AppendAttributeToMapL( aMap, attrList, KConfigurationAttrDescription, KHspsLiwDescription );
       
  1057             }
       
  1058         if ( aItemMask & CHspsLiwUtilities::EPluginMapLocked )
       
  1059             {
       
  1060             //Add plugin locked status - locked/removable/none(default)
       
  1061             AppendAttributeToMapL( aMap,
       
  1062                     attrList,
       
  1063                     KConfigurationAttrLockingStatus,
       
  1064                     KHspsLiwLockingStatus,
       
  1065                     KHspsLiwLockingNone );
       
  1066             }        
       
  1067         
       
  1068         err = KErrNone;
       
  1069         }
       
  1070 
       
  1071     return err;
       
  1072     }
       
  1073 
       
  1074 // -----------------------------------------------------------------------------
       
  1075 // Builds items map.
       
  1076 // -----------------------------------------------------------------------------
       
  1077 //
       
  1078 TInt CHspsLiwUtilities::BuildItemsMapL( ChspsDomNode& aItem, 
       
  1079                                           CLiwDefaultMap& aMap )
       
  1080     {
       
  1081     TInt err = KErrNone;
       
  1082     //Append attributes
       
  1083     //create attribute list
       
  1084     ChspsDomList& attrList = aItem.AttributeList();
       
  1085     //Add itemId
       
  1086     AppendAttributeToMapL( aMap, attrList, KItemAttrId, KHspsLiwItemId );
       
  1087     //Add name
       
  1088     AppendAttributeToMapL( aMap, attrList, KItemAttrName, KHspsLiwItemName );
       
  1089     
       
  1090     //create list
       
  1091     CLiwDefaultList* list = CLiwDefaultList::NewL();
       
  1092     CleanupStack::PushL( list );
       
  1093     //get children
       
  1094     ChspsDomList& properties = aItem.ChildNodes();
       
  1095     TInt length = properties.Length();
       
  1096     for( TInt i = 0; i < length; i++ )
       
  1097         {
       
  1098         ChspsDomNode* property;
       
  1099         property = static_cast<ChspsDomNode*>( properties.Item( i ) );
       
  1100         const TDesC8& name = property->Name();
       
  1101         if( name.Compare( KPropertyElement ) == 0)
       
  1102             {
       
  1103             CLiwDefaultMap* map = CLiwDefaultMap::NewL();       
       
  1104             CleanupStack::PushL( map );
       
  1105         
       
  1106             //build attribute.
       
  1107             BuildPropertiesMapL( *property, *map );
       
  1108         
       
  1109             //append attribute to the list              
       
  1110             TLiwVariant mapVariant;
       
  1111             mapVariant.Set( map );
       
  1112             list->AppendL( mapVariant );
       
  1113         
       
  1114             CleanupStack::Pop( map );
       
  1115             map->DecRef();              
       
  1116             }
       
  1117         }
       
  1118     //append list to a map.
       
  1119     TLiwVariant listVariant;
       
  1120     listVariant.Set( list );
       
  1121     aMap.InsertL( KHspsLiwProperties, listVariant );
       
  1122     //cleanup
       
  1123     CleanupStack::Pop( list );
       
  1124     list->DecRef();        
       
  1125     return err;
       
  1126     }
       
  1127 
       
  1128 // -----------------------------------------------------------------------------
       
  1129 // Builds properties map.
       
  1130 // -----------------------------------------------------------------------------
       
  1131 //
       
  1132 TInt CHspsLiwUtilities::BuildPropertiesMapL( ChspsDomNode& aProperty, 
       
  1133                                                CLiwDefaultMap& aMap )
       
  1134     {
       
  1135     TInt err = KErrNone;
       
  1136     //Append attributes
       
  1137     //create attribute list
       
  1138     ChspsDomList& attrList = aProperty.AttributeList();
       
  1139     //Add name
       
  1140     AppendAttributeToMapL( aMap, attrList, KPropertyAttrName, KHspsLiwPropertyName );
       
  1141     //Add value
       
  1142     AppendAttributeToMapL( aMap, attrList, KPropertyAttrValue, KHspsLiwPropertyValue );
       
  1143     
       
  1144     return err;
       
  1145     }
       
  1146 
       
  1147 // -----------------------------------------------------------------------------
       
  1148 // Builds object map.
       
  1149 // -----------------------------------------------------------------------------
       
  1150 //
       
  1151 TInt CHspsLiwUtilities::BuildObjectMapL( ChspsDomNode& aObject, 
       
  1152                                            CLiwDefaultMap& aMap )
       
  1153     {
       
  1154     TInt err = KErrNone;
       
  1155     
       
  1156     ChspsDomList& attrList = aObject.AttributeList();
       
  1157     //Add name
       
  1158     AppendAttributeToMapL( aMap, attrList, KObjectAttrName, KHspsLiwObjectName );
       
  1159     //Add path
       
  1160     AppendAttributeToMapL( aMap, attrList, KObjectAttrPath, KHspsLiwObjectPath );
       
  1161     //Add mediatype
       
  1162     AppendAttributeToMapL( aMap, attrList, KObjectAttrMediatype, KHspsLiwObjectMediatype );
       
  1163     //Add tags
       
  1164     AppendAttributeToMapL( aMap, attrList, KObjectAttrTag, KHspsLiwObjectTag );
       
  1165     
       
  1166     return err;
       
  1167     }
       
  1168 
       
  1169 // -----------------------------------------------------------------------------
       
  1170 // Buils plugin info list
       
  1171 // -----------------------------------------------------------------------------
       
  1172 //
       
  1173 void CHspsLiwUtilities::BuildPluginInfoListL( 
       
  1174     CArrayPtrFlat<ChspsODT>& aList, 
       
  1175     CLiwDefaultList& aPluginInfoList )
       
  1176     {
       
  1177     for ( TInt i = 0; i < aList.Count(); i++ )
       
  1178         {
       
  1179         CLiwDefaultMap* pluginInfoMap = CLiwDefaultMap::NewL();
       
  1180         CleanupStack::PushL( pluginInfoMap );
       
  1181         BuildPluginInfoMapL( *( aList[ i ] ), *pluginInfoMap );
       
  1182         TLiwVariant pluginInfoMapVariant;
       
  1183         pluginInfoMapVariant.Set( pluginInfoMap );
       
  1184         aPluginInfoList.AppendL( pluginInfoMapVariant );
       
  1185         CleanupStack::Pop( pluginInfoMap );
       
  1186         pluginInfoMap->DecRef();
       
  1187         }
       
  1188     }
       
  1189 
       
  1190 // -----------------------------------------------------------------------------
       
  1191 // Buils plugin info map
       
  1192 // -----------------------------------------------------------------------------
       
  1193 //
       
  1194 void CHspsLiwUtilities::BuildPluginInfoMapL( 
       
  1195     ChspsODT& aPluginHeader, 
       
  1196     CLiwDefaultMap& aPluginInfoMap )
       
  1197     {
       
  1198     // pluginInfo.uid ( 10 -> uid 32 bit as a hex string, 0xXXXXXXXX )
       
  1199     TBuf8<10> uid;
       
  1200     uid.Append( '0' );
       
  1201     uid.Append( 'x' );
       
  1202     uid.AppendNum( aPluginHeader.ThemeUid(), EHex );
       
  1203     aPluginInfoMap.InsertL( KHspsLiwUid, TLiwVariant( uid ) );
       
  1204     // pluginInfo.interface ( 10 -> uid 32 bit as a hex string, 0xXXXXXXXX )
       
  1205     TBuf8<10> interface;
       
  1206     interface.Append( '0' );
       
  1207     interface.Append( 'x' );
       
  1208     interface.AppendNum( aPluginHeader.RootUid(), EHex );
       
  1209     aPluginInfoMap.InsertL( KHspsLiwInterface, TLiwVariant( interface ) );
       
  1210     // pluginInfo.type ( enumeration to 8 bit string )
       
  1211     HBufC8* type;
       
  1212     GetConfigurationTypeStrL( aPluginHeader.ConfigurationType(), &type );
       
  1213     CleanupStack::PushL( type );
       
  1214     TPtr8 typePtr = type->Des();
       
  1215     aPluginInfoMap.InsertL( KHspsLiwType, TLiwVariant( typePtr ) );
       
  1216     CleanupStack::PopAndDestroy( type );
       
  1217     // pluginInfo.name ( 16 bit string to 8 bit string )
       
  1218     HBufC8* name = HBufC8::NewL( ( aPluginHeader.ThemeFullName() ).Length() );
       
  1219     CleanupStack::PushL( name );
       
  1220     TPtr8 namePtr = name->Des();
       
  1221     namePtr.Copy( aPluginHeader.ThemeFullName() );
       
  1222     aPluginInfoMap.InsertL( KHspsLiwName, TLiwVariant( namePtr ) );
       
  1223     CleanupStack::PopAndDestroy( name );
       
  1224 
       
  1225     TBuf8<10> multiInstance;
       
  1226     multiInstance.AppendNum( aPluginHeader.MultiInstance());
       
  1227     aPluginInfoMap.InsertL( KHspsLiwMultiInstance,
       
  1228         TLiwVariant( multiInstance ) );
       
  1229     
       
  1230     HBufC8* desc = HBufC8::NewL( ( aPluginHeader.Description() ).Length() );
       
  1231     CleanupStack::PushL( desc );
       
  1232     TPtr8 descPtr = desc->Des();
       
  1233     descPtr.Copy( aPluginHeader.Description() );
       
  1234     aPluginInfoMap.InsertL( KHspsLiwDescription, TLiwVariant( descPtr ) );
       
  1235     CleanupStack::PopAndDestroy( desc );    
       
  1236     
       
  1237     if ( aPluginHeader.LogoFile().Length() )
       
  1238         {
       
  1239         HBufC8* buf8 = HBufC8::NewLC( ( aPluginHeader.LogoFile() ).Length() );        
       
  1240         buf8->Des().Copy( aPluginHeader.LogoFile() );
       
  1241         aPluginInfoMap.InsertL( KHspsLiwLogo, TLiwVariant( *buf8 ) );
       
  1242         CleanupStack::PopAndDestroy( buf8 );
       
  1243         }
       
  1244     if ( aPluginHeader.PreviewFile().Length() )
       
  1245         {
       
  1246         HBufC8* buf8 = HBufC8::NewLC( ( aPluginHeader.PreviewFile() ).Length() );        
       
  1247         buf8->Des().Copy( aPluginHeader.PreviewFile() );
       
  1248         aPluginInfoMap.InsertL( KHspsLiwPreview, TLiwVariant( *buf8 ) );
       
  1249         CleanupStack::PopAndDestroy( buf8 );
       
  1250         }
       
  1251     }
       
  1252 
       
  1253 //----------------------------------------------------------------------------
       
  1254 // CHspsLiwUtilities::GetConfigurationTypeL
       
  1255 // ----------------------------------------------------------------------------
       
  1256 //
       
  1257 void CHspsLiwUtilities::GetConfigurationTypeStrL(
       
  1258     const TUint aType,
       
  1259     HBufC8** aTypeStr )
       
  1260     {
       
  1261     if ( aType == EhspsAppConfiguration )
       
  1262         {
       
  1263         *aTypeStr = HBufC8::NewL( KHspsLiwApplicationConf().Length() );
       
  1264         TPtr8 typePtr = ( *( aTypeStr ) )->Des();
       
  1265         typePtr.Copy( KHspsLiwApplicationConf );
       
  1266         }
       
  1267     else if ( aType == EhspsViewConfiguration )
       
  1268         {
       
  1269         *aTypeStr = HBufC8::NewL( KHspsLiwViewConf().Length() );
       
  1270         TPtr8 typePtr = ( *( aTypeStr ) )->Des();
       
  1271         typePtr.Copy( KHspsLiwViewConf );
       
  1272         }
       
  1273     else if ( aType == EhspsWidgetConfiguration )
       
  1274         {
       
  1275         *aTypeStr = HBufC8::NewL( KHspsLiwWidgetConf().Length() );
       
  1276         TPtr8 typePtr = ( *( aTypeStr ) )->Des();
       
  1277         typePtr.Copy( KHspsLiwWidgetConf );
       
  1278         }
       
  1279     else if ( aType == EhspsTemplateConfiguration )
       
  1280         {
       
  1281         *aTypeStr = HBufC8::NewL( KHspsLiwTemplateConf().Length() );
       
  1282         TPtr8 typePtr = ( *( aTypeStr ) )->Des();
       
  1283         typePtr.Copy( KHspsLiwTemplateConf );
       
  1284         }
       
  1285     else
       
  1286         {
       
  1287         User::Leave( KErrArgument );
       
  1288         }
       
  1289     }
       
  1290 
       
  1291 
       
  1292 //----------------------------------------------------------------------------
       
  1293 // CHspsLiwUtilities::FindChildNodeByTagL
       
  1294 // ----------------------------------------------------------------------------
       
  1295 //
       
  1296 ChspsDomNode* CHspsLiwUtilities::FindChildNodeByTagL(
       
  1297     const TDesC8& aNodeTag, 
       
  1298     ChspsDomNode& aParentNode,
       
  1299     TInt& aIndex )
       
  1300     {
       
  1301     ChspsDomNode* node( NULL );
       
  1302     ChspsDomList& items = aParentNode.ChildNodes();
       
  1303     TInt length = items.Length();
       
  1304     node = NULL;
       
  1305     for ( TInt i = aIndex; i < length && node == NULL; i++ )
       
  1306         {
       
  1307         node = static_cast<ChspsDomNode*>( items.Item( i ) );
       
  1308         const TDesC8& name = node->Name();
       
  1309         if( name.Compare( aNodeTag ) != 0 )
       
  1310             {
       
  1311             node = NULL;
       
  1312             }
       
  1313         else
       
  1314             {
       
  1315             aIndex = i;
       
  1316             }
       
  1317         }
       
  1318     
       
  1319     return node;
       
  1320     }
       
  1321 
       
  1322 //----------------------------------------------------------------------------
       
  1323 // CHspsLiwUtilities::AppendItemsL
       
  1324 // ----------------------------------------------------------------------------
       
  1325 //
       
  1326 void CHspsLiwUtilities::AppendItemsL(
       
  1327     ChspsDomNode& aSettingsNode,
       
  1328     CLiwDefaultList& aList )
       
  1329     {
       
  1330 
       
  1331     ChspsDomNode* itemNode( NULL );
       
  1332     TInt index = 0;
       
  1333     do
       
  1334         {
       
  1335         itemNode = FindChildNodeByTagL(
       
  1336             KItemElement,
       
  1337             aSettingsNode,
       
  1338             index );
       
  1339         if ( itemNode )
       
  1340             {
       
  1341             CLiwDefaultMap* map = CLiwDefaultMap::NewL();        
       
  1342             CleanupStack::PushL( map );
       
  1343 
       
  1344             //build item.
       
  1345             BuildItemsMapL( *itemNode, *map );
       
  1346 
       
  1347             //append item to the list                
       
  1348             TLiwVariant mapVariant;
       
  1349             mapVariant.Set( map );
       
  1350             aList.AppendL( mapVariant );
       
  1351 
       
  1352             CleanupStack::Pop( map );
       
  1353             map->DecRef();
       
  1354             // Find next item element
       
  1355             index++;
       
  1356             }
       
  1357         } while( itemNode );
       
  1358     }
       
  1359 
       
  1360 // -----------------------------------------------------------------------------
       
  1361 // Builds app conf info list
       
  1362 // -----------------------------------------------------------------------------
       
  1363 //
       
  1364 void CHspsLiwUtilities::BuildAppConfInfoListL( 
       
  1365     CArrayPtrFlat<ChspsODT>& aList, 
       
  1366     CLiwDefaultList& aAppConfInfoList )
       
  1367     {
       
  1368     for ( TInt i = 0; i < aList.Count(); i++ )
       
  1369         {
       
  1370         CLiwDefaultMap* appConfInfoMap = CLiwDefaultMap::NewL();
       
  1371         CleanupStack::PushL( appConfInfoMap );
       
  1372         BuildAppConfInfoMapL( *( aList[ i ] ), *appConfInfoMap );
       
  1373         TLiwVariant appConfInfoMapVariant;
       
  1374         appConfInfoMapVariant.Set( appConfInfoMap );
       
  1375         aAppConfInfoList.AppendL( appConfInfoMapVariant );
       
  1376         CleanupStack::Pop( appConfInfoMap );
       
  1377         appConfInfoMap->DecRef();
       
  1378         }
       
  1379     }
       
  1380 
       
  1381 // -----------------------------------------------------------------------------
       
  1382 // Buils app conf info map
       
  1383 // -----------------------------------------------------------------------------
       
  1384 //
       
  1385 void CHspsLiwUtilities::BuildAppConfInfoMapL( 
       
  1386     ChspsODT& aAppConfHeader, 
       
  1387     CLiwDefaultMap& aAppConfInfoMap )
       
  1388     {
       
  1389     // appConfInfo.uid ( 10 -> uid 32 bit as a hex string, 0xXXXXXXXX )
       
  1390     TBuf8<10> uid;
       
  1391     uid.Append( '0' );
       
  1392     uid.Append( 'x' );
       
  1393     uid.AppendNum( aAppConfHeader.ThemeUid(), EHex );
       
  1394     aAppConfInfoMap.InsertL( KHspsLiwUid, TLiwVariant( uid ) );
       
  1395     // pluginInfo.name ( 16 bit string to 8 bit string )
       
  1396     HBufC8* name = HBufC8::NewL( ( aAppConfHeader.ThemeFullName() ).Length() );
       
  1397     CleanupStack::PushL( name );
       
  1398     TPtr8 namePtr = name->Des();
       
  1399     namePtr.Copy( aAppConfHeader.ThemeFullName() );
       
  1400     aAppConfInfoMap.InsertL( KHspsLiwName, TLiwVariant( namePtr ) );
       
  1401     CleanupStack::PopAndDestroy( name );
       
  1402     }
       
  1403 
       
  1404 //----------------------------------------------------------------------------
       
  1405 // CHspsLiwUtilities::BuildPluginListL
       
  1406 // ----------------------------------------------------------------------------
       
  1407 //
       
  1408 void CHspsLiwUtilities::BuildPluginListL(
       
  1409     ChspsDomNode& aRootNode,
       
  1410     TDesC8& aType,
       
  1411     TDesC8& aPluginId,
       
  1412     CLiwDefaultList& aPluginList )
       
  1413     {
       
  1414     
       
  1415     TBool checkPluginId( EFalse );
       
  1416     TBool checkType( EFalse );
       
  1417     if ( aPluginId.Length() )
       
  1418         {
       
  1419         checkPluginId = ETrue;
       
  1420         }
       
  1421     if ( aType.Length() )
       
  1422         {
       
  1423         checkType = ETrue;
       
  1424         }
       
  1425     
       
  1426     ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( aRootNode );
       
  1427     CleanupStack::PushL( iter );
       
  1428     ChspsDomNode* node = iter->First();
       
  1429 
       
  1430     TBool pluginIdFound( EFalse );
       
  1431     while( node && !pluginIdFound )
       
  1432         {
       
  1433         const TDesC8& name = node->Name();
       
  1434         if ( name.Compare( KPluginsElement ) == 0)
       
  1435             {
       
  1436             if ( checkPluginId )
       
  1437                 {
       
  1438                 ChspsDomNode* pluginNode = FindParentNodeByTagL( 
       
  1439                     KPluginElement,
       
  1440                     *node );
       
  1441                 if ( pluginNode )
       
  1442                     {
       
  1443                     TPtrC8 pluginId;
       
  1444                     GetAttributeValueL( 
       
  1445                         *pluginNode, 
       
  1446                         KPluginAttrId, 
       
  1447                         pluginId );
       
  1448                     if ( aPluginId.Compare( pluginId ) == 0 )
       
  1449                         {
       
  1450                         pluginIdFound = ETrue;
       
  1451                         }
       
  1452                     }
       
  1453                 }
       
  1454             if ( !checkPluginId || pluginIdFound )
       
  1455                 {
       
  1456                 ChspsDomList& children = node->ChildNodes();
       
  1457                 TInt length = children.Length();
       
  1458                 for( TInt i = 0; i < length; i++ )
       
  1459                     {
       
  1460                     ChspsDomNode* plugin;
       
  1461                     plugin = static_cast<ChspsDomNode*>( children.Item( i ) );
       
  1462                     TBool typeMatch( EFalse );
       
  1463                     if ( checkType )
       
  1464                         {
       
  1465                         // Check plugin type
       
  1466                         TInt index = 0;
       
  1467                         ChspsDomNode* confNode = FindChildNodeByTagL(
       
  1468                             KConfigurationElement,
       
  1469                             *plugin,
       
  1470                             index );
       
  1471                         if ( confNode )
       
  1472                             {
       
  1473                             TPtrC8 type;
       
  1474                             GetAttributeValueL( 
       
  1475                                 *confNode, 
       
  1476                                 KConfigurationAttrType, 
       
  1477                                 type );
       
  1478                             if ( aType.Compare( type ) == 0 )
       
  1479                                 {
       
  1480                                 typeMatch = ETrue;
       
  1481                                 }
       
  1482                             }
       
  1483                         }
       
  1484                     
       
  1485                     if ( typeMatch || !checkType )
       
  1486                         {
       
  1487                         CLiwDefaultMap* map = CLiwDefaultMap::NewL();
       
  1488                         CleanupStack::PushL( map );
       
  1489                         TInt pluginMapItems = ( 
       
  1490                             CHspsLiwUtilities::EPluginMapId +
       
  1491                             CHspsLiwUtilities::EPluginMapType +
       
  1492                             CHspsLiwUtilities::EPluginMapName +
       
  1493                             CHspsLiwUtilities::EPluginMapActivationState +
       
  1494                             CHspsLiwUtilities::EPluginMapDesc +
       
  1495                             CHspsLiwUtilities::EPluginMapLocked );
       
  1496                         BuildPluginMapL( *plugin, *map, pluginMapItems );
       
  1497                         
       
  1498                         TLiwVariant mapVariant;
       
  1499                         mapVariant.Set( map );
       
  1500                         aPluginList.AppendL( mapVariant );
       
  1501                         
       
  1502                         CleanupStack::Pop( map );
       
  1503                         map->DecRef();
       
  1504                         }
       
  1505                     }
       
  1506                 }
       
  1507             }
       
  1508         node = iter->NextL();
       
  1509         }
       
  1510     CleanupStack::PopAndDestroy( iter );
       
  1511     }
       
  1512 
       
  1513 //----------------------------------------------------------------------------
       
  1514 // CHspsLiwUtilities::FindParentNodeByTagL
       
  1515 // ----------------------------------------------------------------------------
       
  1516 //
       
  1517 ChspsDomNode* CHspsLiwUtilities::FindParentNodeByTagL(
       
  1518     const TDesC8& aNodeTag, 
       
  1519     ChspsDomNode& aChildNode )
       
  1520     {
       
  1521 
       
  1522     TBool found( EFalse );
       
  1523     ChspsDomNode* parentNode = aChildNode.Parent();
       
  1524     while ( !found && parentNode )
       
  1525         {
       
  1526         if ( aNodeTag.Compare( parentNode->Name() ) == 0 )
       
  1527             {
       
  1528             found = ETrue;
       
  1529             }
       
  1530         else
       
  1531             {
       
  1532             parentNode = parentNode->Parent();
       
  1533             }
       
  1534         }
       
  1535     
       
  1536     return parentNode;
       
  1537     }
       
  1538 
       
  1539 // -----------------------------------------------------------------------------
       
  1540 // Creates output parmater list for SetActivePlugin method
       
  1541 // ----------------------------------------------------------------------------- 
       
  1542 void CHspsLiwUtilities::SetActivePluginOutputL( 
       
  1543     CLiwGenericParamList& aOutParamList )
       
  1544     {
       
  1545     
       
  1546     AppendStatusL( KErrNone, aOutParamList );
       
  1547 
       
  1548     }
       
  1549 
       
  1550 // -----------------------------------------------------------------------------
       
  1551 // Creates output parmater list for RestoreConfigurations method
       
  1552 // ----------------------------------------------------------------------------- 
       
  1553 void CHspsLiwUtilities::RestoreConfigurationsOutputL( 
       
  1554     CLiwGenericParamList& aOutParamList )
       
  1555     {    
       
  1556     AppendStatusL( KErrNone, aOutParamList );
       
  1557     }
       
  1558