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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #ifndef __WBCONVERTER_H
17 #define __WBCONVERTER_H
23 // forward declarations
26 class MWbxmlConverterObserver;
28 class CCnvCharacterSetConverter;
30 // consts, defines, enums
36 _LIT8(KWbXmlVersion10,"<?xml version=\"1.0\"?>");
42 _LIT8(KWbPublicIdStartWml,"<!DOCTYPE wml PUBLIC \"");
47 _LIT8(KWbPublicIdStartSi,"<!DOCTYPE si PUBLIC \"");
52 _LIT8(KWbPublicIdStartSl,"<!DOCTYPE sl PUBLIC \"");
59 _LIT(KWbTokenDatabaseWml11,"\\RESOURCE\\WAPPUSH\\WMLC11.TOK");
64 _LIT(KWbTokenDatabaseWml12,"\\RESOURCE\\WAPPUSH\\WMLC12.TOK");
69 _LIT(KWbTokenDatabaseSI10,"\\RESOURCE\\WAPPUSH\\SI10.TOK");
74 _LIT(KWbTokenDatabaseSL10,"\\RESOURCE\\WAPPUSH\\SL10.TOK");
80 _LIT8(KWbPublicIdEnd11,"\" \"http://www.wapforum.org/DTD/wml_1.1.xml\">");
85 _LIT8(KWbPublicIdEnd12,"\" \"http://www.wapforum.org/DTD/wml_1.2.xml\">");
90 _LIT8(KWbPublicIdEndSI10,"\" \"http://www.wapforum.org/DTD/si.dtd\">");
95 _LIT8(KWbPublicIdEndSL10,"\" \"http://www.wapforum.org/DTD/sl.dtd\">");
101 _LIT8(KWbTagStart,"<");
106 _LIT8(KWbTagStartClose,"</");
111 _LIT8(KWbTagEndWithContent,">");
116 _LIT8(KWbTagEndWithoutContent,"/>");
121 _LIT8(KWbVariableStart,"$(");
126 _LIT8(KWbVariableEscaped,":E)");
131 _LIT8(KWbVariableUnescaped,":U)");
136 _LIT8(KWbVariableNoescape,":N)");
141 _LIT8(KWbVariableNormal,")");
146 _LIT8(KWbQuote,"\"");
161 _LIT8(KWbLineBreak,"\n");
167 const TInt8 KWbxmlIdIndex = 0;
172 const TInt8 KWbxmlIdUnknown = 1;
177 const TInt8 KWbxmlIdWml10 = 2;
182 const TInt8 KWbxmlIdWta10 = 3;
187 const TInt8 KWbxmlIdWml11 = 4;
192 const TInt8 KWbxmlIdSI = 5;
197 const TInt8 KWbxmlIdSL = 6;
202 const TInt8 KWbxmlIdWml12 = 9;
204 // Entity translation literals
209 _LIT8(KEntityDollar,"$$");
214 _LIT8(KEntityAmp,"&");
219 _LIT8(KEntityLt,"<");
224 _LIT8(KEntityGt,">");
229 _LIT8(KEntityQuot,""");
234 _LIT8(KEntityApos,"'");
239 _LIT8(KEntityNbsp," ");
244 _LIT8(KEntityShy,"­");
250 const TUint16 KWbxmlSkipLiteralEndTagMagicToken = 0xac1d;
256 class RFileReadStream;
257 //##ModelId=3B6678E20007
258 class CWbxmlConverter : public CBase
265 //##ModelId=3B6678E30199
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();
280 private: // Emumerations
292 EConvertPublicIdValue,
295 EConvertPublicIdName,
302 //##ModelId=3B6678E30080
303 CWbxmlConverter(RFs& aFs);
304 //##ModelId=3B6678E30045
305 void ConstructL(MWbxmlConverterObserver* aObserver, const TDesC* aCharacterEncoding);
307 //##ModelId=3B6678E30044
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
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);
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);
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);
348 // Gets the full path to wmlc token table. Input aTokenFilePath is the path, without the drive.
351 // aTokenFilePath - the path to the token table file.
353 // Rtn: the full path to the token table file. Ownership is transfered to caller.
355 //##ModelId=3B6678E202A6
356 HBufC* FindTokenFileL(const TDesC& aTokenFilePath) const;
358 // Replaces characters originating from chracter entity references with the reference string
359 // For example chracter '&' will be "decoded" back to "&"
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...)
366 // HBufC* - Pointer to the string with replaced stuff
368 //##ModelId=3B6678E20288
369 HBufC* ReplaceCharacterEntitiesL(HBufC* aString);
371 // MWbxmlConverterObserver interface overloads
372 //##ModelId=3B6678E2024C
373 void OutputL(const TUint32 aSource) const;
375 //##ModelId=3B6678E2022E
376 TBool OutputCheckQuoteL(HBufC8& aSource) const;
378 // Helper method to optimise the OutputL oveloads
379 //##ModelId=3B6678E20211
380 void BufferAndOutputL(const TDesC8& aSource) const;
382 // Must exist for Binary Compatibility
383 //##ModelId=3B6678E20210
384 IMPORT_C virtual void CWbxmlConverter_Reserved1();
386 private: // Attributes
388 // For binary compatibility
389 //##ModelId=3B6678E20206
390 TAny* CWbxmlConverter_Reserved;
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;
399 //##ModelId=3B6678E2018D
400 MWbxmlConverterObserver* iObserver;
402 //##ModelId=3B6678E20179
403 TUint8 iWbxmlVersion;
404 //##ModelId=3B6678E20165
405 TUint32 iWbxmlCharset;
406 //##ModelId=3B6678E20151
408 //##ModelId=3B6678E2013D
409 TUint32 iPublicIdIndex;
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
421 //##ModelId=3B6678E200ED
423 //##ModelId=3B6678E200E3
426 //##ModelId=3B6678E200D1
428 //##ModelId=3B6678E200C5
430 //##ModelId=3B6678E200B3
434 //##ModelId=3B6678E200A7
436 //##ModelId=3B6678E20095
437 CArrayFixFlat<TUint16>* iTagStack;
438 //##ModelId=3B6678E2006B
439 TBool iRestrictedOutput;
447 //##ModelId=3B6678E20059
449 //##ModelId=3B6678E2004F
452 //##ModelId=3B6678E20045
453 mutable HBufC8* iOutputBuffer; // Buffered output buffer : Optimisation
455 //##ModelId=3B6678E2003B
456 CCnvCharacterSetConverter* iCharsetConverter;
459 //##ModelId=3B6678E20031
460 RFile iWmlcFile; // Debug stuff
461 //##ModelId=3B6678E20025
462 RFs iWmlcFs; // Debug stuff
467 #endif // __WBCONVERTER_H