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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Implementation of serializer
24 #ifndef XMLENGSERIALIZER_H
25 #define XMLENGSERIALIZER_H
28 #include <xml/dom/xmlengserializationoptions.h>
29 #include <xml/dom/xmlengnode.h>
31 class MXmlEngOutputStream;
34 /** Controls the format of serialization */
35 enum TXmlEngSerializerType
37 /** Default serialization (XML) */
39 /** Serialization to MIME Multipart containing XOP */
41 /** Serialization to XOP Infoset */
42 ESerializerXOPInfoset,
43 /** Serialization to GZip */
47 /** Controls the serialization format */
48 enum TXmlEngSerializationOutput
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.
60 @see TXmlEngSerializerType
62 class CXmlEngSerializer: public CBase
64 friend class CXmlEngSerializerXOP;
65 friend class CXmlEngSerializerGZIP;
69 Creates a serializer of the given type. Returns an instance of this
70 class or a derived class.
72 @param aType Serializer type
73 @return The serializer
74 @leave - One of the system-wide error codes
76 IMPORT_C static CXmlEngSerializer* NewL(TXmlEngSerializerType aType = ESerializerDefault);
79 Sets the output type to file and saves the file name for later
81 @param aFileName The file name of the file to serialize
82 @leave - One of the system-wide error codes
84 IMPORT_C void SetOutputL(const TDesC& aFileName);
87 Sets the output type to buffer and saves the buffer for later serialization.
88 @param aBuffer The buffer to serialize
90 IMPORT_C void SetOutput(RBuf8& aBuffer);
93 Sets the output type to stream and saves the stream for later serialization.
94 @param aBuffer The stream to serialize
96 IMPORT_C void SetOutput(MXmlEngOutputStream& aStream);
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
104 IMPORT_C void SetSerializationOptions(TXmlEngSerializationOptions& aOptions);
107 Serializes a DOM tree to the buffer, file or stream set previously with
108 SetOutputL() or SetOutput().
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
119 IMPORT_C virtual TInt SerializeL(const TXmlEngNode aRoot = TXmlEngNode());
122 Serializes a DOM tree to file. Any filename previously set with
123 SetOutputL(const TDesC&) is ignored.
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
134 IMPORT_C virtual TInt SerializeL(const TDesC& aFileName,
135 const TXmlEngNode aRoot = TXmlEngNode(),
136 const TXmlEngSerializationOptions& aOptions = TXmlEngSerializationOptions());
139 Serializes a DOM tree to file. Any filename previously set with
140 SetOutputL(const TDesC&) is ignored.
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
152 IMPORT_C virtual TInt SerializeL(RFs& aRFs,
153 const TDesC& aFileName,
154 const TXmlEngNode aRoot = TXmlEngNode(),
155 const TXmlEngSerializationOptions& aOptions = TXmlEngSerializationOptions());
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.
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
172 IMPORT_C virtual TInt SerializeL(RBuf8& aBuffer,
173 const TXmlEngNode aRoot = TXmlEngNode(),
174 const TXmlEngSerializationOptions&
175 aOptions = TXmlEngSerializationOptions());
178 virtual ~CXmlEngSerializer();
181 /** Default constructor */
184 /** Second phase constructor. */
190 MXmlEngOutputStream* iOutputStream;
191 TXmlEngSerializationOptions* iSerializationOptions;
192 TXmlEngSerializationOutput iSerializationOutput;
195 #endif /* XMLENGSERIALIZER_H */