|
1 // Copyright (c) 1997-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 // |
|
15 |
|
16 #ifndef __WBCONVERTER_H |
|
17 #define __WBCONVERTER_H |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <s32stor.h> |
|
21 #include <f32file.h> |
|
22 |
|
23 // forward declarations |
|
24 // |
|
25 class CWbxmlToken; |
|
26 class MWbxmlConverterObserver; |
|
27 class CByteList; |
|
28 class CCnvCharacterSetConverter; |
|
29 |
|
30 // consts, defines, enums |
|
31 // |
|
32 /** |
|
33 @publishedAll |
|
34 @deprecated |
|
35 */ |
|
36 _LIT8(KWbXmlVersion10,"<?xml version=\"1.0\"?>"); |
|
37 |
|
38 /** |
|
39 @publishedAll |
|
40 @deprecated |
|
41 */ |
|
42 _LIT8(KWbPublicIdStartWml,"<!DOCTYPE wml PUBLIC \""); |
|
43 /** |
|
44 @publishedAll |
|
45 @deprecated |
|
46 */ |
|
47 _LIT8(KWbPublicIdStartSi,"<!DOCTYPE si PUBLIC \""); |
|
48 /** |
|
49 @publishedAll |
|
50 @deprecated |
|
51 */ |
|
52 _LIT8(KWbPublicIdStartSl,"<!DOCTYPE sl PUBLIC \""); |
|
53 |
|
54 |
|
55 /** |
|
56 @publishedAll |
|
57 @deprecated |
|
58 */ |
|
59 _LIT(KWbTokenDatabaseWml11,"\\RESOURCE\\WAPPUSH\\WMLC11.TOK"); |
|
60 /** |
|
61 @publishedAll |
|
62 @deprecated |
|
63 */ |
|
64 _LIT(KWbTokenDatabaseWml12,"\\RESOURCE\\WAPPUSH\\WMLC12.TOK"); |
|
65 /** |
|
66 @publishedAll |
|
67 @deprecated |
|
68 */ |
|
69 _LIT(KWbTokenDatabaseSI10,"\\RESOURCE\\WAPPUSH\\SI10.TOK"); |
|
70 /** |
|
71 @publishedAll |
|
72 @deprecated |
|
73 */ |
|
74 _LIT(KWbTokenDatabaseSL10,"\\RESOURCE\\WAPPUSH\\SL10.TOK"); |
|
75 |
|
76 /** |
|
77 @publishedAll |
|
78 @deprecated |
|
79 */ |
|
80 _LIT8(KWbPublicIdEnd11,"\" \"http://www.wapforum.org/DTD/wml_1.1.xml\">"); |
|
81 /** |
|
82 @publishedAll |
|
83 @deprecated |
|
84 */ |
|
85 _LIT8(KWbPublicIdEnd12,"\" \"http://www.wapforum.org/DTD/wml_1.2.xml\">"); |
|
86 /** |
|
87 @publishedAll |
|
88 @deprecated |
|
89 */ |
|
90 _LIT8(KWbPublicIdEndSI10,"\" \"http://www.wapforum.org/DTD/si.dtd\">"); |
|
91 /** |
|
92 @publishedAll |
|
93 @deprecated |
|
94 */ |
|
95 _LIT8(KWbPublicIdEndSL10,"\" \"http://www.wapforum.org/DTD/sl.dtd\">"); |
|
96 |
|
97 /** |
|
98 @publishedAll |
|
99 @deprecated |
|
100 */ |
|
101 _LIT8(KWbTagStart,"<"); |
|
102 /** |
|
103 @publishedAll |
|
104 @deprecated |
|
105 */ |
|
106 _LIT8(KWbTagStartClose,"</"); |
|
107 /** |
|
108 @publishedAll |
|
109 @deprecated |
|
110 */ |
|
111 _LIT8(KWbTagEndWithContent,">"); |
|
112 /** |
|
113 @publishedAll |
|
114 @deprecated |
|
115 */ |
|
116 _LIT8(KWbTagEndWithoutContent,"/>"); |
|
117 /** |
|
118 @publishedAll |
|
119 @deprecated |
|
120 */ |
|
121 _LIT8(KWbVariableStart,"$("); |
|
122 /** |
|
123 @publishedAll |
|
124 @deprecated |
|
125 */ |
|
126 _LIT8(KWbVariableEscaped,":E)"); |
|
127 /** |
|
128 @publishedAll |
|
129 @deprecated |
|
130 */ |
|
131 _LIT8(KWbVariableUnescaped,":U)"); |
|
132 /** |
|
133 @publishedAll |
|
134 @deprecated |
|
135 */ |
|
136 _LIT8(KWbVariableNoescape,":N)"); |
|
137 /** |
|
138 @publishedAll |
|
139 @deprecated |
|
140 */ |
|
141 _LIT8(KWbVariableNormal,")"); |
|
142 /** |
|
143 @publishedAll |
|
144 @deprecated |
|
145 */ |
|
146 _LIT8(KWbQuote,"\""); |
|
147 /** |
|
148 @publishedAll |
|
149 @deprecated |
|
150 */ |
|
151 _LIT8(KWbSpace," "); |
|
152 /** |
|
153 @publishedAll |
|
154 @deprecated |
|
155 */ |
|
156 _LIT8(KWbTab,"\t"); |
|
157 /** |
|
158 @publishedAll |
|
159 @deprecated |
|
160 */ |
|
161 _LIT8(KWbLineBreak,"\n"); |
|
162 |
|
163 /** |
|
164 @publishedAll |
|
165 @deprecated |
|
166 */ |
|
167 const TInt8 KWbxmlIdIndex = 0; |
|
168 /** |
|
169 @publishedAll |
|
170 @deprecated |
|
171 */ |
|
172 const TInt8 KWbxmlIdUnknown = 1; |
|
173 /** |
|
174 @publishedAll |
|
175 @deprecated |
|
176 */ |
|
177 const TInt8 KWbxmlIdWml10 = 2; |
|
178 /** |
|
179 @publishedAll |
|
180 @deprecated |
|
181 */ |
|
182 const TInt8 KWbxmlIdWta10 = 3; |
|
183 /** |
|
184 @publishedAll |
|
185 @deprecated |
|
186 */ |
|
187 const TInt8 KWbxmlIdWml11 = 4; |
|
188 /** |
|
189 @publishedAll |
|
190 @deprecated |
|
191 */ |
|
192 const TInt8 KWbxmlIdSI = 5; |
|
193 /** |
|
194 @publishedAll |
|
195 @deprecated |
|
196 */ |
|
197 const TInt8 KWbxmlIdSL = 6; |
|
198 /** |
|
199 @publishedAll |
|
200 @deprecated |
|
201 */ |
|
202 const TInt8 KWbxmlIdWml12 = 9; |
|
203 |
|
204 // Entity translation literals |
|
205 /** |
|
206 @publishedAll |
|
207 @deprecated |
|
208 */ |
|
209 _LIT8(KEntityDollar,"$$"); |
|
210 /** |
|
211 @publishedAll |
|
212 @deprecated |
|
213 */ |
|
214 _LIT8(KEntityAmp,"&"); |
|
215 /** |
|
216 @publishedAll |
|
217 @deprecated |
|
218 */ |
|
219 _LIT8(KEntityLt,"<"); |
|
220 /** |
|
221 @publishedAll |
|
222 @deprecated |
|
223 */ |
|
224 _LIT8(KEntityGt,">"); |
|
225 /** |
|
226 @publishedAll |
|
227 @deprecated |
|
228 */ |
|
229 _LIT8(KEntityQuot,"""); |
|
230 /** |
|
231 @publishedAll |
|
232 @deprecated |
|
233 */ |
|
234 _LIT8(KEntityApos,"'"); |
|
235 /** |
|
236 @publishedAll |
|
237 @deprecated |
|
238 */ |
|
239 _LIT8(KEntityNbsp," "); |
|
240 /** |
|
241 @publishedAll |
|
242 @deprecated |
|
243 */ |
|
244 _LIT8(KEntityShy,"­"); |
|
245 |
|
246 /** |
|
247 @publishedAll |
|
248 @deprecated |
|
249 */ |
|
250 const TUint16 KWbxmlSkipLiteralEndTagMagicToken = 0xac1d; |
|
251 |
|
252 |
|
253 // |
|
254 // CWbxmlConverter |
|
255 // |
|
256 class RFileReadStream; |
|
257 //##ModelId=3B6678E20007 |
|
258 class CWbxmlConverter : public CBase |
|
259 /** |
|
260 @publishedAll |
|
261 @deprecated |
|
262 */ |
|
263 { |
|
264 public: // Methods |
|
265 //##ModelId=3B6678E30199 |
|
266 ~CWbxmlConverter(); |
|
267 |
|
268 // NOTE: input data really is 8bit bytecode |
|
269 //##ModelId=3B6678E300F9 |
|
270 IMPORT_C static CWbxmlConverter* NewL(RFs& aFs, MWbxmlConverterObserver* aObserver); |
|
271 //##ModelId=3B6678E300BD |
|
272 IMPORT_C static CWbxmlConverter* NewLC(RFs& aFs, MWbxmlConverterObserver* aObserver); |
|
273 //##ModelId=3B6678E30135 |
|
274 IMPORT_C static CWbxmlConverter* NewL(RFs& aFs, MWbxmlConverterObserver* aObserver, const TDesC* aCharacterEncoding); |
|
275 //##ModelId=3B6678E3009F |
|
276 IMPORT_C void ProcessDataL(HBufC8& aBuffer); |
|
277 //##ModelId=3B6678E3009E |
|
278 IMPORT_C void CommitL(); |
|
279 |
|
280 private: // Emumerations |
|
281 |
|
282 enum TGotoState |
|
283 { |
|
284 EGotoStreaming = 1, |
|
285 EGotoString, |
|
286 EGotoOpaque |
|
287 }; |
|
288 enum TConvertState |
|
289 { |
|
290 EConvertError = 1, |
|
291 EConvertVersion, |
|
292 EConvertPublicIdValue, |
|
293 EConvertCharset, |
|
294 EConvertStringTable, |
|
295 EConvertPublicIdName, |
|
296 EConvertData, |
|
297 EConvertFinished |
|
298 }; |
|
299 |
|
300 private: // Methods |
|
301 |
|
302 //##ModelId=3B6678E30080 |
|
303 CWbxmlConverter(RFs& aFs); |
|
304 //##ModelId=3B6678E30045 |
|
305 void ConstructL(MWbxmlConverterObserver* aObserver, const TDesC* aCharacterEncoding); |
|
306 |
|
307 //##ModelId=3B6678E30044 |
|
308 void HandleDataL(); |
|
309 //##ModelId=3B6678E30009 |
|
310 void SetNextStateL(const TInt aResult, const TConvertState aState); |
|
311 //##ModelId=3B6678E30008 |
|
312 TInt ConvertWbxmlVersionL(); |
|
313 //##ModelId=3B6678E203E8 |
|
314 TInt ConvertPublicIdValueL(); // Extract PublicId |
|
315 //##ModelId=3B6678E203E7 |
|
316 TInt ConvertPublicIdNameL(); // Report PublicId |
|
317 //##ModelId=3B6678E203E6 |
|
318 TInt ConvertCharsetL(); |
|
319 //##ModelId=3B6678E203DE |
|
320 TInt ConvertStringTableL(); |
|
321 //##ModelId=3B6678E203DD |
|
322 TInt ConvertDataL(); |
|
323 //##ModelId=3B6678E203DC |
|
324 TInt ConvertDataStreamingL(); |
|
325 //##ModelId=3B6678E203D3 |
|
326 TInt ConvertDataStringL(); |
|
327 //##ModelId=3B6678E203D2 |
|
328 TInt ConvertOpaqueDataL(); |
|
329 //##ModelId=3B6678E203B4 |
|
330 HBufC16* FormatDateStringL(TDesC8& aData); |
|
331 |
|
332 //##ModelId=3B6678E20396 |
|
333 TInt OpenTokenFileL(HBufC& aFileName); |
|
334 //##ModelId=3B6678E2035A |
|
335 void ReadTokenFileL(RFileReadStream& aStream, HBufC8& aBuffer); |
|
336 //##ModelId=3B6678E2033C |
|
337 TInt LoadTokensL(HBufC* aBuffer); |
|
338 |
|
339 //##ModelId=3B6678E2030A |
|
340 TInt ExtractMultiByte(TUint32* aMultiByte, TInt aSkipHeader); |
|
341 //##ModelId=3B6678E202E3 |
|
342 void Indent(const TInt aCount) const; |
|
343 //##ModelId=3B6678E202E2 |
|
344 void FinishStringL(); |
|
345 //##ModelId=3B6678E202C4 |
|
346 HBufC16* CharsetConvertDataL(TDesC8& aData); |
|
347 |
|
348 // Gets the full path to wmlc token table. Input aTokenFilePath is the path, without the drive. |
|
349 // |
|
350 // In: |
|
351 // aTokenFilePath - the path to the token table file. |
|
352 // |
|
353 // Rtn: the full path to the token table file. Ownership is transfered to caller. |
|
354 // |
|
355 //##ModelId=3B6678E202A6 |
|
356 HBufC* FindTokenFileL(const TDesC& aTokenFilePath) const; |
|
357 |
|
358 // Replaces characters originating from chracter entity references with the reference string |
|
359 // For example chracter '&' will be "decoded" back to "&" |
|
360 // |
|
361 // In: |
|
362 // aString - The original string containing the undedcoded characters. |
|
363 // This string can get ReAllocated during the process - DO NOT USE THIS POINTER |
|
364 // AFTER THE CALL to this method. (use the returned one instead...) |
|
365 // Return: |
|
366 // HBufC* - Pointer to the string with replaced stuff |
|
367 // |
|
368 //##ModelId=3B6678E20288 |
|
369 HBufC* ReplaceCharacterEntitiesL(HBufC* aString); |
|
370 |
|
371 // MWbxmlConverterObserver interface overloads |
|
372 //##ModelId=3B6678E2024C |
|
373 void OutputL(const TUint32 aSource) const; |
|
374 |
|
375 //##ModelId=3B6678E2022E |
|
376 TBool OutputCheckQuoteL(HBufC8& aSource) const; |
|
377 |
|
378 // Helper method to optimise the OutputL oveloads |
|
379 //##ModelId=3B6678E20211 |
|
380 void BufferAndOutputL(const TDesC8& aSource) const; |
|
381 |
|
382 // Must exist for Binary Compatibility |
|
383 //##ModelId=3B6678E20210 |
|
384 IMPORT_C virtual void CWbxmlConverter_Reserved1(); |
|
385 |
|
386 private: // Attributes |
|
387 |
|
388 // For binary compatibility |
|
389 //##ModelId=3B6678E20206 |
|
390 TAny* CWbxmlConverter_Reserved; |
|
391 |
|
392 // Attributes |
|
393 // Note: conversion table from disk ie. you can change it at runtime |
|
394 //##ModelId=3B6678E201F2 |
|
395 CArrayPtrFlat<CWbxmlToken>* iTagArray; |
|
396 //##ModelId=3B6678E201D3 |
|
397 CArrayPtrFlat<CWbxmlToken>* iAttArray; |
|
398 |
|
399 //##ModelId=3B6678E2018D |
|
400 MWbxmlConverterObserver* iObserver; |
|
401 |
|
402 //##ModelId=3B6678E20179 |
|
403 TUint8 iWbxmlVersion; |
|
404 //##ModelId=3B6678E20165 |
|
405 TUint32 iWbxmlCharset; |
|
406 //##ModelId=3B6678E20151 |
|
407 TUint32 iPublicId; |
|
408 //##ModelId=3B6678E2013D |
|
409 TUint32 iPublicIdIndex; |
|
410 |
|
411 // Note: must handle source as 8bit data even in Unicode compile! |
|
412 //##ModelId=3B6678E2012B |
|
413 CByteList* iByteList; |
|
414 //##ModelId=3B6678E2011F |
|
415 HBufC8* iStringTable; |
|
416 //##ModelId=3B6678E2010D |
|
417 HBufC8* iPublicIdStr; |
|
418 //##ModelId=3B6678E20101 |
|
419 RFs& iFs; |
|
420 |
|
421 //##ModelId=3B6678E200ED |
|
422 TInt iState; |
|
423 //##ModelId=3B6678E200E3 |
|
424 TUint32 iContinue; |
|
425 |
|
426 //##ModelId=3B6678E200D1 |
|
427 TUint8 iVariable; |
|
428 //##ModelId=3B6678E200C5 |
|
429 TUint8 hasAttrs; |
|
430 //##ModelId=3B6678E200B3 |
|
431 TUint8 hasContent; |
|
432 |
|
433 |
|
434 //##ModelId=3B6678E200A7 |
|
435 TInt iTagIndex; |
|
436 //##ModelId=3B6678E20095 |
|
437 CArrayFixFlat<TUint16>* iTagStack; |
|
438 //##ModelId=3B6678E2006B |
|
439 TBool iRestrictedOutput; |
|
440 |
|
441 enum TParsing |
|
442 { |
|
443 EParseNot = 0, |
|
444 EParseTag, |
|
445 EParseAttrs |
|
446 }; |
|
447 //##ModelId=3B6678E20059 |
|
448 TParsing iParsing; |
|
449 //##ModelId=3B6678E2004F |
|
450 TBool iOpenQuote; |
|
451 |
|
452 //##ModelId=3B6678E20045 |
|
453 mutable HBufC8* iOutputBuffer; // Buffered output buffer : Optimisation |
|
454 |
|
455 //##ModelId=3B6678E2003B |
|
456 CCnvCharacterSetConverter* iCharsetConverter; |
|
457 |
|
458 #ifdef __OUTPUT_WMLC |
|
459 //##ModelId=3B6678E20031 |
|
460 RFile iWmlcFile; // Debug stuff |
|
461 //##ModelId=3B6678E20025 |
|
462 RFs iWmlcFs; // Debug stuff |
|
463 #endif |
|
464 |
|
465 }; |
|
466 |
|
467 #endif // __WBCONVERTER_H |
|
468 |
|
469 // |
|
470 // End of file |
|
471 // |