srsf/vcommandmanager/src/vcxmlparser.cpp
changeset 0 bf1d17376201
equal deleted inserted replaced
-1:000000000000 0:bf1d17376201
       
     1 /*
       
     2 * Copyright (c) 2005-2007 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:  Parser for Voice Commands XML files
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32math.h>
       
    21 #include <featmgr.h>
       
    22 #include <parser.h>
       
    23 #include <utf.h>
       
    24 #include "vcxmlparser.h"
       
    25 #include "vcresource.h"
       
    26 #include "rubydebug.h"
       
    27 
       
    28 // CONSTANTS
       
    29 // XML Tags
       
    30 _LIT8( KXmlDocumentTag, "nssvcommands" );
       
    31 _LIT8( KXmlFolderTag, "vcommandfolder" );
       
    32 _LIT8( KXmlVCommandTag, "vcommand" );
       
    33 _LIT8( KXmlSpokenTag, "spoken" ); 
       
    34 _LIT8( KXmlWrittenTag, "written" ); 
       
    35 _LIT8( KXmlExecutesTag, "executes" );
       
    36 _LIT8( KXmlCmdlineparamsTag, "cmdlineparams" );
       
    37 _LIT8( KXmlIconTag, "icon" );
       
    38 _LIT8( KXmlTooltipTag, "tooltip" );
       
    39 
       
    40 // XML attributes
       
    41 _LIT8( KXmlVersionAttr, "version" );
       
    42 _LIT8( KXmlLocFileAttr, "localizationfile" );
       
    43 _LIT8( KXmlLocAttr, "locindex" );
       
    44 _LIT8( KXmlFolderTitleLocAttr, "titlelocindex" );
       
    45 _LIT8( KXmlFolderIconFileAttr, "iconfile" );
       
    46 _LIT8( KXmlFolderIconIndexAttr, "iconindex" );
       
    47 _LIT8( KXmlTtsAttr, "tts" );
       
    48 _LIT8( KXmlModifiableAttr, "modifiable" );
       
    49 _LIT8( KXmlUidAttr, "uid" );
       
    50 _LIT8( KXmlExeAttr, "exe" );
       
    51 
       
    52 // XML attribute values
       
    53 _LIT8( KXmlVersionValue, "1.0" );
       
    54 _LIT8( KXmlTrueValue, "true" );
       
    55 _LIT8( KXmlFalseValue, "false" );
       
    56 
       
    57 // XML file MIME type
       
    58 _LIT8( KMimeType, "text/xml" );
       
    59 
       
    60 static const TInt KNoTags = 0;
       
    61 static const TInt KLastTag = 1;
       
    62 
       
    63 // ============================ MEMBER FUNCTIONS ===============================
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CVcXmlParser::CVcXmlParser
       
    67 // C++ default constructor can NOT contain any code, that
       
    68 // might leave.
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 CVcXmlParser::CVcXmlParser( RFs& aRFs, MVcXmlParserObserver& aObserver )
       
    72  : iObserver( aObserver ), iRFs( aRFs )
       
    73     {
       
    74     // Nothing
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CVcXmlParser::ConstructL
       
    79 // Symbian 2nd phase constructor can leave.
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 void CVcXmlParser::ConstructL()
       
    83     {
       
    84     RUBY_DEBUG_BLOCK( "CVcXmlParser::ConstructL" );
       
    85     
       
    86     ResetVCommandFolder();
       
    87     
       
    88     using namespace Xml;
       
    89     
       
    90     iParser = CParser::NewL( KMimeType, *this );
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CVcXmlParser::NewL
       
    95 // Two-phased constructor.
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 CVcXmlParser* CVcXmlParser::NewL( RFs& aRFs, MVcXmlParserObserver& aObserver )
       
    99     {
       
   100     CVcXmlParser* self = new( ELeave ) CVcXmlParser( aRFs, aObserver );
       
   101     CleanupStack::PushL( self );
       
   102     self->ConstructL();
       
   103     CleanupStack::Pop( self );
       
   104     return self;
       
   105     }
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CVcXmlParser::~CVcXmlParser
       
   109 // Destructor.
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 CVcXmlParser::~CVcXmlParser()
       
   113     {
       
   114     iXmlNesting.Close();
       
   115     ResetVCommandInfo();
       
   116     delete iResource;
       
   117     delete iFolder;
       
   118     delete iFolderTitle;
       
   119     delete iFolderIconFile;
       
   120     delete iAttributeValue;
       
   121     delete iParser;
       
   122     delete iParameters;
       
   123     delete iParameters8;
       
   124     delete iAppName;
       
   125     }
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // CVcXmlParser::ParseFileL
       
   129 // Parses a specific file.
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 void CVcXmlParser::ParseFileL( const TFileName& aFileName )
       
   133     {
       
   134     RUBY_DEBUG_BLOCK( "CVcXmlParser::ParseFileL" );
       
   135     
       
   136     iParser->ParseBeginL();
       
   137     
       
   138     ParseL( *iParser, iRFs, aFileName );
       
   139     }
       
   140 
       
   141 // -----------------------------------------------------------------------------
       
   142 // CVcXmlParser::OnStartDocumentL
       
   143 // Callback from XML parser when beginning of document has been found
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 void CVcXmlParser::OnStartDocumentL( const Xml::RDocumentParameters& /*aDocParam*/, 
       
   147                                      TInt aErrorCode )
       
   148     {
       
   149     RUBY_DEBUG_BLOCKL( "CVcXmlParser::OnStartDocumentL" );
       
   150     
       
   151     delete iResource;
       
   152     iResource = NULL;
       
   153     
       
   154     if ( ( iXmlNesting.Count() == KNoTags ) && ( aErrorCode == KErrNone ) )
       
   155         {
       
   156         iXmlNesting.Append( EXmlStarted );
       
   157         }
       
   158     else
       
   159         {
       
   160         User::Leave( KErrGeneral );
       
   161         }
       
   162     }
       
   163 
       
   164 // -----------------------------------------------------------------------------
       
   165 // CVcXmlParser::OnEndDocumentL
       
   166 // Callback from XML parser when end of document has been reached
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 void CVcXmlParser::OnEndDocumentL( TInt aErrorCode )
       
   170     {
       
   171     RUBY_DEBUG_BLOCKL( "CVcXmlParser::OnEndDocumentL" );
       
   172     
       
   173     if ( ( iXmlNesting.Count() == KLastTag ) && ( aErrorCode == KErrNone ) )
       
   174         {
       
   175         iXmlNesting.Reset();
       
   176         }
       
   177     else
       
   178         {
       
   179         User::Leave( KErrGeneral );
       
   180         }
       
   181     }
       
   182 
       
   183 // -----------------------------------------------------------------------------
       
   184 // CVcXmlParser::OnStartElementL
       
   185 // Callback from XML parser when new element has been found
       
   186 // -----------------------------------------------------------------------------
       
   187 //
       
   188 void CVcXmlParser::OnStartElementL( const Xml::RTagInfo& aElement, 
       
   189 	                                const Xml::RAttributeArray& aAttributes, 
       
   190 	                                TInt aErrorCode )
       
   191     {
       
   192     RUBY_DEBUG_BLOCKL( "CVcXmlParser::OnStartElementL" );
       
   193     __ASSERT_ALWAYS( iXmlNesting.Count() > 0, User::Leave( KErrCorrupt ) );    
       
   194     
       
   195     User::LeaveIfError( aErrorCode );
       
   196 
       
   197     HBufC8* name = ToLowercaseLC( aElement.LocalName().DesC() );
       
   198 
       
   199     // Check what was the previous tag
       
   200     switch ( iXmlNesting[ iXmlNesting.Count() - 1 ] )
       
   201         {
       
   202         case EXmlStarted:
       
   203             {
       
   204             if ( !ResolveDocumentTagL( name->Des(), aAttributes ) )
       
   205                 {
       
   206                 User::Leave( KErrNotFound );
       
   207                 }
       
   208             break;
       
   209             }
       
   210             
       
   211         case EXmlDocument:
       
   212             {
       
   213             if ( !ResolveFolderTagL( name->Des(), aAttributes ) )
       
   214                 {
       
   215                 if ( !ResolveVCommandTagL( name->Des(), aAttributes ) )
       
   216                     {
       
   217                     RUBY_DEBUG0( "VC XML ERROR: <vcommandfolder> or <vcommand> exptected but not found" );
       
   218                     User::Leave( KErrNotFound );
       
   219                     }
       
   220                 }
       
   221             break;
       
   222             }
       
   223         
       
   224         case EXmlFolder:
       
   225             {
       
   226             if ( !ResolveVCommandTagL( name->Des(), aAttributes ) )
       
   227                 {
       
   228                 RUBY_DEBUG0( "VC XML ERROR: <vcommand> exptected but not found" );
       
   229                 User::Leave( KErrNotFound );
       
   230                 }
       
   231 
       
   232             // New voice command starts
       
   233             ResetVCommandInfo();
       
   234              
       
   235             break;
       
   236             }
       
   237         
       
   238         case EXmlVCommand:
       
   239             {
       
   240             if ( !ResolveSpokenTagL( name->Des(), aAttributes ) )
       
   241                 {
       
   242                 if ( !ResolveWrittenTagL( name->Des(), aAttributes ) )
       
   243                     {
       
   244                     if ( !ResolveExecutesTagL( name->Des(), aAttributes ) )
       
   245                         {
       
   246                         if ( !ResolveCmdlineparamsTag( name->Des(), aAttributes ) )
       
   247                             {
       
   248                             if ( !ResolveIconTagL( name->Des(), aAttributes ) )
       
   249                                 {
       
   250                                 if ( !ResolveTooltipTagL( name->Des(), aAttributes ) )
       
   251                                     {
       
   252                                     RUBY_DEBUG0( "VC XML ERROR: <spoken> <written> <executes> or <cmdlineparams> exptected but not found" );   
       
   253                                     User::Leave( KErrNotFound );
       
   254                                     }
       
   255                                 }
       
   256                             }
       
   257                         }
       
   258                     }
       
   259                 }
       
   260             break;
       
   261             }
       
   262             
       
   263         default:
       
   264             {
       
   265             
       
   266             RUBY_DEBUG0( "VC XML ERROR: Unexpected starting tag found" );
       
   267             User::Leave( KErrNotFound );
       
   268             
       
   269             break;
       
   270             }
       
   271 
       
   272         }
       
   273         
       
   274     CleanupStack::PopAndDestroy( name );
       
   275  
       
   276     }
       
   277 
       
   278 // -----------------------------------------------------------------------------
       
   279 // CVcXmlParser::OnEndElementL
       
   280 // Callback from XML parser when ending tag has been found
       
   281 // -----------------------------------------------------------------------------
       
   282 //
       
   283 void CVcXmlParser::OnEndElementL( const Xml::RTagInfo& aElement, 
       
   284                                   TInt aErrorCode )
       
   285     {
       
   286     RUBY_DEBUG_BLOCKL( "CVcXmlParser::OnEndElementL" );
       
   287     __ASSERT_ALWAYS( iXmlNesting.Count() > 0, User::Leave( KErrCorrupt ) );
       
   288     
       
   289     User::LeaveIfError( aErrorCode );
       
   290     
       
   291     HBufC8* name = ToLowercaseLC( aElement.LocalName().DesC() );
       
   292     
       
   293     switch ( iXmlNesting[ iXmlNesting.Count() - 1 ] )
       
   294         {
       
   295         case EXmlDocument:
       
   296             {
       
   297             PopFromStackIfFoundL( name->Des(), KXmlDocumentTag );
       
   298             break;
       
   299             }
       
   300         
       
   301         case EXmlFolder:
       
   302             {
       
   303             PopFromStackIfFoundL( name->Des(), KXmlFolderTag );
       
   304             ResetVCommandFolder();
       
   305             break;
       
   306             }
       
   307         
       
   308         case EXmlVCommand:
       
   309             {
       
   310             PopFromStackIfFoundL( name->Des(), KXmlVCommandTag );
       
   311             CheckVoiceCommmandData();
       
   312             break;
       
   313             }
       
   314             
       
   315          case EXmlSpoken:
       
   316             {
       
   317             PopFromStackIfFoundL( name->Des(), KXmlSpokenTag );
       
   318             break;
       
   319             }
       
   320          
       
   321          case EXmlWritten:
       
   322             {
       
   323             PopFromStackIfFoundL( name->Des(), KXmlWrittenTag );
       
   324             break;
       
   325             }
       
   326         
       
   327          case EXmlExecutes:
       
   328             {
       
   329             PopFromStackIfFoundL( name->Des(), KXmlExecutesTag );
       
   330             break;
       
   331             }
       
   332          
       
   333          case EXmlCmdlineparams:
       
   334             {
       
   335             PopFromStackIfFoundL( name->Des(), KXmlCmdlineparamsTag );   
       
   336                 
       
   337             // Convert content of <cmdlineparams> into unicode
       
   338             // First trim out unnecessary white space
       
   339             TPtr8 des8( iParameters8->Des() );
       
   340             des8.Trim();
       
   341                 
       
   342             // Delete previous unicode buffer and create new
       
   343             delete iParameters;
       
   344             iParameters = NULL;
       
   345             iParameters = CnvUtfConverter::ConvertToUnicodeFromUtf8L( des8 );
       
   346                 
       
   347             break;
       
   348             }
       
   349 
       
   350          case EXmlIcon:
       
   351             {
       
   352             PopFromStackIfFoundL( name->Des(), KXmlIconTag );
       
   353             break;
       
   354             }
       
   355 
       
   356          case EXmlTooltip:
       
   357             {
       
   358             PopFromStackIfFoundL( name->Des(), KXmlTooltipTag );
       
   359             break;
       
   360             }
       
   361            
       
   362         default:
       
   363             {
       
   364             RUBY_DEBUG0( "VC XML ERROR: Ending tag found when not expected" );
       
   365             User::Leave( KErrGeneral );
       
   366             break;
       
   367             }
       
   368 
       
   369         }
       
   370     CleanupStack::PopAndDestroy( name );
       
   371     }
       
   372 
       
   373 // -----------------------------------------------------------------------------
       
   374 // CVcXmlParser::PopFromStackIfFoundL
       
   375 // Checks that last item on stack is the expected one
       
   376 // -----------------------------------------------------------------------------
       
   377 //
       
   378 void CVcXmlParser::PopFromStackIfFoundL( const TDesC8& aTagName, const TDesC8& aExpectedTag )
       
   379     {
       
   380     if ( aTagName != aExpectedTag )
       
   381         {
       
   382         RUBY_DEBUG0( "VC XML ERROR: Unexpected ending tag found" );
       
   383         User::Leave( KErrNotFound );
       
   384         }
       
   385         
       
   386     iXmlNesting.Remove( iXmlNesting.Count() - 1 );    
       
   387     }
       
   388 
       
   389 // -----------------------------------------------------------------------------
       
   390 // CVcXmlParser::OnContentL
       
   391 // Callback from XML parser when element has some content
       
   392 // -----------------------------------------------------------------------------
       
   393 //
       
   394 void CVcXmlParser::OnContentL( const TDesC8& aBytes, TInt aErrorCode )
       
   395     {
       
   396     RUBY_DEBUG_BLOCKL( "CVcXmlParser::OnContentL" );
       
   397     
       
   398     User::LeaveIfError( aErrorCode );
       
   399     
       
   400     TInt lastTag = iXmlNesting.Count() - 1;
       
   401     
       
   402     if ( iXmlNesting[ lastTag ] == EXmlCmdlineparams )
       
   403         {
       
   404         if ( !iParameters8 )
       
   405             {
       
   406             // Create new buffer
       
   407             iParameters8 = HBufC8::NewL( aBytes.Size() );
       
   408             TPtr8 des( iParameters8->Des() );
       
   409             des.Copy( aBytes );
       
   410             }
       
   411         else
       
   412             {
       
   413             // Append at the end of previous stuff
       
   414             iParameters8 = iParameters8->ReAllocL( iParameters8->Size() + aBytes.Size() );
       
   415             TPtr8 des( iParameters8->Des() );
       
   416             des.Append( aBytes );
       
   417             }
       
   418 
       
   419         RUBY_DEBUG0( "<cmdlineparams> content resolved" );
       
   420         }
       
   421     }
       
   422 
       
   423 // -----------------------------------------------------------------------------
       
   424 // CVcXmlParser::OnStartPrefixMappingL
       
   425 // Callback from XML parser
       
   426 // -----------------------------------------------------------------------------
       
   427 //
       
   428 void CVcXmlParser::OnStartPrefixMappingL( const RString& /*aPrefix*/, 
       
   429 	                                      const RString& /*aUri*/, 
       
   430 	                                      TInt /*aErrorCode*/ )
       
   431     {
       
   432     // Nothing
       
   433     }
       
   434 
       
   435 // -----------------------------------------------------------------------------
       
   436 // CVcXmlParser::OnEndPrefixMappingL
       
   437 // Callback from XML parser
       
   438 // -----------------------------------------------------------------------------
       
   439 //
       
   440 void CVcXmlParser::OnEndPrefixMappingL( const RString& /*aPrefix*/, 
       
   441                                         TInt /*aErrorCode*/ )
       
   442     {
       
   443     // Nothing
       
   444     }
       
   445 
       
   446 // -----------------------------------------------------------------------------
       
   447 // CVcXmlParser::OnIgnorableWhiteSpaceL
       
   448 // Callback from XML parser
       
   449 // -----------------------------------------------------------------------------
       
   450 //
       
   451 void CVcXmlParser::OnIgnorableWhiteSpaceL( const TDesC8& /*aBytes*/, 
       
   452                                            TInt /*aErrorCode*/ )
       
   453     {
       
   454     // Nothing
       
   455     }
       
   456 
       
   457 // -----------------------------------------------------------------------------
       
   458 // CVcXmlParser::OnSkippedEntityL
       
   459 // Callback from XML parser
       
   460 // -----------------------------------------------------------------------------
       
   461 //
       
   462 void CVcXmlParser::OnSkippedEntityL( const RString& /*aName*/, 
       
   463                                      TInt /*aErrorCode*/ )
       
   464     {
       
   465     // Nothing
       
   466     }
       
   467 
       
   468 // -----------------------------------------------------------------------------
       
   469 // CVcXmlParser::OnProcessingInstructionL
       
   470 // Callback from XML parser
       
   471 // -----------------------------------------------------------------------------
       
   472 //
       
   473 void CVcXmlParser::OnProcessingInstructionL( const TDesC8& /*aTarget*/, 
       
   474                                              const TDesC8& /*aData*/, 
       
   475 	                                         TInt /*aErrorCode*/ )
       
   476     {
       
   477     // Nothing
       
   478     }
       
   479 
       
   480 // -----------------------------------------------------------------------------
       
   481 // CVcXmlParser::OnError
       
   482 // Callback from XML parser when general error has occured
       
   483 // -----------------------------------------------------------------------------
       
   484 //
       
   485 #if defined(_DEBUG) && !defined(__RUBY_DEBUG_DISABLED)
       
   486 void CVcXmlParser::OnError( TInt aErrorCode )
       
   487     {
       
   488     RUBY_DEBUG1( "CVcXmlParser::OnError general error: [%d]", aErrorCode );
       
   489     }
       
   490 #else
       
   491 void CVcXmlParser::OnError( TInt /*aErrorCode*/ )
       
   492     {
       
   493     // Nothing
       
   494     }
       
   495 #endif // #if defined(_DEBUG) && !defined(__RUBY_DEBUG_DISABLED)
       
   496     
       
   497 // -----------------------------------------------------------------------------
       
   498 // CVcXmlParser::GetExtendedInterface
       
   499 // Callback from XML parser
       
   500 // -----------------------------------------------------------------------------
       
   501 //
       
   502 TAny* CVcXmlParser::GetExtendedInterface( const TInt32 /*aUid*/ )
       
   503     {
       
   504     return NULL;
       
   505     }
       
   506 
       
   507 // -----------------------------------------------------------------------------
       
   508 // CVcXmlParser::CheckAttributeL
       
   509 // Checks the value of certain attribute
       
   510 // -----------------------------------------------------------------------------
       
   511 //
       
   512 TBool CVcXmlParser::CheckAttributeL( const Xml::RAttributeArray& aAttributes,
       
   513                                      const TDesC8& aAttribute, const TDesC8& aValue )
       
   514     {
       
   515     RUBY_DEBUG_BLOCKL( "CVcXmlParser::CheckAttributeL" );
       
   516     
       
   517     TBool resolved( EFalse );
       
   518     
       
   519     // Loop through attribute list
       
   520     for ( TInt iCounter = 0 ; iCounter < aAttributes.Count() ; iCounter++ )
       
   521         {        
       
   522         HBufC8* name = ToLowercaseLC( aAttributes[iCounter].Attribute().LocalName().DesC() );
       
   523        
       
   524         if ( name->Des() == aAttribute )
       
   525             {
       
   526             HBufC8* value = ToLowercaseLC( aAttributes[iCounter].Value().DesC() );
       
   527             
       
   528             // If value is null descriptor, then we just check if attribute exists           
       
   529             if ( aValue == KNullDesC8 || value->Des() == aValue )
       
   530                 {                
       
   531                 resolved = ETrue;
       
   532                 }
       
   533             
       
   534             CleanupStack::PopAndDestroy( value );
       
   535             }
       
   536         CleanupStack::PopAndDestroy( name );
       
   537         }
       
   538         
       
   539     return resolved;
       
   540     }
       
   541     
       
   542 // -----------------------------------------------------------------------------
       
   543 // CVcXmlParser::ResolveDocumentTagL
       
   544 // Resolves the content of <nssvcommands>
       
   545 // -----------------------------------------------------------------------------
       
   546 //
       
   547 TBool CVcXmlParser::ResolveDocumentTagL( const TDesC8& aName, 
       
   548                                         const Xml::RAttributeArray& aAttributes )
       
   549     {
       
   550     RUBY_DEBUG_BLOCKL( "CVcXmlParser::ResolveDocumentTagL" );
       
   551     
       
   552     TBool resolved( EFalse );
       
   553     
       
   554     if ( aName == KXmlDocumentTag )
       
   555         {
       
   556         iXmlNesting.Append( EXmlDocument );
       
   557         resolved = CheckAttributeL( aAttributes, KXmlVersionAttr, KXmlVersionValue );
       
   558         if ( !resolved )
       
   559             {
       
   560             RUBY_DEBUG0( "VC XML ERROR: Version information not found or it does not match" );
       
   561             User::Leave( KErrGeneral );
       
   562             }
       
   563         else
       
   564             {
       
   565             CVcResource* newResource( NULL );
       
   566             TPtrC8 locFileAttr( KXmlLocFileAttr );
       
   567             TRAPD( error, newResource =
       
   568                 CVcResource::NewL( iRFs, Find16ValueL( locFileAttr, aAttributes ) ) );
       
   569 
       
   570             // Delete old resource object if new was found
       
   571             if ( newResource )
       
   572                 {
       
   573                 delete iResource;
       
   574                 iResource = newResource;
       
   575                 }
       
   576         
       
   577             if ( error != KErrNone )
       
   578                 {
       
   579                 resolved = EFalse;
       
   580                 RUBY_DEBUG0( "VC XML ERROR: Resource file load error" );
       
   581                 User::Leave( KErrNotFound );
       
   582                 }
       
   583             }
       
   584         }
       
   585      else
       
   586         {
       
   587         RUBY_DEBUG0( "VC XML ERROR: <nssvoicecommands> exptected but not found" );
       
   588         User::Leave( KErrNotFound );        
       
   589         }
       
   590                
       
   591     return resolved;
       
   592     }
       
   593 
       
   594 // -----------------------------------------------------------------------------
       
   595 // CVcXmlParser::ResolveFolderTagL
       
   596 // Resolves the content of <vcommandfolder>
       
   597 // -----------------------------------------------------------------------------
       
   598 //
       
   599 TBool CVcXmlParser::ResolveFolderTagL( const TDesC8& aName, 
       
   600                                        const Xml::RAttributeArray& aAttributes )
       
   601     {
       
   602     RUBY_DEBUG_BLOCKL( "CVcXmlParser::ResolveFolderTagL" );
       
   603     
       
   604     // Use specific resource file for folder strings if specified
       
   605     CVcResource* mainResource = iResource;
       
   606     
       
   607     CVcResource* newResource( NULL );
       
   608     TPtrC locFile = Find16ValueL( KXmlLocFileAttr, aAttributes );
       
   609     if ( locFile != KNullDesC )
       
   610         {
       
   611         newResource = CVcResource::NewL( iRFs, locFile );
       
   612         }
       
   613                   
       
   614     if ( newResource )
       
   615         {
       
   616         iResource = newResource;
       
   617         CleanupStack::PushL( mainResource );
       
   618         }    
       
   619     
       
   620     // Find folder name
       
   621     TBool resolved = ResolveLocalizedTagL( aName, aAttributes, KXmlFolderTag, 
       
   622                                            EXmlFolder );
       
   623     if ( resolved )
       
   624         {
       
   625         delete iFolder;
       
   626         iFolder = iCurrentLocalizedString;
       
   627         iCurrentLocalizedString = NULL;
       
   628         
       
   629         // Find folder title string
       
   630         TBool titleFound = GetLocalizedStringL( aAttributes, KXmlFolderTitleLocAttr );
       
   631         
       
   632         if ( titleFound )
       
   633             {
       
   634             delete iFolderTitle;
       
   635             iFolderTitle = iCurrentLocalizedString;
       
   636             iCurrentLocalizedString = NULL;
       
   637             }
       
   638             
       
   639         TBool iconFileFound = ResolveFolderIconFileL( aAttributes );
       
   640         RUBY_DEBUG1( "iconFileFound [%d]", iconFileFound );
       
   641         iFolderIconIndex = ResolveFolderIconIndexL( aAttributes );
       
   642        
       
   643         }
       
   644         
       
   645     // Revert back to use the old resource file
       
   646     iResource = mainResource;
       
   647     if ( newResource )
       
   648         {
       
   649         delete newResource;
       
   650         CleanupStack::Pop( mainResource );
       
   651         }
       
   652                 
       
   653     return resolved;
       
   654     }
       
   655 
       
   656 // -----------------------------------------------------------------------------
       
   657 // CVcXmlParser::ResolveVCommandTagL
       
   658 // Resolves the content of <vcommand>
       
   659 // -----------------------------------------------------------------------------
       
   660 //
       
   661 TBool CVcXmlParser::ResolveVCommandTagL( const TDesC8& aName, 
       
   662                                          const Xml::RAttributeArray& aAttributes )
       
   663     {
       
   664     RUBY_DEBUG_BLOCKL( "CVcXmlParser::ResolveVCommandTagL" );
       
   665     
       
   666     TBool resolved( EFalse );
       
   667     if ( aName == KXmlVCommandTag )
       
   668         {
       
   669         resolved = ETrue;
       
   670         iXmlNesting.Append( EXmlVCommand );
       
   671         }
       
   672     
       
   673     if ( resolved )
       
   674         {
       
   675         // TTS on/off  
       
   676         resolved = CheckAttributeL( aAttributes, KXmlTtsAttr, KXmlTrueValue );
       
   677         if ( resolved )
       
   678             {
       
   679             // By default, tts is on
       
   680             iStartImmediately = ETrue;
       
   681             }
       
   682         
       
   683         // Modifiable on/off
       
   684         resolved = CheckAttributeL( aAttributes, KXmlModifiableAttr, KXmlFalseValue );
       
   685         if ( resolved )
       
   686             {
       
   687             iUserCanModify = EFalse;
       
   688             }
       
   689             
       
   690         resolved = ETrue;
       
   691         }
       
   692 
       
   693     return resolved;
       
   694     }
       
   695 
       
   696 
       
   697 // -----------------------------------------------------------------------------
       
   698 // CVcXmlParser::ResolveSpokenTagL
       
   699 // Resolves the content of <spoken>
       
   700 // -----------------------------------------------------------------------------
       
   701 //
       
   702 TBool CVcXmlParser::ResolveSpokenTagL( const TDesC8& aName, 
       
   703                                        const Xml::RAttributeArray& aAttributes )
       
   704     {
       
   705     RUBY_DEBUG_BLOCKL( "CVcXmlParser::ResolveSpokenTagL" );
       
   706     
       
   707     TBool resolved = ResolveLocalizedTagL( aName, aAttributes, KXmlSpokenTag, 
       
   708                                            EXmlSpoken );
       
   709 
       
   710     if ( resolved )
       
   711         {
       
   712         delete iSpokenText;
       
   713         iSpokenText = iCurrentLocalizedString;
       
   714         iCurrentLocalizedString = NULL;
       
   715         }
       
   716     return resolved;
       
   717     }
       
   718 
       
   719 // -----------------------------------------------------------------------------
       
   720 // CVcXmlParser::ResolveWrittenTagL
       
   721 // Resolves the content of <written>
       
   722 // -----------------------------------------------------------------------------
       
   723 //
       
   724 TBool CVcXmlParser::ResolveWrittenTagL( const TDesC8& aName,
       
   725                                         const Xml::RAttributeArray& aAttributes )
       
   726     {
       
   727     RUBY_DEBUG_BLOCKL( "CVcXmlParser::ResolveWrittenTagL" );
       
   728     
       
   729     TBool resolved = ResolveLocalizedTagL( aName, aAttributes, KXmlWrittenTag, 
       
   730                                            EXmlWritten );
       
   731     if ( resolved )
       
   732         {
       
   733         delete iWrittenText;
       
   734         iWrittenText = iCurrentLocalizedString;
       
   735         iCurrentLocalizedString = NULL;
       
   736         }
       
   737     return resolved;
       
   738     }
       
   739 
       
   740 // -----------------------------------------------------------------------------
       
   741 // CVcXmlParser::ResolveTooltipTagL
       
   742 // Resolves the content of <tooltip>
       
   743 // -----------------------------------------------------------------------------
       
   744 //
       
   745 TBool CVcXmlParser::ResolveTooltipTagL( const TDesC8& aName,
       
   746                                         const Xml::RAttributeArray& aAttributes )
       
   747     {
       
   748     RUBY_DEBUG_BLOCKL( "CVcXmlParser::ResolveTooltipTagL" );
       
   749     
       
   750     TBool resolved = ResolveLocalizedTagL( aName, aAttributes, KXmlTooltipTag, 
       
   751                                            EXmlTooltip );
       
   752     if ( resolved )
       
   753         {
       
   754         delete iTooltipText;
       
   755         iTooltipText = iCurrentLocalizedString;
       
   756         iCurrentLocalizedString = NULL;
       
   757         }
       
   758     return resolved;
       
   759     }
       
   760 
       
   761 // -----------------------------------------------------------------------------
       
   762 // CVcXmlParser::ResolveLocalizedTagL
       
   763 // Resolves content of tag which contains localized data
       
   764 // -----------------------------------------------------------------------------
       
   765 //
       
   766 TBool CVcXmlParser::ResolveLocalizedTagL( const TDesC8& aName,
       
   767                                           const Xml::RAttributeArray& aAttributes,
       
   768                                           const TDesC8& aExpectedName,
       
   769                                           TVcXmlTagNesting aTagEnum )
       
   770     {
       
   771     RUBY_DEBUG_BLOCKL( "CVcXmlParser::ResolveLocalizedTagL" );
       
   772     
       
   773     TBool resolved( EFalse );
       
   774     if ( aName == aExpectedName )
       
   775         {
       
   776         resolved = ETrue;
       
   777         iXmlNesting.Append( aTagEnum );
       
   778         
       
   779         resolved = GetLocalizedStringL( aAttributes, KXmlLocAttr );
       
   780         }
       
   781 
       
   782     return resolved;
       
   783     }
       
   784 
       
   785 // -----------------------------------------------------------------------------
       
   786 // CVcXmlParser::ResolveExecutesTagL
       
   787 // Resolves the content of <executes>
       
   788 // -----------------------------------------------------------------------------
       
   789 //
       
   790 TBool CVcXmlParser::ResolveExecutesTagL( const TDesC8& aName,
       
   791                                          const Xml::RAttributeArray& aAttributes )
       
   792     {
       
   793     RUBY_DEBUG_BLOCKL( "CVcXmlParser::ResolveExecutesTagL" );
       
   794     
       
   795     TBool resolved( EFalse );
       
   796    
       
   797     if ( aName == KXmlExecutesTag )
       
   798         {
       
   799         resolved = ETrue;
       
   800         iXmlNesting.Append( EXmlExecutes );
       
   801 
       
   802         iAppId = ResolveUidL( aAttributes );
       
   803         if ( iAppId == KNullUid )
       
   804             {
       
   805             resolved = ResolveExeL( aAttributes );
       
   806             }
       
   807         }
       
   808 
       
   809     return resolved;
       
   810     }
       
   811 
       
   812 // -----------------------------------------------------------------------------
       
   813 // CVcXmlParser::ResolveCmdlineparamsTag
       
   814 // Resolves the content of <cmdlineparams>
       
   815 // -----------------------------------------------------------------------------
       
   816 //
       
   817 TBool CVcXmlParser::ResolveCmdlineparamsTag( const TDesC8& aName, 
       
   818                                              const Xml::RAttributeArray& /*aAttributes*/ )
       
   819     {
       
   820     TBool resolved( EFalse );
       
   821     
       
   822     if ( aName == KXmlCmdlineparamsTag )
       
   823         {
       
   824         iXmlNesting.Append( EXmlCmdlineparams );
       
   825         delete iParameters;
       
   826         delete iParameters8;
       
   827         iParameters = NULL;
       
   828         iParameters8 = NULL;
       
   829         resolved = ETrue;        
       
   830         }
       
   831         
       
   832     return resolved;
       
   833     }
       
   834 
       
   835 // -----------------------------------------------------------------------------
       
   836 // CVcXmlParser::ResolveIconTagL
       
   837 // Resolves the content of <icon>
       
   838 // -----------------------------------------------------------------------------
       
   839 //
       
   840 TBool CVcXmlParser::ResolveIconTagL( const TDesC8& aName,
       
   841                                      const Xml::RAttributeArray& aAttributes )
       
   842     {
       
   843     RUBY_DEBUG_BLOCKL( "CVcXmlParser::ResolveIconTagL" );
       
   844     
       
   845     TBool resolved( EFalse );
       
   846     
       
   847     if ( aName == KXmlIconTag )
       
   848         {
       
   849         resolved = ETrue;
       
   850         iXmlNesting.Append( EXmlIcon );
       
   851 
       
   852         iIcon = ResolveUidL( aAttributes );
       
   853         if ( iIcon == KNullUid )
       
   854             {
       
   855             resolved = EFalse;
       
   856             }
       
   857         }
       
   858 
       
   859     return resolved;
       
   860     }
       
   861 
       
   862 // -----------------------------------------------------------------------------
       
   863 // CVcXmlParser::Find16ValueL
       
   864 // Finds a certain attribute and returns its value as unicode
       
   865 // -----------------------------------------------------------------------------
       
   866 //
       
   867 const TDesC& CVcXmlParser::Find16ValueL( const TDesC8& aName, 
       
   868                                          const Xml::RAttributeArray& aAttributes )
       
   869     {
       
   870     RUBY_DEBUG_BLOCKL( "CVcXmlParser::Find16ValueL" );
       
   871     
       
   872     delete iAttributeValue;
       
   873     iAttributeValue = NULL;
       
   874     
       
   875     iAttributeValue = CnvUtfConverter::ConvertToUnicodeFromUtf8L( Find8ValueL( aName, aAttributes ) );
       
   876        
       
   877     return *iAttributeValue;
       
   878     }
       
   879 
       
   880 // -----------------------------------------------------------------------------
       
   881 // CVcXmlParser::Find8ValueL
       
   882 // Finds a certain attribute and returns its value as utf-8
       
   883 // -----------------------------------------------------------------------------
       
   884 //
       
   885 const TDesC8& CVcXmlParser::Find8ValueL( const TDesC8& aName, 
       
   886                                          const Xml::RAttributeArray& aAttributes )
       
   887     {
       
   888     RUBY_DEBUG_BLOCKL( "CVcXmlParser::Find8ValueL" );
       
   889     
       
   890     // Loop through attribute list
       
   891     for ( TInt iCounter = 0 ; iCounter < aAttributes.Count() ; iCounter++ )
       
   892         {
       
   893         HBufC8* name = ToLowercaseLC( aAttributes[iCounter].Attribute().LocalName().DesC() );
       
   894         
       
   895         if ( name->Des() == aName )
       
   896             {
       
   897             CleanupStack::PopAndDestroy( name );
       
   898 
       
   899             return aAttributes[iCounter].Value().DesC();
       
   900             }
       
   901         CleanupStack::PopAndDestroy( name );
       
   902         }
       
   903         
       
   904     return KNullDesC8;
       
   905     }
       
   906     
       
   907 // -----------------------------------------------------------------------------
       
   908 // CVcXmlParser::ResetVCommandFolder
       
   909 // Destroys the data of one voice command folder
       
   910 // -----------------------------------------------------------------------------
       
   911 //
       
   912 void CVcXmlParser::ResetVCommandFolder()
       
   913     {
       
   914     delete iFolder;
       
   915     iFolder = HBufC16::New( 0 );
       
   916     
       
   917     delete iFolderTitle;
       
   918     iFolderTitle = HBufC16::New( 0 );
       
   919     
       
   920     delete iFolderIconFile;
       
   921     iFolderIconFile = HBufC16::New( 0 );
       
   922     
       
   923     iFolderIconIndex = -1;
       
   924     
       
   925     ResetVCommandInfo();
       
   926     }
       
   927 
       
   928 // -----------------------------------------------------------------------------
       
   929 // CVcXmlParser::ResetVCommandInfo
       
   930 // Destroys the data of one voice command
       
   931 // -----------------------------------------------------------------------------
       
   932 //
       
   933 void CVcXmlParser::ResetVCommandInfo()
       
   934     {
       
   935     delete iWrittenText;
       
   936     iWrittenText = NULL;
       
   937     delete iSpokenText;
       
   938     iSpokenText = NULL;
       
   939     delete iTooltipText;
       
   940     iTooltipText = NULL;
       
   941     delete iParameters;
       
   942     iParameters = NULL;
       
   943     delete iParameters8;
       
   944     iParameters8 = NULL;
       
   945     delete iAppName;
       
   946     iAppName = NULL;
       
   947     
       
   948     iAppId = KNullUid;
       
   949     iIcon = KNullUid;
       
   950     
       
   951     iStartImmediately = EFalse;
       
   952     iUserCanModify = ETrue;
       
   953     }
       
   954 
       
   955 // -----------------------------------------------------------------------------
       
   956 // CVcXmlParser::CheckVoiceCommmandData
       
   957 // Checks if all mandatory data for one voice command is available and makes
       
   958 // callback based on that
       
   959 // -----------------------------------------------------------------------------
       
   960 //
       
   961 void CVcXmlParser::CheckVoiceCommmandData()
       
   962     {
       
   963     if ( iWrittenText && ( iAppId != KNullUid || iAppName ) )
       
   964         {
       
   965         RUBY_DEBUG0( "CVcXmlParser::CheckVoiceCommmandData(): All required data for voice command found ok" );
       
   966         
       
   967         // folder icon file is optional
       
   968         // if it is not present, reference to KNullDesC should be passed
       
   969         const TDesC* pFolderIconFile =iFolderIconFile;
       
   970         if( !pFolderIconFile )
       
   971             {
       
   972             pFolderIconFile = &KNullDesC;
       
   973             }
       
   974         
       
   975         iObserver.MvcxpoVoiceCommandFound( *iWrittenText, *iSpokenText, 
       
   976                                            *iTooltipText, *iFolder, *iFolderTitle, 
       
   977                                            *iParameters, iIcon,
       
   978                                            iAppId, *iAppName,
       
   979                                            iStartImmediately, iUserCanModify,
       
   980                                            *pFolderIconFile, iFolderIconIndex );
       
   981         }
       
   982     else
       
   983         {
       
   984         RUBY_DEBUG0( "VC XML ERROR: Mandatory data not found for Voice Command" );
       
   985         }
       
   986     }
       
   987 
       
   988 // -----------------------------------------------------------------------------
       
   989 // CVcXmlParser::GetLocalizedStringL
       
   990 // Reads localized string from resource file
       
   991 // -----------------------------------------------------------------------------
       
   992 //
       
   993 TBool CVcXmlParser::GetLocalizedStringL( const Xml::RAttributeArray& aAttributes,
       
   994                                          const TDesC8& aAttributeName )
       
   995     {
       
   996     RUBY_DEBUG_BLOCKL( "CVcXmlParser::GetLocalizedStringL" );
       
   997     
       
   998     TBool resolved( EFalse );
       
   999     iCurrentLocalizedString = NULL;
       
  1000     
       
  1001     // Resource file object should have been initialized
       
  1002     if ( !iResource )
       
  1003         {
       
  1004         return resolved;
       
  1005         }
       
  1006 
       
  1007     // locIndex is key to the localized resource file
       
  1008     TPtrC8 locAttr( aAttributeName );    
       
  1009     TPtrC locIndex = Find16ValueL( locAttr, aAttributes );
       
  1010     
       
  1011     if ( locIndex != KNullDesC )
       
  1012         {
       
  1013         HBufC* command = NULL;
       
  1014         // Find string from loc file based on key
       
  1015         TRAPD( error,  command = &iResource->GetCommandL( locIndex ) );
       
  1016         if ( error == KErrNone )
       
  1017             {
       
  1018             // Make a copy of localized string
       
  1019             TPtr des = command->Des();
       
  1020             delete iCurrentLocalizedString;
       
  1021             iCurrentLocalizedString = des.Alloc();
       
  1022             resolved = ETrue;
       
  1023             }
       
  1024         else
       
  1025             {
       
  1026             resolved = EFalse;
       
  1027             iCurrentLocalizedString = NULL;
       
  1028             RUBY_DEBUG0( "VC XML ERROR: Cannot resolve localized string" );
       
  1029             User::Leave( KErrGeneral );
       
  1030             }
       
  1031         }
       
  1032         
       
  1033     return resolved;
       
  1034     }
       
  1035 
       
  1036 // -----------------------------------------------------------------------------
       
  1037 // CVcXmlParser::ResolveUidL
       
  1038 // Resolves the content of uid="0x1234567" attribute
       
  1039 // -----------------------------------------------------------------------------
       
  1040 //
       
  1041 TUid CVcXmlParser::ResolveUidL( const Xml::RAttributeArray& aAttributes )
       
  1042     {
       
  1043     RUBY_DEBUG_BLOCKL( "CVcXmlParser::ResolveUidL" );
       
  1044     
       
  1045     _LIT( KHexIdentifierLowercase, "0x" );
       
  1046     _LIT( KHexIdentifierUppercase, "0X" );
       
  1047     const TInt KHexIndentifierLength = 2;
       
  1048     
       
  1049     TUid newUid( KNullUid );
       
  1050     
       
  1051     TPtrC uidDes = Find16ValueL( KXmlUidAttr, aAttributes );
       
  1052     
       
  1053     if ( uidDes != KNullDesC )
       
  1054         {
       
  1055         TPtrC ptr( uidDes );
       
  1056         // Check if string starts with 0x or 0X
       
  1057         if ( ( uidDes.Find( KHexIdentifierLowercase ) == 0 ) ||
       
  1058              ( uidDes.Find( KHexIdentifierUppercase ) == 0 ) )
       
  1059             {
       
  1060             ptr.Set( uidDes.Right( uidDes.Length() - KHexIndentifierLength ) );
       
  1061             }
       
  1062         
       
  1063         // Do conversion from string to number
       
  1064         TLex lex( ptr );
       
  1065         TInt64 intUid( 0 );
       
  1066         TInt error = lex.Val( intUid, EHex );
       
  1067         newUid.iUid = intUid;
       
  1068         }
       
  1069         
       
  1070     return newUid;
       
  1071     }
       
  1072 
       
  1073 // -----------------------------------------------------------------------------
       
  1074 // CVcXmlParser::ResolveExeL
       
  1075 // Resolves the content of exe="name.exe" attribute
       
  1076 // -----------------------------------------------------------------------------
       
  1077 //
       
  1078 TBool CVcXmlParser::ResolveExeL( const Xml::RAttributeArray& aAttributes )
       
  1079     {
       
  1080     RUBY_DEBUG_BLOCKL( "CVcXmlParser::ResolveExeL" );
       
  1081     
       
  1082     TBool resolved( EFalse );
       
  1083     
       
  1084     TPtrC nameDes = Find16ValueL( KXmlExeAttr, aAttributes );
       
  1085     if ( nameDes != KNullDesC )
       
  1086         {
       
  1087         delete iAppName;
       
  1088         iAppName = NULL;
       
  1089         
       
  1090         iAppName = HBufC::NewL( nameDes.Length() );
       
  1091         TPtr namePtr = iAppName->Des();
       
  1092         namePtr.Copy( nameDes );
       
  1093         
       
  1094         resolved = ETrue;
       
  1095         }
       
  1096         
       
  1097     return resolved;
       
  1098     }
       
  1099     
       
  1100 // -----------------------------------------------------------------------------
       
  1101 // CVcXmlParser::ToLowercaseLC
       
  1102 // Converts given string to lowercase
       
  1103 // -----------------------------------------------------------------------------
       
  1104 //
       
  1105 HBufC8* CVcXmlParser::ToLowercaseLC( const TDesC8& aString )
       
  1106     {
       
  1107     // RUBY_DEBUG0( "CVcXmlParser::ToLowercaseLC START" );
       
  1108     
       
  1109     // Convert string to lowercase    
       
  1110     HBufC8* string = HBufC8::NewL( aString.Length() );
       
  1111     CleanupStack::PushL( string );
       
  1112     TPtr8 des = string->Des();
       
  1113     des.Copy( aString );
       
  1114     des.LowerCase();
       
  1115     
       
  1116     //RUBY_DEBUG0( "CVcXmlParser::ToLowercaseLC EXIT" );
       
  1117     
       
  1118     return string;
       
  1119     }
       
  1120 
       
  1121 // -----------------------------------------------------------------------------
       
  1122 // Reads the iconfile attribute and constructs the file name or
       
  1123 // sets it to NULL
       
  1124 // 
       
  1125 // @params aAttributes List of XML attributes
       
  1126 // @return ETrue if resolved successfully, EFalse otherwise
       
  1127 // -----------------------------------------------------------------------------
       
  1128 TBool CVcXmlParser::ResolveFolderIconFileL( const Xml::RAttributeArray& aAttributes )
       
  1129 	{
       
  1130     RUBY_DEBUG_BLOCKL( "CVcXmlParser::ResolveFolderIconFileL" );
       
  1131     
       
  1132     TBool resolved( EFalse );
       
  1133     delete iFolderIconFile;
       
  1134     iFolderIconFile = NULL;
       
  1135     
       
  1136     TPtrC nameDes = Find16ValueL( KXmlFolderIconFileAttr, aAttributes );
       
  1137     if ( nameDes != KNullDesC )
       
  1138         {
       
  1139         iFolderIconFile = HBufC::NewL( nameDes.Length() );
       
  1140         TPtr folderIconFilePtr = iFolderIconFile->Des();
       
  1141         folderIconFilePtr.Copy( nameDes );
       
  1142         
       
  1143         resolved = ETrue;
       
  1144         }
       
  1145         
       
  1146     return resolved;
       
  1147 	
       
  1148 	}
       
  1149 
       
  1150 // -----------------------------------------------------------------------------
       
  1151 // Reads the iconindex attribute and stores the index or sets it to 0
       
  1152 // 
       
  1153 // @params aAttributes List of XML attributes
       
  1154 // @return ETrue if resolved successfully, EFalse otherwise
       
  1155 // -----------------------------------------------------------------------------
       
  1156 TInt CVcXmlParser::ResolveFolderIconIndexL( const Xml::RAttributeArray& aAttributes )
       
  1157 	{
       
  1158 	RUBY_DEBUG_BLOCKL( "CVcXmlParser::ResolveFolderIconIndexL" );
       
  1159 	
       
  1160 	TInt index = -1;
       
  1161     
       
  1162     TPtrC indexDes = Find16ValueL( KXmlFolderIconIndexAttr, aAttributes );
       
  1163     
       
  1164     if ( indexDes != KNullDesC )
       
  1165         {
       
  1166         TPtrC ptr( indexDes );
       
  1167         
       
  1168         // Do conversion from string to number
       
  1169         TLex lex( ptr );
       
  1170         TInt error = lex.Val( index );
       
  1171         if( error != KErrNone )
       
  1172         	{
       
  1173         	RUBY_ERROR1( "Converting icon index from string to int resulted in [%d]", error );
       
  1174         	index = -1;
       
  1175         	}
       
  1176         }
       
  1177         
       
  1178     return index;	
       
  1179 	}
       
  1180 
       
  1181 // End of File