diff -r 417699dc19c9 -r c7e9f1c97567 xml/legacyminidomparser/xmlparser/inc/gmxmlparser.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xml/legacyminidomparser/xmlparser/inc/gmxmlparser.h Mon Sep 13 13:16:40 2010 +0530 @@ -0,0 +1,510 @@ +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// This file contains the declaration of the generic CMDXMLParser class +// which is responsible for creating a DOM structure +// from a given XML file. +// +// + +/** + @file +*/ + +#ifndef __GMXMLPARSER_H__ +#define __GMXMLPARSER_H__ + +#include +#include +#include +#include + +//forward reference +class CMDXMLDocument; +class CMDXMLEntityConverter; +class CMDXMLElement; +class MXMLDtd; + + + +class MMDXMLParserObserver +/** Abstract observer interface for notification when XML parsing is complete. + +It should be implemented by users of CMDXMLParser +@publishedAll +@released*/ + { +public: + /** + Call back function used to inform a client of the Parser when a parsing operation completes. + */ + virtual void ParseFileCompleteL() = 0; + }; + +class MMDXMLParserDataProvider +/** Abstract data source interface for XML data source. + +The user of CMDXMLParser must build one of these to encapsulate the data source +that they wish to parse. CMDXMLParser implements a file-based data source to +implement the functionality of the ParseFile function. + +@publishedAll +@released*/ + { +public: + /** Status codes returned by GetData() implementations. */ + enum TDataProviderResults + { + KMoreData, //< Returned by the interface implementation when it is returning more data. + KDataStreamError, //< Returned by the interface when an unrecoverable error prevents obtaining more data. A recoverable error should be represented by KDataNotReady. + KDataStreamEnd //< Returned by the interface when there is no more data to come. + }; + +public: + /** + The XML Parser calls this on a specific data provider to get more data + when required. + + Note that the TPtrC supplied may be used by the parser at any time + between the return of this call and the next call that the parser + makes out. + + Your data provider must not move the data pointed to until the + parser has indicated that it's done with that block by asking for + another. + + Ownership of the data pointed to remains with the data provider. + + + General comments on efficiency + ------------------------------ + + The parser is designed such that it processes the whole data block + provided in one go. It will automatically become asynchronous when + another block is required - the data provider only needs to supply + data. + + Because of this design, it allows the data provider to indirectly + control the amount of processing time that will be needed + in a single block. + + It is a good idea to balance the need for the fastest possible + processing with the need for client application responsiveness by + ensuring that the amount of data passed in a single block is not + too large. However, it is worth bearing in mind that the parser + will convert UTF8 data streams in blocks of 32 characters, and + supplying blocks of smaller length than this will result in a + slight loss of efficiency. + + @param aPtr On return, the data provided + @param aStatus Asynchronous status to be completed by the function with a + TDataProviderResults value + */ + virtual void GetData(TPtrC8 &aPtr, TRequestStatus &aStatus) = 0; + /** + Called to indicate that use of the data source is complete. + */ + virtual void Disconnect() = 0; + }; + +class CMDXMLParserFileDataSource; + +class CMDXMLParser: public CActive +/** Creates a DOM structure from a given XML file. + +The parsing operation is asynchronous and is initiated by a call to ParseFile(). +On completion, the created DOM document can be retrieved through DetachXMLDoc(). + +Note the following ownership rules for the DOM document: + +1. calling DetachXMLDoc() transfers ownership of the document to the client + +2. if the parser is asked to parse a new file while it still owns an existing +DOM document, it will delete the old document. + +@publishedAll +@released +*/ + { +public: + /** Allocates and constructs a new XML parser, specifying a DTD. + + @param aParserObserver XML parser observer + @leave KErrNoMemory Out of memory + @return New XML parser */ + IMPORT_C static CMDXMLParser* NewL(MMDXMLParserObserver* aParserObserver); + + /** Allocates and constructs a new XML parser, specifying a DTD. + + @param aParserObserver XML parser observer + @param aDtdRepresentation DTD validator + @leave KErrNoMemory Out of memory + @return New XML parser */ + IMPORT_C static CMDXMLParser* NewL(MMDXMLParserObserver* aParserObserver, MXMLDtd* aDtdRepresentation); + + /** Allocates and constructs a new XML parser, leaving the object on the cleanup + stack. + + @param aParserObserver XML parser observer + @leave KErrNoMemory Out of memory + @return New XML parser */ + IMPORT_C static CMDXMLParser* NewLC(MMDXMLParserObserver* aParserObserver); + + /** Allocates and constructs a new XML parser, leaving the object on the cleanup + stack. + + @param aParserObserver XML parser observer + @param aDtdRepresentation DTD validator + @leave KErrNoMemory Out of memory + @return New XML parser */ + IMPORT_C static CMDXMLParser* NewLC(MMDXMLParserObserver* aParserObserver, MXMLDtd* aDtdRepresentation); + + + /** Destructor. */ + IMPORT_C ~CMDXMLParser(); + + /** Gets the last error found by the parser. + + @return Error code + */ + IMPORT_C TInt Error() const; + + /** + Get the severity of the most severe error found. + @return the maximum error severity + */ + IMPORT_C TXMLErrorCodeSeverity ErrorSeverity() const; + + /** Gets the created DOM. + + This should be called after the conclusion of the parser process. + + Note that the function sets the internal variable pointing to the document + to NULL, so this function can only be called once per file parse. The caller + takes ownership of the document, and must delete it when its use is complete. + + @return The created DOM */ + IMPORT_C CMDXMLDocument* DetachXMLDoc(); + + /** Parses a specified XML file into a DOM object tree. + + @param aRFs File server session + @param aFileToParse The file name to parse + @return KErrNone if success or a file read error code */ + IMPORT_C TInt ParseFile(RFs aRFs, const TDesC& aFileToParse); + + IMPORT_C TInt ParseFile(RFile& aFileHandleToParse); + + /** Parses a specified XML Data Source into a DOM object tree. + Use ParseSourceL() function in preference to ParseSource() + @param aSource MMDXMLParserDataProvider pointer + */ + inline void ParseSource(MMDXMLParserDataProvider *aSource) + { + TRAP_IGNORE(ParseSourceL(aSource)); + } + + /** Parses a specified XML Data Source into a DOM object tree. + @param aSource MMDXMLParserDataProvider pointer + */ + IMPORT_C void ParseSourceL(MMDXMLParserDataProvider *aSource); + + /** Defines input stream character widths. */ + enum TMDXMLParserInputCharWidth + { + EAscii = 0x01, //< ASCII + EUnicode = 0x02 // iUnicodeConversion; // buffer to temporarily hold the results of conversion from UTF8 to Unicode + TInt iUnicodeConversionLen; // number of characters stored in our intermediate buffer + TInt iUnicodeReadPos; // next character to send from our intermediate buffer + TBuf<1> iSpareChar; + + /* member variables used when parsing a local file */ + TDesC *iFileToParse; + RFs iRFs; + RFile iFileHandleToParse; + + TBool iEndOfTag; + + /* member variables used in DoParseLoopL() */ + TBool iOpened; + TBool iClosed; + CMDXMLElement* iNewElement; + CMDXMLElement* iParentElement; + HBufC* iText; + enum EParserStates + { + KInitFromFile, + KDetermineCharset, + KWaitingForData, + KParseData, + KSpanDataGap, + KFinished + }; + + EParserStates iState; + EParserStates iPreviousState; + TInt iSuspiciousCharacter; + TBool iStoreInvalid; // controls whether invalid elements and attributes are stored in the DOM. + TBool iPreserve; + + }; + +#endif