omads/omadsextensions/dsutils/emailxmlutils/inc/nsmlxmlparser.h
changeset 1 95fdac6ccb5c
parent 0 dab8a81a92de
child 2 19dc812fb587
equal deleted inserted replaced
0:dab8a81a92de 1:95fdac6ccb5c
     1 /*
       
     2 * Copyright (c) 2004 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:  Email XML parser
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // 1.2 Changes: nsmlxmlparser module added
       
    20 
       
    21 
       
    22 #ifndef __NSMLXMLPARSER_H__
       
    23 #define __NSMLXMLPARSER_H__
       
    24 
       
    25 // ------------------------------------------------------------------------------------------------
       
    26 // Includes
       
    27 // ------------------------------------------------------------------------------------------------
       
    28 #include <e32base.h>
       
    29 #include <s32strm.h>
       
    30 #include "nsmlEmailmtmdefs.h"
       
    31 
       
    32 
       
    33 // ------------------------------------------------------------------------------------------------
       
    34 // Defines for binary size optimization
       
    35 // ------------------------------------------------------------------------------------------------
       
    36 #define __NO_XML_COMMENTS_
       
    37 //#define __NO_EMPTY_ELEMENTS_
       
    38 
       
    39 
       
    40 // ------------------------------------------------------------------------------------------------
       
    41 // Class forward declarations
       
    42 // ------------------------------------------------------------------------------------------------
       
    43 class CNSmlXmlParser;
       
    44 class CNSmlExtData;
       
    45 
       
    46 
       
    47 // ------------------------------------------------------------------------------------------------
       
    48 // Typedefs
       
    49 // ------------------------------------------------------------------------------------------------
       
    50 // the array used for xval-values
       
    51 typedef CArrayPtrFlat<HBufC8> CNSmlXValArray;
       
    52 // the array used for extension data
       
    53 typedef CArrayPtrFlat<CNSmlExtData> CNSmlExtDataArray;
       
    54 // the array used for truncate info attachments data
       
    55 typedef RPointerArray<CNSmlAttachmentTruncateInfo> RNSmlAttachArray;
       
    56 // the array used for truncate info body data
       
    57 typedef RPointerArray<CNSmlBodyTruncateInfo> RNSmlBodyArray;
       
    58 
       
    59 
       
    60 // ------------------------------------------------------------------------------------------------
       
    61 // constants
       
    62 // ------------------------------------------------------------------------------------------------
       
    63 
       
    64 // the maximum length of an integer in characters
       
    65 const TInt KIntegerMaxLength = 12;
       
    66 
       
    67 // the length of a datetime in characters
       
    68 const TInt KDateTimeLength = 16;
       
    69 
       
    70 // the length of element start (<) and end (>)
       
    71 const TInt KElementStartEndWidth = 2;
       
    72 
       
    73 // constants used with files
       
    74 const TInt KReadDataLength = 512;
       
    75 const TUint KFileReadAccess	= EFileRead|EFileShareAny;
       
    76 const TUint KFileWriteAccess = EFileWrite|EFileShareExclusive;
       
    77 const TInt KMaxEmailItemFileNameLength = 256;
       
    78 _LIT(KEmailItemFile, "c:\\system\\temp\\emailitem.txt");
       
    79 _LIT(KEmailItemPath, "c:\\system\\temp\\");
       
    80 
       
    81 const TInt KNSmlEmailItemDrive = EDriveC;
       
    82 
       
    83 // Whitespace characters
       
    84 const TText KWhitespaceEmpty = ' ';
       
    85 const TText KWhitespaceLineFeed = '\r';
       
    86 const TText KWhitespaceNewLine = '\n';
       
    87 const TText KWhitespaceTabular = '\t';
       
    88 const TText KWhitespaceLineFeedNewLine = '\r\n';
       
    89 
       
    90 const TText KCharacterSlash = '/';
       
    91 
       
    92 // CData
       
    93 _LIT8(KCDataStart,		"<![CDATA[");
       
    94 _LIT8(KCDataEnd,		"]]>");
       
    95 _LIT8(KCDataInnerEnd,	"]]]]>&gt;<![CDATA[");
       
    96 
       
    97 #ifndef __NO_XML_COMMENTS_
       
    98 // Xml comments
       
    99 _LIT8(KCommentStart,	"<!--");
       
   100 _LIT8(KCommentEnd,		"-->");
       
   101 #endif
       
   102 
       
   103 const TText KElementStart = '<';
       
   104 const TText KElementEnd = '>';
       
   105 
       
   106 // Xml entities
       
   107 _LIT8(KEntityLT,	"&lt;");
       
   108 _LIT8(KEntityGT,	"&gt;");
       
   109 _LIT8(KEntityAMP,	"&amp;");
       
   110 _LIT8(KEntityAPOS,	"&apos;");
       
   111 _LIT8(KEntityQUOT,	"&quot;");
       
   112 
       
   113 // special characters
       
   114 _LIT8(KLessThan,	"<");
       
   115 _LIT8(KGreaterThan,	">");
       
   116 _LIT8(KAmpersand,	"&");
       
   117 _LIT8(KApostrophe,	"\'");
       
   118 _LIT8(KQuotation,	"\"");
       
   119 
       
   120 // boolean string representations
       
   121 _LIT8(KStringTrue,	"true");
       
   122 _LIT8(KStringFalse,	"false");
       
   123 
       
   124 // empty string
       
   125 _LIT8(KStringEmpty,	"");
       
   126 
       
   127 // email spesific elements
       
   128 _LIT8(KEmailElement,			"Email");
       
   129 _LIT8(KEmailReadElement,		"read");
       
   130 _LIT8(KEmailForwardedElement,	"forwarded");
       
   131 _LIT8(KEmailRepliedElement,		"replied");
       
   132 _LIT8(KEmailReceivedElement,	"received");
       
   133 _LIT8(KEmailCreatedElement,		"created");
       
   134 _LIT8(KEmailModifiedElement,	"modified");
       
   135 _LIT8(KEmailDeletedElement,		"deleted");
       
   136 _LIT8(KEmailFlaggedElement,		"flagged");
       
   137 _LIT8(KEmailItemElement,		"emailitem");
       
   138 
       
   139 // truncated info spesific elements
       
   140 _LIT8(KTruncatedElement,		"truncated");
       
   141 _LIT8(KTruncatedBodyElement,	"body");
       
   142 _LIT8(KTruncatedAttachElement,	"attach");
       
   143 _LIT8(KTruncatedSizeElement,	"size");
       
   144 _LIT8(KTruncatedTypeElement,	"type");
       
   145 _LIT8(KTruncatedNameElement,	"name");
       
   146 
       
   147 // extension spesific elements
       
   148 _LIT8(KExtElement,		"Ext");
       
   149 _LIT8(KExtXNamElement,	"XNam");
       
   150 _LIT8(KExtXValElement,	"XVal");
       
   151 
       
   152 // folder spesific elements
       
   153 _LIT8(KFolderElement,			"Folder");
       
   154 _LIT8(KFolderNameElement,		"name");
       
   155 _LIT8(KFolderCreatedElement,	"created");
       
   156 _LIT8(KFolderModifiedElement,	"modified");
       
   157 _LIT8(KFolderAccessedElement,	"accessed");
       
   158 _LIT8(KFolderAttributesElement,	"attributes");
       
   159 _LIT8(KFolderRoleElement,		"role");
       
   160 
       
   161 // folder attributes
       
   162 _LIT8(KAttributeHiddenElement,		"h");
       
   163 _LIT8(KAttributeSystemElement,		"s");
       
   164 _LIT8(KAttributeArchivedElement,	"a");
       
   165 _LIT8(KAttributeDeleteElement,		"d");
       
   166 _LIT8(KAttributeWritableElement,	"w");
       
   167 _LIT8(KAttributeReadableElement,	"r");
       
   168 _LIT8(KAttributeExecutableElement,	"x");
       
   169 
       
   170 
       
   171 // The error values returned from parser and generator functions
       
   172 enum TNSmlParserGeneratorError
       
   173 	{
       
   174 	EErrorNone,				// no error
       
   175 	EOutOfMemory,			// out of memory
       
   176 	EMandatoryFieldNotFound,// XNam inside Ext missing
       
   177 	EInvalidBooleanValue,	// Invalid value inside boolean elements
       
   178 	EInvalidIntegerValue,	// Invalid value inside integer elements
       
   179 	EInvalidDatetimeValue,	// Invalid value inside datetime elements
       
   180 	EInvalidCDataStructure,	// CDATA error
       
   181 	EInvalidXmlError, 		// Xml includes invalid data, i.e. xml generally against dtd
       
   182 	EInvalidFilename,		// file was not found or the filename was otherwise erroneous
       
   183 	EUnknownError			// Unknown error
       
   184 	};
       
   185 
       
   186 
       
   187 // enumeration for boolean values
       
   188 enum TNSmlBoolean
       
   189 	{
       
   190 	EBooleanMissing = 0, // not included in the xml
       
   191 	EBooleanTrue,
       
   192 	EBooleanFalse
       
   193 	};
       
   194 
       
   195 
       
   196 // extension data (found in both email and folder)
       
   197 class CNSmlExtData : public CBase
       
   198 	{
       
   199 public:
       
   200 	IMPORT_C static CNSmlExtData* NewL();
       
   201 	IMPORT_C static CNSmlExtData* NewLC();
       
   202 	IMPORT_C virtual ~CNSmlExtData();
       
   203 
       
   204 	IMPORT_C void AddXValL( HBufC8* aXVal );
       
   205 
       
   206 	IMPORT_C void GenerateXmlL( TPtr8& aXml, const CNSmlXmlParser* aParser ) const;
       
   207 	IMPORT_C TInt CountXmlSize( const CNSmlXmlParser* aParser ) const;
       
   208 	IMPORT_C void ConvertIntoEntitiesL( const CNSmlXmlParser* aParser );
       
   209 
       
   210 private:
       
   211 	CNSmlExtData();
       
   212 	void ConstructL();
       
   213 
       
   214 public:
       
   215 	HBufC8* iXNam;
       
   216 	CNSmlXValArray* iXVals;
       
   217 	};
       
   218 
       
   219 
       
   220 // folder attributes
       
   221 struct TNSmlFolderAttributeData
       
   222 	{
       
   223 	IMPORT_C TNSmlFolderAttributeData();
       
   224 
       
   225 	/*
       
   226 	* Returns the count of attributes that are not EBooleanMissing.
       
   227 	*/
       
   228 	IMPORT_C TInt AttributeCount() const;
       
   229 
       
   230 	IMPORT_C void GenerateXml( TPtr8& aXml, const CNSmlXmlParser* aParser ) const;
       
   231 	IMPORT_C TInt CountXmlSize( const CNSmlXmlParser* aParser ) const;
       
   232 
       
   233 	TNSmlBoolean iHidden;
       
   234 	TNSmlBoolean iSystem;
       
   235 	TNSmlBoolean iArchived;
       
   236 	TNSmlBoolean iDelete;
       
   237 	TNSmlBoolean iWritable;
       
   238 	TNSmlBoolean iReadable;
       
   239 	TNSmlBoolean iExecutable;
       
   240 	};
       
   241 
       
   242 
       
   243 // truncate info data
       
   244 class CNSmlTruncatedData : public CBase
       
   245 	{
       
   246 public:
       
   247 	IMPORT_C static CNSmlTruncatedData* NewL();
       
   248 	IMPORT_C static CNSmlTruncatedData* NewLC();
       
   249 	IMPORT_C virtual ~CNSmlTruncatedData();
       
   250 
       
   251 	IMPORT_C void AddAttachmentL(HBufC8* aName, TInt aSize, HBufC8* aType);
       
   252 	IMPORT_C void AddBodyL(TInt aSize, HBufC8* aType);
       
   253 
       
   254 	IMPORT_C void GenerateXmlL( TPtr8& aXml, const CNSmlXmlParser* aParser ) const;
       
   255 	IMPORT_C TInt CountXmlSizeL( const CNSmlXmlParser* aParser ) const;
       
   256 	IMPORT_C void ConvertIntoEntitiesL( const CNSmlXmlParser* aParser );
       
   257 
       
   258 private:
       
   259 	CNSmlTruncatedData();
       
   260 	void ConstructL();
       
   261 
       
   262 public:
       
   263 	RNSmlBodyArray iBodys;
       
   264 	RNSmlAttachArray iAttachments;
       
   265 	};
       
   266 
       
   267 
       
   268 // Base class for actual parsergenerators. 
       
   269 // Implements basic utilities for parsing and generating the xml.
       
   270 class CNSmlXmlParser : public CBase  
       
   271 	{
       
   272 public:
       
   273 	/*
       
   274 	* The constructor.
       
   275 	*/
       
   276 	IMPORT_C CNSmlXmlParser();
       
   277 
       
   278 	/*
       
   279 	* The destructor.
       
   280 	*/
       
   281 	IMPORT_C virtual ~CNSmlXmlParser();
       
   282 
       
   283 	/*
       
   284 	* Parses through the given xml and places the data it contains to 
       
   285 	* member variables.	Removes all the comments from the original string.
       
   286 	* @param aXml The xml to be parsed.
       
   287 	* @return 
       
   288 	*/
       
   289 	virtual TNSmlParserGeneratorError ParseXml( HBufC8* aXml ) =0;
       
   290 
       
   291 	/*
       
   292 	* Generates xml using the data in member variables of the child class. 
       
   293 	* aXml contains the generated xml when method returns successfully. 
       
   294 	* Caller should not instantiate 
       
   295 	* the buffer, since this method counts the size of the xml and 
       
   296 	* instantiates the buffer using the size as its maximum size.
       
   297 	* Caller gets the control of the buffer when method returns.
       
   298 	* @param aXml A pointer to a buffer, which is instantiated in this 
       
   299 	* method and contains the xml when method returns succesfully.
       
   300 	* @return 
       
   301 	*/
       
   302 	virtual TNSmlParserGeneratorError GenerateXml( HBufC8*& aXml ) =0;
       
   303 
       
   304 	/*
       
   305 	* Counts the size of the generated xml, when the xml would be generated 
       
   306 	* using the data in child class' member variables.
       
   307 	*/
       
   308 	virtual TInt CountXmlSizeL() =0;
       
   309 
       
   310 	/* utility functions */
       
   311 
       
   312 	void PreProcessL( HBufC8* aXml ) const;
       
   313 
       
   314 	TPtrC8 BooleanToString( const TNSmlBoolean aValue ) const;
       
   315 	TBuf8<KDateTimeLength> DateTimeToStringL( const TTime& aValue ) const;
       
   316 	TBuf8<KIntegerMaxLength> IntegerToString( const TInt aValue ) const;
       
   317 
       
   318 	TNSmlBoolean StringToBooleanL( const TPtrC8& aValue ) const;
       
   319 	TInt StringToIntegerL( const TPtrC8& aValue ) const;
       
   320 	// Note: Ignores UTC-times (Z-ending) and treats them as local time!
       
   321 	TTime StringToTTimeL( TPtrC8& aValue ) const;
       
   322 
       
   323 	void AppendElement( TPtr8& aPtr, const TDesC8& aElementName, const TDesC8& aValue ) const;
       
   324 	void AppendElement( TPtr8& aPtr, const TDesC8& aElementName ) const;
       
   325 	void AppendEndElement( TPtr8& aPtr, const TDesC8& aElementName ) const;
       
   326 
       
   327 	TInt SizeOfElements( const TDesC8& aElementName ) const;
       
   328 	TInt SizeOfBoolean( const TNSmlBoolean aValue, const TDesC8& aElementName ) const;
       
   329 	TInt SizeOfDatetime( const TDesC8& aElementName ) const;
       
   330 	TInt SizeOfInteger( const TDesC8& aElementName ) const;
       
   331 	TInt SizeOfString( const HBufC8* aValue, const TDesC8& aElementName ) const;
       
   332 
       
   333 	TInt EntitiesToCharactersL( HBufC8*& aXml, TInt aStartPos, TInt aEndPos ) const;
       
   334 	TInt CharactersToEntitiesL( HBufC8*& aXml, TInt aStartPos, TInt aEndPos ) const;
       
   335 
       
   336 	TBool IsWhitespace( const TDesC8& aText ) const;
       
   337 	void LeaveIfNotWhiteSpaceL( const TDesC8& aText ) const;
       
   338 
       
   339 	TNSmlParserGeneratorError CheckError( const TInt error ) const;
       
   340 
       
   341 protected:
       
   342 	// parsing methods
       
   343 	void ParseL( TPtrC8& aXml );
       
   344 	void AddToCompleteL( const TPtrC8 aStr );
       
   345 	void ResetBufferL( HBufC8*& aBuf ) const;
       
   346 	void AddToBufferL( const TText c, HBufC8*& aBuf ) const;
       
   347 
       
   348 	virtual void NextElementL( TPtrC8 aElement ) =0;
       
   349 	virtual void NextDataL( TPtrC8 aData ) =0;
       
   350 
       
   351 private:
       
   352 	TInt ReplaceL( HBufC8*& aText, const TDesC8& aTarget, const TDesC8& aItem, TInt aStartPos, TInt aEndPos ) const;
       
   353 	void CheckDatetimeErrorL( const TInt error ) const;
       
   354 
       
   355 protected:
       
   356 	HBufC8* iBuffer;
       
   357 	HBufC8* iCompleteBuffer;
       
   358 	};
       
   359 
       
   360 
       
   361 
       
   362 // Email parser. Implements the parsing and generating of Email xml.
       
   363 class CNSmlEmailParser : public CNSmlXmlParser
       
   364 	{
       
   365 public:
       
   366 	IMPORT_C static CNSmlEmailParser* NewL();
       
   367 	IMPORT_C static CNSmlEmailParser* NewLC();
       
   368 	IMPORT_C virtual ~CNSmlEmailParser();
       
   369 
       
   370 	IMPORT_C virtual TNSmlParserGeneratorError ParseXml( HBufC8* aXml );
       
   371 	IMPORT_C virtual TNSmlParserGeneratorError GenerateXml( HBufC8*& aXml );
       
   372 	IMPORT_C virtual TInt CountXmlSizeL();
       
   373 
       
   374 	IMPORT_C void AddExtL( CNSmlExtData* aExt );
       
   375 
       
   376 protected:
       
   377 	virtual void NextElementL( TPtrC8 aElement );
       
   378 	virtual void NextDataL( TPtrC8 aData );
       
   379 
       
   380 	virtual void HandleNextEmailItemDataL( TPtrC8 aData );
       
   381 	virtual void HandleNextEmailItemStartL() {}; // nothing to do
       
   382 	virtual void HandleNextEmailItemEndL() {}; // nothing to do
       
   383 
       
   384 	void ConvertIntoEntitiesL();
       
   385 
       
   386 	CNSmlEmailParser();
       
   387 	void ConstructL();
       
   388 
       
   389 protected:
       
   390 	
       
   391 	// the email elements (states) in the order they appear in DTD
       
   392 	enum TNSmlCurrentEmailElement
       
   393 		{
       
   394 		ENone = 0,
       
   395 		EEmail,
       
   396 		ERead, 
       
   397 		EForwarded,
       
   398 		EReplied,
       
   399 		EReceived,
       
   400 		ECreated,
       
   401 		EModified,
       
   402 		EDeleted,
       
   403 		EFlagged,
       
   404 		EEmailItem,
       
   405 		ETrunc,
       
   406 		ETruncBody,
       
   407 		ETruncBodySize,
       
   408 		ETruncBodyType,
       
   409 		ETruncAttach,
       
   410 		ETruncAttachName,
       
   411 		ETruncAttachSize,
       
   412 		ETruncAttachType, 
       
   413 		EExt,
       
   414 		EExtXNam,
       
   415 		EExtXVal
       
   416 		};
       
   417 	
       
   418 	// struct used in email parsing to know which members are already set
       
   419 	struct TNSmlSetEmailValues
       
   420 		{
       
   421 		TNSmlSetEmailValues();
       
   422 		void Reset();
       
   423 		
       
   424 		TBool iEmail;
       
   425 		TBool iRead;
       
   426 		TBool iForwarded;
       
   427 		TBool iReplied;
       
   428 		TBool iDeleted;
       
   429 		TBool iFlagged;
       
   430 		TBool iReceived;
       
   431 		TBool iCreated;
       
   432 		TBool iModified;
       
   433 		TBool iEmailItem;
       
   434 		TBool iTrunc;
       
   435 		TBool iTruncBodySize;
       
   436 		TBool iTruncBodyType;
       
   437 		TBool iTruncAttachSize;
       
   438 		TBool iTruncAttachType;
       
   439 		TBool iTruncAttachName;
       
   440 		TBool iXNam;
       
   441 		};
       
   442 	
       
   443 private:
       
   444 	void StartElementStateChangeL( TNSmlCurrentEmailElement aCurrentState, TNSmlCurrentEmailElement aNextState, TBool aIsSet = EFalse );
       
   445 	void EndElementStateChangeL( TNSmlCurrentEmailElement aCurrentState, TNSmlCurrentEmailElement aNextState );
       
   446 	
       
   447 	void GenerateEmailXmlL( HBufC8*& aXml );
       
   448 
       
   449 public:
       
   450 
       
   451 	/*
       
   452 	* The values of the data below is treated as follows:
       
   453 	* When constructing this data from an xml, boolean values 
       
   454 	* are EBooleanTrue, when <field>true</field>, EBooleanFalse 
       
   455 	* when <field>false</field> OR <field/>, and EBooleanMissing 
       
   456 	* when the field is not present in the xml. Datetime values 
       
   457 	* are equal to Time::NullTTime when the field is missing (they should 
       
   458 	* never be empty). Text values (HBufC8*) are NULL when the field is 
       
   459 	* missing, an empty string when <field></field> OR <field/> and the 
       
   460 	* actual value between elements if there is data between those 
       
   461 	* elements. iExt is never NULL, but when iExt->Count() 
       
   462 	* equals to zero, there are no extensions present in the xml.
       
   463 	*
       
   464 	* These same rules are used when generating xml from 
       
   465 	* this data object.
       
   466 	*/
       
   467 
       
   468 	TNSmlBoolean iRead;
       
   469 	TNSmlBoolean iForwarded;
       
   470 	TNSmlBoolean iReplied;
       
   471 	TTime iReceived;
       
   472 	TTime iCreated;
       
   473 	TTime iModified;
       
   474 	HBufC8* iEmailItem;
       
   475 	TNSmlBoolean iDeleted;
       
   476 	TNSmlBoolean iFlagged;
       
   477 	CNSmlTruncatedData* iTruncated;
       
   478 	CNSmlExtDataArray* iExt;
       
   479 
       
   480 protected:
       
   481 	TNSmlSetEmailValues iSetValues;
       
   482 	TNSmlCurrentEmailElement iCurrentState;
       
   483 	TNSmlCurrentEmailElement iLastState;
       
   484 
       
   485 private:
       
   486 
       
   487 	TInt iTruncSize;
       
   488 	HBufC8* iTruncType;
       
   489 	HBufC8* iTruncName;
       
   490 	CNSmlExtData* iExtData;
       
   491 	};
       
   492 
       
   493 
       
   494 
       
   495 // ------------------------------------------------------------------------------------------------
       
   496 // Parses and generates the xml using files/streams. If emailitem is present, it is 
       
   497 // stored in a file.
       
   498 // ------------------------------------------------------------------------------------------------
       
   499 class CNSmlEmailFileParser : public CNSmlEmailParser
       
   500 	{
       
   501 public:
       
   502 	IMPORT_C static CNSmlEmailFileParser* NewL();
       
   503 	IMPORT_C static CNSmlEmailFileParser* NewLC();
       
   504 	IMPORT_C virtual ~CNSmlEmailFileParser();
       
   505 
       
   506 	IMPORT_C virtual TNSmlParserGeneratorError ParseXml( HBufC8* aXml );
       
   507 	IMPORT_C virtual TNSmlParserGeneratorError ParseXml( RReadStream& aRs );
       
   508 	IMPORT_C virtual TNSmlParserGeneratorError GenerateXml( HBufC8*& aXml );
       
   509 	IMPORT_C virtual TNSmlParserGeneratorError GenerateXml( RWriteStream& aWs );
       
   510 	IMPORT_C virtual TInt CountXmlSizeL();
       
   511 
       
   512 protected:
       
   513 	virtual void HandleNextEmailItemDataL( TPtrC8 aData );
       
   514 	virtual void HandleNextEmailItemStartL();
       
   515 	virtual void HandleNextEmailItemEndL();
       
   516 
       
   517 private:
       
   518 	void ParseFromStreamL( RReadStream& rs );
       
   519 	void ParsePieceL( TPtrC8& aXml, TBool aLastPiece = EFalse );
       
   520 	TUint RemoveIncompleteL( HBufC8* aPiece, RReadStream& aStream );
       
   521 	TUint CheckPiece( const TPtrC8 aEnd ) const;
       
   522 	void PreProcessPieceL( HBufC8* aXml );
       
   523 
       
   524 	void GenerateEmailXmlL( RWriteStream& aWs );
       
   525 
       
   526 	void ResetParserL();
       
   527 	void ResetPreProcessor();
       
   528 
       
   529 	HBufC* Buf8ToBuf16( const HBufC8* buf8 ) const;
       
   530 
       
   531 	CNSmlEmailFileParser();
       
   532 	void ConstructL();
       
   533 
       
   534 public:
       
   535 
       
   536 	TBool iUseEmailItem; // whether or not emailitem should be used in generation
       
   537 
       
   538 private:
       
   539 
       
   540 	// xml parsing state
       
   541 	TBool iReadingElementName;
       
   542 	TBool iReadingCData;
       
   543 #ifndef __NO_XML_COMMENTS_
       
   544 	TBool iReadingComment;
       
   545 #endif
       
   546 	TBool iReadingEmailItemData;
       
   547 
       
   548 	// pre-processing state
       
   549 	TInt iCdataStartPos;
       
   550 	TInt iCdataEndPos;
       
   551 
       
   552 	// file handling
       
   553 	RFs iRfs;
       
   554 	RFileWriteStream iWriteStream;
       
   555 	
       
   556 	HBufC* iEmailItemFile;
       
   557 	TBool iFirstPiece;
       
   558 	TBool iCdataFoundFromFirstPiece;
       
   559 	};
       
   560 
       
   561 
       
   562 
       
   563 
       
   564 // Folder parser. Implements parsing and generating of Folder xml.
       
   565 class CNSmlFolderParser : public CNSmlXmlParser
       
   566 	{
       
   567 public:
       
   568 	IMPORT_C static CNSmlFolderParser* NewL();
       
   569 	IMPORT_C static CNSmlFolderParser* NewLC();
       
   570 	IMPORT_C virtual ~CNSmlFolderParser();
       
   571 
       
   572 	IMPORT_C virtual TNSmlParserGeneratorError ParseXml( HBufC8* aXml );
       
   573 	IMPORT_C virtual TNSmlParserGeneratorError GenerateXml( HBufC8*& aXml );
       
   574 	IMPORT_C virtual TInt CountXmlSizeL() ;
       
   575 
       
   576 	IMPORT_C void AddExtL( CNSmlExtData* aExt );
       
   577 
       
   578 protected:
       
   579 	virtual void NextElementL( TPtrC8 aElement );
       
   580 	virtual void NextDataL( TPtrC8 aData );
       
   581 
       
   582 protected:
       
   583 	
       
   584 	// the folder elements (states) in the order they appear in DTD
       
   585 	enum TNSmlCurrentFolderElement
       
   586 		{
       
   587 		EFolderNone = 0,
       
   588 		EFolder,
       
   589 		EFolderName, 
       
   590 		EFolderCreated,
       
   591 		EFolderModified,
       
   592 		EFolderAccessed,
       
   593 		EAttributes,
       
   594 		EAttributesH,
       
   595 		EAttributesS,
       
   596 		EAttributesA,
       
   597 		EAttributesD,
       
   598 		EAttributesW,
       
   599 		EAttributesR,
       
   600 		EAttributesX,
       
   601 		EFolderRole,
       
   602 		EFolderExt,
       
   603 		EFolderExtXNam,
       
   604 		EFolderExtXVal
       
   605 		};
       
   606 	
       
   607 	// struct used in folder parsing (which members are already set)
       
   608 	struct TNSmlSetFolderValues
       
   609 		{
       
   610 		TNSmlSetFolderValues();
       
   611 		void Reset();
       
   612 		
       
   613 		TBool iFolder;
       
   614 		TBool iName;
       
   615 		TBool iCreated;
       
   616 		TBool iModified;
       
   617 		TBool iAccessed;
       
   618 		TBool iAttributes;
       
   619 		TBool iAttributesH;
       
   620 		TBool iAttributesS;
       
   621 		TBool iAttributesA;
       
   622 		TBool iAttributesD;
       
   623 		TBool iAttributesW;
       
   624 		TBool iAttributesR;
       
   625 		TBool iAttributesX;
       
   626 		TBool iRole;
       
   627 		TBool iXNam;
       
   628 		};
       
   629 	
       
   630 private:
       
   631 	void StartElementStateChangeL( TNSmlCurrentFolderElement aCurrentState, TNSmlCurrentFolderElement aNextState, TBool aIsSet = EFalse );
       
   632 	void EndElementStateChangeL( TNSmlCurrentFolderElement aCurrentState, TNSmlCurrentFolderElement aNextState );
       
   633 
       
   634 	void GenerateFolderXmlL( HBufC8*& aXml );
       
   635 	void ConvertIntoEntitiesL();
       
   636 
       
   637 	CNSmlFolderParser();
       
   638 	void ConstructL();
       
   639 
       
   640 public:
       
   641 	HBufC8* iName;
       
   642 	TTime iCreated;
       
   643 	TTime iModified;
       
   644 	TTime iAccessed;
       
   645 	TNSmlFolderAttributeData iAttributes;
       
   646 	HBufC8* iRole;
       
   647 	CNSmlExtDataArray* iExt;
       
   648 
       
   649 private:
       
   650 	TNSmlCurrentFolderElement iCurrentState;
       
   651 	TNSmlCurrentFolderElement iLastState;
       
   652 	TNSmlSetFolderValues iSetValues;
       
   653 
       
   654 	CNSmlExtData* iExtData;
       
   655 	};
       
   656 
       
   657 
       
   658 
       
   659 #endif // __NSMLXMLPARSER_H__