xml/xmldomandxpath/src/xmlengineserializer/xmlengserializergzip.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 // Node container implementation
       
    15 //
       
    16 
       
    17 #include <xml/dom/xmlengdocument.h>
       
    18 #include <xml/dom/xmlengerrors.h>
       
    19 #include "xmlengserializergzip.h"
       
    20 #include "xmlenggzipoutputstream.h"
       
    21 #include "xmlenggzipfileoutputstream.h"
       
    22 #include "xmlenggzipbufferoutputstream.h"
       
    23 #include "ezgzip.h"
       
    24 #include <xml/dom/xmlengserializeerrors.h>
       
    25 
       
    26 
       
    27 
       
    28 TInt CXmlEngSerializerGZIP::SerializeToFileL(RFs& aRFs,
       
    29                           const TDesC& aFileName,
       
    30                           const TXmlEngNode aNode,
       
    31                           const TXmlEngSerializationOptions& aOpt)
       
    32     {
       
    33     RFile outFile;
       
    34     
       
    35     User::LeaveIfError(outFile.Replace(aRFs,aFileName,EFileStream | EFileWrite | EFileShareExclusive));
       
    36     CleanupClosePushL(outFile);
       
    37 
       
    38     CXmlEngGZIPFileOutputStream* gzfos = CXmlEngGZIPFileOutputStream::NewLC(outFile,aRFs);
       
    39     TRAPD(err,aNode.OwnerDocument().SaveL(*gzfos,aNode,aOpt));
       
    40     TInt sErr = gzfos->CheckError();
       
    41     if(sErr)
       
    42         {
       
    43         User::Leave(sErr);
       
    44         }
       
    45     if(err)
       
    46         {
       
    47         User::Leave(err);
       
    48         }
       
    49     
       
    50     TInt fSize;
       
    51     outFile.Size(fSize);
       
    52     CleanupStack::PopAndDestroy(gzfos);
       
    53     CleanupStack::PopAndDestroy(&outFile);
       
    54     
       
    55     return fSize;
       
    56     }
       
    57 
       
    58 TInt CXmlEngSerializerGZIP::SerializeToBufferL(RBuf8& aBuf,
       
    59                                             const TXmlEngNode aNode,
       
    60                                             const TXmlEngSerializationOptions& aOpt)
       
    61     {
       
    62     CXmlEngGZIPBufferOutputStream* gzbos = CXmlEngGZIPBufferOutputStream::NewLC(aBuf);
       
    63     TRAPD(err,aNode.OwnerDocument().SaveL(*gzbos,aNode,aOpt));
       
    64     TInt sErr = gzbos->CheckError();
       
    65     if(sErr)
       
    66         {
       
    67         User::Leave(sErr);
       
    68         }
       
    69     if(err)
       
    70         {
       
    71         User::Leave(err);
       
    72         }
       
    73     CleanupStack::PopAndDestroy(gzbos);
       
    74     return aBuf.Size();
       
    75     }
       
    76     
       
    77 TInt CXmlEngSerializerGZIP::SerializeToStreamL(MXmlEngOutputStream& aStream,
       
    78                                             const TXmlEngNode aNode,
       
    79                                             const TXmlEngSerializationOptions& aOpt)
       
    80     {
       
    81     CXmlEngGZIPOutputStream* gzbos = CXmlEngGZIPOutputStream::NewLC(aStream);
       
    82     TInt size = 0;
       
    83     TRAPD(err,size = aNode.OwnerDocument().SaveL(*gzbos,aNode,aOpt));
       
    84     TInt sErr = gzbos->CheckError();
       
    85     if(sErr)
       
    86         {
       
    87         User::Leave(sErr);
       
    88         }
       
    89     if(err)
       
    90         {
       
    91         User::Leave(err);
       
    92         }
       
    93     CleanupStack::PopAndDestroy(gzbos);
       
    94     return size;
       
    95     }
       
    96 
       
    97 // --------------------------------------------------------------------------------------
       
    98 // Constructor
       
    99 // --------------------------------------------------------------------------------------
       
   100 //
       
   101 CXmlEngSerializerGZIP* CXmlEngSerializerGZIP::NewL()
       
   102    {
       
   103    CXmlEngSerializerGZIP* self = new (ELeave) CXmlEngSerializerGZIP();
       
   104    return self;
       
   105    }
       
   106 
       
   107 // --------------------------------------------------------------------------------------
       
   108 // Serializes TXmlEngNode to file
       
   109 // --------------------------------------------------------------------------------------
       
   110 //
       
   111 TInt CXmlEngSerializerGZIP::SerializeL(const TXmlEngNode aRoot)
       
   112     {
       
   113     TXmlEngSerializationOptions* defPtr = NULL;
       
   114     TXmlEngSerializationOptions def = TXmlEngSerializationOptions();
       
   115     if(iSerializationOptions )
       
   116     	{
       
   117     	defPtr = iSerializationOptions;
       
   118     	}
       
   119     else
       
   120         {
       
   121         defPtr = &def;
       
   122         }
       
   123     
       
   124 	RXmlEngDocument doc = aRoot.OwnerDocument(); 
       
   125 	
       
   126 	switch(iSerializationOutput)
       
   127 		{
       
   128 		case ESerializeToFile:
       
   129 			{
       
   130             if (!iOutFileName)
       
   131 	            {
       
   132 	            User::Leave(KXmlEngErrNoParameters);
       
   133 	            } 	
       
   134 	        return SerializeL(iOutFileName->Des(), aRoot, *defPtr);
       
   135 			}
       
   136 		case ESerializeToBuffer:
       
   137 			{
       
   138 			return SerializeL(*iBuffer, aRoot, *defPtr);
       
   139 			}
       
   140 		case ESerializeToStream:
       
   141 			{
       
   142 			if(!iOutputStream)
       
   143 			    {
       
   144 			    User::Leave(KXmlEngErrNoParameters);
       
   145 			    }
       
   146 			return SerializeToStreamL(*iOutputStream, aRoot, *defPtr);
       
   147 			}
       
   148 		default:
       
   149 			{
       
   150 			User::Leave(KErrNotSupported);
       
   151 			}						
       
   152 		}
       
   153 	return KErrGeneral; //should never happen
       
   154     }
       
   155 
       
   156 // --------------------------------------------------------------------------------------
       
   157 // Serializes TXmlEngNode to file
       
   158 // --------------------------------------------------------------------------------------
       
   159 //
       
   160 TInt CXmlEngSerializerGZIP::SerializeL( RFs& aRFs, 
       
   161 									 const TDesC& aFileName, 
       
   162 									 const TXmlEngNode aRoot,
       
   163 									 const TXmlEngSerializationOptions& aOptions )
       
   164     {
       
   165     return SerializeToFileL(aRFs, aFileName, aRoot, aOptions);
       
   166     }
       
   167 
       
   168 // --------------------------------------------------------------------------------------
       
   169 // Serializes TXmlEngNode to file
       
   170 // --------------------------------------------------------------------------------------
       
   171 //
       
   172 TInt CXmlEngSerializerGZIP::SerializeL( const TDesC& aFileName, 
       
   173                                      const TXmlEngNode aRoot,
       
   174 									 const TXmlEngSerializationOptions& aOptions )
       
   175     {
       
   176     RFs rfs;
       
   177     User::LeaveIfError(rfs.Connect());
       
   178     CleanupClosePushL(rfs);
       
   179     TInt outSize = SerializeToFileL(rfs, aFileName, aRoot, aOptions);
       
   180     CleanupStack::PopAndDestroy(&rfs);
       
   181     return outSize;
       
   182     }
       
   183 
       
   184 // --------------------------------------------------------------------------------------
       
   185 // Serializes TXmlEngNode to buffer
       
   186 // --------------------------------------------------------------------------------------
       
   187 //
       
   188 TInt CXmlEngSerializerGZIP::SerializeL( RBuf8& aBuffer, 
       
   189                                      const TXmlEngNode aRoot, 										  
       
   190 									 const TXmlEngSerializationOptions& aOptions)
       
   191     {
       
   192     return SerializeToBufferL(aBuffer,aRoot,aOptions);
       
   193     } 
       
   194   
       
   195 // --------------------------------------------------------------------------------------
       
   196 // Constructor
       
   197 // --------------------------------------------------------------------------------------
       
   198 //
       
   199 CXmlEngSerializerGZIP::CXmlEngSerializerGZIP()
       
   200     {
       
   201     }
       
   202     
       
   203 // --------------------------------------------------------------------------------------
       
   204 // Destructor
       
   205 // --------------------------------------------------------------------------------------
       
   206 //
       
   207 CXmlEngSerializerGZIP::~CXmlEngSerializerGZIP()
       
   208     {
       
   209     }  
       
   210 
       
   211