homescreensrv_plat/sapi_homescreenplugin/src/hspsliwutilities.cpp
changeset 0 79c6a41cd166
child 3 ff572005ac23
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:  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 	    	const TDesC8& value = attr->Value();
       
   687 	        if( value.Compare( aNodeIdentifier ) == 0 )
       
   688 	        	{
       
   689 	        	found = ETrue;
       
   690 	        	targetNode = node;
       
   691 	        	}
       
   692 	    	}
       
   693 	    node = iter->NextL();
       
   694 		}	
       
   695     CleanupStack::PopAndDestroy( iter );
       
   696 	return *targetNode;
       
   697 	}
       
   698 
       
   699 // -----------------------------------------------------------------------------
       
   700 // Finds a node from a dom document.
       
   701 // Looks for the next node tag.
       
   702 // -----------------------------------------------------------------------------
       
   703 ChspsDomNode& CHspsLiwUtilities::FindRootNodeByTagL( 
       
   704 		const TDesC8& aNodeTag,
       
   705 		 ChspsDomNode& aDomNode )
       
   706 	{
       
   707 	ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( aDomNode );
       
   708 	CleanupStack::PushL( iter );
       
   709 	ChspsDomNode* targetNode( NULL );
       
   710 	ChspsDomNode* node = iter->First();
       
   711 	TBool found = EFalse;
       
   712 	while( !found && node )
       
   713 		{
       
   714 	    const TDesC8& name = node->Name();
       
   715 	    if ( name.Compare( aNodeTag ) == 0 )
       
   716 	        {  
       
   717         	found = ETrue;
       
   718         	targetNode = node;
       
   719 	        }
       
   720 	    node = iter->NextL();
       
   721 		}	
       
   722     CleanupStack::PopAndDestroy( iter );
       
   723 	return *targetNode;
       
   724 	}
       
   725 
       
   726 // -----------------------------------------------------------------------------
       
   727 // Appends found attributes into the LIW map instance
       
   728 // -----------------------------------------------------------------------------
       
   729 //
       
   730 TInt CHspsLiwUtilities::AppendAttributeToMapL( CLiwDefaultMap& aMap, 
       
   731 		                              ChspsDomList& aAttrList, 
       
   732 		                              const TDesC8& aDomName,
       
   733 		                              const TDesC8& aLiwName,
       
   734 		                              const TDesC8& aDefaultValue )
       
   735 	{
       
   736 	TInt err = KErrNone;
       
   737 	ChspsDomAttribute* attr = static_cast<ChspsDomAttribute*>( 
       
   738 											aAttrList.FindByName(aDomName) );	            
       
   739 	if( attr )
       
   740         {
       
   741         const TDesC8& value = attr->Value(); 
       
   742         aMap.InsertL( aLiwName, TLiwVariant( value ) );                                  
       
   743         }   
       
   744     else
       
   745     	{
       
   746     	aMap.InsertL( aLiwName, TLiwVariant( aDefaultValue ) );
       
   747    	}
       
   748     return err;
       
   749 	}
       
   750 
       
   751 // -----------------------------------------------------------------------------
       
   752 // Builds a plugin map.
       
   753 // -----------------------------------------------------------------------------
       
   754 //
       
   755 TInt CHspsLiwUtilities::BuildConfigurationMapL( ChspsDomNode& aConfigurationNode, 
       
   756 		                                   CLiwDefaultMap& aMap )
       
   757 	{
       
   758 	TInt err = KErrNone;	
       
   759 	//Get plugin info.
       
   760 	const TDesC8& name = aConfigurationNode.Name();
       
   761     ChspsDomList& attrList = aConfigurationNode.AttributeList();
       
   762     if ( name == KConfigurationElement )
       
   763         {    
       
   764         //Add id
       
   765         AppendAttributeToMapL( aMap, attrList, KConfigurationAttrId, KHspsLiwId );
       
   766         //Add pluginUid
       
   767         AppendAttributeToMapL( aMap, attrList, KConfigurationAttrUid, KHspsLiwUid );
       
   768         //Add type
       
   769         AppendAttributeToMapL( aMap, attrList, KConfigurationAttrType, KHspsLiwType );
       
   770         //Add interface
       
   771         AppendAttributeToMapL( aMap, attrList, KConfigurationAttrInterface, 
       
   772         													KHspsLiwInterface );
       
   773         //Add name
       
   774         AppendAttributeToMapL( aMap, attrList, KConfigurationAttrName, KHspsLiwName );
       
   775 
       
   776         //Add multiinstance
       
   777         AppendAttributeToMapL( aMap, attrList, KConfigurationAttrMultiInstance,
       
   778             KHspsLiwMultiInstance );
       
   779         
       
   780         //Add desc
       
   781         AppendAttributeToMapL( aMap, attrList, KConfigurationAttrDescription,
       
   782                 KHspsLiwDescription );
       
   783 
       
   784         // Add state
       
   785         AppendAttributeToMapL( aMap, attrList, KConfigurationAttrState, KHspsLiwState );
       
   786 
       
   787         // Add max_child
       
   788         AppendAttributeToMapL( aMap,
       
   789                 attrList,
       
   790                 KConfigurationAttrMaxChild,
       
   791                 KHspsLiwMaxChild,
       
   792                 KMaxChildDefault );        
       
   793         
       
   794         //Add list of plugins.
       
   795        	//create list where maps are added.
       
   796       	AppendPluginsFlatL( aConfigurationNode, aMap );      	     	
       
   797         //Add list of settings.
       
   798         AppendSettingsL( aConfigurationNode, aMap );
       
   799         //Add list of resources.
       
   800         AppendResourcesL( aConfigurationNode, aMap );
       
   801         }
       
   802     else
       
   803     	{
       
   804     	//should be always configuration element.
       
   805     	}
       
   806 	return err;
       
   807 	}
       
   808 
       
   809 // -----------------------------------------------------------------------------
       
   810 // Builds and appends a plugins to a map. Plugins are appended without chidren 
       
   811 // plugins, settings or resources.
       
   812 // -----------------------------------------------------------------------------
       
   813 //
       
   814 TInt CHspsLiwUtilities::AppendPluginsFlatL( ChspsDomNode& aConfigurationNode, 
       
   815 						 CLiwDefaultMap& aMap )
       
   816 	{
       
   817 	TInt err = KErrNone;
       
   818 	//create a list for plugins.
       
   819 	CLiwDefaultList* list = CLiwDefaultList::NewL();
       
   820 	CleanupStack::PushL( list );
       
   821 	
       
   822 	ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( 
       
   823 														   aConfigurationNode );
       
   824 	CleanupStack::PushL( iter );
       
   825  	TBool found = EFalse;
       
   826  	ChspsDomNode* node = iter->First();
       
   827 
       
   828 	//find plugins element.
       
   829 	while( !found && node )
       
   830 		{
       
   831 		const TDesC8& name = node->Name();
       
   832 		if ( name.Compare( KPluginsElement ) == 0)
       
   833 			{
       
   834 	    	//iterate plugin information
       
   835 	    	ChspsDomList& children = node->ChildNodes();
       
   836 	    	TInt length = children.Length();
       
   837 	    	for( TInt i = 0; i < length; i++ )
       
   838 	    		{
       
   839 	    		ChspsDomNode* plugin;
       
   840 	    		plugin = static_cast<ChspsDomNode*>( children.Item( i ) );
       
   841 	    		//create a plugin map and add it to the list.
       
   842 	    		CLiwDefaultMap* map = CLiwDefaultMap::NewL();
       
   843 	    		CleanupStack::PushL( map );
       
   844 
       
   845                 TInt pluginMapItems = ( 
       
   846                     CHspsLiwUtilities::EPluginMapId +
       
   847                     CHspsLiwUtilities::EPluginMapUid +
       
   848                     CHspsLiwUtilities::EPluginMapActivationState +
       
   849                     CHspsLiwUtilities::EPluginMapLocked );
       
   850                 BuildPluginMapL( *plugin, *map, pluginMapItems );
       
   851                 
       
   852                 //append map to the list                
       
   853                 TLiwVariant mapVariant;
       
   854                 mapVariant.Set( map );
       
   855                 list->AppendL( mapVariant );
       
   856                 
       
   857                 CleanupStack::Pop( map );
       
   858                 map->DecRef();
       
   859                 }
       
   860             found = ETrue;
       
   861             }
       
   862         node = iter->NextL();
       
   863         }
       
   864      
       
   865     //append list to a map.
       
   866     TLiwVariant listVariant;
       
   867     listVariant.Set( list );
       
   868     aMap.InsertL( KHspsLiwPlugins, listVariant );
       
   869     
       
   870     CleanupStack::PopAndDestroy( iter );
       
   871     CleanupStack::Pop( list );
       
   872     list->DecRef();    
       
   873     
       
   874     return err; 
       
   875     }
       
   876 
       
   877 // -----------------------------------------------------------------------------
       
   878 // Builds and appends settings to a map.
       
   879 // -----------------------------------------------------------------------------
       
   880 //
       
   881 TInt CHspsLiwUtilities::AppendSettingsL( 
       
   882     ChspsDomNode& aConfigurationNode, 
       
   883     CLiwDefaultMap& aMap )
       
   884     {
       
   885     TInt err( KErrNone );
       
   886     TInt index( 0 );
       
   887     
       
   888     //create list
       
   889     CLiwDefaultList* list = CLiwDefaultList::NewL();
       
   890     CleanupStack::PushL( list );
       
   891     //get control (child of configuration node)
       
   892     ChspsDomNode* node( NULL );
       
   893     node = FindChildNodeByTagL( 
       
   894         KControlElement, 
       
   895         aConfigurationNode,
       
   896         index );
       
   897 
       
   898     if( node )
       
   899         {
       
   900         // get settings node (child of control node)
       
   901         node = FindChildNodeByTagL(
       
   902             KSettingsElement,
       
   903             *node,
       
   904             index );
       
   905         if ( node )
       
   906             {
       
   907             // append item maps to settings list
       
   908             AppendItemsL( *node, *list );
       
   909             }
       
   910         else
       
   911             {
       
   912             // there should always be a settings element
       
   913             err = KErrNotFound;
       
   914             }
       
   915         }
       
   916     else
       
   917         {
       
   918         //there should always be a control element.
       
   919         err = KErrNotFound;
       
   920         }
       
   921     
       
   922     User::LeaveIfError( err );
       
   923     
       
   924     //append list to a map.
       
   925     TLiwVariant listVariant;
       
   926     listVariant.Set( list );
       
   927     aMap.InsertL( KHspsLiwSettings, listVariant );
       
   928     //cleanup.
       
   929     CleanupStack::Pop( list );
       
   930     list->DecRef();    
       
   931     
       
   932     return err;
       
   933     }
       
   934 
       
   935 // -----------------------------------------------------------------------------
       
   936 // Builds and appends resources to a map.
       
   937 // -----------------------------------------------------------------------------
       
   938 //
       
   939 TInt CHspsLiwUtilities::AppendResourcesL( ChspsDomNode& aConfigurationNode, 
       
   940                                             CLiwDefaultMap& aMap )
       
   941     {    
       
   942     TInt err = KErrNone;
       
   943     //create list.
       
   944     CLiwDefaultList* list = CLiwDefaultList::NewL();
       
   945     CleanupStack::PushL( list );    
       
   946     //find resources.
       
   947     ChspsDomList& children = aConfigurationNode.ChildNodes();
       
   948     TInt length = children.Length();
       
   949     for( TInt i = 0; i < length; i++ )
       
   950         {
       
   951         ChspsDomNode* child;
       
   952         child = static_cast<ChspsDomNode*>( children.Item( i ) );
       
   953         const TDesC8& childName = child->Name();
       
   954         if( childName.Compare( KResourcesElement ) == 0)
       
   955             {
       
   956             ChspsDomList& objects = child->ChildNodes();
       
   957             TInt length = objects.Length();
       
   958             for( TInt i = 0; i < length; i++ )
       
   959                 {
       
   960                 //put object elements to the list.
       
   961                 ChspsDomNode* object;
       
   962                 object = static_cast<ChspsDomNode*>( objects.Item( i ) );
       
   963                 const TDesC8& objectName = object->Name();
       
   964                 if( objectName.Compare( KObjectElement ) == 0)
       
   965                     {
       
   966                     CLiwDefaultMap* map = CLiwDefaultMap::NewL();
       
   967                     CleanupStack::PushL( map );
       
   968                     
       
   969                     BuildObjectMapL( *object, *map );
       
   970                     
       
   971                     ///append object to the list                
       
   972                     TLiwVariant mapVariant;
       
   973                     mapVariant.Set( map );
       
   974                     list->AppendL( mapVariant );
       
   975                     
       
   976                     CleanupStack::Pop( map );
       
   977                     map->DecRef();
       
   978                     }                
       
   979                 }
       
   980             //There should be only one.
       
   981             break;
       
   982             }
       
   983         }
       
   984     //append list to a map.
       
   985     TLiwVariant listVariant;
       
   986     listVariant.Set( list );
       
   987     aMap.InsertL( KHspsLiwResources, listVariant );    
       
   988     //cleanup.
       
   989     CleanupStack::Pop( list );
       
   990     list->DecRef();    
       
   991     return err;
       
   992     }
       
   993 
       
   994 // -----------------------------------------------------------------------------
       
   995 // Builds plugin map without resources, settings or child plugins.
       
   996 // -----------------------------------------------------------------------------
       
   997 //
       
   998 TInt CHspsLiwUtilities::BuildPluginMapL( 
       
   999     ChspsDomNode& aPluginNode, 
       
  1000     CLiwDefaultMap& aMap,
       
  1001     TInt aItemMask )
       
  1002     {
       
  1003     TInt err( KErrNotFound );
       
  1004 
       
  1005     // Get plugin info.
       
  1006     const TDesC8& name = aPluginNode.Name();
       
  1007     ChspsDomList& attrList = aPluginNode.AttributeList();
       
  1008     
       
  1009     if ( name == KPluginElement )
       
  1010         {
       
  1011         if ( aItemMask & CHspsLiwUtilities::EPluginMapId )
       
  1012             {
       
  1013             //Add plugin id
       
  1014             AppendAttributeToMapL( aMap, attrList, KPluginAttrId, KHspsLiwId );
       
  1015             }
       
  1016         if ( aItemMask & CHspsLiwUtilities::EPluginMapUid )
       
  1017             {
       
  1018             //Add plugin uid
       
  1019             AppendAttributeToMapL( aMap, attrList, KPluginAttrUid, KHspsLiwUid );
       
  1020             }
       
  1021         if ( aItemMask & CHspsLiwUtilities::EPluginMapType ||
       
  1022              aItemMask & CHspsLiwUtilities::EPluginMapName )
       
  1023             {
       
  1024             // Get plugin type and name from Configuration node attribute list
       
  1025             TInt index = 0;
       
  1026             ChspsDomNode* confNode = FindChildNodeByTagL( 
       
  1027                 KConfigurationElement,
       
  1028                 aPluginNode,
       
  1029                 index );
       
  1030             if ( confNode )
       
  1031                 {
       
  1032                 ChspsDomList&confNodeAttrList = confNode->AttributeList();
       
  1033                 if ( aItemMask & CHspsLiwUtilities::EPluginMapType )
       
  1034                     {
       
  1035                     // Add plugin type
       
  1036                     AppendAttributeToMapL( aMap, confNodeAttrList, KConfigurationAttrType, KHspsLiwType );
       
  1037                     }
       
  1038                 if ( aItemMask & CHspsLiwUtilities::EPluginMapName )
       
  1039                     {
       
  1040                     // Add plugin type
       
  1041                     AppendAttributeToMapL( aMap, confNodeAttrList, KConfigurationAttrName, KHspsLiwName );
       
  1042                     }
       
  1043                 }
       
  1044             }
       
  1045         if ( aItemMask & CHspsLiwUtilities::EPluginMapActivationState )
       
  1046             {
       
  1047             //Add plugin activation state
       
  1048             AppendAttributeToMapL( aMap, attrList, KPluginAttrActive, KHspsLiwActivationState );
       
  1049             }
       
  1050         if ( aItemMask & CHspsLiwUtilities::EPluginMapDesc )
       
  1051             {
       
  1052             //Add plugin description
       
  1053             AppendAttributeToMapL( aMap, attrList, KConfigurationAttrDescription, KHspsLiwDescription );
       
  1054             }
       
  1055         if ( aItemMask & CHspsLiwUtilities::EPluginMapLocked )
       
  1056             {
       
  1057             //Add plugin locked status - locked/removable/none(default)
       
  1058             AppendAttributeToMapL( aMap,
       
  1059                     attrList,
       
  1060                     KConfigurationAttrLockingStatus,
       
  1061                     KHspsLiwLockingStatus,
       
  1062                     KHspsLiwLockingNone );
       
  1063             }        
       
  1064         
       
  1065         err = KErrNone;
       
  1066         }
       
  1067 
       
  1068     return err;
       
  1069     }
       
  1070 
       
  1071 // -----------------------------------------------------------------------------
       
  1072 // Builds items map.
       
  1073 // -----------------------------------------------------------------------------
       
  1074 //
       
  1075 TInt CHspsLiwUtilities::BuildItemsMapL( ChspsDomNode& aItem, 
       
  1076                                           CLiwDefaultMap& aMap )
       
  1077     {
       
  1078     TInt err = KErrNone;
       
  1079     //Append attributes
       
  1080     //create attribute list
       
  1081     ChspsDomList& attrList = aItem.AttributeList();
       
  1082     //Add itemId
       
  1083     AppendAttributeToMapL( aMap, attrList, KItemAttrId, KHspsLiwItemId );
       
  1084     //Add name
       
  1085     AppendAttributeToMapL( aMap, attrList, KItemAttrName, KHspsLiwItemName );
       
  1086     
       
  1087     //create list
       
  1088     CLiwDefaultList* list = CLiwDefaultList::NewL();
       
  1089     CleanupStack::PushL( list );
       
  1090     //get children
       
  1091     ChspsDomList& properties = aItem.ChildNodes();
       
  1092     TInt length = properties.Length();
       
  1093     for( TInt i = 0; i < length; i++ )
       
  1094         {
       
  1095         ChspsDomNode* property;
       
  1096         property = static_cast<ChspsDomNode*>( properties.Item( i ) );
       
  1097         const TDesC8& name = property->Name();
       
  1098         if( name.Compare( KPropertyElement ) == 0)
       
  1099             {
       
  1100             CLiwDefaultMap* map = CLiwDefaultMap::NewL();       
       
  1101             CleanupStack::PushL( map );
       
  1102         
       
  1103             //build attribute.
       
  1104             BuildPropertiesMapL( *property, *map );
       
  1105         
       
  1106             //append attribute to the list              
       
  1107             TLiwVariant mapVariant;
       
  1108             mapVariant.Set( map );
       
  1109             list->AppendL( mapVariant );
       
  1110         
       
  1111             CleanupStack::Pop( map );
       
  1112             map->DecRef();              
       
  1113             }
       
  1114         }
       
  1115     //append list to a map.
       
  1116     TLiwVariant listVariant;
       
  1117     listVariant.Set( list );
       
  1118     aMap.InsertL( KHspsLiwProperties, listVariant );
       
  1119     //cleanup
       
  1120     CleanupStack::Pop( list );
       
  1121     list->DecRef();        
       
  1122     return err;
       
  1123     }
       
  1124 
       
  1125 // -----------------------------------------------------------------------------
       
  1126 // Builds properties map.
       
  1127 // -----------------------------------------------------------------------------
       
  1128 //
       
  1129 TInt CHspsLiwUtilities::BuildPropertiesMapL( ChspsDomNode& aProperty, 
       
  1130                                                CLiwDefaultMap& aMap )
       
  1131     {
       
  1132     TInt err = KErrNone;
       
  1133     //Append attributes
       
  1134     //create attribute list
       
  1135     ChspsDomList& attrList = aProperty.AttributeList();
       
  1136     //Add name
       
  1137     AppendAttributeToMapL( aMap, attrList, KPropertyAttrName, KHspsLiwPropertyName );
       
  1138     //Add value
       
  1139     AppendAttributeToMapL( aMap, attrList, KPropertyAttrValue, KHspsLiwPropertyValue );
       
  1140     
       
  1141     return err;
       
  1142     }
       
  1143 
       
  1144 // -----------------------------------------------------------------------------
       
  1145 // Builds object map.
       
  1146 // -----------------------------------------------------------------------------
       
  1147 //
       
  1148 TInt CHspsLiwUtilities::BuildObjectMapL( ChspsDomNode& aObject, 
       
  1149                                            CLiwDefaultMap& aMap )
       
  1150     {
       
  1151     TInt err = KErrNone;
       
  1152     
       
  1153     ChspsDomList& attrList = aObject.AttributeList();
       
  1154     //Add name
       
  1155     AppendAttributeToMapL( aMap, attrList, KObjectAttrName, KHspsLiwObjectName );
       
  1156     //Add path
       
  1157     AppendAttributeToMapL( aMap, attrList, KObjectAttrPath, KHspsLiwObjectPath );
       
  1158     //Add mediatype
       
  1159     AppendAttributeToMapL( aMap, attrList, KObjectAttrMediatype, KHspsLiwObjectMediatype );
       
  1160     //Add tags
       
  1161     AppendAttributeToMapL( aMap, attrList, KObjectAttrTag, KHspsLiwObjectTag );
       
  1162     
       
  1163     return err;
       
  1164     }
       
  1165 
       
  1166 // -----------------------------------------------------------------------------
       
  1167 // Buils plugin info list
       
  1168 // -----------------------------------------------------------------------------
       
  1169 //
       
  1170 void CHspsLiwUtilities::BuildPluginInfoListL( 
       
  1171     CArrayPtrFlat<ChspsODT>& aList, 
       
  1172     CLiwDefaultList& aPluginInfoList )
       
  1173     {
       
  1174     for ( TInt i = 0; i < aList.Count(); i++ )
       
  1175         {
       
  1176         CLiwDefaultMap* pluginInfoMap = CLiwDefaultMap::NewL();
       
  1177         CleanupStack::PushL( pluginInfoMap );
       
  1178         BuildPluginInfoMapL( *( aList[ i ] ), *pluginInfoMap );
       
  1179         TLiwVariant pluginInfoMapVariant;
       
  1180         pluginInfoMapVariant.Set( pluginInfoMap );
       
  1181         aPluginInfoList.AppendL( pluginInfoMapVariant );
       
  1182         CleanupStack::Pop( pluginInfoMap );
       
  1183         pluginInfoMap->DecRef();
       
  1184         }
       
  1185     }
       
  1186 
       
  1187 // -----------------------------------------------------------------------------
       
  1188 // Buils plugin info map
       
  1189 // -----------------------------------------------------------------------------
       
  1190 //
       
  1191 void CHspsLiwUtilities::BuildPluginInfoMapL( 
       
  1192     ChspsODT& aPluginHeader, 
       
  1193     CLiwDefaultMap& aPluginInfoMap )
       
  1194     {
       
  1195     // pluginInfo.uid ( 10 -> uid 32 bit as a hex string, 0xXXXXXXXX )
       
  1196     TBuf8<10> uid;
       
  1197     uid.Append( '0' );
       
  1198     uid.Append( 'x' );
       
  1199     uid.AppendNum( aPluginHeader.ThemeUid(), EHex );
       
  1200     aPluginInfoMap.InsertL( KHspsLiwUid, TLiwVariant( uid ) );
       
  1201     // pluginInfo.interface ( 10 -> uid 32 bit as a hex string, 0xXXXXXXXX )
       
  1202     TBuf8<10> interface;
       
  1203     interface.Append( '0' );
       
  1204     interface.Append( 'x' );
       
  1205     interface.AppendNum( aPluginHeader.RootUid(), EHex );
       
  1206     aPluginInfoMap.InsertL( KHspsLiwInterface, TLiwVariant( interface ) );
       
  1207     // pluginInfo.type ( enumeration to 8 bit string )
       
  1208     HBufC8* type;
       
  1209     GetConfigurationTypeStrL( aPluginHeader.ConfigurationType(), &type );
       
  1210     CleanupStack::PushL( type );
       
  1211     TPtr8 typePtr = type->Des();
       
  1212     aPluginInfoMap.InsertL( KHspsLiwType, TLiwVariant( typePtr ) );
       
  1213     CleanupStack::PopAndDestroy( type );
       
  1214     // pluginInfo.name ( 16 bit string to 8 bit string )
       
  1215     HBufC8* name = HBufC8::NewL( ( aPluginHeader.ThemeFullName() ).Length() );
       
  1216     CleanupStack::PushL( name );
       
  1217     TPtr8 namePtr = name->Des();
       
  1218     namePtr.Copy( aPluginHeader.ThemeFullName() );
       
  1219     aPluginInfoMap.InsertL( KHspsLiwName, TLiwVariant( namePtr ) );
       
  1220     CleanupStack::PopAndDestroy( name );
       
  1221 
       
  1222     TBuf8<10> multiInstance;
       
  1223     multiInstance.AppendNum( aPluginHeader.MultiInstance());
       
  1224     aPluginInfoMap.InsertL( KHspsLiwMultiInstance,
       
  1225         TLiwVariant( multiInstance ) );
       
  1226     
       
  1227     HBufC8* desc = HBufC8::NewL( ( aPluginHeader.Description() ).Length() );
       
  1228     CleanupStack::PushL( desc );
       
  1229     TPtr8 descPtr = desc->Des();
       
  1230     descPtr.Copy( aPluginHeader.Description() );
       
  1231     aPluginInfoMap.InsertL( KHspsLiwDescription, TLiwVariant( descPtr ) );
       
  1232     CleanupStack::PopAndDestroy( desc );    
       
  1233     
       
  1234     if ( aPluginHeader.LogoFile().Length() )
       
  1235         {
       
  1236         HBufC8* buf8 = HBufC8::NewLC( ( aPluginHeader.LogoFile() ).Length() );        
       
  1237         buf8->Des().Copy( aPluginHeader.LogoFile() );
       
  1238         aPluginInfoMap.InsertL( KHspsLiwLogo, TLiwVariant( *buf8 ) );
       
  1239         CleanupStack::PopAndDestroy( buf8 );
       
  1240         }
       
  1241     if ( aPluginHeader.PreviewFile().Length() )
       
  1242         {
       
  1243         HBufC8* buf8 = HBufC8::NewLC( ( aPluginHeader.PreviewFile() ).Length() );        
       
  1244         buf8->Des().Copy( aPluginHeader.PreviewFile() );
       
  1245         aPluginInfoMap.InsertL( KHspsLiwPreview, TLiwVariant( *buf8 ) );
       
  1246         CleanupStack::PopAndDestroy( buf8 );
       
  1247         }
       
  1248     }
       
  1249 
       
  1250 //----------------------------------------------------------------------------
       
  1251 // CHspsLiwUtilities::GetConfigurationTypeL
       
  1252 // ----------------------------------------------------------------------------
       
  1253 //
       
  1254 void CHspsLiwUtilities::GetConfigurationTypeStrL(
       
  1255     const TUint aType,
       
  1256     HBufC8** aTypeStr )
       
  1257     {
       
  1258     if ( aType == EhspsAppConfiguration )
       
  1259         {
       
  1260         *aTypeStr = HBufC8::NewL( KHspsLiwApplicationConf().Length() );
       
  1261         TPtr8 typePtr = ( *( aTypeStr ) )->Des();
       
  1262         typePtr.Copy( KHspsLiwApplicationConf );
       
  1263         }
       
  1264     else if ( aType == EhspsViewConfiguration )
       
  1265         {
       
  1266         *aTypeStr = HBufC8::NewL( KHspsLiwViewConf().Length() );
       
  1267         TPtr8 typePtr = ( *( aTypeStr ) )->Des();
       
  1268         typePtr.Copy( KHspsLiwViewConf );
       
  1269         }
       
  1270     else if ( aType == EhspsWidgetConfiguration )
       
  1271         {
       
  1272         *aTypeStr = HBufC8::NewL( KHspsLiwWidgetConf().Length() );
       
  1273         TPtr8 typePtr = ( *( aTypeStr ) )->Des();
       
  1274         typePtr.Copy( KHspsLiwWidgetConf );
       
  1275         }
       
  1276     else if ( aType == EhspsTemplateConfiguration )
       
  1277         {
       
  1278         *aTypeStr = HBufC8::NewL( KHspsLiwTemplateConf().Length() );
       
  1279         TPtr8 typePtr = ( *( aTypeStr ) )->Des();
       
  1280         typePtr.Copy( KHspsLiwTemplateConf );
       
  1281         }
       
  1282     else
       
  1283         {
       
  1284         User::Leave( KErrArgument );
       
  1285         }
       
  1286     }
       
  1287 
       
  1288 
       
  1289 //----------------------------------------------------------------------------
       
  1290 // CHspsLiwUtilities::FindChildNodeByTagL
       
  1291 // ----------------------------------------------------------------------------
       
  1292 //
       
  1293 ChspsDomNode* CHspsLiwUtilities::FindChildNodeByTagL(
       
  1294     const TDesC8& aNodeTag, 
       
  1295     ChspsDomNode& aParentNode,
       
  1296     TInt& aIndex )
       
  1297     {
       
  1298     ChspsDomNode* node( NULL );
       
  1299     ChspsDomList& items = aParentNode.ChildNodes();
       
  1300     TInt length = items.Length();
       
  1301     node = NULL;
       
  1302     for ( TInt i = aIndex; i < length && node == NULL; i++ )
       
  1303         {
       
  1304         node = static_cast<ChspsDomNode*>( items.Item( i ) );
       
  1305         const TDesC8& name = node->Name();
       
  1306         if( name.Compare( aNodeTag ) != 0 )
       
  1307             {
       
  1308             node = NULL;
       
  1309             }
       
  1310         else
       
  1311             {
       
  1312             aIndex = i;
       
  1313             }
       
  1314         }
       
  1315     
       
  1316     return node;
       
  1317     }
       
  1318 
       
  1319 //----------------------------------------------------------------------------
       
  1320 // CHspsLiwUtilities::AppendItemsL
       
  1321 // ----------------------------------------------------------------------------
       
  1322 //
       
  1323 void CHspsLiwUtilities::AppendItemsL(
       
  1324     ChspsDomNode& aSettingsNode,
       
  1325     CLiwDefaultList& aList )
       
  1326     {
       
  1327 
       
  1328     ChspsDomNode* itemNode( NULL );
       
  1329     TInt index = 0;
       
  1330     do
       
  1331         {
       
  1332         itemNode = FindChildNodeByTagL(
       
  1333             KItemElement,
       
  1334             aSettingsNode,
       
  1335             index );
       
  1336         if ( itemNode )
       
  1337             {
       
  1338             CLiwDefaultMap* map = CLiwDefaultMap::NewL();        
       
  1339             CleanupStack::PushL( map );
       
  1340 
       
  1341             //build item.
       
  1342             BuildItemsMapL( *itemNode, *map );
       
  1343 
       
  1344             //append item to the list                
       
  1345             TLiwVariant mapVariant;
       
  1346             mapVariant.Set( map );
       
  1347             aList.AppendL( mapVariant );
       
  1348 
       
  1349             CleanupStack::Pop( map );
       
  1350             map->DecRef();
       
  1351             // Find next item element
       
  1352             index++;
       
  1353             }
       
  1354         } while( itemNode );
       
  1355     }
       
  1356 
       
  1357 // -----------------------------------------------------------------------------
       
  1358 // Builds app conf info list
       
  1359 // -----------------------------------------------------------------------------
       
  1360 //
       
  1361 void CHspsLiwUtilities::BuildAppConfInfoListL( 
       
  1362     CArrayPtrFlat<ChspsODT>& aList, 
       
  1363     CLiwDefaultList& aAppConfInfoList )
       
  1364     {
       
  1365     for ( TInt i = 0; i < aList.Count(); i++ )
       
  1366         {
       
  1367         CLiwDefaultMap* appConfInfoMap = CLiwDefaultMap::NewL();
       
  1368         CleanupStack::PushL( appConfInfoMap );
       
  1369         BuildAppConfInfoMapL( *( aList[ i ] ), *appConfInfoMap );
       
  1370         TLiwVariant appConfInfoMapVariant;
       
  1371         appConfInfoMapVariant.Set( appConfInfoMap );
       
  1372         aAppConfInfoList.AppendL( appConfInfoMapVariant );
       
  1373         CleanupStack::Pop( appConfInfoMap );
       
  1374         appConfInfoMap->DecRef();
       
  1375         }
       
  1376     }
       
  1377 
       
  1378 // -----------------------------------------------------------------------------
       
  1379 // Buils app conf info map
       
  1380 // -----------------------------------------------------------------------------
       
  1381 //
       
  1382 void CHspsLiwUtilities::BuildAppConfInfoMapL( 
       
  1383     ChspsODT& aAppConfHeader, 
       
  1384     CLiwDefaultMap& aAppConfInfoMap )
       
  1385     {
       
  1386     // appConfInfo.uid ( 10 -> uid 32 bit as a hex string, 0xXXXXXXXX )
       
  1387     TBuf8<10> uid;
       
  1388     uid.Append( '0' );
       
  1389     uid.Append( 'x' );
       
  1390     uid.AppendNum( aAppConfHeader.ThemeUid(), EHex );
       
  1391     aAppConfInfoMap.InsertL( KHspsLiwUid, TLiwVariant( uid ) );
       
  1392     // pluginInfo.name ( 16 bit string to 8 bit string )
       
  1393     HBufC8* name = HBufC8::NewL( ( aAppConfHeader.ThemeFullName() ).Length() );
       
  1394     CleanupStack::PushL( name );
       
  1395     TPtr8 namePtr = name->Des();
       
  1396     namePtr.Copy( aAppConfHeader.ThemeFullName() );
       
  1397     aAppConfInfoMap.InsertL( KHspsLiwName, TLiwVariant( namePtr ) );
       
  1398     CleanupStack::PopAndDestroy( name );
       
  1399     }
       
  1400 
       
  1401 //----------------------------------------------------------------------------
       
  1402 // CHspsLiwUtilities::BuildPluginListL
       
  1403 // ----------------------------------------------------------------------------
       
  1404 //
       
  1405 void CHspsLiwUtilities::BuildPluginListL(
       
  1406     ChspsDomNode& aRootNode,
       
  1407     TDesC8& aType,
       
  1408     TDesC8& aPluginId,
       
  1409     CLiwDefaultList& aPluginList )
       
  1410     {
       
  1411     
       
  1412     TBool checkPluginId( EFalse );
       
  1413     TBool checkType( EFalse );
       
  1414     if ( aPluginId.Length() )
       
  1415         {
       
  1416         checkPluginId = ETrue;
       
  1417         }
       
  1418     if ( aType.Length() )
       
  1419         {
       
  1420         checkType = ETrue;
       
  1421         }
       
  1422     
       
  1423     ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( aRootNode );
       
  1424     CleanupStack::PushL( iter );
       
  1425     ChspsDomNode* node = iter->First();
       
  1426 
       
  1427     TBool pluginIdFound( EFalse );
       
  1428     while( node && !pluginIdFound )
       
  1429         {
       
  1430         const TDesC8& name = node->Name();
       
  1431         if ( name.Compare( KPluginsElement ) == 0)
       
  1432             {
       
  1433             if ( checkPluginId )
       
  1434                 {
       
  1435                 ChspsDomNode* pluginNode = FindParentNodeByTagL( 
       
  1436                     KPluginElement,
       
  1437                     *node );
       
  1438                 if ( pluginNode )
       
  1439                     {
       
  1440                     TPtrC8 pluginId;
       
  1441                     GetAttributeValueL( 
       
  1442                         *pluginNode, 
       
  1443                         KPluginAttrId, 
       
  1444                         pluginId );
       
  1445                     if ( aPluginId.Compare( pluginId ) == 0 )
       
  1446                         {
       
  1447                         pluginIdFound = ETrue;
       
  1448                         }
       
  1449                     }
       
  1450                 }
       
  1451             if ( !checkPluginId || pluginIdFound )
       
  1452                 {
       
  1453                 ChspsDomList& children = node->ChildNodes();
       
  1454                 TInt length = children.Length();
       
  1455                 for( TInt i = 0; i < length; i++ )
       
  1456                     {
       
  1457                     ChspsDomNode* plugin;
       
  1458                     plugin = static_cast<ChspsDomNode*>( children.Item( i ) );
       
  1459                     TBool typeMatch( EFalse );
       
  1460                     if ( checkType )
       
  1461                         {
       
  1462                         // Check plugin type
       
  1463                         TInt index = 0;
       
  1464                         ChspsDomNode* confNode = FindChildNodeByTagL(
       
  1465                             KConfigurationElement,
       
  1466                             *plugin,
       
  1467                             index );
       
  1468                         if ( confNode )
       
  1469                             {
       
  1470                             TPtrC8 type;
       
  1471                             GetAttributeValueL( 
       
  1472                                 *confNode, 
       
  1473                                 KConfigurationAttrType, 
       
  1474                                 type );
       
  1475                             if ( aType.Compare( type ) == 0 )
       
  1476                                 {
       
  1477                                 typeMatch = ETrue;
       
  1478                                 }
       
  1479                             }
       
  1480                         }
       
  1481                     
       
  1482                     if ( typeMatch || !checkType )
       
  1483                         {
       
  1484                         CLiwDefaultMap* map = CLiwDefaultMap::NewL();
       
  1485                         CleanupStack::PushL( map );
       
  1486                         TInt pluginMapItems = ( 
       
  1487                             CHspsLiwUtilities::EPluginMapId +
       
  1488                             CHspsLiwUtilities::EPluginMapType +
       
  1489                             CHspsLiwUtilities::EPluginMapName +
       
  1490                             CHspsLiwUtilities::EPluginMapActivationState +
       
  1491                             CHspsLiwUtilities::EPluginMapDesc +
       
  1492                             CHspsLiwUtilities::EPluginMapLocked );
       
  1493                         BuildPluginMapL( *plugin, *map, pluginMapItems );
       
  1494                         
       
  1495                         TLiwVariant mapVariant;
       
  1496                         mapVariant.Set( map );
       
  1497                         aPluginList.AppendL( mapVariant );
       
  1498                         
       
  1499                         CleanupStack::Pop( map );
       
  1500                         map->DecRef();
       
  1501                         }
       
  1502                     }
       
  1503                 }
       
  1504             }
       
  1505         node = iter->NextL();
       
  1506         }
       
  1507     CleanupStack::PopAndDestroy( iter );
       
  1508     }
       
  1509 
       
  1510 //----------------------------------------------------------------------------
       
  1511 // CHspsLiwUtilities::FindParentNodeByTagL
       
  1512 // ----------------------------------------------------------------------------
       
  1513 //
       
  1514 ChspsDomNode* CHspsLiwUtilities::FindParentNodeByTagL(
       
  1515     const TDesC8& aNodeTag, 
       
  1516     ChspsDomNode& aChildNode )
       
  1517     {
       
  1518 
       
  1519     TBool found( EFalse );
       
  1520     ChspsDomNode* parentNode = aChildNode.Parent();
       
  1521     while ( !found && parentNode )
       
  1522         {
       
  1523         if ( aNodeTag.Compare( parentNode->Name() ) == 0 )
       
  1524             {
       
  1525             found = ETrue;
       
  1526             }
       
  1527         else
       
  1528             {
       
  1529             parentNode = parentNode->Parent();
       
  1530             }
       
  1531         }
       
  1532     
       
  1533     return parentNode;
       
  1534     }
       
  1535 
       
  1536 // -----------------------------------------------------------------------------
       
  1537 // Creates output parmater list for SetActivePlugin method
       
  1538 // ----------------------------------------------------------------------------- 
       
  1539 void CHspsLiwUtilities::SetActivePluginOutputL( 
       
  1540     CLiwGenericParamList& aOutParamList )
       
  1541     {
       
  1542     
       
  1543     AppendStatusL( KErrNone, aOutParamList );
       
  1544 
       
  1545     }