csxhelp/HelpEngine/src/CSXHHTMLContentParser.cpp
branchRCL_3
changeset 5 d06b1526f62c
parent 1 27f5851bd5a5
child 11 91bbff48ea9c
equal deleted inserted replaced
1:27f5851bd5a5 5:d06b1526f62c
    21 #include "CSXHKywdTOC1.h"
    21 #include "CSXHKywdTOC1.h"
    22 #include "CSXHHtmlTOC2.h"
    22 #include "CSXHHtmlTOC2.h"
    23 #include "CSXHHelpDataBase.h"
    23 #include "CSXHHelpDataBase.h"
    24 #include "csxhconstants.h"
    24 #include "csxhconstants.h"
    25 #include "CSXHRuntimeIndexing.h"
    25 #include "CSXHRuntimeIndexing.h"
       
    26 #include "csxhviewids.h"
    26 
    27 
    27 #include <eikenv.h> 
    28 #include <eikenv.h> 
    28 #include <utf.h>
    29 #include <utf.h>
    29 #include <data_caging_path_literals.hrh>
    30 #include <data_caging_path_literals.hrh>
    30 #include <zipfile.h>
    31 #include <zipfile.h>
   106 
   107 
   107     // begin runtime index XML generating
   108     // begin runtime index XML generating
   108     //   
   109     //   
   109     iIndexing = CCSXHRuntimeIndexing::NewL();
   110     iIndexing = CCSXHRuntimeIndexing::NewL();
   110     TInt driveListSize = DirList.Length();
   111     TInt driveListSize = DirList.Length();
   111     TBool dirExists = iIndexing->IndexFileExists();
   112     TBool dirExists = iIndexing->IndexFileExistsL();
   112     CDirScan* scanner=CDirScan::NewLC(FileSession);
   113     CDirScan* scanner=CDirScan::NewLC(FileSession);
   113 #ifdef _DEBUG
   114 #ifdef _DEBUG
   114     RDebug::Print(_L("runtime indexing object successfully build"));
   115     RDebug::Print(_L("runtime indexing object successfully build"));
   115 #endif
   116 #endif
   116     for(TInt dir(0); dir < driveListSize; dir++)
   117     for(TInt dir(0); dir < driveListSize; dir++)
   122             
   123             
   123         if  ( ( error == KErrNone ) && 
   124         if  ( ( error == KErrNone ) && 
   124                 (DirList[dir] && info.iType != EMediaNotPresent))
   125                 (DirList[dir] && info.iType != EMediaNotPresent))
   125             {
   126             {
   126             RFs::DriveToChar( dir, driveLetter );
   127             RFs::DriveToChar( dir, driveLetter );
   127             TInt dirChanged = iIndexing->CheckDirChange( driveLetter );
   128             TInt dirChanged = iIndexing->CheckDirChangeL( driveLetter );
   128             rootDir->Delete( 0, rootDir->Length() );//Clear the previous contents                  
   129             rootDir->Delete( 0, rootDir->Length() );//Clear the previous contents                  
   129             rootDir->Append( driveLetter );
   130             rootDir->Append( driveLetter );
   130 
   131 
   131             if  ( dirExists 
   132             if  ( dirExists 
   132                     && ( dirChanged == KNoChange
   133                     && ( dirChanged == KNoChange
   148                     // help content folder removed due to some reason (uninstall/crash?)
   149                     // help content folder removed due to some reason (uninstall/crash?)
   149                     // delete index file in case it exist
   150                     // delete index file in case it exist
   150 #ifdef _DEBUG
   151 #ifdef _DEBUG
   151                     RDebug::Print( _L("no resource folder, delete index.xml if exists") );
   152                     RDebug::Print( _L("no resource folder, delete index.xml if exists") );
   152 #endif
   153 #endif
   153                     iIndexing->DeleteIndexFile( driveLetter );
   154                     iIndexing->DeleteIndexFileL( driveLetter );
   154                     }
   155                     }
   155                 }
   156                 }
   156             else
   157             else
   157                 {
   158                 {
   158                 // xml not exist or install/uninstall not happend
   159                 // xml not exist or install/uninstall not happend
   160                 if( GetHTMLContentPathForDriveL( rootDir,iCoeEnv ) )
   161                 if( GetHTMLContentPathForDriveL( rootDir,iCoeEnv ) )
   161                     {
   162                     {
   162 #ifdef _DEBUG
   163 #ifdef _DEBUG
   163                     RDebug::Print( _L("No index, scan folder for parsing, drive letter: %d"), dir );
   164                     RDebug::Print( _L("No index, scan folder for parsing, drive letter: %d"), dir );
   164 #endif
   165 #endif
   165                     iIndexing->BeginIndexFile( driveLetter );
   166                     iIndexing->BeginIndexFileL( driveLetter );
   166                     scanner->SetScanDataL(*rootDir
   167                     scanner->SetScanDataL(*rootDir
   167                                     ,KEntryAttDir|KEntryAttMatchExclusive,
   168                                     ,KEntryAttDir|KEntryAttMatchExclusive,
   168                                     ESortByName|EAscending, CDirScan::EScanDownTree);
   169                                     ESortByName|EAscending, CDirScan::EScanDownTree);
   169                     ScanAndParseXMLfileToCreateTOC1ObjectL(FileSession,scanner,aDataBase,
   170                     ScanAndParseXMLfileToCreateTOC1ObjectL(FileSession,scanner,aDataBase,
   170                                                         dir,XMLParser);  
   171                                                         dir,XMLParser);  
   234     TBuf<KMaxFileName> masterFile;
   235     TBuf<KMaxFileName> masterFile;
   235 
   236 
   236     iIndexing->GetPrivatePath( masterFile );
   237     iIndexing->GetPrivatePath( masterFile );
   237     masterFile.Append( aDrive );
   238     masterFile.Append( aDrive );
   238     masterFile.Append( KFwdSlash );
   239     masterFile.Append( KFwdSlash );
   239     iIndexing->AppendLocale( masterFile );
   240     iIndexing->AppendLocaleL( masterFile );
   240     masterFile.Append( KMasterMetaFile );
   241     masterFile.Append( KMasterMetaFile );
   241     if(BaflUtils::FileExists( FileSession,masterFile ) )
   242     if(BaflUtils::FileExists( FileSession,masterFile ) )
   242         {
   243         {
   243 #ifdef _DEBUG
   244 #ifdef _DEBUG
   244         RDebug::Print(_L("index exist begin to parse!    %c"), TUint( aDrive ) );
   245         RDebug::Print(_L("index exist begin to parse!    %c"), TUint( aDrive ) );
   255         iXmlReader->SetContentHandler(*aPrevHandler);
   256         iXmlReader->SetContentHandler(*aPrevHandler);
   256         CleanupStack::PopAndDestroy(masterMetaHandler);
   257         CleanupStack::PopAndDestroy(masterMetaHandler);
   257         }
   258         }
   258 
   259 
   259     return ETrue;
   260     return ETrue;
       
   261     }
       
   262 
       
   263 TBool CCSXHHTMLContentParser::IsRedirectedL(CCSXHHelpDataBase *aDataBase, 
       
   264 		                      const TDesC &aPath, TUid &aUid, TCoeContextName &aContextName)											   
       
   265     {
       
   266     RFs& FileSession = iCoeEnv->FsSession();
       
   267     TBuf<KMaxFileName> redirectFile( aPath );
       
   268     redirectFile.Append( KRedirectFile );
       
   269     TBool result = EFalse;
       
   270     
       
   271     if ( BaflUtils::FileExists( FileSession, redirectFile ) )
       
   272         {
       
   273         CCSXHXMLParseHandler_RedirectFile* XMLParser = 
       
   274                      CCSXHXMLParseHandler_RedirectFile::NewL(iCoeEnv, aUid, aContextName);
       
   275         XMLParser->SetDataBasePtr( aDataBase );
       
   276      
       
   277         CleanupStack::PushL( XMLParser );      
       
   278         InitializeReaderL( XMLParser );
       
   279         // ParseL is not in async
       
   280         iXmlReader->ParseL( FileSession, redirectFile );
       
   281         if ( XMLParser->IsTargetPathFound() )
       
   282         	{
       
   283             TBuf<KMaxFileName>& targetContextName = XMLParser->TargetContextName();
       
   284             if ( targetContextName.Length() <= aContextName.MaxLength() )
       
   285             	{
       
   286         	    aUid = XMLParser->TargetUid();
       
   287         	    aContextName = targetContextName;
       
   288         	    result = ETrue;
       
   289                 }
       
   290         	}
       
   291         CleanupStack::PopAndDestroy( XMLParser );
       
   292         ClearReader();
       
   293         }
       
   294 
       
   295     return result;
   260     }
   296     }
   261     
   297     
   262 void CCSXHHTMLContentParser::GenerateTOC2ListL(CCSXHGenericTOC1& 
   298 void CCSXHHTMLContentParser::GenerateTOC2ListL(CCSXHGenericTOC1& 
   263 aGenericTOC1Object, RPointerArray<CCSXHHelpContentBase>* GenericTOC2List)
   299 aGenericTOC1Object, RPointerArray<CCSXHHelpContentBase>* GenericTOC2List)
   264     {
   300     {
   313 
   349 
   314 void CCSXHHTMLContentParser::ScanAndParseXMLfileToCreateTOC1ObjectL(RFs& FileSession,
   350 void CCSXHHTMLContentParser::ScanAndParseXMLfileToCreateTOC1ObjectL(RFs& FileSession,
   315                                                                  CDirScan* scanner,
   351                                                                  CDirScan* scanner,
   316                                                                  CCSXHHelpDataBase* aDataBase,
   352                                                                  CCSXHHelpDataBase* aDataBase,
   317                                                                  const TInt& aDrive,
   353                                                                  const TInt& aDrive,
   318                                                                  CCSXHXMLParseHandler* XMLParser
   354                                                                  CCSXHXMLParseHandler_MetaFile* XMLParser
   319                                                                   )
   355                                                                   )
   320     {
   356     {
   321      CDir* entryList = NULL;
   357      CDir* entryList = NULL;
   322     scanner->NextL(entryList);
   358     scanner->NextL(entryList);
   323     if(!entryList)
   359     if(!entryList)
   324         return;
   360         return;
   325  
   361  
   326     CleanupStack::PushL(entryList);
   362     CleanupStack::PushL(entryList);
   327     TInt entryCount = entryList->Count();           
   363     TInt entryCount = entryList->Count();           
   328      
   364          
   329     TLinearOrder<CCSXHHelpContentBase> anOrder(Orderer<CCSXHHelpContentBase>); 
   365     TInt ROMDrive;
       
   366     RFs::CharToDrive( PathInfo::RomRootPath()[0], ROMDrive );
   330     
   367     
   331     TBuf<KMaxFileName> lookup;
   368     TBuf<KMaxFileName> lookup;
   332     
   369     
   333 
   370 
   334     while(entryCount--)
   371     while(entryCount--)
   352             {
   389             {
   353 			if(CheckFeatureIDL(XMLParser->GetFeatureIds()))
   390 			if(CheckFeatureIDL(XMLParser->GetFeatureIds()))
   354             	{            
   391             	{            
   355             	if(!IsAppUIdPresentAlready(entry.iName))
   392             	if(!IsAppUIdPresentAlready(entry.iName))
   356 					{
   393 					{
   357 		            CCSXHHtmlTOC1* CategoryObj = CCSXHHtmlTOC1::NewL(
   394 					CCSXHHtmlTOC1* CategoryObj = NULL;
   358 		                                        XMLParser->GetApplicationName(),entry.iName,aDrive);
   395 		            TBool duplicateToc = EFalse;
   359 		            if ( !CategoryObj )
   396 		            
       
   397 		            TInt32 priority = XMLParser->Priority();
       
   398 		            // Now we take a walk if it's application helps (priority == 0)
       
   399 		           
       
   400 		            if ( (priority != 0) 
       
   401 		            	&& ( ( aDrive == ROMDrive ) || IsRomBasedContentL( FileSession, entry.iName ) ) )
   360 		                {
   402 		                {
   361 		                continue;
   403 		                if ( priority < KHighestPriority )
       
   404 		                	{
       
   405 		                    priority = KHighestPriority;
       
   406 		                	}
       
   407 		                else if ( priority > KLowestPriority )
       
   408 		                	{
       
   409 		                    priority = KLowestPriority;
       
   410 		                	}
       
   411 		                
       
   412 		                CategoryObj = CCSXHHtmlTOC1::NewL(
       
   413 		                		           XMLParser->GetApplicationName(),entry.iName,aDrive, 
       
   414 		                		           KCSXHToc2ViewID, priority);
       
   415 		                if(CategoryObj && aDataBase->GetMainTopics()->InsertChildWithPriority(CategoryObj,EFalse))
       
   416 		            	    iHtmlTOC1List.Append(CategoryObj);//Keep a local copy 
       
   417 		                else
       
   418 		                    duplicateToc = ETrue;
   362 		                }
   419 		                }
   363 		            iIndexing->RuntimeGenerateIndexL( *CategoryObj, XMLParser->GetFeatureIds() );
   420 		            else 
   364 		            if(CategoryObj && aDataBase->GetMainTopics()->InsertChild(CategoryObj,EFalse))
   421 		           		{
   365 		            	iHtmlTOC1List.Append(CategoryObj);//Keep a local copy*/ 
   422 		           		CategoryObj = CCSXHHtmlTOC1::NewL(
   366 					else
   423 		           		                    XMLParser->GetApplicationName(),entry.iName, aDrive, 
   367 						{
   424 		           		                    KCSXHToc2AppHelpsViewID, 0);
   368 						if(CategoryObj)  
   425 		           		               
   369 		            		iDuplicateHelpTopicList.Append(CategoryObj);	
   426 		           		if(CategoryObj && aDataBase->GetAppHelpsTopics()->InsertChild(CategoryObj,EFalse))
   370 						}			            	
   427 		                                    iHtmlTOC1List.Append(CategoryObj);//Keep a local copy 
   371 					}
   428 		           		else
       
   429 		           		    duplicateToc = ETrue;
       
   430 		           		}
       
   431 		            if ( CategoryObj )
       
   432 		            	{
       
   433 		                iIndexing->RuntimeGenerateIndexL( *CategoryObj, XMLParser->GetFeatureIds() );
       
   434 
       
   435                         if( duplicateToc )
       
   436                         	{
       
   437                             iDuplicateHelpTopicList.Append(CategoryObj);
       
   438                         	}
       
   439 		            	}
       
   440 		            }
   372             	}         
   441             	}         
   373             }
   442             }
   374         }       
   443         }       
   375 
   444 
   376     CleanupStack::PopAndDestroy(entryList);
   445     CleanupStack::PopAndDestroy(entryList);
   377     }
   446     }
       
   447 TBool CCSXHHTMLContentParser::IsRomBasedContentL( RFs& FileSession, const TDesC &aUid )
       
   448     {
       
   449 #ifdef __WINSCW__
       
   450     return ETrue;
       
   451 #endif
       
   452     
       
   453 	TBool result = EFalse;
       
   454 	CDirScan* scanner=CDirScan::NewLC(FileSession);
       
   455 	TBuf<KMaxFileName> rootDir;
       
   456 	rootDir.Append( 'z' );
       
   457 	        	
       
   458 	if( GetHTMLContentPathForDriveL( &rootDir,iCoeEnv ) )
       
   459 		{
       
   460 	    scanner->SetScanDataL(rootDir,KEntryAttDir|KEntryAttMatchExclusive,
       
   461 	                                    ESortByName|EAscending, CDirScan::EScanDownTree);
       
   462         CDir* entryList = NULL;
       
   463         scanner->NextL(entryList);
       
   464     
       
   465         if ( !entryList )
       
   466         	{
       
   467             CleanupStack::PopAndDestroy( scanner );
       
   468             return EFalse;
       
   469         	}
       
   470  
       
   471         TInt entryCount = entryList->Count();           
       
   472     
       
   473         while ( entryCount-- )
       
   474             {
       
   475             TEntry entry=(*entryList)[entryCount]; 
       
   476             if ( ( entry.iName ).CompareC(aUid) == 0 )
       
   477         	    {
       
   478                 result = ETrue;
       
   479             	break;
       
   480         	    }
       
   481             }
       
   482         delete entryList;
       
   483 		}
       
   484     
       
   485     CleanupStack::PopAndDestroy( scanner );
       
   486  
       
   487     return result;
       
   488     }
   378     
   489     
   379 void CCSXHHTMLContentParser::InsertHTMLToc1L(
   490 void CCSXHHTMLContentParser::InsertHTMLToc1L(
   380             const TDesC &appUidName,const TDesC &appName, 
   491             const TDesC &appUidName,const TDesC &appName, 
   381             const TInt& aDrive , CCSXHHelpDataBase* aDataBase, const TDesC &FeatureIds)
   492             const TInt& aDrive , CCSXHHelpDataBase* aDataBase, 
       
   493             const TDesC &FeatureIds, TInt32 aPriority )
   382     {
   494     {
   383 	if(CheckFeatureIDL(FeatureIds))
   495 	if(CheckFeatureIDL(FeatureIds))
   384 	    {
   496 	    {
   385 	    if(!IsAppUIdPresentAlready(appUidName)) 
   497 	    if(!IsAppUIdPresentAlready(appUidName)) 
   386 		    {    
   498             {    
   387 			CCSXHHtmlTOC1* CategoryObj = CCSXHHtmlTOC1::NewL(appName,appUidName,aDrive);
   499             CCSXHHtmlTOC1* CategoryObj = NULL;
   388 		    if(CategoryObj && aDataBase->GetMainTopics()->InsertChild(CategoryObj,EFalse))
   500             TBool duplicateToc = EFalse;
   389 		    	iHtmlTOC1List.Append(CategoryObj);//Keep a local copy*/ 
   501             // Now we take a walk if it's application helps (priority == 0)
   390 		    else
   502             if ( aPriority == 0 )
   391 		    	{
   503                 {
   392 		    	if(CategoryObj)  
   504                 CategoryObj = CCSXHHtmlTOC1::NewL(appName,appUidName,aDrive,
   393 	           		iDuplicateHelpTopicList.Append(CategoryObj);			    	
   505                 		                          KCSXHToc2AppHelpsViewID,aPriority);
   394 		    	}
   506                 // Hardcode EDriveZ as ROM drive, need to be runtime check?
       
   507                 if(CategoryObj && aDataBase->GetAppHelpsTopics()->InsertChild(CategoryObj,EFalse))
       
   508                     iHtmlTOC1List.Append(CategoryObj);//Keep a local copy 
       
   509                 else
       
   510                     duplicateToc = ETrue;
       
   511                 }
       
   512             else
       
   513                 {
       
   514                 CategoryObj = CCSXHHtmlTOC1::NewL(appName,appUidName,aDrive,
       
   515                 		                          KCSXHToc2ViewID,aPriority);
       
   516                 if(CategoryObj && aDataBase->GetMainTopics()->InsertChildWithPriority(CategoryObj,EFalse))
       
   517                     iHtmlTOC1List.Append(CategoryObj);//Keep a local copy*/ 
       
   518                 else
       
   519                     duplicateToc = ETrue;
       
   520                 }
       
   521 
       
   522             if( CategoryObj && duplicateToc )  
       
   523                 iDuplicateHelpTopicList.Append(CategoryObj);			    	
   395 		    }
   524 		    }
   396 	    }	
   525 	    }	
   397     }
   526     }
   398     
   527     
   399 HBufC8* CCSXHHTMLContentParser::GetContentsFromFileL(const TDesC& htmlFile,CCoeEnv* aCoeEnv,
   528 HBufC8* CCSXHHTMLContentParser::GetContentsFromFileL(const TDesC& htmlFile,CCoeEnv* aCoeEnv,
   571     CleanupStack::PopAndDestroy(lookup);
   700     CleanupStack::PopAndDestroy(lookup);
   572     CleanupStack::PopAndDestroy(XMLParser);  
   701     CleanupStack::PopAndDestroy(XMLParser);  
   573     ClearReader();
   702     ClearReader();
   574     }
   703     }
   575     
   704     
   576 CCSXHHelpContentBase* CCSXHHTMLContentParser::GetContextTopic
   705 CCSXHHelpContentBase* CCSXHHTMLContentParser::GetContextTopicL( 
   577 (const TUid& aUid, const TDesC& contextName)
   706 		CCSXHHelpDataBase *aDataBase, 
   578     {
   707 		TUid &aUid, 
   579     int toc1Count = iHtmlTOC1List.Count();
   708 		TCoeContextName &aContextName
   580     CCSXHHtmlTOC1* toc1,*temptoc1;
   709 		)
   581     
   710     {
   582     for(int i = 0; i < toc1Count; ++i)
   711     TBuf<KMaxFileName> path;
       
   712     TInt32 toc1Count = iHtmlTOC1List.Count();
       
   713     TInt32 dupToc1Count = iDuplicateHelpTopicList.Count();
       
   714     CCSXHHtmlTOC1 *toc1 = NULL;
       
   715     CCSXHHtmlTOC1 *temptoc1 = NULL;
       
   716     TBool redirected = EFalse;
       
   717     
       
   718     for ( TInt32 i = 0; i < toc1Count; ++i )
   583         {
   719         {
   584         toc1 = iHtmlTOC1List[i];
   720         toc1 = iHtmlTOC1List[i];
   585         if(aUid == toc1->GetAppUid())
   721         if ( aUid == toc1->GetAppUid() )
   586             {
   722             {
   587             return toc1->GetContextTopic(contextName);      
   723             toc1->GetHelpFileL( path );
       
   724             if ( IsRedirectedL( aDataBase, path, aUid, aContextName ) )
       
   725             	{
       
   726                 redirected = ETrue;
       
   727             	}
       
   728             else
       
   729             	{
       
   730                 return toc1->GetContextTopic( aContextName );
       
   731             	}
       
   732             break;
   588             }
   733             }
   589         }
   734         }
   590         
   735     
   591     toc1Count = iDuplicateHelpTopicList.Count();
   736     if ( !redirected )
   592 	for(int i = 0; i < toc1Count; ++i)
   737         {
   593 		{
   738         for ( TInt32 i = 0; i < dupToc1Count; ++i )
   594 		toc1 = iDuplicateHelpTopicList[i];
   739             {
   595         if(aUid == toc1->GetAppUid())
   740     	    toc1 = iDuplicateHelpTopicList[i];
   596         	{
   741     	    if ( aUid == toc1->GetAppUid() )
   597     		temptoc1 = GetCorrespondingTOC1FromMainArray(toc1->GetName());        		
   742     	        {
   598     		return temptoc1->GetContextTopic(contextName);
   743     	        toc1->GetHelpFileL( path );
   599         	}
   744     	        if ( IsRedirectedL( aDataBase, path, aUid, aContextName ) )
   600 		}    
   745     	            {
       
   746     	            redirected = ETrue;
       
   747     	            }
       
   748     	        else
       
   749     	            {
       
   750     	            temptoc1 = GetCorrespondingTOC1FromMainArray(toc1->GetName());        		
       
   751     	            return temptoc1->GetContextTopic( aContextName );
       
   752     	            }
       
   753     	        }
       
   754             }
       
   755         }
       
   756     	
       
   757     if ( redirected )
       
   758     	{
       
   759     	for ( TInt32 i = 0; i < toc1Count; ++i )
       
   760     	    {
       
   761     	    toc1 = iHtmlTOC1List[i];
       
   762     	    if ( aUid == toc1->GetAppUid() )
       
   763     	        {    
       
   764     	        return toc1->GetContextTopic( aContextName );
       
   765     	        }
       
   766     	    }
       
   767     	
       
   768     	for ( TInt32 i = 0; i < dupToc1Count; ++i )
       
   769     	    {
       
   770     	    toc1 = iDuplicateHelpTopicList[i];
       
   771     	    if ( aUid == toc1->GetAppUid() )
       
   772     	        {
       
   773     	    	temptoc1 = GetCorrespondingTOC1FromMainArray( toc1->GetName() );        		
       
   774     	    	return temptoc1->GetContextTopic( aContextName );
       
   775     	    	}
       
   776     	    }
       
   777     	}
       
   778         
   601     return NULL;
   779     return NULL;
   602     }
   780     }
   603     
   781     
   604 CCSXHHelpContentBase* CCSXHHTMLContentParser::GetHtmlTopicForUrlL(const TDesC& aUrl)
   782 CCSXHHelpContentBase* CCSXHHTMLContentParser::GetHtmlTopicForUrlL(const TDesC& aUrl)
   605     {
   783     {