contentstorage/casrv/cawidgetscanner/src/cawidgetscannerparser.cpp
changeset 93 82b66994846c
parent 92 782e3408c2ab
child 94 dbb8300717f7
equal deleted inserted replaced
92:782e3408c2ab 93:82b66994846c
    22 #include <xmlengnodelist.h>
    22 #include <xmlengnodelist.h>
    23 #include <xmlengdomparser.h>
    23 #include <xmlengdomparser.h>
    24 #include <xmlengdocument.h>
    24 #include <xmlengdocument.h>
    25 #include <utf.h>
    25 #include <utf.h>
    26 
    26 
       
    27 #include "cadef.h"
    27 #include "cawidgetscannerparser.h"
    28 #include "cawidgetscannerparser.h"
    28 #include "widgetscannerutils.h"
    29 #include "widgetscannerutils.h"
    29 
    30 
    30 // CONSTANTS
    31 // CONSTANTS
    31 
    32 
    44 _LIT8(KLibrary, "library" );
    45 _LIT8(KLibrary, "library" );
    45 _LIT8(KTitle, "title" );
    46 _LIT8(KTitle, "title" );
    46 _LIT8(KDescription, "description" );
    47 _LIT8(KDescription, "description" );
    47 _LIT8(KHidden, "hidden" );
    48 _LIT8(KHidden, "hidden" );
    48 _LIT8(KIconUri, "iconuri" );
    49 _LIT8(KIconUri, "iconuri" );
    49 
    50 _LIT8(KWidgetProvider, "widgetprovider");
       
    51 
       
    52 _LIT8(KWidgetManifest, "hswidgetmanifest");
       
    53 _LIT8(KIcon, "icon");
       
    54 _LIT8(KServiceXml, "servicexml");
    50 
    55 
    51 // ============================ MEMBER FUNCTIONS ===============================
    56 // ============================ MEMBER FUNCTIONS ===============================
    52 
    57 
    53 // -----------------------------------------------------------------------------
    58 // -----------------------------------------------------------------------------
    54 // CCaWidgetScannerParser::CCaWidgetScannerParser
    59 // CCaWidgetScannerParser::CCaWidgetScannerParser
   103 // Destructor
   108 // Destructor
   104 // -----------------------------------------------------------------------------
   109 // -----------------------------------------------------------------------------
   105 //
   110 //
   106 CCaWidgetScannerParser::~CCaWidgetScannerParser()
   111 CCaWidgetScannerParser::~CCaWidgetScannerParser()
   107     {
   112     {
       
   113     delete iWidgetDescriptor;
   108     iImportPath.Close();
   114     iImportPath.Close();
   109     iWidgets.ResetAndDestroy();
   115     iWidgets.ResetAndDestroy();
   110     iDomImpl.Close();
   116     iDomImpl.Close();
   111     }
   117     }
   112 
   118 
   198     RXmlEngDOMParser parser;
   204     RXmlEngDOMParser parser;
   199     CleanupClosePushL(parser);
   205     CleanupClosePushL(parser);
   200     User::LeaveIfError(parser.Open(iDomImpl));
   206     User::LeaveIfError(parser.Open(iDomImpl));
   201     RXmlEngDocument doc = parser.ParseFileL(aFilePath, KChunkSize);
   207     RXmlEngDocument doc = parser.ParseFileL(aFilePath, KChunkSize);
   202     CleanupClosePushL(doc);
   208     CleanupClosePushL(doc);
   203     TXmlEngElement docElement = doc.AsElement();
   209     TXmlEngElement docElement = doc.DocumentElement();
   204     TXmlEngElement element;
   210 
   205     RXmlEngNodeList<TXmlEngElement> elementList;
   211     if (docElement.Name() == KWidgetProvider) {
   206     CleanupClosePushL(elementList);
   212         TXmlEngElement element;
   207 
   213         RXmlEngNodeList<TXmlEngElement> elementList;
   208     element = docElement.FirstChild().AsElement();
   214         CleanupClosePushL(elementList);
   209     element.GetElementsByTagNameL(elementList, KWidget);
   215         docElement.GetElementsByTagNameL(elementList, KWidget);
   210 
   216 
   211     while (elementList.HasNext())
   217         while (elementList.HasNext())
   212         {
       
   213         element = elementList.Next();
       
   214         if ( element.HasAttributes() )
       
   215             {
   218             {
   216             ParseWidgetL( aFilePath, element, aPackageUid );
   219             element = elementList.Next();
       
   220             if ( element.HasAttributes() )
       
   221                 {
       
   222                 ParseWidgetL( aFilePath, element, aPackageUid );
       
   223                 }
   217             }
   224             }
   218         }
   225         CleanupStack::PopAndDestroy(&elementList);
   219     CleanupStack::PopAndDestroy(&elementList);
   226     } else if (docElement.Name() == KWidgetManifest) {
       
   227 
       
   228         delete iWidgetDescriptor;
       
   229         iWidgetDescriptor = NULL;
       
   230         iWidgetDescriptor = CCaWidgetDescription::NewL();
       
   231         iWidgetDescriptor->SetPackageUidL(aPackageUid);
       
   232         iWidgetDescriptor->SetVisible(ETrue);
       
   233 
       
   234 
       
   235         SetMmcIdL( iWidgetDescriptor );
       
   236 
       
   237         RXmlEngNodeList<TXmlEngElement> childElementList;
       
   238         CleanupClosePushL(childElementList);
       
   239         docElement.GetChildElements(childElementList);
       
   240         TXmlEngElement element;
       
   241         while (childElementList.HasNext())
       
   242           {
       
   243           element = childElementList.Next();
       
   244           if (element.Name() == KUri)
       
   245               {
       
   246               ParseUriL(element);
       
   247               }
       
   248           else if (element.Name() == KTitle)
       
   249               {
       
   250               ParseTitleL(element);
       
   251               }
       
   252           else if (element.Name() == KIcon)
       
   253               {
       
   254               ParseIconL(element,aPackageUid);
       
   255               }
       
   256           else if (element.Name() == KDescription)
       
   257               {
       
   258               ParseDescriptionL(element);
       
   259               }
       
   260           else if (element.Name() == KHidden)
       
   261               {
       
   262               ParseHiddenL(element);
       
   263               }
       
   264           else if (element.Name() == KServiceXml)
       
   265               {
       
   266               ParseServiceXmlL(element);
       
   267               }
       
   268            }
       
   269         CleanupStack::PopAndDestroy(&childElementList);
       
   270 
       
   271         //set path for hs to use, trim last 2 chars (doubleslash)
       
   272         HBufC *libraryPath = GetManifestDirectoryPathLC( aPackageUid );
       
   273         iWidgetDescriptor->SetPathL(libraryPath->Mid(0,libraryPath->Length()-1));
       
   274         CleanupStack::PopAndDestroy(libraryPath);
       
   275         
       
   276         HBufC *libraryPath2 = GetManifestDirectoryPathLC( aPackageUid );
       
   277         libraryPath2 = libraryPath2->ReAllocL(libraryPath2->Length() + iWidgetDescriptor->GetUri().Length());
       
   278         CleanupStack::Pop(1);
       
   279         CleanupStack::PushL(libraryPath2);
       
   280         libraryPath2->Des().Append(iWidgetDescriptor->GetUri());
       
   281         iWidgetDescriptor->SetLibraryL(*libraryPath2);
       
   282         CleanupStack::PopAndDestroy(libraryPath2);
       
   283         
       
   284                 
       
   285         TTime modificationTime;
       
   286         iFs.Modified( aFilePath, modificationTime);
       
   287         TInt64 modificationIntTime = modificationTime.Int64();
       
   288         RBuf16 rBuf;
       
   289         rBuf.CleanupClosePushL();
       
   290         rBuf.CreateL( KModificationTimeLength );
       
   291         rBuf.AppendNum( modificationIntTime );
       
   292         iWidgetDescriptor->SetModificationTimeL( rBuf );
       
   293         CleanupStack::PopAndDestroy( &rBuf );
       
   294 
       
   295         TInt index = iWidgets.Find( iWidgetDescriptor, CCaWidgetDescription::Compare );
       
   296         if ( index != KErrNotFound )
       
   297             {
       
   298             delete iWidgets[index];
       
   299             iWidgets.Remove( index );
       
   300             }
       
   301         iWidgets.AppendL( iWidgetDescriptor );//ownership transfer
       
   302         iWidgetDescriptor = NULL;
       
   303     }
       
   304 
   220     CleanupStack::PopAndDestroy(&doc);
   305     CleanupStack::PopAndDestroy(&doc);
   221     CleanupStack::PopAndDestroy(&parser);
   306     CleanupStack::PopAndDestroy(&parser);
   222     }
   307     }
   223 
   308 
   224 // ----------------------------------------------------------------------------
   309 // ----------------------------------------------------------------------------
   362 
   447 
   363     if( hidden->Compare( KTrue ) == 0 )
   448     if( hidden->Compare( KTrue ) == 0 )
   364         {
   449         {
   365         aWidget->SetVisible( EFalse );
   450         aWidget->SetVisible( EFalse );
   366         }
   451         }
       
   452     else
       
   453         {
       
   454         aWidget->SetVisible( ETrue );
       
   455         }
   367     CleanupStack::PopAndDestroy( hidden );
   456     CleanupStack::PopAndDestroy( hidden );
   368 }
   457 }
   369 
   458 
   370 // ----------------------------------------------------------------------------
   459 // ----------------------------------------------------------------------------
   371 //
   460 //
   401 {
   490 {
   402     TChar removableDrive;
   491     TChar removableDrive;
   403     User::LeaveIfError( DriveInfo::GetDefaultDrive(
   492     User::LeaveIfError( DriveInfo::GetDefaultDrive(
   404                 DriveInfo::EDefaultRemovableMassStorage, removableDrive ) );
   493                 DriveInfo::EDefaultRemovableMassStorage, removableDrive ) );
   405 
   494 
       
   495     TChar massStorageDrive;
       
   496     User::LeaveIfError( DriveInfo::GetDefaultDrive(
       
   497                 DriveInfo::EDefaultMassStorage, massStorageDrive ) );
   406     if( iCurrentDriveLetter == removableDrive )
   498     if( iCurrentDriveLetter == removableDrive )
   407         {
   499         {
   408         widget->SetMmcId( WidgetScannerUtils::CurrentMmcId( iFs ) );
   500         RBuf mmcId;
       
   501         mmcId.CreateL(KMassStorageIdLength);
       
   502         mmcId.CleanupClosePushL();
       
   503         WidgetScannerUtils::CurrentMmcId( iFs, mmcId );
       
   504         widget->SetMmcIdL( mmcId );
       
   505         CleanupStack::PopAndDestroy( &mmcId );
       
   506         }
       
   507     else if( iCurrentDriveLetter == massStorageDrive )
       
   508         {
       
   509         widget->SetMmcIdL( KCaMassStorage );
   409         }
   510         }
   410 }
   511 }
   411 
   512 
   412 // ----------------------------------------------------------------------------
   513 // ----------------------------------------------------------------------------
   413 //
   514 //
   427 //
   528 //
   428 // ----------------------------------------------------------------------------
   529 // ----------------------------------------------------------------------------
   429 //
   530 //
   430 HBufC* CCaWidgetScannerParser::FullPathLC( )
   531 HBufC* CCaWidgetScannerParser::FullPathLC( )
   431     {
   532     {
   432     HBufC* result = HBufC16::NewLC( iImportPath.Length() + KDriveLetterLength );
   533     HBufC* result =
       
   534         HBufC16::NewLC( iImportPath.Length() + KDriveLetterLength );
   433     TPtr modifier( result->Des() );
   535     TPtr modifier( result->Des() );
   434     modifier.Append( iCurrentDriveLetter );
   536     modifier.Append( iCurrentDriveLetter );
   435     modifier.Append( KColen );
   537     modifier.Append( KColen );
   436     modifier.Append( iImportPath );
   538     modifier.Append( iImportPath );
   437     return result;
   539     return result;
   452     modifier.Append( aDirectoryName );
   554     modifier.Append( aDirectoryName );
   453     modifier.Append( KDoubleSlash );
   555     modifier.Append( KDoubleSlash );
   454     return result;
   556     return result;
   455     }
   557     }
   456 
   558 
       
   559 void CCaWidgetScannerParser::ParseUriL(TXmlEngElement & aElement)
       
   560     {
       
   561     if (aElement.Text().Length())
       
   562         {
       
   563         HBufC *utf16 =
       
   564             CnvUtfConverter::ConvertToUnicodeFromUtf8L( aElement.Text() );
       
   565         CleanupStack::PushL( utf16 );
       
   566         iWidgetDescriptor->SetUriL( *utf16 );
       
   567         CleanupStack::PopAndDestroy( utf16 );
       
   568         }
       
   569 
       
   570     }
       
   571 void CCaWidgetScannerParser::ParseTitleL(TXmlEngElement & aElement)
       
   572     {
       
   573     if (aElement.Text().Length())
       
   574         {
       
   575         HBufC *utf16 =
       
   576             CnvUtfConverter::ConvertToUnicodeFromUtf8L( aElement.Text() );
       
   577         CleanupStack::PushL( utf16 );
       
   578         iWidgetDescriptor->SetTitleL( *utf16 );
       
   579         CleanupStack::PopAndDestroy( utf16 );
       
   580         }
       
   581     }
       
   582 void CCaWidgetScannerParser::ParseIconL(TXmlEngElement & aElement,
       
   583     const TDesC & aPackageUid )
       
   584     {
       
   585     HBufC *utf16 =
       
   586         CnvUtfConverter::ConvertToUnicodeFromUtf8L( aElement.Text() );
       
   587     CleanupStack::PushL( utf16 );
       
   588     if ( utf16->Compare( KNullDesC ) )
       
   589         {
       
   590         HBufC* iconUriPath = GetManifestDirectoryPathLC( aPackageUid );
       
   591         iconUriPath = iconUriPath->ReAllocL( iconUriPath->Length() + utf16->Length() );
       
   592         CleanupStack::Pop(1);
       
   593         CleanupStack::PushL(iconUriPath);
       
   594         TPtr iconUriPathModifier( iconUriPath->Des() );
       
   595         iconUriPathModifier.Append( *utf16 );
       
   596         iWidgetDescriptor->SetIconUriL( *iconUriPath );
       
   597         CleanupStack::PopAndDestroy( iconUriPath );
       
   598         }
       
   599 
       
   600     CleanupStack::PopAndDestroy( utf16 );
       
   601     }
       
   602 
       
   603 void CCaWidgetScannerParser::ParseDescriptionL(TXmlEngElement & aElement)
       
   604     {
       
   605     HBufC *desc =
       
   606         CnvUtfConverter::ConvertToUnicodeFromUtf8L( aElement.Text() );
       
   607     CleanupStack::PushL( desc );
       
   608 
       
   609     if( desc->Compare( KNullDesC ) != 0 )
       
   610        {
       
   611        iWidgetDescriptor->SetDescriptionL( *desc );
       
   612        }
       
   613     CleanupStack::PopAndDestroy( desc );
       
   614     }
       
   615 void CCaWidgetScannerParser::ParseHiddenL( TXmlEngElement& aElement )
       
   616     {
       
   617     if( aElement.Text().Compare( _L8("true") ) == 0 )
       
   618         {
       
   619         iWidgetDescriptor->SetVisible( EFalse );
       
   620         }
       
   621 
       
   622     }
       
   623 void CCaWidgetScannerParser::ParseServiceXmlL( TXmlEngElement& aElement )
       
   624     {
       
   625     HBufC *serviceXml = CnvUtfConverter::ConvertToUnicodeFromUtf8L( aElement.Text() );
       
   626     CleanupStack::PushL( serviceXml );
       
   627        
       
   628     if (serviceXml->Compare(KNullDesC) != 0)
       
   629         {
       
   630         iWidgetDescriptor->SetServiceXmlL( *serviceXml );
       
   631         }
       
   632     CleanupStack::PopAndDestroy( serviceXml );
       
   633     }
   457 //  End of File
   634 //  End of File