xml/xmldomandxpath/inc/xmlengineserializer/xmlengserializer.h
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 serializer
       
    15 //
       
    16 
       
    17 
       
    18 
       
    19 /**
       
    20  @file
       
    21  @publishedAll
       
    22  @released
       
    23 */
       
    24 #ifndef XMLENGSERIALIZER_H
       
    25 #define XMLENGSERIALIZER_H
       
    26 
       
    27 #include <e32base.h>
       
    28 #include <xml/dom/xmlengserializationoptions.h>
       
    29 #include <xml/dom/xmlengnode.h>
       
    30 
       
    31 class MXmlEngOutputStream;
       
    32 class RFs;
       
    33 
       
    34 /** Controls the format of serialization */
       
    35 enum TXmlEngSerializerType
       
    36 	{
       
    37 	/** Default serialization (XML) */
       
    38 	ESerializerDefault,
       
    39 	/** Serialization to MIME Multipart containing XOP */
       
    40 	ESerializerXOP,
       
    41 	/** Serialization to XOP Infoset */
       
    42 	ESerializerXOPInfoset,
       
    43 	/** Serialization to GZip */
       
    44 	ESerializerGZip
       
    45 	};
       
    46 
       
    47 /** Controls the serialization format */
       
    48 enum TXmlEngSerializationOutput
       
    49 	{
       
    50 	ESerializeToFile,
       
    51 	ESerializeToBuffer,
       
    52 	ESerializeToStream
       
    53 	};
       
    54 
       
    55 /**
       
    56 Provides the serializer interface and provides common functionality to all
       
    57 serializers.  Implements default serialization (plain XML).  Derived classes
       
    58 implement serialization to other formats.
       
    59 
       
    60 @see TXmlEngSerializerType
       
    61 */
       
    62 class CXmlEngSerializer: public CBase
       
    63     {
       
    64 	friend class CXmlEngSerializerXOP;
       
    65 	friend class CXmlEngSerializerGZIP;
       
    66 
       
    67 public:
       
    68     /**
       
    69 	Creates a serializer of the given type.  Returns an instance of this
       
    70 	class or a derived class.
       
    71 
       
    72     @param aType Serializer type    
       
    73     @return The serializer
       
    74 	@leave - One of the system-wide error codes
       
    75     */
       
    76     IMPORT_C static CXmlEngSerializer* NewL(TXmlEngSerializerType aType = ESerializerDefault);
       
    77    
       
    78 	/**
       
    79 	Sets the output type to file and saves the file name for later
       
    80 	serialization.
       
    81 	@param aFileName The file name of the file to serialize
       
    82 	@leave - One of the system-wide error codes
       
    83     */
       
    84     IMPORT_C void SetOutputL(const TDesC& aFileName);
       
    85 
       
    86 	/**
       
    87 	Sets the output type to buffer and saves the buffer for later serialization.
       
    88 	@param aBuffer The buffer to serialize
       
    89     */
       
    90     IMPORT_C void SetOutput(RBuf8& aBuffer);
       
    91 
       
    92 	/**
       
    93 	Sets the output type to stream and saves the stream for later serialization.
       
    94 	@param aBuffer The stream to serialize
       
    95     */
       
    96     IMPORT_C void SetOutput(MXmlEngOutputStream& aStream);
       
    97 
       
    98     /**
       
    99     Sets the serialization options
       
   100 	@param aOptions The serialization options to set.  Ownership is not
       
   101 	transferred and aOptions must stay in scope for the lifetime of the
       
   102 	serializer.
       
   103     */
       
   104     IMPORT_C void SetSerializationOptions(TXmlEngSerializationOptions& aOptions);	
       
   105 
       
   106 	/**
       
   107 	Serializes a DOM tree to the buffer, file or stream set previously with
       
   108 	SetOutputL() or SetOutput().
       
   109 
       
   110     @param aRoot The root node of the DOM tree to be serialized
       
   111     @return The number of bytes written
       
   112 	@leave KXmlEngErrNoParameters No previous call to SetOutputL() or SetOutput().
       
   113 	@leave KErrNotSupported Unsupported serialization type
       
   114 	@leave KXmlEngErrWrongEncoding Encoding not understood
       
   115 	@leave KXmlEngErrWrongUseofAPI Document of root node is NULL
       
   116     @leave KXmlEngErrNegativeOutputSize The data to be serialized has a negative size
       
   117     @leave - One of the system-wide error codes
       
   118     */
       
   119     IMPORT_C virtual TInt SerializeL(const TXmlEngNode aRoot = TXmlEngNode());
       
   120 
       
   121     /**
       
   122 	Serializes a DOM tree to file.  Any filename previously set with
       
   123 	SetOutputL(const TDesC&) is ignored.
       
   124     
       
   125     @param aFileName The file name to serialize to
       
   126     @param aRoot The root node of the DOM tree to be serialized     
       
   127     @param aOptions The serialization options	 	 
       
   128     @return The number of bytes written
       
   129 	@leave KXmlEngErrWrongEncoding Encoding not understood
       
   130 	@leave KXmlEngErrWrongUseofAPI Document of root node is NULL
       
   131     @leave KXmlEngErrNegativeOutputSize The data to be serialized has a negative size
       
   132 	@leave - One of the system-wide error codes
       
   133     */
       
   134     IMPORT_C virtual TInt SerializeL(const TDesC& aFileName, 
       
   135 			    const TXmlEngNode aRoot = TXmlEngNode(),
       
   136 			    const TXmlEngSerializationOptions& aOptions = TXmlEngSerializationOptions());
       
   137                                         									  		
       
   138     /**
       
   139     Serializes a DOM tree to file.  Any filename previously set with
       
   140 	SetOutputL(const TDesC&) is ignored. 
       
   141 
       
   142     @param aRFs File Server session
       
   143     @param aFileName The file name to serialize to
       
   144     @param aRoot The root node of the DOM tree to be serialized     
       
   145     @param aOptions The serialization options	 	 
       
   146     @return The number of bytes written
       
   147 	@leave KXmlEngErrWrongEncoding Encoding not understood
       
   148 	@leave KXmlEngErrWrongUseofAPI Document of root node is NULL
       
   149     @leave KXmlEngErrNegativeOutputSize The data to be serialized has a negative size
       
   150 	@leave - One of the system-wide error codes
       
   151     */
       
   152     IMPORT_C virtual TInt SerializeL(RFs& aRFs, 
       
   153 			const TDesC& aFileName, 
       
   154 			const TXmlEngNode aRoot = TXmlEngNode(),
       
   155 			const TXmlEngSerializationOptions& aOptions = TXmlEngSerializationOptions());
       
   156 				
       
   157     /**
       
   158 	Serializes a DOM tree to buffer.  Any buffer previously set with
       
   159 	SetOutputL(RBuf8&) is ignored.  Any existing data in aBuffer is destroyed.
       
   160 	This function allocates memory for the buffer and the caller must close the
       
   161 	buffer when finished.
       
   162      
       
   163     @param aBuffer The buffer to serialize to
       
   164     @param aRoot The root node of DOM tree
       
   165     @param aOptions The serialization options
       
   166     @return The number of bytes written
       
   167 	@leave KXmlEngErrWrongEncoding Encoding not understood
       
   168 	@leave KXmlEngErrWrongUseofAPI Document of root node is NULL
       
   169     @leave KXmlEngErrNegativeOutputSize The data to be serialized has a negative size
       
   170 	@leave - One of the system-wide error codes
       
   171     */
       
   172     IMPORT_C virtual TInt SerializeL(RBuf8& aBuffer, 
       
   173                             const TXmlEngNode aRoot = TXmlEngNode(),
       
   174                             const TXmlEngSerializationOptions& 
       
   175                             aOptions = TXmlEngSerializationOptions());
       
   176                             
       
   177     /** Destructor */
       
   178     virtual ~CXmlEngSerializer();
       
   179 
       
   180 private:
       
   181     /** Default constructor */
       
   182     CXmlEngSerializer();
       
   183     
       
   184    /** Second phase constructor. */
       
   185     void ConstructL();
       
   186     
       
   187 private:
       
   188 	HBufC*                           iOutFileName;
       
   189 	RBuf8*                           iBuffer;
       
   190 	MXmlEngOutputStream*		     iOutputStream;
       
   191 	TXmlEngSerializationOptions*     iSerializationOptions;
       
   192 	TXmlEngSerializationOutput       iSerializationOutput;
       
   193     };
       
   194 
       
   195 #endif /* XMLENGSERIALIZER_H */
       
   196