csxhelp/HelpEngine/src/CSXHHTMLContentParser.cpp
branchRCL_3
changeset 44 12f60d9a73b3
parent 40 0d1adf67ec1b
child 45 cbffe13eac63
equal deleted inserted replaced
40:0d1adf67ec1b 44:12f60d9a73b3
     1 /*
       
     2 * Copyright (c) 2006 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:  CCSXHHTMLContentParser class definition
       
    15 *
       
    16 */
       
    17 
       
    18 #include "CSXHHTMLContentParser.h"
       
    19 #include "CSXHXMLParseHandler.h"
       
    20 #include "CSXHHtmlTOC1.h"
       
    21 #include "CSXHKywdTOC1.h"
       
    22 #include "CSXHHtmlTOC2.h"
       
    23 #include "CSXHHelpDataBase.h"
       
    24 #include "csxhconstants.h"
       
    25 #include "CSXHRuntimeIndexing.h"
       
    26 #include "CSXHViewIDs.h"
       
    27 
       
    28 #include <eikenv.h> 
       
    29 #include <utf.h>
       
    30 #include <data_caging_path_literals.hrh>
       
    31 #include <zipfile.h>
       
    32 #include <bautils.h>
       
    33 #include <SenXmlReader.h> 
       
    34 #include <f32file.h>
       
    35 #include <pathinfo.h> 
       
    36 
       
    37 //Input Language variation changes
       
    38 #include <PtiEngine.h>
       
    39 
       
    40 const TInt KOffset = 2;
       
    41         
       
    42 CCSXHHTMLContentParser* CCSXHHTMLContentParser::NewL(CCoeEnv* aCoeEnv)
       
    43     {
       
    44     CCSXHHTMLContentParser* self = CCSXHHTMLContentParser::NewLC(aCoeEnv);
       
    45     CleanupStack::Pop(self);
       
    46     return self;
       
    47     }
       
    48     
       
    49 CCSXHHTMLContentParser* CCSXHHTMLContentParser::NewLC(CCoeEnv* aCoeEnv)
       
    50     {
       
    51     CCSXHHTMLContentParser* self = new (ELeave) CCSXHHTMLContentParser(aCoeEnv);
       
    52     CleanupStack::PushL(self);
       
    53     self->ConstructL();
       
    54     return self;
       
    55     }
       
    56     
       
    57 void CCSXHHTMLContentParser::ConstructL()
       
    58     {
       
    59     //RUNTIME
       
    60     GetSupportedFeatureListL();
       
    61     }
       
    62     
       
    63 CCSXHHTMLContentParser::CCSXHHTMLContentParser(CCoeEnv* aCoeEnv) : iCoeEnv(aCoeEnv)
       
    64     {
       
    65     }
       
    66     
       
    67 CCSXHHTMLContentParser::~CCSXHHTMLContentParser()
       
    68     {
       
    69     delete iXmlReader;
       
    70     
       
    71     //No need to delete the entries here, it will be done by the database
       
    72     iHtmlTOC1List.Close();
       
    73     
       
    74     //Delete all contents from the array.
       
    75     TInt count =    iDuplicateHelpTopicList.Count();
       
    76     CCSXHHtmlTOC1* toc1;
       
    77     for(TInt i=0;i<count;++i )
       
    78         {
       
    79         toc1 = iDuplicateHelpTopicList[i];
       
    80         delete toc1;
       
    81         }
       
    82     iDuplicateHelpTopicList.Reset();    
       
    83     iDuplicateHelpTopicList.Close();
       
    84     
       
    85     // Closes the array and frees all memory allocated to the array.
       
    86    // iSupportedFeatures.Close();
       
    87     
       
    88     delete iSupportedInputLanguages;
       
    89     delete iFeatureManager_FeatureIds;
       
    90     delete iIndexing;
       
    91     }
       
    92     
       
    93 void CCSXHHTMLContentParser::GenerateTOC1ListL(CCSXHHelpDataBase* aDataBase)
       
    94     {       
       
    95     RFs& FileSession = iCoeEnv->FsSession();
       
    96 
       
    97     TDriveList DirList; 
       
    98     if(FileSession.DriveList(DirList) != KErrNone)
       
    99         return; 
       
   100     CCSXHXMLParseHandler_MetaFile* XMLParser = CCSXHXMLParseHandler_MetaFile::NewL(iCoeEnv); 
       
   101     CleanupStack::PushL(XMLParser);   
       
   102     InitializeReaderL(XMLParser);
       
   103     
       
   104       
       
   105     TBuf<KMaxFileName>* rootDir = new(ELeave) TBuf<KMaxFileName>;
       
   106     CleanupStack::PushL(rootDir);//5
       
   107 
       
   108     // begin runtime index XML generating
       
   109     //   
       
   110     iIndexing = CCSXHRuntimeIndexing::NewL();
       
   111     TInt driveListSize = DirList.Length();
       
   112     TBool dirExists = iIndexing->IndexFileExistsL();
       
   113     CDirScan* scanner=CDirScan::NewLC(FileSession);
       
   114 #ifdef _DEBUG
       
   115     RDebug::Print(_L("runtime indexing object successfully build"));
       
   116 #endif
       
   117     for(TInt dir(0); dir < driveListSize; dir++)
       
   118         {
       
   119         TInt error;
       
   120         TDriveInfo info;
       
   121         TChar driveLetter = '?';
       
   122         error = FileSession.Drive(info, dir);
       
   123             
       
   124         if  ( ( error == KErrNone ) && 
       
   125                 (DirList[dir] && info.iType != EMediaNotPresent))
       
   126             {
       
   127             RFs::DriveToChar( dir, driveLetter );
       
   128             TInt dirChanged = iIndexing->CheckDirChangeL( driveLetter );
       
   129             rootDir->Delete( 0, rootDir->Length() );//Clear the previous contents                  
       
   130             rootDir->Append( driveLetter );
       
   131 
       
   132             if  ( dirExists 
       
   133                     && ( dirChanged == KNoChange
       
   134                         || dirChanged == KNoDirExist) )
       
   135                 {
       
   136                 // xml exist and no install/uninstall happened
       
   137                 // while Z needs special process once its index file exists
       
   138 #ifdef _DEBUG
       
   139                 RDebug::Print(_L("Used to launch, scan drive number:  %d"), dir);
       
   140 #endif
       
   141                 if ( dirChanged == KNoChange )
       
   142                     {
       
   143                     // no modify helps, so just parse index.xml
       
   144                     //
       
   145                     HandleMasterMetaFileL( aDataBase, driveLetter, XMLParser );
       
   146                     }
       
   147                 else // KNoDirExist
       
   148                     {
       
   149                     // help content folder removed due to some reason (uninstall/crash?)
       
   150                     // delete index file in case it exist
       
   151 #ifdef _DEBUG
       
   152                     RDebug::Print( _L("no resource folder, delete index.xml if exists") );
       
   153 #endif
       
   154                     iIndexing->DeleteIndexFileL( driveLetter );
       
   155                     }
       
   156                 }
       
   157             else
       
   158                 {
       
   159                 // xml not exist or install/uninstall not happend
       
   160                 //
       
   161                 if( GetHTMLContentPathForDriveL( rootDir,iCoeEnv ) )
       
   162                     {
       
   163 #ifdef _DEBUG
       
   164                     RDebug::Print( _L("No index, scan folder for parsing, drive letter: %d"), dir );
       
   165 #endif
       
   166                     iIndexing->BeginIndexFileL( driveLetter );
       
   167                     scanner->SetScanDataL(*rootDir
       
   168                                     ,KEntryAttDir|KEntryAttMatchExclusive,
       
   169                                     ESortByName|EAscending, CDirScan::EScanDownTree);
       
   170                     ScanAndParseXMLfileToCreateTOC1ObjectL(FileSession,scanner,aDataBase,
       
   171                                                         dir,XMLParser);  
       
   172                                                         
       
   173                     iIndexing->FinishAndCloseIndexFileL();
       
   174                     
       
   175                     }
       
   176                 
       
   177                 }
       
   178 
       
   179             }
       
   180         }
       
   181     CleanupStack::PopAndDestroy( scanner );
       
   182     CleanupStack::PopAndDestroy(rootDir);
       
   183     CleanupStack::PopAndDestroy(XMLParser);
       
   184     
       
   185     ClearReader();
       
   186     }
       
   187 
       
   188 TBool CCSXHHTMLContentParser::GetHTMLContentPathForDriveL(TBuf<KMaxFileName>* aContentDrive,CCoeEnv *aCoeEnv)
       
   189     {
       
   190     // get the path to language level
       
   191     // Input: aContentDrive == C or E or Z
       
   192     // Output: aContentDrive == C:\\resource\\xhtml\\01\\ (or Z:\\resource\\xhtml\\31\\)
       
   193     //
       
   194     aContentDrive->Append(KXhtmlFolder);
       
   195     TInt len = aContentDrive->Length();
       
   196     RFs& FileSession = aCoeEnv->FsSession();
       
   197     RArray<TLanguage> langs;
       
   198        BaflUtils::GetDowngradePathL(FileSession,User::Language(),langs);
       
   199             
       
   200     for(int i = 0; i < langs.Count(); ++i)
       
   201         {
       
   202         TLanguage lang = langs[i];
       
   203         //TSW Error: UKAL-6YL72P
       
   204         //Tool chain uses full symbian language id in 
       
   205         //the directory name, which is not detected by help application.
       
   206         //
       
   207         if(lang < 10)
       
   208             {
       
   209             aContentDrive->AppendNumFixedWidth(lang,EDecimal,2);
       
   210             }
       
   211         else
       
   212             {
       
   213             aContentDrive->AppendNum(lang);
       
   214             }
       
   215         
       
   216         aContentDrive->Append(KFwdSlash);
       
   217         if(BaflUtils::PathExists(FileSession,*aContentDrive))
       
   218             {
       
   219             langs.Reset();
       
   220             return ETrue;
       
   221             }
       
   222         else
       
   223             {
       
   224             aContentDrive->Delete((len-1),aContentDrive->Length()-len);
       
   225             }    
       
   226         }
       
   227         langs.Reset();
       
   228         return EFalse;
       
   229     }
       
   230     
       
   231 TBool CCSXHHTMLContentParser::HandleMasterMetaFileL(CCSXHHelpDataBase* aDataBase, 
       
   232                         TChar& aDrive, MSenContentHandlerClient *aPrevHandler)                                               
       
   233     {
       
   234     RFs& FileSession = iCoeEnv->FsSession();
       
   235     TBuf<KMaxFileName> masterFile;
       
   236 
       
   237     iIndexing->GetPrivatePath( masterFile );
       
   238     masterFile.Append( aDrive );
       
   239     masterFile.Append( KFwdSlash );
       
   240     iIndexing->AppendLocaleL( masterFile );
       
   241     masterFile.Append( KMasterMetaFile );
       
   242     if(BaflUtils::FileExists( FileSession,masterFile ) )
       
   243         {
       
   244 #ifdef _DEBUG
       
   245         RDebug::Print(_L("index exist begin to parse!    %c"), TUint( aDrive ) );
       
   246 #endif
       
   247         CCSXHXMLParseHandler_MasterMetaFile* masterMetaHandler = 
       
   248         CCSXHXMLParseHandler_MasterMetaFile::NewL(iCoeEnv);
       
   249         masterMetaHandler->SetDataBasePtr(aDataBase);
       
   250         masterMetaHandler->SetHtmlContentParserPtr(this);
       
   251         CleanupStack::PushL(masterMetaHandler);      
       
   252     
       
   253         iXmlReader->SetContentHandler(*masterMetaHandler);
       
   254         // ParseL is not in async
       
   255         iXmlReader->ParseL(FileSession,masterFile);
       
   256         iXmlReader->SetContentHandler(*aPrevHandler);
       
   257         CleanupStack::PopAndDestroy(masterMetaHandler);
       
   258         }
       
   259 
       
   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;
       
   296     }
       
   297     
       
   298 void CCSXHHTMLContentParser::GenerateTOC2ListL(CCSXHGenericTOC1& 
       
   299 aGenericTOC1Object, RPointerArray<CCSXHHelpContentBase>* GenericTOC2List)
       
   300     {
       
   301     CCSXHXMLParseHandler_IndexFile* XMLParser = CCSXHXMLParseHandler_IndexFile::NewL(iCoeEnv);
       
   302     CleanupStack::PushL(XMLParser);      
       
   303     InitializeReaderL(XMLParser);
       
   304         
       
   305     XMLParser->SetArray(GenericTOC2List);
       
   306     XMLParser->SetGenericTOC1Object(aGenericTOC1Object);
       
   307     XMLParser->SetHtmlContentParserPtr(this);
       
   308     RFs& FileSession = iCoeEnv->FsSession();
       
   309     CCSXHHtmlTOC1* toc1 = STATIC_CAST(CCSXHHtmlTOC1*,&aGenericTOC1Object);
       
   310     TBuf<KMaxFileName> lookupindexfile;
       
   311     toc1->GetHelpFileL(lookupindexfile);
       
   312     XMLParser->SetPath(lookupindexfile);
       
   313     lookupindexfile.Append(KIndexFile);              
       
   314  
       
   315     if(BaflUtils::FileExists(FileSession,lookupindexfile))
       
   316         iXmlReader->ParseL (FileSession,lookupindexfile);
       
   317     
       
   318     TBuf<KMaxFileName>HelpContentName(toc1->GetName());
       
   319     int toc1Count = iDuplicateHelpTopicList.Count();
       
   320     
       
   321      for(int i=0;i < toc1Count;i++)
       
   322         {    
       
   323         CCSXHHtmlTOC1* temptoc1 = iDuplicateHelpTopicList[i];
       
   324             
       
   325         if(temptoc1->GetName().CompareF(HelpContentName) == 0)
       
   326             {    
       
   327             TBuf<KMaxFileName> lookup;
       
   328             temptoc1->GetHelpFileL(lookup);
       
   329             XMLParser->SetPath(lookup);
       
   330             lookup.Append(KIndexFile);              
       
   331          
       
   332             if(BaflUtils::FileExists(FileSession,lookup))
       
   333                 iXmlReader->ParseL (FileSession,lookup);
       
   334             }
       
   335         }
       
   336     
       
   337     CleanupStack::PopAndDestroy(XMLParser);
       
   338     ClearReader();
       
   339     }       
       
   340         
       
   341 TAny* CCSXHHTMLContentParser::GetTopicContentL(CCSXHGenericTOC2* aTopic)
       
   342     {
       
   343     CCSXHHtmlTOC2* topic = STATIC_CAST(CCSXHHtmlTOC2*,aTopic);
       
   344     TBuf<KMaxFileName> htmlFile;
       
   345     topic->GetHtmlFileName(htmlFile);
       
   346     return GetContentsFromFileL(htmlFile,iCoeEnv,iFeatureControl);
       
   347     }
       
   348     
       
   349 
       
   350 void CCSXHHTMLContentParser::ScanAndParseXMLfileToCreateTOC1ObjectL(
       
   351         RFs& FileSession,
       
   352         CDirScan* scanner,
       
   353         CCSXHHelpDataBase* aDataBase,
       
   354         const TInt& aDrive,
       
   355         CCSXHXMLParseHandler_MetaFile* XMLParser
       
   356         )
       
   357     {
       
   358     CDir* entryList = NULL;
       
   359     scanner->NextL(entryList);
       
   360     if (!entryList)
       
   361         {
       
   362         return;
       
   363         }
       
   364  
       
   365     CleanupStack::PushL(entryList);
       
   366     
       
   367     TInt entryCount = entryList->Count();     
       
   368     TInt ROMDrive;
       
   369     RFs::CharToDrive(PathInfo::RomRootPath()[0], ROMDrive);
       
   370     TBuf<KMaxFileName> lookup;
       
   371 
       
   372     while (entryCount--)
       
   373         {
       
   374         TEntry entry = (*entryList)[entryCount];
       
   375         
       
   376         //Clear the previous values
       
   377         lookup.Delete(0, lookup.Length());
       
   378         lookup.Append(scanner->FullPath());
       
   379         lookup.Append(entry.iName); 
       
   380         lookup.Append(KFwdSlash);
       
   381         lookup.Append(KMetaFile);
       
   382         
       
   383         //Check whether a file exists        
       
   384         if (!BaflUtils::FileExists(FileSession,lookup))
       
   385             continue;
       
   386         
       
   387         TRAPD(parserResult, iXmlReader->ParseL(FileSession, lookup));
       
   388         if (parserResult == KErrNone)
       
   389             {
       
   390             if (CheckFeatureIDL(XMLParser->GetFeatureIds()))
       
   391                 {            
       
   392                 if (!IsAppUIdPresentAlready(entry.iName))
       
   393                     {
       
   394                     TBool isRomBased = EFalse;
       
   395                     TInt32 priority = XMLParser->Priority();
       
   396                     
       
   397                     // Now we take a walk if it's application helps (priority == 0)
       
   398                     if ((priority != 0) 
       
   399                         && ((aDrive == ROMDrive) || IsRomBasedContentL(FileSession, entry.iName)))
       
   400                         {
       
   401                         if (priority < KHighestPriority)
       
   402                             {
       
   403                             priority = KHighestPriority;
       
   404                             }
       
   405                         else if (priority > KLowestPriority)
       
   406                             {
       
   407                             priority = KLowestPriority;
       
   408                             }
       
   409                         
       
   410                         isRomBased = ETrue;
       
   411                         }
       
   412                     else 
       
   413                         {
       
   414                         priority = 0;
       
   415                         }
       
   416                     
       
   417                     CCSXHHtmlTOC1* categoryObj = CCSXHHtmlTOC1::NewL(XMLParser->GetApplicationName(), entry.iName, aDrive, 
       
   418                             isRomBased ? KCSXHToc2ViewID : KCSXHToc2AppHelpsViewID, priority);
       
   419                     if (!categoryObj->IsValid())
       
   420                         {
       
   421                         delete categoryObj;
       
   422                         }
       
   423                     else
       
   424                         {
       
   425                         CleanupStack::PushL(categoryObj);
       
   426                         if (isRomBased)
       
   427                             {
       
   428                             if (aDataBase->GetMainTopics()->InsertChildWithPriority(categoryObj, EFalse))
       
   429                                 {
       
   430                                 iHtmlTOC1List.AppendL(categoryObj);
       
   431                                 }
       
   432                             else
       
   433                                 {
       
   434                                 iDuplicateHelpTopicList.AppendL(categoryObj);
       
   435                                 }
       
   436                             }
       
   437                         else
       
   438                             {
       
   439                             if (aDataBase->GetAppHelpsTopics()->InsertChild(categoryObj, EFalse))
       
   440                                 {
       
   441                                 iHtmlTOC1List.AppendL(categoryObj);
       
   442                                 }
       
   443                             else
       
   444                                 {
       
   445                                 iDuplicateHelpTopicList.AppendL(categoryObj);
       
   446                                 }
       
   447                             }
       
   448                         
       
   449                         iIndexing->RuntimeGenerateIndexL(*categoryObj, XMLParser->GetFeatureIds());
       
   450                         CleanupStack::Pop(categoryObj);
       
   451                         }
       
   452                     }
       
   453                 }         
       
   454             }
       
   455         }       
       
   456 
       
   457     CleanupStack::PopAndDestroy(entryList);
       
   458     }
       
   459 
       
   460 TBool CCSXHHTMLContentParser::IsRomBasedContentL( RFs& FileSession, const TDesC &aUid )
       
   461     {
       
   462 #ifdef __WINSCW__
       
   463     return ETrue;
       
   464 #endif
       
   465     
       
   466     TBool result = EFalse;
       
   467     CDirScan* scanner=CDirScan::NewLC(FileSession);
       
   468     TBuf<KMaxFileName> rootDir;
       
   469     rootDir.Append( 'z' );
       
   470                 
       
   471     if( GetHTMLContentPathForDriveL( &rootDir,iCoeEnv ) )
       
   472         {
       
   473         scanner->SetScanDataL(rootDir,KEntryAttDir|KEntryAttMatchExclusive,
       
   474                                         ESortByName|EAscending, CDirScan::EScanDownTree);
       
   475         CDir* entryList = NULL;
       
   476         scanner->NextL(entryList);
       
   477     
       
   478         if ( !entryList )
       
   479             {
       
   480             CleanupStack::PopAndDestroy( scanner );
       
   481             return EFalse;
       
   482             }
       
   483  
       
   484         TInt entryCount = entryList->Count();           
       
   485     
       
   486         while ( entryCount-- )
       
   487             {
       
   488             TEntry entry=(*entryList)[entryCount]; 
       
   489             if ( ( entry.iName ).CompareC(aUid) == 0 )
       
   490                 {
       
   491                 result = ETrue;
       
   492                 break;
       
   493                 }
       
   494             }
       
   495         delete entryList;
       
   496         }
       
   497     
       
   498     CleanupStack::PopAndDestroy( scanner );
       
   499  
       
   500     return result;
       
   501     }
       
   502     
       
   503 void CCSXHHTMLContentParser::InsertHTMLToc1L(
       
   504         const TDesC& aAppUidName,
       
   505         const TDesC& aAppName, 
       
   506         const TInt& aDrive,
       
   507         CCSXHHelpDataBase* aDataBase, 
       
   508         const TDesC& aFeatureIds, 
       
   509         TInt32 aPriority
       
   510         )
       
   511     {
       
   512     if (CheckFeatureIDL(aFeatureIds))
       
   513         {
       
   514         if (!IsAppUIdPresentAlready(aAppUidName)) 
       
   515             {
       
   516             // Now we take a walk if it's application helps (priority == 0)
       
   517             CCSXHHtmlTOC1* categoryObj = CCSXHHtmlTOC1::NewL(aAppName,aAppUidName, aDrive,
       
   518                     aPriority == 0 ? KCSXHToc2AppHelpsViewID : KCSXHToc2ViewID, aPriority);
       
   519             
       
   520             if (categoryObj->IsValid())
       
   521                 {
       
   522                 CleanupStack::PushL(categoryObj);
       
   523                 if (aPriority == 0)
       
   524                     {
       
   525                     if (aDataBase->GetAppHelpsTopics()->InsertChild(categoryObj, EFalse))
       
   526                         {
       
   527                         iHtmlTOC1List.AppendL(categoryObj);
       
   528                         }
       
   529                     else
       
   530                         {
       
   531                         iDuplicateHelpTopicList.AppendL(categoryObj);
       
   532                         }
       
   533                     }
       
   534                 else
       
   535                     {
       
   536                     if (aDataBase->GetMainTopics()->InsertChildWithPriority(categoryObj, EFalse))
       
   537                         {
       
   538                         iHtmlTOC1List.AppendL(categoryObj); //Keep a local copy*/
       
   539                         }
       
   540                     else
       
   541                         {
       
   542                         iDuplicateHelpTopicList.AppendL(categoryObj);
       
   543                         }
       
   544                     }
       
   545                 CleanupStack::Pop(categoryObj);
       
   546                 }
       
   547             else
       
   548                 {
       
   549                 delete categoryObj;
       
   550                 }                    
       
   551             }
       
   552         }    
       
   553     }
       
   554     
       
   555 HBufC8* CCSXHHTMLContentParser::GetContentsFromFileL(const TDesC& htmlFile,CCoeEnv* aCoeEnv,
       
   556             RFeatureControl& aFeatureControl) 
       
   557     {
       
   558     RFs& fileSession = aCoeEnv->FsSession();        
       
   559     TInt SlashPosition = htmlFile.LocateReverse('\\');    
       
   560     TBuf<KMaxFileName>* CompressedFile = new (ELeave) TBuf<KMaxFileName>; 
       
   561     CleanupStack::PushL(CompressedFile); //1
       
   562     CompressedFile->Copy(htmlFile.Mid(0,SlashPosition+1));
       
   563     CompressedFile->Append(KContentZipFile);    
       
   564     
       
   565     HBufC8* CssContent = CreateBufferForCSSContentL(aFeatureControl);
       
   566        
       
   567     if(!BaflUtils::FileExists(fileSession,*CompressedFile))
       
   568         {
       
   569         CleanupStack::PopAndDestroy(CompressedFile);
       
   570         
       
   571         HBufC8* buffer = GetContentsFromHTMLFileL(htmlFile,aCoeEnv);
       
   572         
       
   573         return MergeCssAndHTMLContentL(buffer,CssContent);
       
   574         }
       
   575         
       
   576     // Create an instance of CZipFile.
       
   577     CZipFile* zipFile = CZipFile::NewL(fileSession, *CompressedFile);    
       
   578     CleanupStack::PushL(zipFile); //2
       
   579         
       
   580     // Iterate and get the file name
       
   581     CZipFileMemberIterator* members = zipFile->GetMembersL();
       
   582     CleanupStack::PushL(members);//3
       
   583     CZipFileMember* member = members->NextL(); // Get the first file in zip
       
   584     
       
   585     TInt nCount=0;    
       
   586     const TBuf<KMaxFileName>*Fname;
       
   587     TBuf<KMaxFileName> *HtmlFileName = new (ELeave) TBuf<KMaxFileName>;
       
   588     CleanupStack::PushL(HtmlFileName); //4
       
   589     HtmlFileName->Copy(htmlFile.Mid(SlashPosition+1));
       
   590     for(nCount=0;member!=NULL;nCount++)
       
   591         {         
       
   592          Fname = member->Name();    
       
   593          if(Fname->Compare(*HtmlFileName)==0 )
       
   594             {
       
   595             break;
       
   596             }        
       
   597         delete member;    
       
   598         member = members->NextL();        
       
   599         }
       
   600 
       
   601     if(NULL == member)
       
   602         {
       
   603         CleanupStack::PopAndDestroy(HtmlFileName);
       
   604         CleanupStack::PopAndDestroy(members);
       
   605         CleanupStack::PopAndDestroy(zipFile);
       
   606         CleanupStack::PopAndDestroy(CompressedFile);
       
   607         
       
   608         HBufC8* buffer = GetContentsFromHTMLFileL(htmlFile,aCoeEnv);
       
   609         return MergeCssAndHTMLContentL(buffer,CssContent);
       
   610         }
       
   611         
       
   612     CleanupStack::PushL(member);//5
       
   613     RZipFileMemberReaderStream* stream;
       
   614     zipFile->GetInputStreamL(member, stream);
       
   615     CleanupStack::PushL(stream);//6
       
   616         
       
   617     // Extracts aFileName to a buffer.
       
   618     // If the file is quite huge, then read the file in streaming mode.
       
   619     // For example, use 4KB buffer and read it in an active object.
       
   620     HBufC8* buffer = HBufC8::NewLC(member->UncompressedSize());//5
       
   621     TPtr8 bufferPtr(buffer->Des());
       
   622     User::LeaveIfError(stream->Read(bufferPtr, member->UncompressedSize()));
       
   623 
       
   624     // Release all the resources.   
       
   625     CleanupStack::Pop(buffer);
       
   626     CleanupStack::PopAndDestroy(stream); 
       
   627     CleanupStack::PopAndDestroy(member);
       
   628     CleanupStack::PopAndDestroy(HtmlFileName);
       
   629     CleanupStack::PopAndDestroy(members);
       
   630     CleanupStack::PopAndDestroy(zipFile);
       
   631     CleanupStack::PopAndDestroy(CompressedFile);
       
   632     
       
   633     return MergeCssAndHTMLContentL(buffer,CssContent);
       
   634     }
       
   635 
       
   636 TBool CCSXHHTMLContentParser::HandleMasterKeywordFileL(CCSXHHelpDataBase* aDataBase)
       
   637     {
       
   638     RFs& FileSession = iCoeEnv->FsSession();
       
   639     CCSXHXMLParseHandler_MasterKywd* XMLParser_MasterKywd = CCSXHXMLParseHandler_MasterKywd::NewL(iCoeEnv);  
       
   640     CleanupStack::PushL(XMLParser_MasterKywd);  
       
   641     InitializeReaderL(XMLParser_MasterKywd);
       
   642     XMLParser_MasterKywd->SetHtmlContentParserPtr(this);
       
   643     XMLParser_MasterKywd->SetDataBasePtr(aDataBase);
       
   644     TBool bMasterKeywordFilePresent = EFalse;
       
   645     
       
   646     //Check for the availability of Master Keyword file
       
   647     TBuf<KMaxFileName>* Master_kywdPath = new(ELeave) TBuf<KMaxFileName>;
       
   648     CleanupStack::PushL(Master_kywdPath);//5
       
   649     Master_kywdPath->Append(PathInfo::RomRootPath().Left(1));
       
   650     GetHTMLContentPathForDriveL(Master_kywdPath,iCoeEnv);
       
   651     Master_kywdPath->Append(KMasterKywdFile);
       
   652     
       
   653     if(BaflUtils::FileExists(FileSession,*Master_kywdPath))
       
   654         {        
       
   655         TRAP_IGNORE(iXmlReader->ParseL(FileSession,*Master_kywdPath ));
       
   656         bMasterKeywordFilePresent = ETrue;
       
   657         }    
       
   658     
       
   659     //KMasterKywdFile;
       
   660     CleanupStack::PopAndDestroy(Master_kywdPath);
       
   661     CleanupStack::PopAndDestroy(XMLParser_MasterKywd);
       
   662     ClearReader();    
       
   663     
       
   664     return bMasterKeywordFilePresent;
       
   665     }
       
   666     
       
   667 void CCSXHHTMLContentParser::GenerateKywdTOC1ListL(CCSXHHelpDataBase* aDataBase)
       
   668     {
       
   669     if(!iHtmlTOC1List.Count())
       
   670         return;
       
   671     TBool bMasterKeywordFilePresent = HandleMasterKeywordFileL(aDataBase);
       
   672     
       
   673     CCSXHXMLParseHandler_Kywd* XMLParser = CCSXHXMLParseHandler_Kywd::NewL(iCoeEnv);  
       
   674     CleanupStack::PushL(XMLParser);  
       
   675     InitializeReaderL(XMLParser);
       
   676     
       
   677     XMLParser->SetDataBasePtr(aDataBase);
       
   678     XMLParser->SetIsTOC2(EFalse);
       
   679     XMLParser->SetHtmlContentParserPtr(this);
       
   680     
       
   681     //Parse keyword.xml file from Main Array list
       
   682     ParseKeywdFileAndCreatekywdTOC1ObjectsL(iHtmlTOC1List,XMLParser,bMasterKeywordFilePresent);
       
   683     
       
   684     //Parse keyword.xml file from duplicate Array list
       
   685     ParseKeywdFileAndCreatekywdTOC1ObjectsL(iDuplicateHelpTopicList,XMLParser,bMasterKeywordFilePresent);
       
   686     
       
   687     CleanupStack::PopAndDestroy(XMLParser);
       
   688     ClearReader();
       
   689     }
       
   690     
       
   691 void CCSXHHTMLContentParser::GenerateTOC2ListForKeywordSearchL
       
   692 (CCSXHHelpDataBase* aDataBase,CCSXHKywdTOC1* aKywdTOC1Object)
       
   693     {
       
   694     RPointerArray<CCSXHHtmlTOC1>* TOC1HtmlList = aKywdTOC1Object->GetHtmlTOC1List();
       
   695     if(!TOC1HtmlList)
       
   696         return;
       
   697     
       
   698     CCSXHXMLParseHandler_Kywd* XMLParser = CCSXHXMLParseHandler_Kywd::NewL(iCoeEnv);
       
   699     CleanupStack::PushL(XMLParser);      
       
   700     InitializeReaderL(XMLParser);
       
   701     
       
   702     int toc1Count = TOC1HtmlList->Count();
       
   703     CCSXHHtmlTOC1* toc1;
       
   704 
       
   705     RFs& FileSession = iCoeEnv->FsSession();
       
   706     
       
   707     XMLParser->SetDataBasePtr(aDataBase);
       
   708     XMLParser->SetIsTOC2(ETrue);
       
   709     XMLParser->SetHtmlContentParserPtr(this);
       
   710     
       
   711     TBuf<KMaxFileName>* lookup = new(ELeave)TBuf<KMaxFileName>;
       
   712     CleanupStack::PushL(lookup);//3
       
   713     XMLParser->SetTOC1Title(aKywdTOC1Object->GetName());
       
   714     for(int i = 0; i < toc1Count ; ++i )
       
   715         {
       
   716         toc1 = (*TOC1HtmlList)[i];
       
   717         //Get Corresponding toc1 from Main array and set toc1 object
       
   718         XMLParser->SetCurrentHtmlToc1(GetCorrespondingTOC1FromMainArray(toc1->GetName()));
       
   719         //Clear the previous values
       
   720         lookup->Delete(0,lookup->Length());
       
   721         toc1->GetHelpFileL(*lookup);
       
   722         XMLParser->SetPath(*lookup);
       
   723         lookup->Append(KKeywordsFile);
       
   724         TRAP_IGNORE(iXmlReader->ParseL (FileSession,*lookup ));
       
   725         aDataBase->IncrementKeywordSearchCount();
       
   726         }   
       
   727     CleanupStack::PopAndDestroy(lookup);
       
   728     CleanupStack::PopAndDestroy(XMLParser);  
       
   729     ClearReader();
       
   730     }
       
   731     
       
   732 CCSXHHelpContentBase* CCSXHHTMLContentParser::GetContextTopicL( 
       
   733         CCSXHHelpDataBase *aDataBase, 
       
   734         TUid &aUid, 
       
   735         TCoeContextName &aContextName
       
   736         )
       
   737     {
       
   738     TBuf<KMaxFileName> path;
       
   739     TInt32 toc1Count = iHtmlTOC1List.Count();
       
   740     TInt32 dupToc1Count = iDuplicateHelpTopicList.Count();
       
   741     CCSXHHtmlTOC1 *toc1 = NULL;
       
   742     CCSXHHtmlTOC1 *temptoc1 = NULL;
       
   743     TBool redirected = EFalse;
       
   744     
       
   745     for ( TInt32 i = 0; i < toc1Count; ++i )
       
   746         {
       
   747         toc1 = iHtmlTOC1List[i];
       
   748         if ( aUid == toc1->GetAppUid() )
       
   749             {
       
   750             toc1->GetHelpFileL( path );
       
   751             if ( IsRedirectedL( aDataBase, path, aUid, aContextName ) )
       
   752                 {
       
   753                 redirected = ETrue;
       
   754                 }
       
   755             else
       
   756                 {
       
   757                 return toc1->GetContextTopic( aContextName );
       
   758                 }
       
   759             break;
       
   760             }
       
   761         }
       
   762     
       
   763     if ( !redirected )
       
   764         {
       
   765         for ( TInt32 i = 0; i < dupToc1Count; ++i )
       
   766             {
       
   767             toc1 = iDuplicateHelpTopicList[i];
       
   768             if ( aUid == toc1->GetAppUid() )
       
   769                 {
       
   770                 toc1->GetHelpFileL( path );
       
   771                 if ( IsRedirectedL( aDataBase, path, aUid, aContextName ) )
       
   772                     {
       
   773                     redirected = ETrue;
       
   774                     }
       
   775                 else
       
   776                     {
       
   777                     temptoc1 = GetCorrespondingTOC1FromMainArray(toc1->GetName());                
       
   778                     return temptoc1->GetContextTopic( aContextName );
       
   779                     }
       
   780                 }
       
   781             }
       
   782         }
       
   783         
       
   784     if ( redirected )
       
   785         {
       
   786         for ( TInt32 i = 0; i < toc1Count; ++i )
       
   787             {
       
   788             toc1 = iHtmlTOC1List[i];
       
   789             if ( aUid == toc1->GetAppUid() )
       
   790                 {    
       
   791                 return toc1->GetContextTopic( aContextName );
       
   792                 }
       
   793             }
       
   794         
       
   795         for ( TInt32 i = 0; i < dupToc1Count; ++i )
       
   796             {
       
   797             toc1 = iDuplicateHelpTopicList[i];
       
   798             if ( aUid == toc1->GetAppUid() )
       
   799                 {
       
   800                 temptoc1 = GetCorrespondingTOC1FromMainArray( toc1->GetName() );                
       
   801                 return temptoc1->GetContextTopic( aContextName );
       
   802                 }
       
   803             }
       
   804         }
       
   805         
       
   806     return NULL;
       
   807     }
       
   808     
       
   809 CCSXHHelpContentBase* CCSXHHTMLContentParser::GetHtmlTopicForUrlL(const TDesC& aUrl)
       
   810     {
       
   811     CCSXHHelpContentBase* tocobj = GetObjectBasedonUrlL(iHtmlTOC1List,aUrl,ETrue);
       
   812     
       
   813     if(NULL == tocobj)
       
   814         tocobj = GetObjectBasedonUrlL(iDuplicateHelpTopicList,aUrl,EFalse);
       
   815     
       
   816     return tocobj;        
       
   817     }
       
   818 
       
   819 CCSXHHelpContentBase* CCSXHHTMLContentParser::GetObjectBasedonUrlL(RPointerArray<CCSXHHtmlTOC1>& aTOC1ObjectsArray,
       
   820         const TDesC& aUrl, TBool aMainArrayList)    
       
   821     {
       
   822         /*For URLs of form 
       
   823         file:://<Drive Name>:/system/xhtml/<Lang ID>/<App UID>/Html name
       
   824       We can have help topics for other cases, help topic objects not possible   
       
   825     */
       
   826     TBuf<KMaxFileName> aFileUrl;
       
   827     
       
   828     int toc1Count = aTOC1ObjectsArray.Count();
       
   829     CCSXHHtmlTOC1* toc1,*temptoc1;
       
   830     for(int j = 0; j < toc1Count; ++j)
       
   831         {
       
   832         toc1 = aTOC1ObjectsArray[j];
       
   833         TBuf<KMaxFileName> htmlFile;
       
   834         toc1->GetHelpFileL(htmlFile);
       
   835         
       
   836         //Convert fwd slashes to back slashes
       
   837         TInt i = htmlFile.Find(KFwdSlash) ;
       
   838         while (KErrNotFound != i)
       
   839             {
       
   840             htmlFile.Replace(i,1,KBackSlash);
       
   841             i = htmlFile.Find(KFwdSlash) ;
       
   842             }
       
   843         
       
   844         i = aUrl.FindC(htmlFile);
       
   845         if(i != KErrNotFound)
       
   846             {
       
   847             TFileName fileName;
       
   848             i = aUrl.LocateReverseF('/');
       
   849             fileName = aUrl.Mid(i + 1);
       
   850             if(aMainArrayList)
       
   851                 temptoc1 = toc1;
       
   852             else
       
   853                 temptoc1 = GetCorrespondingTOC1FromMainArray(toc1->GetName());    
       
   854             
       
   855             return temptoc1->GetHtmlTopicForFile(fileName);
       
   856             }
       
   857         }
       
   858     return NULL;    
       
   859     }
       
   860 
       
   861 void CCSXHHTMLContentParser::GetHtmlFileL(CCoeEnv* coeEnv,const short& aDir,
       
   862                                             const TAppUid& aUid,TBuf<KMaxFileName>& aFileName)
       
   863     {
       
   864     aFileName.Copy(KEmptyString);
       
   865     
       
   866     RFs& FileSession = coeEnv->FsSession();
       
   867     TDriveList DirList; 
       
   868     if( (FileSession.DriveList(DirList)<KErrNone) ||
       
   869         (aDir >= DirList.Length()))
       
   870         return; 
       
   871     
       
   872     TChar driveLetter = '?';
       
   873     TDriveInfo info;
       
   874     TInt error = FileSession.Drive(info, aDir);
       
   875     if  ((error == KErrNone) && 
       
   876         (DirList[aDir] && info.iType != EMediaNotPresent))
       
   877         {
       
   878         RFs::DriveToChar(aDir, driveLetter);
       
   879 
       
   880         aFileName.Append(driveLetter);
       
   881         GetHTMLContentPathForDriveL(&aFileName,coeEnv);
       
   882         aUid.AppendUid(aFileName);
       
   883         aFileName.Append(KFwdSlash);
       
   884         }
       
   885     }
       
   886 
       
   887 void CCSXHHTMLContentParser::InitializeReaderL(CCSXHXMLParseHandler* aXMLParser)
       
   888     {
       
   889     if(iXmlReader == NULL )
       
   890         {       
       
   891         iXmlReader = CSenXmlReader::NewL();
       
   892         iXmlReader->SetContentHandler(*aXMLParser);
       
   893         }
       
   894     }
       
   895 void CCSXHHTMLContentParser::ClearReader()
       
   896     {
       
   897     delete iXmlReader;
       
   898     iXmlReader = NULL;
       
   899     }
       
   900     
       
   901 TBool CCSXHHTMLContentParser::IsUidCategoryPresent(const TUid& aUid)
       
   902     {
       
   903     int toc1Count = iHtmlTOC1List.Count();
       
   904     CCSXHHtmlTOC1* toc1;    
       
   905     for(int i = 0; i < toc1Count; ++i)
       
   906         {
       
   907         toc1 = iHtmlTOC1List[i];
       
   908         if(aUid == toc1->GetAppUid())
       
   909             return ETrue;
       
   910         }
       
   911     
       
   912     toc1Count = iDuplicateHelpTopicList.Count();
       
   913     for(int i = 0; i < toc1Count; ++i)
       
   914         {
       
   915         toc1 = iDuplicateHelpTopicList[i];
       
   916         if(aUid == toc1->GetAppUid())
       
   917             return ETrue;
       
   918         }    
       
   919     return EFalse;  
       
   920     }
       
   921 
       
   922 TBool CCSXHHTMLContentParser::GetHTMLToc1(const TDesC& aUid,CCSXHXMLParseHandler* aParser)
       
   923     {
       
   924     TUint AppId;
       
   925     
       
   926     if(!aUid.Length())
       
   927         return EFalse;
       
   928 
       
   929     TLex FolderUid(aUid.Mid(KOffset));
       
   930     FolderUid.Val(AppId,EHex);
       
   931     TUid ApplicationUid = TUid::Uid((TInt)AppId);
       
   932     
       
   933     int toc1Count = iHtmlTOC1List.Count();
       
   934     
       
   935     CCSXHHtmlTOC1* toc1;    
       
   936     for(int i = 0; i < toc1Count; ++i)
       
   937         {
       
   938         toc1 = iHtmlTOC1List[i];
       
   939         if(ApplicationUid == toc1->GetAppUid())
       
   940             {
       
   941             STATIC_CAST(CCSXHXMLParseHandler_MasterKywd*,aParser)->SetCurrentHtmlToc1(toc1); 
       
   942             return ETrue;
       
   943             }            
       
   944         }
       
   945     
       
   946     toc1Count = iDuplicateHelpTopicList.Count();            
       
   947     for(int i = 0; i < toc1Count; ++i)
       
   948         {
       
   949         toc1 = iDuplicateHelpTopicList[i];
       
   950         if(ApplicationUid == toc1->GetAppUid())
       
   951             {
       
   952             STATIC_CAST(CCSXHXMLParseHandler_MasterKywd*,aParser)->SetCurrentHtmlToc1(toc1); 
       
   953             return ETrue;
       
   954             }            
       
   955         }
       
   956                 
       
   957     return EFalse;  
       
   958     }
       
   959 
       
   960 //To get Corresponding toc1 from main array.
       
   961 CCSXHHtmlTOC1* CCSXHHTMLContentParser::GetCorrespondingTOC1FromMainArray(const TDesC& aApplicationName)
       
   962     {
       
   963     TInt toc1Count = iHtmlTOC1List.Count();
       
   964     CCSXHHtmlTOC1* toc1;
       
   965     for(int i=0;i<toc1Count;++i)
       
   966         {
       
   967         toc1 = iHtmlTOC1List[i];
       
   968         if(toc1->GetName().CompareF(aApplicationName) == 0)
       
   969             return toc1;
       
   970         }
       
   971     
       
   972     return NULL;
       
   973     }
       
   974 
       
   975 //Check UId is already present in the list.    
       
   976 TBool CCSXHHTMLContentParser::IsAppUIdPresentAlready(const TDesC& aUid)
       
   977     {
       
   978     TBool result = EFalse;
       
   979     TInt toc1Count = iHtmlTOC1List.Count();
       
   980     CCSXHHtmlTOC1* toc1;
       
   981     
       
   982     TUint AppId;
       
   983     TLex FolderUid(aUid.Mid(KOffset));
       
   984     FolderUid.Val(AppId,EHex);
       
   985     TUid ApplicationUid = TUid::Uid((TInt)AppId);
       
   986     
       
   987     for(int i=0;i<toc1Count;++i)
       
   988         {
       
   989         toc1 = iHtmlTOC1List[i];
       
   990         if(ApplicationUid == toc1->GetAppUid())
       
   991             {
       
   992             result = ETrue;
       
   993             break;
       
   994             }            
       
   995         }
       
   996         
       
   997     toc1Count =    iDuplicateHelpTopicList.Count();    
       
   998     for(int i=0;i<toc1Count;++i)
       
   999         {
       
  1000         toc1 = iDuplicateHelpTopicList[i];
       
  1001         if(ApplicationUid == toc1->GetAppUid())
       
  1002             {
       
  1003             result = ETrue;
       
  1004             break;
       
  1005             }
       
  1006         }        
       
  1007         
       
  1008     return result;    
       
  1009 
       
  1010     }
       
  1011     
       
  1012 void CCSXHHTMLContentParser::ParseKeywdFileAndCreatekywdTOC1ObjectsL(
       
  1013         RPointerArray<CCSXHHtmlTOC1>& aTOC1ObjectsArray,
       
  1014         CCSXHXMLParseHandler_Kywd* XMLParser, TBool bMasterKeywordFilePresent)
       
  1015     {
       
  1016     int toc1Count = aTOC1ObjectsArray.Count();
       
  1017     CCSXHHtmlTOC1* toc1;
       
  1018      
       
  1019     TBuf<KMaxFileName>* lookup = new(ELeave)TBuf<KMaxFileName>;
       
  1020     CleanupStack::PushL(lookup);//1
       
  1021     
       
  1022     RFs& FileSession = iCoeEnv->FsSession();
       
  1023     
       
  1024         for(int i = 0; i < toc1Count; ++i)
       
  1025         {
       
  1026         toc1 = aTOC1ObjectsArray[i];
       
  1027         
       
  1028         if(bMasterKeywordFilePresent && toc1->IsROMDrive())
       
  1029             continue;
       
  1030         
       
  1031         //Clear the previous values
       
  1032         lookup->Delete(0,lookup->Length());
       
  1033         
       
  1034         toc1->GetHelpFileL(*lookup);
       
  1035         lookup->Append(KKeywordsFile);
       
  1036         
       
  1037           //Check whether a file exists        
       
  1038         if(!BaflUtils::FileExists(FileSession,*lookup))
       
  1039             continue;
       
  1040         
       
  1041         XMLParser->SetCurrentHtmlToc1(toc1);
       
  1042         TRAP_IGNORE(iXmlReader->ParseL(FileSession,*lookup ));
       
  1043         }
       
  1044 
       
  1045     CleanupStack::PopAndDestroy(lookup);  
       
  1046     }
       
  1047 
       
  1048 //RUNTIME
       
  1049 void CCSXHHTMLContentParser::GetSupportedFeatureListL()
       
  1050     {
       
  1051     RFeatureUidArray SupportedFeatures;    
       
  1052     TInt err = iFeatureControl.Connect();
       
  1053     if ( err == KErrNone )
       
  1054         {
       
  1055          // ListSupportedFeatures() returns one of the Symbian error codes.
       
  1056          err = iFeatureControl.ListSupportedFeatures( SupportedFeatures );
       
  1057              
       
  1058          // Remember to call CloseL after using RFeatureControl.
       
  1059          // It disconnects the Feature Manager server.
       
  1060          iFeatureControl.Close();  
       
  1061         }
       
  1062     //As per new req. add true, flase to id and create an array.
       
  1063     
       
  1064     iFeatureManager_FeatureIds = new (ELeave) CDesCArrayFlat(2); 
       
  1065     
       
  1066     TBuf<25>CurrFId;
       
  1067     
       
  1068     for(TInt i=0;i<SupportedFeatures.Count();i++)
       
  1069         {
       
  1070         CurrFId.Copy(KEmptyString);    
       
  1071         CurrFId.AppendNum(SupportedFeatures[i].iUid);
       
  1072         iFeatureManager_FeatureIds->AppendL(CurrFId);
       
  1073         
       
  1074         CurrFId.Copy(KTrue_StringtoAppend);    
       
  1075         CurrFId.AppendNum(SupportedFeatures[i].iUid);
       
  1076         iFeatureManager_FeatureIds->AppendL(CurrFId);
       
  1077         
       
  1078         CurrFId.Copy(KFalse_StringtoAppend);    
       
  1079         CurrFId.AppendNum(SupportedFeatures[i].iUid);
       
  1080         iFeatureManager_FeatureIds->AppendL(CurrFId);        
       
  1081         }
       
  1082         
       
  1083     //Input Language variation changes
       
  1084     //-----------------------------------------
       
  1085     //Create an array with supported input language        
       
  1086     CPtiEngine* ptiEngine = CPtiEngine::NewL();
       
  1087     CleanupStack::PushL( ptiEngine );
       
  1088     
       
  1089     CArrayFix<TInt>* languageCodeArray = new(ELeave)CArrayFixFlat<TInt>(2);
       
  1090     
       
  1091     ptiEngine->GetAvailableLanguagesL( languageCodeArray );
       
  1092     
       
  1093     TInt nCount = languageCodeArray->Count();
       
  1094     
       
  1095     iSupportedInputLanguages = new (ELeave) CDesCArrayFlat(2); 
       
  1096     
       
  1097     //Codescanner gives error, if member variables are pushed.
       
  1098     //CleanupStack::PushL( iSupportedInputLanguages );
       
  1099     
       
  1100     for(TInt i=0; i<nCount;i++)
       
  1101         {
       
  1102         TInt languageCode = languageCodeArray->At(i);
       
  1103         TBuf<25>Currlang(_L("LANGUAGE_"));
       
  1104         if(languageCode < 10)
       
  1105             Currlang.AppendNumFixedWidth(languageCode,EDecimal,2);
       
  1106         else
       
  1107             Currlang.AppendNum(languageCode);
       
  1108         
       
  1109         iSupportedInputLanguages->AppendL(Currlang);
       
  1110         }
       
  1111     
       
  1112     //CleanupStack::Pop(iSupportedInputLanguages);    
       
  1113     CleanupStack::PopAndDestroy( ptiEngine );
       
  1114     
       
  1115     delete languageCodeArray;    
       
  1116     //-----------------------------------------
       
  1117     
       
  1118     SupportedFeatures.Close();
       
  1119     }
       
  1120     
       
  1121 //RUNTIME
       
  1122 TBool CCSXHHTMLContentParser::CheckFeatureIDL(const TDesC& aFeatureIds)
       
  1123     {
       
  1124     if(/*KHexPrefixLength == aFeatureIds.Length() &&*/ 
       
  1125         KErrNotFound != aFeatureIds.Find(KDefaultFeatureIdStringTemp))
       
  1126         {
       
  1127         return ETrue;
       
  1128         }
       
  1129             
       
  1130     HBufC* Ids = HBufC::NewLC(aFeatureIds.Length());    
       
  1131     TPtr CurrentFeatureIds = Ids->Des();    
       
  1132     CurrentFeatureIds.Copy(aFeatureIds);
       
  1133     CleanupStack::Pop(Ids);
       
  1134         
       
  1135     CDesCArray* FeatureIdList = new (ELeave) CDesCArrayFlat(2); ;
       
  1136     TInt EndPos = CurrentFeatureIds.Locate(' ');
       
  1137     
       
  1138     CleanupStack::PushL(FeatureIdList);
       
  1139                 
       
  1140     while (KErrNotFound != EndPos)
       
  1141         {
       
  1142                 FeatureIdList->AppendL(CurrentFeatureIds.Mid(0,EndPos));// FId_Val);            
       
  1143         CurrentFeatureIds = CurrentFeatureIds.Mid(EndPos+1);
       
  1144         EndPos = CurrentFeatureIds.Locate(' ') ;
       
  1145         }
       
  1146 
       
  1147     if(KErrNotFound == EndPos && 0!= CurrentFeatureIds.Length())
       
  1148         {
       
  1149         FeatureIdList->AppendL(CurrentFeatureIds);
       
  1150         }    
       
  1151     
       
  1152     CleanupStack::Pop(FeatureIdList); 
       
  1153      
       
  1154     TInt position;        
       
  1155     if(KErrNone == FeatureIdList->Find(KDefaultFeatureIdString,position) || 
       
  1156        KErrNone == FeatureIdList->Find(KDefaultFeatureIdStringTemp,position) )
       
  1157         {
       
  1158         delete FeatureIdList;
       
  1159         delete Ids;
       
  1160         return ETrue;
       
  1161         }
       
  1162         
       
  1163     TInt nCount = FeatureIdList->MdcaCount();
       
  1164     
       
  1165     
       
  1166     //FeatureManager list contains all enabled featureIds, appended with true, and false.
       
  1167     //New Req. text associated with true_featureId, should be displayed, if Id is enabled.
       
  1168     //else, if featureId is disabled, text associated with false_featureId should be displayed. 
       
  1169     // 1. if featureId string contains "false" and it is not in the list, return ETrue.
       
  1170     // 2. if featureId string does not contain "false" and it is present in the list, return ETrue.
       
  1171     // 3. if featureId is part of input language, return ETrue.
       
  1172     for(TInt j=0;j < nCount;j++)
       
  1173         {
       
  1174         if(
       
  1175             (KErrNotFound != FeatureIdList->MdcaPoint(j).Find(KFalseString) &&
       
  1176             KErrNone != iFeatureManager_FeatureIds->Find(FeatureIdList->MdcaPoint(j),position))||
       
  1177         
       
  1178             (KErrNotFound == FeatureIdList->MdcaPoint(j).Find(KFalseString) &&
       
  1179             KErrNone == iFeatureManager_FeatureIds->Find(FeatureIdList->MdcaPoint(j),position)) ||
       
  1180         
       
  1181             KErrNone == iSupportedInputLanguages->Find(FeatureIdList->MdcaPoint(j),position)
       
  1182         )                        
       
  1183             {
       
  1184             delete FeatureIdList;
       
  1185             delete Ids;
       
  1186             return ETrue;
       
  1187             }        
       
  1188         }
       
  1189                 
       
  1190     delete Ids;        
       
  1191     delete FeatureIdList;    
       
  1192     return EFalse;        
       
  1193     }    
       
  1194     
       
  1195 HBufC8* CCSXHHTMLContentParser::CreateBufferForCSSContentL(RFeatureControl& aFeatureControl)
       
  1196     {    
       
  1197     RFeatureUidArray SupportedFeatures;
       
  1198     TInt err = aFeatureControl.Connect();
       
  1199     if ( err == KErrNone )
       
  1200         {
       
  1201          // ListSupportedFeatures() returns one of the Symbian error codes.
       
  1202          err = aFeatureControl.ListSupportedFeatures( SupportedFeatures );
       
  1203              
       
  1204          // Remember to call CloseL after using RFeatureControl.
       
  1205          // It disconnects the Feature Manager server.
       
  1206          aFeatureControl.Close();                    
       
  1207         }
       
  1208     
       
  1209         //Input Language variation changes
       
  1210     //-----------------------------------------
       
  1211 
       
  1212     CPtiEngine* ptiEngine = CPtiEngine::NewL();
       
  1213     CleanupStack::PushL( ptiEngine );
       
  1214 
       
  1215     CArrayFix<TInt>* languageCodeArray = new(ELeave)CArrayFixFlat<TInt>(2);
       
  1216 
       
  1217     ptiEngine->GetAvailableLanguagesL( languageCodeArray );
       
  1218     
       
  1219     TInt nInputLangCount = languageCodeArray->Count();
       
  1220     TInt nCount = SupportedFeatures.Count();    
       
  1221 
       
  1222     HBufC8* CssContent = HBufC8::NewLC(nCount * KMaxUnits * 6 + nInputLangCount * 3 + 400);
       
  1223     TPtr8 bufferPtr(CssContent->Des());
       
  1224     
       
  1225     AppendStyleSheetContent_listitem(bufferPtr,nCount,SupportedFeatures,*languageCodeArray);
       
  1226     AppendStyleSheetContent_paragraph(bufferPtr,nCount,SupportedFeatures,*languageCodeArray);
       
  1227     AppendStyleSheetContent_ahref(bufferPtr,nCount,SupportedFeatures,*languageCodeArray);
       
  1228     AppendStyleSheetContent_none(bufferPtr,nCount,SupportedFeatures);    
       
  1229         
       
  1230     SupportedFeatures.Close();                
       
  1231     
       
  1232     CleanupStack::Pop(CssContent);    
       
  1233     
       
  1234     //Input Language variation changes
       
  1235     //-----------------------------------------
       
  1236     CleanupStack::PopAndDestroy( ptiEngine );    
       
  1237 
       
  1238     delete languageCodeArray;
       
  1239     //-----------------------------------------
       
  1240 
       
  1241     return CssContent;
       
  1242     }
       
  1243     
       
  1244 HBufC8* CCSXHHTMLContentParser::GetContentsFromHTMLFileL(const TDesC& htmlFile,CCoeEnv* aCoeEnv)
       
  1245     {
       
  1246     RFs& fsSession = aCoeEnv->FsSession();             
       
  1247     RFile file; 
       
  1248         
       
  1249     TInt err = file.Open(fsSession,htmlFile,EFileRead|EFileShareReadersOrWriters);
       
  1250     if(KErrNone == err)
       
  1251         {
       
  1252         TInt FileSize;
       
  1253         HBufC8* htmlFileContent = NULL;
       
  1254         if(KErrNone == file.Size(FileSize))
       
  1255             {
       
  1256             htmlFileContent = HBufC8::NewLC(FileSize);
       
  1257             TPtr8 PtrContent = htmlFileContent->Des();
       
  1258             
       
  1259             file.Read(PtrContent);    
       
  1260             CleanupStack::Pop(htmlFileContent);                
       
  1261             }        
       
  1262         file.Close();
       
  1263         return htmlFileContent;
       
  1264         }
       
  1265     else
       
  1266         {        
       
  1267         return NULL;
       
  1268         }
       
  1269     }
       
  1270     
       
  1271 HBufC8* CCSXHHTMLContentParser::MergeCssAndHTMLContentL(HBufC8* aHTMLBuffer, HBufC8* aCssContent)
       
  1272     {
       
  1273     TInt BufferLength=0;
       
  1274     if(aHTMLBuffer)
       
  1275         BufferLength = aHTMLBuffer->Size();
       
  1276     
       
  1277     if(aCssContent)
       
  1278         BufferLength += aCssContent->Size();
       
  1279     
       
  1280     HBufC8* Htmlbuffer = HBufC8::NewLC(BufferLength);
       
  1281     
       
  1282     TPtr8 HtmlbufferPtr(Htmlbuffer->Des());
       
  1283     
       
  1284     if(aCssContent)
       
  1285         {
       
  1286         HtmlbufferPtr.Copy(aCssContent->Des());
       
  1287         delete aCssContent;
       
  1288         }
       
  1289         
       
  1290     if(aHTMLBuffer)
       
  1291         {
       
  1292         HtmlbufferPtr.Append(aHTMLBuffer->Des());
       
  1293         delete aHTMLBuffer;    
       
  1294         }
       
  1295     
       
  1296     if(Htmlbuffer)
       
  1297         CleanupStack::Pop(Htmlbuffer);
       
  1298     
       
  1299     return Htmlbuffer;    
       
  1300     }
       
  1301 
       
  1302 void CCSXHHTMLContentParser::AppendStyleSheetContent_listitem(TPtr8& abufferptr,TInt aFeatureIdCount,
       
  1303                                                     RFeatureUidArray& aSupportedFeatures,
       
  1304                                                     CArrayFix<TInt>& alanguageCodeArray)
       
  1305     {
       
  1306     //List Items
       
  1307     //---------------------------------------------------------
       
  1308     abufferptr.Copy(KCsstext_First);
       
  1309     
       
  1310     for(TInt i=0;i<aFeatureIdCount;++i)
       
  1311         {
       
  1312         TBuf<KMaxFileName> FeatureId;
       
  1313         FeatureId.Format(KtextFormat_true_l,aSupportedFeatures[i].iUid);
       
  1314         //FeatureId.Append(KComma);
       
  1315         abufferptr.Append(FeatureId);        
       
  1316         }
       
  1317         
       
  1318     for(TInt i=0;i<alanguageCodeArray.Count();++i)
       
  1319         {
       
  1320         TBuf<KMaxFileName> FeatureId;
       
  1321         if(alanguageCodeArray[i] < 10)
       
  1322             FeatureId.Format(KtextFormat_lang_0l,alanguageCodeArray[i]);
       
  1323         else
       
  1324             FeatureId.Format(KtextFormat_lang_l,alanguageCodeArray[i]);
       
  1325         
       
  1326         abufferptr.Append(FeatureId);        
       
  1327         }
       
  1328         
       
  1329     abufferptr.Append(KDefaultFeatureId);        
       
  1330     abufferptr.Append(KCsstext_displayp_li);        
       
  1331     abufferptr.Append(KCsstext_Last);
       
  1332     //---------------------------------------------------------
       
  1333     }
       
  1334 
       
  1335 void CCSXHHTMLContentParser::AppendStyleSheetContent_paragraph(TPtr8& abufferptr,TInt aFeatureIdCount,
       
  1336                                                     RFeatureUidArray& aSupportedFeatures,
       
  1337                                                     CArrayFix<TInt>& alanguageCodeArray)
       
  1338     {
       
  1339     //Paragraph
       
  1340     //---------------------------------------------------------
       
  1341     abufferptr.Append(KCsstext_First);
       
  1342     for(TInt i=0;i<aFeatureIdCount;++i)
       
  1343         {
       
  1344         TBuf<KMaxFileName> FeatureId;
       
  1345         FeatureId.Format(KtextFormat_true_b,aSupportedFeatures[i].iUid);
       
  1346         //FeatureId.Append(KComma);
       
  1347         
       
  1348         abufferptr.Append(FeatureId);        
       
  1349         }
       
  1350         
       
  1351     for(TInt i=0;i<alanguageCodeArray.Count();++i)
       
  1352         {
       
  1353         TBuf<KMaxFileName> FeatureId;
       
  1354         if(alanguageCodeArray[i] < 10)
       
  1355             FeatureId.Format(KtextFormat_lang_0b,alanguageCodeArray[i]);
       
  1356         else
       
  1357             FeatureId.Format(KtextFormat_lang_b,alanguageCodeArray[i]);
       
  1358         
       
  1359         abufferptr.Append(FeatureId);        
       
  1360         }
       
  1361         
       
  1362     abufferptr.Append(KDefaultFeatureId);
       
  1363     abufferptr.Append(KCsstext_displayp_p);        
       
  1364     abufferptr.Append(KCsstext_Last);
       
  1365     
       
  1366     //---------------------------------------------------------
       
  1367     }
       
  1368 
       
  1369 void CCSXHHTMLContentParser::AppendStyleSheetContent_ahref(TPtr8& abufferptr,TInt aFeatureIdCount,
       
  1370                                                 RFeatureUidArray& aSupportedFeatures,
       
  1371                                                 CArrayFix<TInt>& alanguageCodeArray)
       
  1372     {
       
  1373     //A href
       
  1374     //---------------------------------------------------------
       
  1375     abufferptr.Append(KCsstext_First);
       
  1376     for(TInt i=0;i<aFeatureIdCount;++i)
       
  1377         {
       
  1378         TBuf<KMaxFileName> FeatureId;
       
  1379         FeatureId.Format(KtextFormat_true_a,aSupportedFeatures[i].iUid);        
       
  1380         abufferptr.Append(FeatureId);        
       
  1381         }
       
  1382     
       
  1383     for(TInt i=0;i<alanguageCodeArray.Count();++i)
       
  1384         {
       
  1385         TBuf<KMaxFileName> FeatureId;
       
  1386         if(alanguageCodeArray[i] < 10)
       
  1387             FeatureId.Format(KtextFormat_lang_0a,alanguageCodeArray[i]);
       
  1388         else
       
  1389             FeatureId.Format(KtextFormat_lang_a,alanguageCodeArray[i]);
       
  1390         abufferptr.Append(FeatureId);        
       
  1391         }
       
  1392         
       
  1393     abufferptr.Append(KDefaultFeatureId);
       
  1394     abufferptr.Append(KCsstext_displayp_a);        
       
  1395     abufferptr.Append(KCsstext_Last);
       
  1396     
       
  1397     //---------------------------------------------------------
       
  1398     }
       
  1399 
       
  1400 void CCSXHHTMLContentParser::AppendStyleSheetContent_none(TPtr8& abufferptr,TInt aFeatureIdCount,
       
  1401                                                     RFeatureUidArray& aSupportedFeatures
       
  1402                                                     )
       
  1403     {
       
  1404     //False
       
  1405     //---------------------------------------------------------
       
  1406     abufferptr.Append(KCsstext_First);
       
  1407     for(TInt i=0;i<aFeatureIdCount;++i)
       
  1408         {
       
  1409         TBuf<KMaxFileName> FeatureId;
       
  1410         FeatureId.Format(KtextFormat_false,aSupportedFeatures[i].iUid,aSupportedFeatures[i].iUid,aSupportedFeatures[i].iUid);
       
  1411         abufferptr.Append(FeatureId);        
       
  1412         }
       
  1413         
       
  1414     abufferptr.Append(KDefaultFeatureId);
       
  1415     abufferptr.Append(KCsstext_displayp_n);        
       
  1416     abufferptr.Append(KCsstext_Last);
       
  1417     
       
  1418     //---------------------------------------------------------
       
  1419     }