|
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: Imps engine wbxml message encoder |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef CImpsEncodeWbXml_H |
|
21 #define CImpsEncodeWbXml_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> |
|
25 #include "ImpsMessageInterpreterApi.h" |
|
26 #include "nw_encoder_domencoder.h" |
|
27 #include "ImpsXmlUtils.h" |
|
28 #include "impscommonenums.h" |
|
29 |
|
30 // CONSTANTS |
|
31 const TInt KImpsMaxDictionaries = 2; |
|
32 const TInt KImpsValueListAlternative = 0x01; |
|
33 const TInt KImpsValueListOptional = 0x02; |
|
34 const TInt KImpsValueListMultiple = 0x04; |
|
35 const TInt KImpsValueListOnceOrMore = 0x08; |
|
36 const TInt KImpsValueListEnd = 0x10; |
|
37 const TInt KImpsValueListEmpty = 0x20; |
|
38 const TInt KImpsSubList = 0x40; |
|
39 const TInt KImpsMaxTextItemCount = 2; |
|
40 const TInt KImpsExtraElemEnd = -2; |
|
41 |
|
42 // FORWARD DECLARATIONS |
|
43 class MImpsKey; |
|
44 |
|
45 // CLASS DECLARATION |
|
46 |
|
47 class CImpsEncodeWbXml :public CBase, public MImpsEncoder |
|
48 { |
|
49 public: // Constructors and destructor |
|
50 |
|
51 /** |
|
52 * Two-phased constructor. |
|
53 */ |
|
54 static CImpsEncodeWbXml* NewL(); |
|
55 |
|
56 /** |
|
57 * Destructor. |
|
58 */ |
|
59 virtual ~CImpsEncodeWbXml(); |
|
60 |
|
61 public: // New functions |
|
62 |
|
63 /** |
|
64 * method builds wbxml encoded message based on data |
|
65 * included in class aImpsData |
|
66 * @param aImpsData reference to MImpsDataAccessor class. |
|
67 * @param aEncodeBuffer buffer to hold the encoded message, |
|
68 * @return (parser) error code |
|
69 */ |
|
70 void EncodeMessageL( |
|
71 MImpsDataAccessor& aImpsData, |
|
72 CBufFlat& aEncodeBuffer ); |
|
73 |
|
74 private: |
|
75 |
|
76 /** |
|
77 * Destructor |
|
78 */ |
|
79 virtual void Destroy(); |
|
80 |
|
81 /** |
|
82 * wbxml message MIME type |
|
83 * @return MIME type |
|
84 */ |
|
85 virtual TPtrC8 MimeType(); |
|
86 |
|
87 |
|
88 struct SImpsValueList { |
|
89 TInt Begin; |
|
90 TInt Length; |
|
91 TInt Next; |
|
92 TInt Current; |
|
93 TInt CurrentLength; |
|
94 TInt Flags; |
|
95 }; |
|
96 |
|
97 /** |
|
98 * C++ default constructor. |
|
99 */ |
|
100 CImpsEncodeWbXml( ); |
|
101 |
|
102 /** |
|
103 * By default constructor is private. |
|
104 */ |
|
105 void ConstructL(); |
|
106 |
|
107 // By default, prohibit copy constructor |
|
108 CImpsEncodeWbXml( const CImpsEncodeWbXml& ); |
|
109 |
|
110 // Prohibit assigment operator |
|
111 CImpsEncodeWbXml& operator= ( const CImpsEncodeWbXml& ); |
|
112 |
|
113 /** |
|
114 * method adds one element to DOM tree |
|
115 * @param aElement element name |
|
116 * @param aNode parent DOM node |
|
117 * @param aNode element index if may exist multiple times |
|
118 * @return error code |
|
119 */ |
|
120 TInt EncodeElementL(TDesC &aElement, NW_DOM_ElementNode_t* aNode, TInt aIndex); |
|
121 |
|
122 /** |
|
123 * method creates dictionary, which maps WBXML tokens to DTD tags |
|
124 * @return error code |
|
125 */ |
|
126 TInt CreateDictionary( ); |
|
127 |
|
128 /** |
|
129 * method reads one element declaration from DTD |
|
130 * @param aElement element name |
|
131 * @return error code |
|
132 */ |
|
133 TPtrC ReadElementDeclaration(TDesC &aElement); |
|
134 |
|
135 /** |
|
136 * method stores node value to DOM tree |
|
137 * @param aToken element WBXML token value |
|
138 * @param aNode element DOM node |
|
139 * @param aValue element value |
|
140 * @return error code |
|
141 */ |
|
142 TInt EncodeValueL(TInt aToken, NW_DOM_TextNode_t* aNode,TInt aValue); |
|
143 |
|
144 /** |
|
145 * method reads next value in element declaration |
|
146 * @param aValueList |
|
147 * @return value |
|
148 */ |
|
149 TPtrC ReadNextValue(SImpsValueList* aValueList,TPtrC aValues); |
|
150 |
|
151 /** |
|
152 * method adds attribute values to element DOM node |
|
153 * @param aToken element WBXML token value |
|
154 * @param aNode element DOM node |
|
155 * @return error code |
|
156 */ |
|
157 TInt EncodeAttributes(TInt aToken, NW_DOM_ElementNode_t* aNode); |
|
158 |
|
159 /** |
|
160 * method encodes alternative values in WV element decralation |
|
161 * @param aToken element WBXML token value |
|
162 * @param aNode parent DOM node |
|
163 * @return error code |
|
164 */ |
|
165 TInt EncodeSubListL(TPtrC aValue, NW_DOM_TextNode_t* aNode); |
|
166 |
|
167 /** |
|
168 * method encodes multibyte integer value |
|
169 * @param aValue integer value |
|
170 * @param aBuffer for encoded value |
|
171 */ |
|
172 void StoreInteger(TUint32 aValue, TPtr8 aBuffer); |
|
173 |
|
174 /** |
|
175 * method sets DTD pointer |
|
176 * @param aOffset offset in DTD buffer |
|
177 * @param aLength string length |
|
178 * @return new pointer value |
|
179 */ |
|
180 TPtrC SetPointer(TInt aOffset,TInt aLength ); |
|
181 |
|
182 /** |
|
183 * method count string length |
|
184 * @param aPtr contains string |
|
185 * @return string length |
|
186 */ |
|
187 TInt CountContentSize(TDesC*& aPtr); |
|
188 |
|
189 /** |
|
190 * method counts message content size |
|
191 * @param aToken content size token |
|
192 * @return success code |
|
193 */ |
|
194 TInt SetContentSizeL(TInt aToken, NW_DOM_ElementNode_t* aNode); |
|
195 |
|
196 /** |
|
197 * method selects alternative value |
|
198 * @param aToken element token |
|
199 * @param aValue |
|
200 * @return alternative value |
|
201 */ |
|
202 // TInt SelectAlternativeValueL(TInt aToken, TPtrC aValue); |
|
203 |
|
204 /** |
|
205 * method updates data accessor key |
|
206 * @param aToken element token |
|
207 */ |
|
208 void PopAccessKeyL(TInt aToken); |
|
209 |
|
210 /** |
|
211 * method fetches next element |
|
212 * @param aValueList |
|
213 * @param aElementCounter |
|
214 * @param aRcode |
|
215 * @param aElementList |
|
216 * @param aCurrentElement |
|
217 * @return next element |
|
218 */ |
|
219 TPtrC FetchNextElement(SImpsValueList* aValueList,TInt& aElementCounter,TInt& aRcode, |
|
220 TPtrC aElementList,TPtrC aCurrentElement); |
|
221 |
|
222 /** |
|
223 * method updates data accessor key |
|
224 * @param aToken element token |
|
225 * @param aIndex element index |
|
226 */ |
|
227 TInt SetDataAccessorKeyL(TInt aToken,TInt aIndex); |
|
228 |
|
229 /** |
|
230 * method reads sub element list |
|
231 * @param aElement |
|
232 * @param aValueList |
|
233 */ |
|
234 void ReadElementList(TPtrC aElement, SImpsValueList* aValueList); |
|
235 |
|
236 /** |
|
237 * method reads wbxml token value |
|
238 * @param aElement |
|
239 * @return wbxml token |
|
240 */ |
|
241 TInt ReadToken(TPtrC aElement); |
|
242 |
|
243 /** |
|
244 * method stores 8 bit string to DOM node |
|
245 * @param aToken element token |
|
246 * @param aElemCount |
|
247 * @return |
|
248 */ |
|
249 TInt EncodeString8L(TInt aToken,TInt& aElemCount); |
|
250 |
|
251 /** |
|
252 * method stores extension value to DOM node |
|
253 * @param aToken element token |
|
254 * @param aElemCount |
|
255 * @return |
|
256 */ |
|
257 TInt EncodeExtL(TInt aToken,TInt& aElemCount); |
|
258 |
|
259 /** |
|
260 * method stores string to DOM node |
|
261 * @param aToken element token |
|
262 * @param aElemCount |
|
263 * @return |
|
264 */ |
|
265 TInt EncodeStringL(TInt aToken,TInt& aElemCount); |
|
266 |
|
267 /** |
|
268 * method stores integer value to DOM node |
|
269 * @param aToken element token |
|
270 * @param aElemCount |
|
271 * @return |
|
272 */ |
|
273 TInt EncodeIntegerL(TInt aToken,TInt& aElemCount); |
|
274 |
|
275 /** |
|
276 * method stores boolean value to DOM node |
|
277 * @param aToken element token |
|
278 * @param aElemCount |
|
279 * @return |
|
280 */ |
|
281 TInt EncodeBooleanL(TInt aToken,TInt& aElemCount); |
|
282 |
|
283 /** |
|
284 * method searches possible prefix from string |
|
285 * @param aString is given string |
|
286 * @param aOffset |
|
287 * @return possible prefix |
|
288 */ |
|
289 TInt SearchPrefix(TPtrC8 aString,TInt& aOffset); |
|
290 |
|
291 private: // Data |
|
292 |
|
293 TInt iError; |
|
294 CBufFlat* iEncodeBuffer; |
|
295 MImpsDataAccessor* iImpsData; |
|
296 MImpsKey* iAccessKey; |
|
297 NW_DOM_DocumentNode_t* iDocument; |
|
298 TInt iPosition; |
|
299 TInt iCurrentDictionary; |
|
300 HBufC* iCspDtd; |
|
301 HBufC* iContentDtd; |
|
302 HBufC* iPresenceDtd; |
|
303 TInt iValuePosition; |
|
304 TInt iElementPosition; |
|
305 TInt iDictionaryCount; |
|
306 NW_WBXML_Dictionary_t* iDictionaries[KImpsMaxDictionaries]; |
|
307 CImpsWbXmlData* iWbXmlData; |
|
308 HBufC* iElementValue; |
|
309 HBufC8* iStoreValue; |
|
310 NW_String_t iString; |
|
311 NW_WBXML_Opaque_t iOpaque; |
|
312 NW_DOM_TextItem_t iTextItem[KImpsMaxTextItemCount]; |
|
313 NW_DOM_AttrVal_t iAttribute; |
|
314 TInt iNameSpace; |
|
315 TImpsKeyType iKeyType; |
|
316 TInt iPEC; |
|
317 CImpsXmlUtils* iXmlUtils; |
|
318 TImpsCspVersion iCspVersion; |
|
319 |
|
320 }; |
|
321 |
|
322 #endif // ?INCLUDE_H |
|
323 |
|
324 // End of File |