xml/xmldomandxpath/src/xmlengineserializer/xmlengdeserializergzip.cpp
changeset 0 e35f40988205
equal deleted inserted replaced
-1:000000000000 0:e35f40988205
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Implementation of GZIP deserializer
       
    15 //
       
    16 
       
    17 #include <xml/parser.h>
       
    18 #include <xml/parserfeature.h>
       
    19 #include <ezgzip.h>
       
    20 
       
    21 #include <xml/dom/xmlengerrors.h>
       
    22 #include "xmlengdeserializergzip.h"
       
    23 #include "xmlenggzipbufferdeserializebm.h"
       
    24 #include "xmlenggzipfiledeserializer.h"
       
    25 
       
    26 #include <xml/dom/xmlengserializeerrors.h>
       
    27 
       
    28 
       
    29 using namespace Xml;
       
    30 
       
    31 // --------------------------------------------------------------------------------------
       
    32 // Constructor
       
    33 // --------------------------------------------------------------------------------------
       
    34 //
       
    35 CXmlEngDeserializerGZIP* CXmlEngDeserializerGZIP::NewL( MContentHandler& aContentHandler )
       
    36 	{   
       
    37 	CXmlEngDeserializerGZIP* self = new (ELeave) CXmlEngDeserializerGZIP( );
       
    38 	CleanupStack::PushL( self ); 
       
    39 	self->ConstructL( aContentHandler );
       
    40 	CleanupStack::Pop();
       
    41 	return self;
       
    42 	}
       
    43 
       
    44 // --------------------------------------------------------------------------------------
       
    45 // Deserialize document
       
    46 // --------------------------------------------------------------------------------------
       
    47 //
       
    48 void CXmlEngDeserializerGZIP::DeserializeL( const TDesC& aFileName,
       
    49 											const TXmlEngParsingOptions& /*aOptions*/ ) 
       
    50     {
       
    51 	RFs fs;
       
    52 	User::LeaveIfError(fs.Connect());
       
    53 	CleanupClosePushL(fs); 
       
    54 	DeserializeL(fs, aFileName);
       
    55 	CleanupStack::PopAndDestroy(&fs);
       
    56 	}
       
    57    
       
    58 // --------------------------------------------------------------------------------------
       
    59 // Deserialize document
       
    60 // --------------------------------------------------------------------------------------
       
    61 //
       
    62 void CXmlEngDeserializerGZIP::DeserializeL( RFs& aRFs, 
       
    63 											const TDesC& aFileName,
       
    64 											const TXmlEngParsingOptions& /*aOptions*/ ) 
       
    65     {
       
    66     CXmlEngGZipFileDeserializer* deser = CXmlEngGZipFileDeserializer::NewLC( iParser, aRFs, aFileName, KOutputBufferSize );
       
    67     
       
    68     while ( deser->InflateL() )
       
    69         {
       
    70         /* empty */
       
    71         }
       
    72     
       
    73     CleanupStack::PopAndDestroy( deser );
       
    74     }
       
    75 
       
    76 // --------------------------------------------------------------------------------------
       
    77 // Deserialize document
       
    78 // --------------------------------------------------------------------------------------
       
    79 //
       
    80 void CXmlEngDeserializerGZIP::DeserializeL( const TDesC8& aBuffer,
       
    81 											const TXmlEngParsingOptions& /*aOptions*/ ) 
       
    82     {
       
    83     CXmlEngGZipBufferDeserializeBM* bm = CXmlEngGZipBufferDeserializeBM::NewLC( iParser, aBuffer, KOutputBufferSize );
       
    84     CEZDecompressor* decompressor = CEZDecompressor::NewLC( *bm );
       
    85     
       
    86     while ( decompressor->InflateL() )
       
    87         {
       
    88         /* empty */
       
    89         }
       
    90     
       
    91     CleanupStack::PopAndDestroy( decompressor );
       
    92     CleanupStack::PopAndDestroy( bm );
       
    93     }
       
    94 
       
    95 // --------------------------------------------------------------------------------------
       
    96 // Deserialize document
       
    97 // --------------------------------------------------------------------------------------
       
    98 //
       
    99 void CXmlEngDeserializerGZIP::DeserializeL()
       
   100     {
       
   101 	switch(iSerializationOutput)
       
   102 		{
       
   103 		case EDeserializeFromFile:
       
   104 			{
       
   105 			if(!iInputFileName)
       
   106 				{
       
   107 				User::Leave(KXmlEngErrNoParameters);
       
   108 				}
       
   109 		    RFs fs; 
       
   110 		    CleanupClosePushL(fs);
       
   111 		    User::LeaveIfError(fs.Connect());    				
       
   112 		    DeserializeL(fs, iInputFileName->Des());			
       
   113 			CleanupStack::PopAndDestroy(&fs);
       
   114 			break;
       
   115 			}
       
   116 		case EDeserializeFromBuffer:
       
   117 			{
       
   118 			if(iBuffer.Length() == 0)
       
   119 				{
       
   120 				User::Leave(KXmlEngErrNoParameters);
       
   121 				}
       
   122 			DeserializeL(iBuffer);			
       
   123 			break;
       
   124 			}
       
   125 		default:
       
   126 			{
       
   127 			User::Leave(KErrGeneral);
       
   128 			}						
       
   129 		}   
       
   130     }
       
   131 
       
   132 // --------------------------------------------------------------------------------------
       
   133 // Default Constructor
       
   134 // --------------------------------------------------------------------------------------
       
   135 //
       
   136 CXmlEngDeserializerGZIP::CXmlEngDeserializerGZIP()
       
   137     {
       
   138     }
       
   139     
       
   140 // --------------------------------------------------------------------------------------
       
   141 // Destructor
       
   142 // --------------------------------------------------------------------------------------
       
   143 //
       
   144 CXmlEngDeserializerGZIP::~CXmlEngDeserializerGZIP()
       
   145     {
       
   146     }
       
   147 
       
   148