idlehomescreen/xmluirendering/uiengine/src/xncomposer.cpp
changeset 0 f72a12da539e
child 2 08c6ee43b396
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     1 /*
       
     2 * Copyright (c) 2008-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:  Application configuration composer
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <s32file.h>
       
    20 
       
    21 // User includes
       
    22 #include "xncomposer.h"
       
    23 #include "xnplugindata.h"
       
    24 #include "xnrootdata.h"
       
    25 #include "xnviewdata.h"
       
    26 #include "xnodt.h"
       
    27 #include "xnproperty.h"
       
    28 #include "xnresource.h"
       
    29 #include "xndomdocument.h"
       
    30 #include "xndomnode.h"
       
    31 #include "xndomlist.h"
       
    32 #include "xndomattribute.h"
       
    33 #include "xnpanic.h"
       
    34 #include "xnplugindefs.h"
       
    35 
       
    36 // Constants
       
    37 _LIT8( KStateWaitConfirmation, "WaitForConfirmation" );
       
    38 _LIT8( KStateError, "Error" );
       
    39 
       
    40 _LIT8( KXmluiml, "xmluiml" );
       
    41 _LIT8( KApp, "application" );
       
    42 _LIT8( KViews, "views" );
       
    43 _LIT8( KWidget, "widget" );
       
    44 _LIT8( KUseEmptyWidget, "use_empty_widget" );
       
    45 _LIT8( KRemovable, "removable" );
       
    46 
       
    47 _LIT8( KEmptyWidgetUid, "0x2001F47F" );
       
    48 
       
    49 _LIT( KCDrive, "C:" );
       
    50 _LIT8( KTagXuikon, "xuikon" );
       
    51 
       
    52 using namespace hspswrapper;
       
    53 
       
    54 // ======== LOCAL FUNCTIONS ========
       
    55 // ---------------------------------------------------------------------------
       
    56 // Finds recursively node by name
       
    57 // @return    returns pointer to desired node, NULL if nothing found 
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 CXnDomNode* FindNodeByName( CXnDomNode* aNode, const TDesC8& aName )
       
    61     {
       
    62     if ( !aNode )
       
    63         {        
       
    64         return NULL;
       
    65         }
       
    66 
       
    67     if ( aNode->Name() == aName )
       
    68         {
       
    69         return aNode;
       
    70         }
       
    71 
       
    72     CXnDomList& list( aNode->ChildNodes() );
       
    73 
       
    74     for ( TInt i = 0; i < list.Length() ; i++ )
       
    75         {
       
    76         CXnDomNode* retval( FindNodeByName(
       
    77                 static_cast< CXnDomNode* >( list.Item( i ) ), aName ) );
       
    78 
       
    79         if ( retval )
       
    80             {
       
    81             return retval;
       
    82             }
       
    83         }
       
    84 
       
    85     return NULL;
       
    86     }
       
    87 
       
    88 // ---------------------------------------------------------------------------
       
    89 // FindNodeById
       
    90 // Finds recursively node by id
       
    91 // @return    returns pointer to desired node, NULL if nothing found 
       
    92 // ---------------------------------------------------------------------------
       
    93 //
       
    94 CXnDomNode* FindNodeById( CXnDomNode* aNode, const TDesC8& aId )
       
    95     {
       
    96     if ( !aNode )
       
    97         {        
       
    98         return NULL;
       
    99         }
       
   100 
       
   101     CXnDomList& attributes( aNode->AttributeList() );
       
   102 
       
   103     CXnDomAttribute* id(
       
   104         static_cast< CXnDomAttribute* >(
       
   105                 attributes.FindByName( XnPropertyNames::common::KId ) ) );
       
   106 
       
   107     if ( id && id->Value() == aId )
       
   108         {
       
   109         return aNode;
       
   110         }
       
   111 
       
   112     CXnDomList& list( aNode->ChildNodes() );
       
   113 
       
   114     for ( TInt i = 0; i < list.Length() ; i++ )
       
   115         {
       
   116         CXnDomNode* retval( FindNodeById(
       
   117                 static_cast< CXnDomNode* >( list.Item( i ) ), aId ) );
       
   118 
       
   119         if ( retval )
       
   120             {
       
   121             return retval;
       
   122             }
       
   123         }
       
   124 
       
   125     return NULL;
       
   126     }
       
   127 
       
   128 // ----------------------------------------------------------------------------
       
   129 // UpdateResourcesPathL
       
   130 // ----------------------------------------------------------------------------
       
   131 //
       
   132 static void UpdateResourcesPathL( CArrayPtrSeg< CXnResource >& aList, 
       
   133     TPtrC aNewPath )
       
   134     {
       
   135     TFileName newFilename;
       
   136 
       
   137     for ( TInt i = 0; i < aList.Count(); i++ )
       
   138         {
       
   139         CXnResource& res( *aList[i] );
       
   140         const TDesC& filename( res.FileName() );
       
   141 
       
   142         TParsePtrC fileParser( filename );
       
   143         TPtrC nameAndExt( fileParser.NameAndExt() );
       
   144 
       
   145         newFilename = aNewPath;
       
   146         newFilename.Append( nameAndExt );
       
   147 
       
   148         res.SetFileNameL( newFilename );
       
   149         }
       
   150     }
       
   151 
       
   152 // --------------------------------------------------------------------------
       
   153 // UpdateSettingsL
       
   154 // 
       
   155 // --------------------------------------------------------------------------
       
   156 //
       
   157 static void UpdateSettingsL( const TDesC8& aElementId,
       
   158     RPointerArray< CPropertyMap >& aProperties, CXnDomNode& aRootNode )
       
   159     {    
       
   160     CXnDomNode* node( FindNodeById( &aRootNode, aElementId ) );
       
   161 
       
   162     if( !node )
       
   163         {
       
   164         return;
       
   165         }
       
   166 
       
   167     CXnDomStringPool& sp( node->StringPool() );
       
   168 
       
   169     for ( TInt i = 0; i < aProperties.Count(); i++ )
       
   170         {
       
   171         CPropertyMap* property( aProperties[i] );
       
   172 
       
   173         const TDesC8& name( property->Name() );
       
   174         const TDesC8& value( property->Value() );
       
   175 
       
   176         CXnDomList& attributes( node->AttributeList() );
       
   177 
       
   178         CXnDomAttribute* attribute(
       
   179             static_cast< CXnDomAttribute* >( attributes.FindByName( name ) ) );
       
   180 
       
   181         if ( attribute )
       
   182             {
       
   183             // Update current attribute
       
   184             attribute->SetValueL( value );
       
   185             }
       
   186         else
       
   187             {
       
   188             // Need to create new attribute
       
   189             attribute = CXnDomAttribute::NewL( name, sp );
       
   190             CleanupStack::PushL( attribute );
       
   191 
       
   192             attribute->SetValueL( value );
       
   193 
       
   194             node->AttributeList().AddItemL( attribute );
       
   195             CleanupStack::Pop( attribute );
       
   196             }
       
   197         }
       
   198     }
       
   199 
       
   200 
       
   201 // --------------------------------------------------------------------------
       
   202 // UpdatePluginFromSettingsL()
       
   203 // Updates plugin from settings
       
   204 // --------------------------------------------------------------------------
       
   205 //
       
   206 static void UpdatePluginFromSettingsL( CHspsConfiguration& aConfiguration,
       
   207     CXnDomNode& aRootNode )
       
   208     {
       
   209     RPointerArray< CItemMap >& settings( aConfiguration.Settings() );
       
   210 
       
   211     for ( TInt i = 0; i < settings.Count(); i++ )
       
   212         {
       
   213         CItemMap* setting( settings[i] );
       
   214 
       
   215         const TDesC8& itemId( setting->ItemId() );
       
   216 
       
   217         RPointerArray< CPropertyMap >& properties( setting->Properties() );
       
   218 
       
   219         UpdateSettingsL( itemId, properties, aRootNode );
       
   220         }
       
   221     }
       
   222 
       
   223 // --------------------------------------------------------------------------
       
   224 // MergeLD()
       
   225 // --------------------------------------------------------------------------
       
   226 //
       
   227 static CXnDomNode* MergeLD( CXnDomNode* aRoot,  
       
   228     CXnPluginData& aPluginData, TBool aMergeView = EFalse )
       
   229     {
       
   230     CXnDomNode* parent( aPluginData.Owner() );
       
   231     
       
   232     CXnDomNode* childToFind( NULL );
       
   233 
       
   234     if ( aMergeView )
       
   235         {
       
   236         childToFind = FindNodeByName( aRoot, KView );
       
   237         }
       
   238     else
       
   239         {
       
   240         childToFind = FindNodeByName( aRoot, KWidget );
       
   241         }
       
   242     
       
   243     if( !childToFind || aRoot->Name() != KXmluiml )
       
   244         {
       
   245         delete aRoot;
       
   246         
       
   247         return NULL;
       
   248         }
       
   249 
       
   250     aPluginData.SetNode( childToFind );
       
   251     
       
   252     CXnDomList& list( aRoot->ChildNodes() );
       
   253            
       
   254     TInt index( list.ItemIndex( *childToFind ) );   
       
   255     
       
   256     CXnDomNode* node =
       
   257         static_cast< CXnDomNode* >( list.Item( index ) );
       
   258     
       
   259     list.RemoveItem( index );
       
   260 
       
   261     // sets namespace recursively
       
   262     node->SetOwnershipL( aPluginData.PluginId() );
       
   263     
       
   264     // Takes ownership
       
   265     parent->AddChildL( node );
       
   266 
       
   267     delete aRoot;
       
   268     aRoot = NULL;
       
   269         
       
   270     if ( aMergeView )
       
   271         {
       
   272         // Return the last view
       
   273         TInt index( parent->ChildNodes().Length() - 1 );
       
   274 
       
   275         return ( static_cast< CXnDomNode* >(
       
   276             parent->ChildNodes().Item( index ) ) );
       
   277         }
       
   278     else
       
   279         {
       
   280         // Return <widget>
       
   281         return node;
       
   282         }
       
   283     }
       
   284 
       
   285 // --------------------------------------------------------------------------
       
   286 // UseEmptyWidget
       
   287 // Determines whether to use empty widget in this view configuration
       
   288 // --------------------------------------------------------------------------
       
   289 //
       
   290 static TBool UseEmptyWidget( CXnDomNode& aView )
       
   291     {    
       
   292     CXnDomAttribute* attribute(
       
   293         static_cast< CXnDomAttribute* >( 
       
   294                 aView.AttributeList().FindByName( KUseEmptyWidget ) ) );
       
   295 
       
   296     if ( attribute && attribute->Value() == XnPropertyNames::KTrue )
       
   297         {
       
   298         return ETrue;
       
   299         }
       
   300     
       
   301     return EFalse;
       
   302     }
       
   303 
       
   304 // --------------------------------------------------------------------------
       
   305 // Removable
       
   306 // Determines whether this plugin is removable
       
   307 // --------------------------------------------------------------------------
       
   308 //
       
   309 static TBool Removable( CXnDomNode& aPlugin )
       
   310     {    
       
   311     CXnDomAttribute* attribute(
       
   312         static_cast< CXnDomAttribute* >( 
       
   313                 aPlugin.AttributeList().FindByName( KRemovable ) ) );
       
   314 
       
   315     if ( attribute && attribute->Value() == XnPropertyNames::KFalse )
       
   316         {
       
   317         return EFalse;
       
   318         }
       
   319     
       
   320     return ETrue;
       
   321     }
       
   322 
       
   323 // ======== MEMBER FUNCTIONS ========
       
   324 // --------------------------------------------------------------------------
       
   325 // CXnComposer::NewL
       
   326 // Two-phased constructor.
       
   327 // --------------------------------------------------------------------------
       
   328 //
       
   329 CXnComposer* CXnComposer::NewL( CHspsWrapper& aWrapper )
       
   330     {
       
   331     CXnComposer* self = new ( ELeave ) CXnComposer( aWrapper );
       
   332     CleanupStack::PushL( self );
       
   333     self->ConstructL();
       
   334     CleanupStack::Pop( self );
       
   335 
       
   336     return self;
       
   337     }
       
   338 
       
   339 // --------------------------------------------------------------------------
       
   340 // CXnComposer::~CXnComposer
       
   341 // Destructor
       
   342 // --------------------------------------------------------------------------
       
   343 //
       
   344 CXnComposer::~CXnComposer()
       
   345     {
       
   346     iFs.Close();
       
   347     }
       
   348 
       
   349 // --------------------------------------------------------------------------
       
   350 // CXnComposer::CXnComposer
       
   351 // C++ default constructor can NOT contain any code, that
       
   352 // might leave.
       
   353 // --------------------------------------------------------------------------
       
   354 //
       
   355 CXnComposer::CXnComposer( CHspsWrapper& aWrapper )
       
   356     : iWrapper( aWrapper )
       
   357     {
       
   358     }
       
   359 
       
   360 // --------------------------------------------------------------------------
       
   361 // CXnComposer::ConstructL
       
   362 // Symbian 2nd phase constructor can leave.
       
   363 // --------------------------------------------------------------------------
       
   364 //
       
   365 void CXnComposer::ConstructL()
       
   366     {
       
   367     User::LeaveIfError( iFs.Connect() );
       
   368     }
       
   369 
       
   370 // --------------------------------------------------------------------------
       
   371 // CXnComposer::ComposeRootL()
       
   372 // Composes the application root configuration
       
   373 // --------------------------------------------------------------------------
       
   374 //
       
   375 CXnODT* CXnComposer::ComposeRootL( CXnRootData& aRootData )
       
   376     {
       
   377     // Not owned
       
   378     iODT = NULL;
       
   379     
       
   380     // Get application configuration
       
   381     CHspsConfiguration* configuration( iWrapper.GetAppConfigurationL() );
       
   382     CleanupStack::PushL( configuration );
       
   383 
       
   384     const TDesC8& state( configuration->PluginInfo().ConfigurationState() );
       
   385     
       
   386     aRootData.SetConfigurationIdL( configuration->ConfId() );
       
   387            
       
   388     if ( state.CompareF( KStateError ) == 0 || 
       
   389         configuration->Resources().Count() == 0 )
       
   390         {
       
   391         CleanupStack::PopAndDestroy( configuration );
       
   392         
       
   393         return NULL;       
       
   394         }
       
   395         
       
   396     // Get application configuration odt resource
       
   397     CXnODT* odt = CXnODT::NewL();
       
   398     CleanupStack::PushL( odt );
       
   399     
       
   400     // Save for later usage, not owned
       
   401     iODT = odt;
       
   402     
       
   403     // Find a resource which can be internalized
       
   404     const CObjectMap* resourceObject = FindObject( 
       
   405             configuration->Resources(), KTagXuikon() );
       
   406     if ( !resourceObject )
       
   407         {
       
   408         CleanupStack::PopAndDestroy( 2, configuration );
       
   409         
       
   410         return NULL;
       
   411         }
       
   412     
       
   413     CXnDomNode* root( GetOdtL( *resourceObject, aRootData ) );       
       
   414     if ( !root )
       
   415         {        
       
   416         CleanupStack::PopAndDestroy( 2, configuration );
       
   417         
       
   418         return NULL;
       
   419         }
       
   420     
       
   421     odt->DomDocument().SetRootNode( root );
       
   422       
       
   423     // "views" node is the owner node of view nodes
       
   424     CXnDomNode* views( FindNodeByName( root, KViews ) );
       
   425         
       
   426     if ( !views )
       
   427         {
       
   428         CleanupStack::PopAndDestroy( 2, configuration );
       
   429         
       
   430         return NULL;        
       
   431         }
       
   432 
       
   433     CPluginInfo& info( configuration->PluginInfo() );
       
   434 
       
   435     aRootData.SetOwner( root );
       
   436     aRootData.SetNode( views );
       
   437     
       
   438     aRootData.SetPluginNameL( info.Name() );
       
   439     aRootData.SetPluginUidL( info.Uid() );
       
   440     
       
   441     aRootData.SetPluginTypeL( KApp );
       
   442     
       
   443     aRootData.SetMaxPages( info.MaxChild() );
       
   444 
       
   445     // Get plugins (= views) in this application configuration
       
   446     RPointerArray< CPluginMap >& plugins( configuration->PluginMaps() );
       
   447 
       
   448     if ( ( plugins.Count() == 0 ) || ( aRootData.MaxPages() <= 0 ) )
       
   449         {
       
   450         CleanupStack::PopAndDestroy( 2, configuration );
       
   451         
       
   452         return NULL;
       
   453         }
       
   454     
       
   455     RPointerArray< CXnPluginData >& array( aRootData.PluginData() );
       
   456     
       
   457     TInt index( 0 );
       
   458     
       
   459     for ( TInt i = 0; ( i < plugins.Count() ) && ( i < aRootData.MaxPages() );
       
   460         i++ )
       
   461         {
       
   462         CPluginMap* plugin( plugins[i] );
       
   463         
       
   464         CXnViewData* view = CXnViewData::NewLC( aRootData );
       
   465 
       
   466         // Give view data ownership to CXnRootData
       
   467         array.AppendL( view );                                 
       
   468         CleanupStack::Pop( view );
       
   469        
       
   470         view->SetOwner( views );  
       
   471         
       
   472         view->SetPluginIdL( plugin->PluginId() );
       
   473                 
       
   474         if ( plugin->ActivationState() )
       
   475             {            
       
   476             index = i;            
       
   477             }
       
   478 
       
   479         view->SetLockingStatus( plugin->LockingStatus() );
       
   480         }
       
   481 
       
   482     CXnViewData* initial( static_cast< CXnViewData* >( array[ index ] ) );
       
   483     
       
   484     initial->SetInitial();
       
   485         
       
   486     CleanupStack::Pop( odt );
       
   487     
       
   488     CleanupStack::PopAndDestroy( configuration );
       
   489                     
       
   490     // Ownership is granted to the caller
       
   491     return odt;          
       
   492     }
       
   493 
       
   494 // --------------------------------------------------------------------------
       
   495 // CXnComposer::ComposeViewL()
       
   496 // Composes a view
       
   497 // --------------------------------------------------------------------------
       
   498 //
       
   499 TInt CXnComposer::ComposeViewL( CXnViewData& aViewData )
       
   500     {    
       
   501     TInt retval( KXnErrPluginFailure );
       
   502     
       
   503     if ( aViewData.PluginId() == KNullDesC8 )
       
   504         {
       
   505         return retval;
       
   506         }
       
   507     
       
   508     // Get view configuration
       
   509     CHspsConfiguration* configuration(
       
   510         iWrapper.GetPluginConfigurationL( aViewData.PluginId() ) );
       
   511     CleanupStack::PushL( configuration );
       
   512 
       
   513     const TDesC8& state( configuration->PluginInfo().ConfigurationState() );
       
   514                      
       
   515     if ( state.CompareF( KStateError ) == 0 || 
       
   516         configuration->Resources().Count() == 0 )
       
   517         {               
       
   518         CleanupStack::PopAndDestroy( configuration );
       
   519         
       
   520         return retval;
       
   521         }
       
   522                   
       
   523     aViewData.SetConfigurationIdL( configuration->ConfId() );    
       
   524     aViewData.SetPluginStateL( KStateWaitConfirmation );
       
   525     
       
   526     // Find a resource which can be internalized
       
   527     const CObjectMap* resourceObject = FindObject( 
       
   528                 configuration->Resources(), KTagXuikon );
       
   529     if ( !resourceObject )
       
   530         {
       
   531         CleanupStack::PopAndDestroy( configuration );
       
   532         
       
   533         return retval;
       
   534         }
       
   535     
       
   536     CXnDomNode* root( GetOdtL( *resourceObject, aViewData ) );
       
   537     if ( !root )
       
   538         {               
       
   539         CleanupStack::PopAndDestroy( configuration );
       
   540         
       
   541         return retval;        
       
   542         }
       
   543 
       
   544     root->SetNamespaceL( aViewData.PluginId() );
       
   545     
       
   546     // Merge view to root. Note that root will be obsolete after this call
       
   547     CXnDomNode* viewRoot( MergeLD( root, aViewData, ETrue ) );
       
   548     
       
   549     if ( viewRoot )
       
   550         {                                                     
       
   551         // Finalise view data              
       
   552         CPluginInfo& info( configuration->PluginInfo() );
       
   553         aViewData.SetPluginNameL( info.Name() );
       
   554         aViewData.SetPluginUidL( info.Uid() );
       
   555 
       
   556         aViewData.SetPluginTypeL( KView );
       
   557         
       
   558         // Find first <plugin> element from this view
       
   559         CXnDomNode* pluginNode( FindNodeByName( viewRoot, KPlugin ) );
       
   560 
       
   561         UpdatePluginFromSettingsL( *configuration, *viewRoot );
       
   562                 
       
   563         aViewData.SetUseEmptyWidget( UseEmptyWidget( *viewRoot )  );   
       
   564         
       
   565         if ( pluginNode )
       
   566             {            
       
   567             // This assumes all <plugin> elements are siblings
       
   568             CXnDomNode* pluginParent( pluginNode->Parent() );   
       
   569             
       
   570             CXnDomList& list( pluginParent->ChildNodes() );
       
   571         
       
   572             // Get plugins configuration
       
   573             RPointerArray< CPluginMap >& plugins( configuration->PluginMaps() );
       
   574                     
       
   575             RPointerArray< CXnPluginData >& array( aViewData.PluginData() );
       
   576 
       
   577             TInt count( 0 );
       
   578             
       
   579             for ( TInt i = 0; i < list.Length(); i++ )
       
   580                 {
       
   581                 CXnDomNode* node =
       
   582                     static_cast< CXnDomNode* >( list.Item( i ) );
       
   583         
       
   584                 // We are interested only about <plugin> elements
       
   585                 if ( node->Name() == KPlugin )
       
   586                     {
       
   587                     // Create plugin data
       
   588                     CXnPluginData* widget = CXnPluginData::NewLC( aViewData );
       
   589             
       
   590                     // Give ownership to view data
       
   591                     array.AppendL( widget );
       
   592                     CleanupStack::Pop( widget );
       
   593                             
       
   594                     // <plugin> element
       
   595                     widget->SetOwner( node );
       
   596                     
       
   597                     if ( count < plugins.Count() )
       
   598                         {                        
       
   599                         widget->SetPluginIdL( plugins[ count ]->PluginId() );
       
   600                         }
       
   601                     
       
   602                     count++;
       
   603                     }        
       
   604                 }                           
       
   605             }
       
   606         
       
   607         retval = KErrNone;
       
   608         }
       
   609     
       
   610     CleanupStack::PopAndDestroy( configuration );
       
   611     
       
   612     return retval;
       
   613     }
       
   614 
       
   615 // --------------------------------------------------------------------------
       
   616 // ComposeWidgetL()
       
   617 // Composes a widget
       
   618 // --------------------------------------------------------------------------
       
   619 //
       
   620 TInt CXnComposer::ComposeWidgetL( CXnPluginData& aPluginData )     
       
   621     {    
       
   622     TInt retval( KXnErrPluginFailure );
       
   623     
       
   624     if ( aPluginData.PluginId() == KNullDesC8 )
       
   625         {
       
   626         return retval;
       
   627         }
       
   628     
       
   629     // Get widget configuration
       
   630     CHspsConfiguration* configuration(
       
   631         iWrapper.GetPluginConfigurationL( aPluginData.PluginId() ) );
       
   632     CleanupStack::PushL( configuration );
       
   633 
       
   634     // Empty widget is not composed at all
       
   635     if ( configuration->PluginInfo().Uid().CompareF( KEmptyWidgetUid ) == 0 )
       
   636         {
       
   637         aPluginData.SetEmptyL( aPluginData.PluginId() );
       
   638         
       
   639         CleanupStack::PopAndDestroy( configuration );
       
   640         
       
   641         return KErrNone;
       
   642         }
       
   643     
       
   644     const TDesC8& state( configuration->PluginInfo().ConfigurationState() );
       
   645                      
       
   646     if ( state.CompareF( KStateError ) == 0 || 
       
   647         configuration->Resources().Count() == 0 )
       
   648         {               
       
   649         CleanupStack::PopAndDestroy( configuration );
       
   650         
       
   651         return retval;       
       
   652         }
       
   653     
       
   654     aPluginData.SetConfigurationIdL( configuration->ConfId() );    
       
   655     aPluginData.SetPluginStateL( KStateWaitConfirmation );
       
   656                               
       
   657     // Find a resource which can be internalized
       
   658     const CObjectMap* resourceObject = FindObject( 
       
   659                 configuration->Resources(), KTagXuikon );
       
   660     if ( !resourceObject )
       
   661         {
       
   662         CleanupStack::PopAndDestroy( configuration );
       
   663         
       
   664         return retval;
       
   665         }
       
   666     
       
   667     CXnDomNode* root( GetOdtL( *resourceObject, aPluginData ) );
       
   668     if ( !root )
       
   669         {
       
   670         CleanupStack::PopAndDestroy( configuration );        
       
   671 
       
   672         return retval;        
       
   673         }
       
   674 
       
   675     // Update plugin namespace
       
   676     root->SetNamespaceL( aPluginData.PluginId() );
       
   677 
       
   678     // Nested plugins are not supported currently. 
       
   679     // Note root will be obsolete after this call.
       
   680     CXnDomNode* widgetRoot( MergeLD( root, aPluginData ) );
       
   681 
       
   682     if ( widgetRoot )
       
   683         {
       
   684         // Finalise plugin data
       
   685         CPluginInfo& info( configuration->PluginInfo() );
       
   686         
       
   687         aPluginData.SetPluginNameL( info.Name() );
       
   688         aPluginData.SetPluginUidL( info.Uid() );
       
   689 
       
   690         aPluginData.SetPluginTypeL( info.Type() );
       
   691 
       
   692         UpdatePluginFromSettingsL( *configuration, *widgetRoot );
       
   693         
       
   694         if ( info.Type() == KKeyTemplate )
       
   695             {
       
   696             CXnDomNode* node( FindNodeByName( widgetRoot, KContentSourceNode ) );
       
   697             
       
   698             if ( node )
       
   699                 {
       
   700                 CXnDomList& attributes( node->AttributeList() );
       
   701                  
       
   702                 CXnDomAttribute* attribute( static_cast< CXnDomAttribute* >(
       
   703                     attributes.FindByName( KName ) ) );
       
   704                 
       
   705                 if ( attribute )
       
   706                     {
       
   707                     aPluginData.SetPublisherNameL( attribute->Value() );
       
   708                     }
       
   709                 }
       
   710             }
       
   711         
       
   712         aPluginData.SetRemovable( Removable( *widgetRoot ) );
       
   713 
       
   714         retval = KErrNone;                       
       
   715         }
       
   716     
       
   717     CleanupStack::PopAndDestroy( configuration );
       
   718     
       
   719     return retval;
       
   720     }
       
   721 
       
   722 // --------------------------------------------------------------------------
       
   723 // CXnComposer::GetOdtL()
       
   724 //
       
   725 // --------------------------------------------------------------------------
       
   726 //
       
   727 CXnDomNode* CXnComposer::GetOdtL( const CObjectMap& aObject,
       
   728     CXnPluginData& aPluginData )
       
   729     {
       
   730     if( !iODT )
       
   731         {
       
   732         return NULL;
       
   733         }
       
   734     
       
   735     CXnDomNode* root( NULL ); 
       
   736     
       
   737     TBuf8< KMaxFileName > resource;
       
   738     TFileName privatePath;
       
   739     TFileName filename;
       
   740 
       
   741     // Get private path
       
   742     User::LeaveIfError( iFs.PrivatePath( privatePath ) );
       
   743 
       
   744     // Get resource path and name
       
   745     resource = aObject.Path();
       
   746     resource.Append( aObject.NameL() );
       
   747 
       
   748     // Copy from TBuf8 to TBuf
       
   749     filename.Copy( resource );
       
   750 
       
   751     // insert private path and
       
   752     filename.Insert( 0, privatePath );
       
   753 
       
   754     // ... c-drive
       
   755     filename.Insert( 0, KCDrive );
       
   756 
       
   757     RFile file;
       
   758 
       
   759     User::LeaveIfError( file.Open( iFs, filename, EFileShareReadersOnly ) );
       
   760     CleanupClosePushL( file );
       
   761 
       
   762     TInt size( 0 );
       
   763     file.Size( size );
       
   764 
       
   765     if ( size )
       
   766         {
       
   767         CFileStore* store( CDirectFileStore::FromLC( file ) );
       
   768 
       
   769         RStoreReadStream instream;
       
   770         CleanupClosePushL( instream );
       
   771 
       
   772         instream.OpenLC( *store, store->Root() );
       
   773 
       
   774         // Consume header
       
   775         CXnODT::InternalizeHeaderL( instream );
       
   776         
       
   777         CArrayPtrSeg< CXnResource >* list( 
       
   778             CXnODT::InternalizeResourceListL( instream ) );
       
   779         
       
   780         aPluginData.SetResources( list );
       
   781 
       
   782         // Set correct resource path
       
   783         UpdateResourcesPathL( 
       
   784             *list, TParsePtrC( filename ).DriveAndPath() );            
       
   785                         
       
   786         root = iODT->InternalizeDomDocumentL( instream );
       
   787 
       
   788         // Destroy the stream object, close the instream, destroy store
       
   789         CleanupStack::PopAndDestroy( 3, store );
       
   790         }
       
   791 
       
   792     CleanupStack::PopAndDestroy( &file );
       
   793 
       
   794     return root;
       
   795     }
       
   796 
       
   797 // --------------------------------------------------------------------------
       
   798 // CXnComposer::FindObject()
       
   799 // Finds an object from the provided array 
       
   800 // --------------------------------------------------------------------------
       
   801 //
       
   802 const CObjectMap* CXnComposer::FindObject( 
       
   803         RPointerArray<CObjectMap>& aResourceObjects,
       
   804         const TDesC8& aTag ) const
       
   805     {
       
   806     CObjectMap* object = NULL;
       
   807     
       
   808     const TInt count = aResourceObjects.Count();
       
   809     if ( count )
       
   810         {   
       
   811         
       
   812         // Find an object with the provided tag
       
   813         for( TInt objectIndex=0; objectIndex < count; objectIndex++ )
       
   814             {
       
   815             CObjectMap* o = aResourceObjects[ objectIndex ];
       
   816             if ( o->Tag() == aTag )
       
   817                 {
       
   818                 object = o;
       
   819                 break;
       
   820                 }
       
   821             }
       
   822         
       
   823         // If the tag was not found, return first object
       
   824         if( !object )
       
   825             {
       
   826             object = aResourceObjects[ 0 ];
       
   827             }
       
   828         }
       
   829     
       
   830     return object;
       
   831     }
       
   832 
       
   833 //  End of File