|
1 /* |
|
2 * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: interface for Presence XML Serializer. |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef __MPENGXMLSERIALIZER_H |
|
19 #define __MPENGXMLSERIALIZER_H |
|
20 |
|
21 // INCLUDES |
|
22 #include <E32Std.h> |
|
23 |
|
24 |
|
25 //CONSTANTS |
|
26 |
|
27 /** |
|
28 * Serializer panic reasons. |
|
29 * @since 2.1 |
|
30 */ |
|
31 enum TPEngSerializerPanics |
|
32 { |
|
33 EPEngSrlzr_AttributeNotAllowed = 0, |
|
34 EPEngSrlzr_EndTagNotAllowed = 1, |
|
35 EPEngSrlzr_EmptyInputString = 2, |
|
36 EPEngSrlzr_EndTagNameMismatch = 3, |
|
37 EPEngSrlzr_StateStackUnderflow = 4, |
|
38 EPEngSrlzr_XmlMarkupCharNotAllowed = 5, |
|
39 }; |
|
40 |
|
41 /** |
|
42 * Serializer panic category. |
|
43 * @since 2.1 |
|
44 */ |
|
45 _LIT( KXmlSerializer, "XMLSerializ" ); |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 //FORWARD DECLARATION |
|
51 class MPEngXMLSerializer; |
|
52 |
|
53 |
|
54 // FUNCTION PROTOTYPES |
|
55 |
|
56 /** |
|
57 * Factory method to create XML Serializer. |
|
58 * |
|
59 * @since 3.0 |
|
60 */ |
|
61 IMPORT_C MPEngXMLSerializer* CreateXmlSerializerL( TDes8& aBuffer ); |
|
62 IMPORT_C MPEngXMLSerializer* CreateXmlSerializerLC( TDes8& aBuffer ); |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 // CLASS DEFINITION |
|
69 /** |
|
70 * This class defines the interface for Presence XML Serializer. |
|
71 * XML serializer is used for generating XML fragments. |
|
72 * |
|
73 * It offers features to write XML tags, XML attributes and actual |
|
74 * XML fragment content. |
|
75 * |
|
76 * @since 2.1 |
|
77 */ |
|
78 class MPEngXMLSerializer |
|
79 { |
|
80 public: //Element handling methods |
|
81 |
|
82 /** |
|
83 * Writes a start tag. |
|
84 * |
|
85 * Writes a start tag with the given name. |
|
86 * If aName is zero length descriptor, |
|
87 * panics in debug builds with EEmptyInputString |
|
88 * and release builds leaves with KErrArgument. |
|
89 * |
|
90 * @since 2.1 |
|
91 * @param aName Tags name. |
|
92 * @return Self. |
|
93 */ |
|
94 virtual MPEngXMLSerializer& StartTagL( const TDesC8& aName ) = 0; |
|
95 |
|
96 |
|
97 /** |
|
98 * Writes an attribute. |
|
99 * |
|
100 * Attributes must be written directly after starting |
|
101 * the tag with StartTagL() method. It is possible write |
|
102 * several attributes by issuing multiple calls to AttributeL(). |
|
103 * If attribute isn't written directly after starting the tag, |
|
104 * panics in debug builds with EPEngSrlzr_AttributeNotAllowed and |
|
105 * leaves on release builds with KErrNotSupported. |
|
106 * |
|
107 * If aName is empty descriptor, panics in debug |
|
108 * builds with EPEngSrlzr_EmptyInputString and release |
|
109 * builds leaves with KErrArgument. However, aValue can |
|
110 * be empty descriptor. |
|
111 * |
|
112 * @since 2.1 |
|
113 * @param aName The attribute name. |
|
114 * @param aValue The attribute value. |
|
115 * @return Self. |
|
116 */ |
|
117 virtual MPEngXMLSerializer& AttributeL( const TDesC8& aName, |
|
118 const TDesC8& aValue ) = 0; |
|
119 |
|
120 |
|
121 /** |
|
122 * Writes end tag. |
|
123 * |
|
124 * Writes end tag with the given name. |
|
125 * (Closes thus lastly written start tag.) |
|
126 * |
|
127 * If there isn't any start tag to close, panics in debug |
|
128 * builds with EPEngSrlzr_EndTagNotAllowed and release builds |
|
129 * leaves with KErrNotSupported. |
|
130 * |
|
131 * If aName is zero length descriptor, |
|
132 * panics in debug builds with EPEngSrlzr_EmptyInputString |
|
133 * and release builds leaves with KErrArgument. |
|
134 * |
|
135 * If passed end tag name aName doesn't match corresponding |
|
136 * start tag name, panics in debug builds with |
|
137 * EPEngSrlzr_EndTagNameMismatch. |
|
138 * For performance reasons this check isn't done on |
|
139 * release builds ==> possible end tag name mismatches |
|
140 * are ignored in release builds. |
|
141 * |
|
142 * @since 2.1 |
|
143 * @param aName Tag name. |
|
144 * @return Self. |
|
145 */ |
|
146 virtual MPEngXMLSerializer& EndTagL( const TDesC8& aName ) = 0; |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 public: //Content writing methods |
|
152 |
|
153 |
|
154 /** |
|
155 * Writes raw protocol value without _ANY_ encoding. |
|
156 * |
|
157 * Checks the written value doesn't contain XML markup characters. |
|
158 * If it contains, handles the error with panic: |
|
159 * EPEngSrlzr_XmlMarkupCharNotAllowed. |
|
160 * |
|
161 * @since 3.0 |
|
162 * @param aValue Raw protocol value to write. |
|
163 * @return Self. |
|
164 */ |
|
165 virtual MPEngXMLSerializer& RawValueL( const TDesC8& aValue ) = 0; |
|
166 |
|
167 |
|
168 /** |
|
169 * Writes 8 bit text. |
|
170 * |
|
171 * Performed steps: |
|
172 * 1. Escapes XML entities. |
|
173 * |
|
174 * @since 3.0 |
|
175 * @param aText Text to write. |
|
176 * @return Self. |
|
177 */ |
|
178 virtual MPEngXMLSerializer& NarrowTextL( const TDesC8& aText ) = 0; |
|
179 |
|
180 |
|
181 /** |
|
182 * Writes Unicode text. |
|
183 * |
|
184 * Performed steps: |
|
185 * 1. Converts text from Unicode to Utf8 |
|
186 * 2. Escapes XML entities |
|
187 * |
|
188 * @since 3.0 |
|
189 * @param aText Text to write. |
|
190 * @return Self. |
|
191 */ |
|
192 virtual MPEngXMLSerializer& UnicodeTextL( const TDesC16& aText ) = 0; |
|
193 |
|
194 |
|
195 /** |
|
196 * Writes WV Address. |
|
197 * |
|
198 * Performed steps: |
|
199 * 1. Escapes WV Address characters |
|
200 * 2. Converts text from Unicode to Utf8 |
|
201 * 3. Escape XML entities |
|
202 * |
|
203 * @since 3.0 |
|
204 * @param aAddress Address to write. |
|
205 * @return Self. |
|
206 */ |
|
207 virtual MPEngXMLSerializer& WvAddressL( const TDesC16& aAddress ) = 0; |
|
208 |
|
209 |
|
210 /** |
|
211 * Writes data in BASE64 format. |
|
212 * |
|
213 * Performed steps: |
|
214 * 1. Coverts data to BASE64 format |
|
215 * |
|
216 * @since 3.0 |
|
217 * @param aData The data to write. |
|
218 * @return Self. |
|
219 */ |
|
220 virtual MPEngXMLSerializer& Base64DataL( const TDesC8& aData ) = 0; |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 public: //Serializer state handling methods |
|
228 |
|
229 /** |
|
230 * Stores serializer current state. |
|
231 * |
|
232 * Stores serializer current state to its internal |
|
233 * state stack. State consists from previously generated |
|
234 * XML fragment and other serializer internal data. |
|
235 * |
|
236 * States are stored to stack like structure and later |
|
237 * serializer state can be restored back to pushed state |
|
238 * or pushed state can be committed. |
|
239 * |
|
240 * On serializer destruction all previously pushed |
|
241 * states are committed automaticly. |
|
242 * |
|
243 * @since 2.1 |
|
244 */ |
|
245 virtual void PushSerializerStateL() = 0; |
|
246 |
|
247 /** |
|
248 * Commits topmost state in the state stack. |
|
249 * |
|
250 * Commits topmost state in the serializer |
|
251 * state stack. If there isn't any state to |
|
252 * commit, panics in debug builds with |
|
253 * EPEngSrlzr_StateStackUnderflow. In |
|
254 * release builds underflow is ignored. |
|
255 * |
|
256 * @since 2.1 |
|
257 */ |
|
258 virtual void CommitState() = 0; |
|
259 |
|
260 /** |
|
261 * Rollbacks the serializer state to topmost |
|
262 * state in the state stack. |
|
263 * |
|
264 * Rollbacks the serializer state to topmost |
|
265 * state in the state stack. If there isn't |
|
266 * any state to commit, panics in debug builds |
|
267 * with EPEngSrlzr_StateStackUnderflow. In |
|
268 * release builds underflow is ignored. |
|
269 * |
|
270 * @since 2.1 |
|
271 */ |
|
272 virtual void RollbackState() = 0; |
|
273 |
|
274 /** |
|
275 * Gets the count of pushed states. |
|
276 * |
|
277 * @since 2.1 |
|
278 * @return Count of pushed states. |
|
279 */ |
|
280 virtual TInt PushedStateCount() = 0; |
|
281 |
|
282 |
|
283 public: //Destructor & Cleanup support |
|
284 |
|
285 /** |
|
286 * Release method. |
|
287 * When called, deletes object and |
|
288 * frees all its resources. |
|
289 * |
|
290 * Concrete serializer object can be thus pushed |
|
291 * on the CleanupStack using CleanupClosePushL(). |
|
292 */ |
|
293 virtual void Close() = 0; |
|
294 |
|
295 |
|
296 /** |
|
297 * Inline virtual destructor. |
|
298 * Concrete instancies can be deleted |
|
299 * trough this interface. |
|
300 */ |
|
301 virtual ~MPEngXMLSerializer() {} |
|
302 |
|
303 }; |
|
304 |
|
305 #endif //__MPENGXMLSERIALIZER_H |
|
306 |
|
307 |
|
308 // End of File |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 |
|
315 |
|
316 |
|
317 |
|
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 |
|
329 |
|
330 |