simpleengine/xmlutils/src/simpledocument.cpp
branchRCL_3
changeset 34 2669f8761a99
parent 18 52d91a16fec3
child 35 fbd2e7cec7ef
equal deleted inserted replaced
31:2580314736af 34:2669f8761a99
   194 // ----------------------------------------------------------
   194 // ----------------------------------------------------------
   195 //
   195 //
   196 void CSimpleDocument::GetDirectContentsL( 
   196 void CSimpleDocument::GetDirectContentsL( 
   197     RPointerArray<MSimpleContent>& aContents )
   197     RPointerArray<MSimpleContent>& aContents )
   198     {
   198     {
   199     CleanupClosePushL( aContents ); 
       
   200     aContents.Reset();
   199     aContents.Reset();
   201     TInt myCount = iContents.Count();
   200     TInt myCount = iContents.Count();
   202     for ( TInt i = 0; i<myCount; i++ )
   201     for ( TInt i = 0; i<myCount; i++ )
   203         {
   202         {
   204         aContents.AppendL( iContents[i] );
   203         User::LeaveIfError( aContents.Append( iContents[i] ));
   205         }
   204         }               
   206     CleanupStack::Pop( &aContents );
       
   207     }
   205     }
   208     
   206     
   209 // ----------------------------------------------------------
   207 // ----------------------------------------------------------
   210 // CSimpleDocument::AddDirectContentL
   208 // CSimpleDocument::AddDirectContentL
   211 // ----------------------------------------------------------
   209 // ----------------------------------------------------------
   653     // Convert all the multipart into CBodyPart.
   651     // Convert all the multipart into CBodyPart.
   654            
   652            
   655     // Let's convert first ROOT element into CBodyPart
   653     // Let's convert first ROOT element into CBodyPart
   656     CBodyPart* root = CBodyPart::NewL();
   654     CBodyPart* root = CBodyPart::NewL();
   657     // Add into cleanup array
   655     // Add into cleanup array
   658     aBodies.AppendL( root );     
   656     aBodies.Append( root );     
   659     CSenElement* e = Root()->BaseElement();
   657     CSenElement* e = Root()->BaseElement();
   660     
   658     
   661     // externalize the document into stream
   659     // externalize the document into stream
   662     CBufFlat* myBuffer = CBufFlat::NewL( KBufferSize );
   660     CBufFlat* myBuffer = CBufFlat::NewL( KBufferSize );
   663     CleanupStack::PushL( myBuffer );        
   661     CleanupStack::PushL( myBuffer );        
   676     using namespace NSimpleDocument::NSimpleRoot;
   674     using namespace NSimpleDocument::NSimpleRoot;
   677     
   675     
   678     // calculate the size of headers
   676     // calculate the size of headers
   679     TInt headerSize = KContentTypeSize + KCIDSize;
   677     TInt headerSize = KContentTypeSize + KCIDSize;
   680     HBufC8* headers = HBufC8::NewL( headerSize );  
   678     HBufC8* headers = HBufC8::NewL( headerSize );  
   681     aBuffers.AppendL( headers );
   679     aBuffers.Append( headers );
   682     TPtr8 pH(headers->Des());
   680     TPtr8 pH(headers->Des());
   683     // append to MIME headers for the root part   
   681     // append to MIME headers for the root part   
   684     pH.Append( NSimpleDocument::NSimpleRoot::KContentType );
   682     pH.Append( NSimpleDocument::NSimpleRoot::KContentType );
   685     pH.Append( NSimpleDocument::NSimpleRoot::KCID );    
   683     pH.Append( NSimpleDocument::NSimpleRoot::KCID );    
   686     root->SetHeaders( pH );    
   684     root->SetHeaders( pH );    
   689     TInt contCount = iContents.Count();
   687     TInt contCount = iContents.Count();
   690     for ( TInt i=0; i<contCount; i++ )
   688     for ( TInt i=0; i<contCount; i++ )
   691         { 
   689         { 
   692         // Let's convert next element into CBodyPart
   690         // Let's convert next element into CBodyPart
   693         CBodyPart* cp = CBodyPart::NewL();
   691         CBodyPart* cp = CBodyPart::NewL();
   694         aBodies.AppendL( cp );                
   692         aBodies.Append( cp );                
   695          
   693          
   696         // Set Headers
   694         // Set Headers
   697         headerSize = NSimpleDocument::NSimpleContent::KContentTypeSize + 
   695         headerSize = NSimpleDocument::NSimpleContent::KContentTypeSize + 
   698                      NSimpleDocument::NSimpleContent::KCIDSize + 
   696                      NSimpleDocument::NSimpleContent::KCIDSize + 
   699                      NSimpleDocument::NSimpleContent::KContentEncodingSize;
   697                      NSimpleDocument::NSimpleContent::KContentEncodingSize;
   700         headerSize += (iContents[i])->ContentID().Length();
   698         headerSize += (iContents[i])->ContentID().Length();
   701         headerSize += (iContents[i])->ContentType().Length();                 
   699         headerSize += (iContents[i])->ContentType().Length();                 
   702         
   700         
   703         headers = HBufC8::NewL( headerSize );
   701         headers = HBufC8::NewL( headerSize );
   704         // Append to cleanup array  
   702         // Append to cleanup array  
   705         aBuffers.AppendL( headers );
   703         aBuffers.Append( headers );
   706         pH.Set( headers->Des() );
   704         pH.Set( headers->Des() );
   707 
   705 
   708         // _LIT8( KMyContentType, "Content-Type: %S\r\n"); 
   706         // _LIT8( KMyContentType, "Content-Type: %S\r\n"); 
   709         TPtrC8 myValue = (iContents[i])->ContentType();     
   707         TPtrC8 myValue = (iContents[i])->ContentType();     
   710         pH.Format( NSimpleDocument::NSimpleContent::KContentType, &myValue );    
   708         pH.Format( NSimpleDocument::NSimpleContent::KContentType, &myValue );    
   716                      
   714                      
   717         // Body
   715         // Body
   718                     
   716                     
   719         // BASE64 encode
   717         // BASE64 encode
   720         HBufC8* body64 = HBufC8::NewL( (iContents[i])->Body().Length() * KB64Expand );  
   718         HBufC8* body64 = HBufC8::NewL( (iContents[i])->Body().Length() * KB64Expand );  
   721         aBuffers.AppendL( body64 );        
   719         aBuffers.Append( body64 );        
   722         TImCodecB64 codec64;
   720         TImCodecB64 codec64;
   723         codec64.Initialise();        
   721         codec64.Initialise();        
   724         TPtr8 desti8 = body64->Des();  
   722         TPtr8 desti8 = body64->Des();  
   725         
   723         
   726         // notice: leave if error?
   724         // notice: leave if error?