Ejemplo n.º 1
0
void  CTestImportContactMergeModeStep::InternalizeFileL(CVersitParser& aParser,const TDesC& aFileName, RFs& fsSession)
     {
     RFile file;
     User::LeaveIfError(file.Open(fsSession, aFileName, EFileRead));
     CleanupClosePushL(file);
     TInt start = 0;
     aParser.InternalizeL(file,start);
     CleanupStack::PopAndDestroy(&file);
     }
// ------------------------------------------------------------------------------------------------
// CNSmlDataModBase::MergeL
// Merges data from old item to new item.
// ------------------------------------------------------------------------------------------------
void CNSmlDataModBase::MergeL( TDes8& aNewItem, const TDesC8& aOldItem,TBool aFieldLevel )
	{
	TBool modified( EFalse );
	CVersitParser* newItemParser = ChildCreateParserLC();
	RDesReadStream newStream( aNewItem );
	CleanupClosePushL( newStream );
	newItemParser->InternalizeL( newStream );
	CVersitParser* oldItemParser = ChildCreateParserLC();
	RDesReadStream oldStream( aOldItem );
	CleanupClosePushL( oldStream );
	oldItemParser->InternalizeL( oldStream );

	// Now we're ready to start analysis
	CArrayPtr<CVersitParser>* newEntities = newItemParser->ArrayOfEntities( EFalse );
	CArrayPtr<CVersitParser>* oldEntities = oldItemParser->ArrayOfEntities( ETrue );

	if( newEntities && oldEntities )
		{
		CleanupPtrArrayPushL( oldEntities );
		for( TInt i = 0; ( i < newEntities->Count() ) && ( i < oldEntities->Count() ); i++ )
			{
			MergeEntityL( newEntities->At( i ), oldEntities->At( i ), modified, aFieldLevel );
			}
		CleanupStack::PopAndDestroy(); // oldEntities
		}
	else
		{
		MergeEntityL( newItemParser, oldItemParser, modified, aFieldLevel );
		}

	// Only update if anything was modified in process
	if ( modified )
		{
		aNewItem.Zero();
		RDesWriteStream dws( aNewItem );
		CleanupClosePushL( dws );
		newItemParser->ExternalizeL( dws );
		dws.CommitL();
		CleanupStack::PopAndDestroy(); // dws
		}

	CleanupStack::PopAndDestroy( 4 ); // oldStream, oldItemParser, newStream, newItemParser
	}
// ------------------------------------------------------------------------------------------------
// CNSmlDataModBase::StripL
// Strips data that is to be transmitted to the sync partner.
// ------------------------------------------------------------------------------------------------
void CNSmlDataModBase::StripL( TDes8& aItem )
	{
	_DBG_FILE("CNSmlDataModBase::StripL(): begin");
	if ( !NeedsMerge() )
		{
		if ( iUsedRemoteMimeType == -1 )
			{
			User::Leave( KErrNotFound );
			}
		return;
		}
	TBool modified( EFalse );
	CVersitParser* parser = ChildCreateParserLC();
	RDesReadStream drs( aItem );
	CleanupClosePushL( drs );
	parser->InternalizeL( drs );

	// Now we're ready to start analysis
	CArrayPtr<CVersitParser>* entities = parser->ArrayOfEntities( EFalse );
	if( entities )
		{
		for( TInt i = 0; i < entities->Count(); i++ )
			{
			StripEntityL( entities->At( i ), modified );
			}
		}
	else
		{
		StripEntityL( parser, modified );
		}

	// Only update if anything was modified in process
	if( modified )
		{
		aItem.Zero();
		RDesWriteStream dws( aItem );
		CleanupClosePushL( dws );
		parser->ExternalizeL( dws );
		dws.CommitL();
		CleanupStack::PopAndDestroy(); // dws
		}
	CleanupStack::PopAndDestroy( 2 ); // drs, parser
	_DBG_FILE("CNSmlDataModBase::StripL(): end");
	}