williamr@2
|
1 |
// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
|
williamr@2
|
2 |
// All rights reserved.
|
williamr@2
|
3 |
// This component and the accompanying materials are made available
|
williamr@4
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
williamr@2
|
5 |
// which accompanies this distribution, and is available
|
williamr@4
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
williamr@2
|
7 |
//
|
williamr@2
|
8 |
// Initial Contributors:
|
williamr@2
|
9 |
// Nokia Corporation - initial contribution.
|
williamr@2
|
10 |
//
|
williamr@2
|
11 |
// Contributors:
|
williamr@2
|
12 |
//
|
williamr@2
|
13 |
// Description:
|
williamr@2
|
14 |
// This file contains the declaration of the generic CMDXMLParser class
|
williamr@2
|
15 |
// which is responsible for creating a DOM structure
|
williamr@2
|
16 |
// from a given XML file.
|
williamr@2
|
17 |
//
|
williamr@2
|
18 |
//
|
williamr@2
|
19 |
|
williamr@2
|
20 |
/**
|
williamr@2
|
21 |
@file
|
williamr@2
|
22 |
*/
|
williamr@2
|
23 |
|
williamr@2
|
24 |
#ifndef __GMXMLPARSER_H__
|
williamr@2
|
25 |
#define __GMXMLPARSER_H__
|
williamr@2
|
26 |
|
williamr@2
|
27 |
#include <e32std.h>
|
williamr@4
|
28 |
#include <txtetext.h>
|
williamr@2
|
29 |
#include <gmxmlconstants.h>
|
williamr@4
|
30 |
#include <f32file.h>
|
williamr@2
|
31 |
|
williamr@2
|
32 |
//forward reference
|
williamr@2
|
33 |
class CMDXMLDocument;
|
williamr@2
|
34 |
class CMDXMLEntityConverter;
|
williamr@2
|
35 |
class CMDXMLElement;
|
williamr@2
|
36 |
class MXMLDtd;
|
williamr@2
|
37 |
|
williamr@2
|
38 |
|
williamr@2
|
39 |
|
williamr@2
|
40 |
class MMDXMLParserObserver
|
williamr@2
|
41 |
/** Abstract observer interface for notification when XML parsing is complete.
|
williamr@2
|
42 |
|
williamr@2
|
43 |
It should be implemented by users of CMDXMLParser
|
williamr@2
|
44 |
@publishedAll
|
williamr@2
|
45 |
@released*/
|
williamr@2
|
46 |
{
|
williamr@2
|
47 |
public:
|
williamr@2
|
48 |
/**
|
williamr@2
|
49 |
Call back function used to inform a client of the Parser when a parsing operation completes.
|
williamr@2
|
50 |
*/
|
williamr@2
|
51 |
virtual void ParseFileCompleteL() = 0;
|
williamr@2
|
52 |
};
|
williamr@2
|
53 |
|
williamr@2
|
54 |
class MMDXMLParserDataProvider
|
williamr@2
|
55 |
/** Abstract data source interface for XML data source.
|
williamr@2
|
56 |
|
williamr@2
|
57 |
The user of CMDXMLParser must build one of these to encapsulate the data source
|
williamr@2
|
58 |
that they wish to parse. CMDXMLParser implements a file-based data source to
|
williamr@2
|
59 |
implement the functionality of the ParseFile function.
|
williamr@2
|
60 |
|
williamr@2
|
61 |
@publishedAll
|
williamr@2
|
62 |
@released*/
|
williamr@2
|
63 |
{
|
williamr@2
|
64 |
public:
|
williamr@2
|
65 |
/** Status codes returned by GetData() implementations. */
|
williamr@2
|
66 |
enum TDataProviderResults
|
williamr@2
|
67 |
{
|
williamr@4
|
68 |
KMoreData, //< Returned by the interface implementation when it is returning more data.
|
williamr@4
|
69 |
KDataStreamError, //< Returned by the interface when an unrecoverable error prevents obtaining more data. A recoverable error should be represented by KDataNotReady.
|
williamr@4
|
70 |
KDataStreamEnd //< Returned by the interface when there is no more data to come.
|
williamr@2
|
71 |
};
|
williamr@2
|
72 |
|
williamr@2
|
73 |
public:
|
williamr@2
|
74 |
/**
|
williamr@2
|
75 |
The XML Parser calls this on a specific data provider to get more data
|
williamr@2
|
76 |
when required.
|
williamr@2
|
77 |
|
williamr@2
|
78 |
Note that the TPtrC supplied may be used by the parser at any time
|
williamr@2
|
79 |
between the return of this call and the next call that the parser
|
williamr@2
|
80 |
makes out.
|
williamr@2
|
81 |
|
williamr@2
|
82 |
Your data provider must not move the data pointed to until the
|
williamr@2
|
83 |
parser has indicated that it's done with that block by asking for
|
williamr@2
|
84 |
another.
|
williamr@2
|
85 |
|
williamr@2
|
86 |
Ownership of the data pointed to remains with the data provider.
|
williamr@2
|
87 |
|
williamr@2
|
88 |
|
williamr@2
|
89 |
General comments on efficiency
|
williamr@2
|
90 |
------------------------------
|
williamr@2
|
91 |
|
williamr@2
|
92 |
The parser is designed such that it processes the whole data block
|
williamr@2
|
93 |
provided in one go. It will automatically become asynchronous when
|
williamr@2
|
94 |
another block is required - the data provider only needs to supply
|
williamr@2
|
95 |
data.
|
williamr@2
|
96 |
|
williamr@2
|
97 |
Because of this design, it allows the data provider to indirectly
|
williamr@2
|
98 |
control the amount of processing time that will be needed
|
williamr@2
|
99 |
in a single block.
|
williamr@2
|
100 |
|
williamr@2
|
101 |
It is a good idea to balance the need for the fastest possible
|
williamr@2
|
102 |
processing with the need for client application responsiveness by
|
williamr@2
|
103 |
ensuring that the amount of data passed in a single block is not
|
williamr@2
|
104 |
too large. However, it is worth bearing in mind that the parser
|
williamr@2
|
105 |
will convert UTF8 data streams in blocks of 32 characters, and
|
williamr@2
|
106 |
supplying blocks of smaller length than this will result in a
|
williamr@2
|
107 |
slight loss of efficiency.
|
williamr@2
|
108 |
|
williamr@2
|
109 |
@param aPtr On return, the data provided
|
williamr@2
|
110 |
@param aStatus Asynchronous status to be completed by the function with a
|
williamr@2
|
111 |
TDataProviderResults value
|
williamr@2
|
112 |
*/
|
williamr@2
|
113 |
virtual void GetData(TPtrC8 &aPtr, TRequestStatus &aStatus) = 0;
|
williamr@2
|
114 |
/**
|
williamr@2
|
115 |
Called to indicate that use of the data source is complete.
|
williamr@2
|
116 |
*/
|
williamr@2
|
117 |
virtual void Disconnect() = 0;
|
williamr@2
|
118 |
};
|
williamr@2
|
119 |
|
williamr@2
|
120 |
class CMDXMLParserFileDataSource;
|
williamr@2
|
121 |
|
williamr@2
|
122 |
class CMDXMLParser: public CActive
|
williamr@2
|
123 |
/** Creates a DOM structure from a given XML file.
|
williamr@2
|
124 |
|
williamr@2
|
125 |
The parsing operation is asynchronous and is initiated by a call to ParseFile().
|
williamr@2
|
126 |
On completion, the created DOM document can be retrieved through DetachXMLDoc().
|
williamr@2
|
127 |
|
williamr@2
|
128 |
Note the following ownership rules for the DOM document:
|
williamr@2
|
129 |
|
williamr@2
|
130 |
1. calling DetachXMLDoc() transfers ownership of the document to the client
|
williamr@2
|
131 |
|
williamr@2
|
132 |
2. if the parser is asked to parse a new file while it still owns an existing
|
williamr@2
|
133 |
DOM document, it will delete the old document.
|
williamr@2
|
134 |
|
williamr@2
|
135 |
@publishedAll
|
williamr@2
|
136 |
@released
|
williamr@2
|
137 |
*/
|
williamr@2
|
138 |
{
|
williamr@2
|
139 |
public:
|
williamr@2
|
140 |
/** Allocates and constructs a new XML parser, specifying a DTD.
|
williamr@2
|
141 |
|
williamr@2
|
142 |
@param aParserObserver XML parser observer
|
williamr@2
|
143 |
@leave KErrNoMemory Out of memory
|
williamr@2
|
144 |
@return New XML parser */
|
williamr@2
|
145 |
IMPORT_C static CMDXMLParser* NewL(MMDXMLParserObserver* aParserObserver);
|
williamr@2
|
146 |
|
williamr@2
|
147 |
/** Allocates and constructs a new XML parser, specifying a DTD.
|
williamr@2
|
148 |
|
williamr@2
|
149 |
@param aParserObserver XML parser observer
|
williamr@2
|
150 |
@param aDtdRepresentation DTD validator
|
williamr@2
|
151 |
@leave KErrNoMemory Out of memory
|
williamr@2
|
152 |
@return New XML parser */
|
williamr@2
|
153 |
IMPORT_C static CMDXMLParser* NewL(MMDXMLParserObserver* aParserObserver, MXMLDtd* aDtdRepresentation);
|
williamr@2
|
154 |
|
williamr@2
|
155 |
/** Allocates and constructs a new XML parser, leaving the object on the cleanup
|
williamr@2
|
156 |
stack.
|
williamr@2
|
157 |
|
williamr@2
|
158 |
@param aParserObserver XML parser observer
|
williamr@2
|
159 |
@leave KErrNoMemory Out of memory
|
williamr@2
|
160 |
@return New XML parser */
|
williamr@2
|
161 |
IMPORT_C static CMDXMLParser* NewLC(MMDXMLParserObserver* aParserObserver);
|
williamr@2
|
162 |
|
williamr@2
|
163 |
/** Allocates and constructs a new XML parser, leaving the object on the cleanup
|
williamr@2
|
164 |
stack.
|
williamr@2
|
165 |
|
williamr@2
|
166 |
@param aParserObserver XML parser observer
|
williamr@2
|
167 |
@param aDtdRepresentation DTD validator
|
williamr@2
|
168 |
@leave KErrNoMemory Out of memory
|
williamr@2
|
169 |
@return New XML parser */
|
williamr@2
|
170 |
IMPORT_C static CMDXMLParser* NewLC(MMDXMLParserObserver* aParserObserver, MXMLDtd* aDtdRepresentation);
|
williamr@2
|
171 |
|
williamr@2
|
172 |
|
williamr@2
|
173 |
/** Destructor. */
|
williamr@2
|
174 |
IMPORT_C ~CMDXMLParser();
|
williamr@2
|
175 |
|
williamr@2
|
176 |
/** Gets the last error found by the parser.
|
williamr@2
|
177 |
|
williamr@2
|
178 |
@return Error code
|
williamr@2
|
179 |
*/
|
williamr@2
|
180 |
IMPORT_C TInt Error() const;
|
williamr@2
|
181 |
|
williamr@2
|
182 |
/**
|
williamr@2
|
183 |
Get the severity of the most severe error found.
|
williamr@2
|
184 |
@return the maximum error severity
|
williamr@2
|
185 |
*/
|
williamr@2
|
186 |
IMPORT_C TXMLErrorCodeSeverity ErrorSeverity() const;
|
williamr@2
|
187 |
|
williamr@2
|
188 |
/** Gets the created DOM.
|
williamr@2
|
189 |
|
williamr@2
|
190 |
This should be called after the conclusion of the parser process.
|
williamr@2
|
191 |
|
williamr@2
|
192 |
Note that the function sets the internal variable pointing to the document
|
williamr@2
|
193 |
to NULL, so this function can only be called once per file parse. The caller
|
williamr@2
|
194 |
takes ownership of the document, and must delete it when its use is complete.
|
williamr@2
|
195 |
|
williamr@2
|
196 |
@return The created DOM */
|
williamr@2
|
197 |
IMPORT_C CMDXMLDocument* DetachXMLDoc();
|
williamr@2
|
198 |
|
williamr@2
|
199 |
/** Parses a specified XML file into a DOM object tree.
|
williamr@2
|
200 |
|
williamr@2
|
201 |
@param aRFs File server session
|
williamr@2
|
202 |
@param aFileToParse The file name to parse
|
williamr@2
|
203 |
@return KErrNone if success or a file read error code */
|
williamr@2
|
204 |
IMPORT_C TInt ParseFile(RFs aRFs, const TDesC& aFileToParse);
|
williamr@2
|
205 |
|
williamr@2
|
206 |
IMPORT_C TInt ParseFile(RFile& aFileHandleToParse);
|
williamr@2
|
207 |
|
williamr@2
|
208 |
/** Parses a specified XML Data Source into a DOM object tree.
|
williamr@2
|
209 |
Use ParseSourceL() function in preference to ParseSource()
|
williamr@2
|
210 |
@param aSource MMDXMLParserDataProvider pointer
|
williamr@2
|
211 |
*/
|
williamr@2
|
212 |
inline void ParseSource(MMDXMLParserDataProvider *aSource)
|
williamr@2
|
213 |
{
|
williamr@2
|
214 |
TRAP_IGNORE(ParseSourceL(aSource));
|
williamr@2
|
215 |
}
|
williamr@2
|
216 |
|
williamr@2
|
217 |
/** Parses a specified XML Data Source into a DOM object tree.
|
williamr@2
|
218 |
@param aSource MMDXMLParserDataProvider pointer
|
williamr@2
|
219 |
*/
|
williamr@2
|
220 |
IMPORT_C void ParseSourceL(MMDXMLParserDataProvider *aSource);
|
williamr@2
|
221 |
|
williamr@2
|
222 |
/** Defines input stream character widths. */
|
williamr@2
|
223 |
enum TMDXMLParserInputCharWidth
|
williamr@2
|
224 |
{
|
williamr@4
|
225 |
EAscii = 0x01, //< ASCII
|
williamr@4
|
226 |
EUnicode = 0x02 //<Unicode
|
williamr@2
|
227 |
};
|
williamr@2
|
228 |
|
williamr@2
|
229 |
/** Sets the input stream character width.
|
williamr@2
|
230 |
*
|
williamr@2
|
231 |
* @param aWidth Character width for incoming stream. Possible values are EAscii and EUnicode (representing Ascii/UTF8 and Unicode respectively).
|
williamr@2
|
232 |
*
|
williamr@2
|
233 |
*/
|
williamr@2
|
234 |
IMPORT_C void SetSourceCharacterWidth(TMDXMLParserInputCharWidth aWidth);
|
williamr@2
|
235 |
|
williamr@2
|
236 |
//Defect fix for INC036136- Enable the use of custom entity converters in GMXML
|
williamr@2
|
237 |
/**
|
williamr@2
|
238 |
* Sets the entity converter to be used for parsing.
|
williamr@2
|
239 |
* and take ownership of the passed entity converter
|
williamr@2
|
240 |
* @param aEntityConverter the entity converter to be used.
|
williamr@2
|
241 |
*/
|
williamr@2
|
242 |
IMPORT_C void SetEntityConverter(CMDXMLEntityConverter* aEntityConverter);
|
williamr@2
|
243 |
//End Defect fix for INC036136
|
williamr@2
|
244 |
|
williamr@2
|
245 |
/**
|
williamr@2
|
246 |
Controls whether invalid elements and attributes are added to the DOM.
|
williamr@2
|
247 |
@param aStoreInvalid ETrue if invalid content should be stored, EFalse otherwise.
|
williamr@2
|
248 |
*/
|
williamr@2
|
249 |
IMPORT_C void SetStoreInvalid(TBool aStoreInvalid);
|
williamr@2
|
250 |
|
williamr@2
|
251 |
/**
|
williamr@2
|
252 |
Controls whether whitespaces are handled by XML parser or by client.
|
williamr@2
|
253 |
@param aPreserve ETrue if all whitespaces should be preserved (handled by client), EFalse otherwise.
|
williamr@2
|
254 |
*/
|
williamr@2
|
255 |
IMPORT_C void SetWhiteSpaceHandlingMode(TBool aPreserve);
|
williamr@2
|
256 |
|
williamr@2
|
257 |
public: // public functions used by other classes within the .dll, not for Export.
|
williamr@2
|
258 |
/** Gets the entity converter.
|
williamr@2
|
259 |
|
williamr@2
|
260 |
@return The entity converter */
|
williamr@2
|
261 |
CMDXMLEntityConverter* EntityConverter();
|
williamr@2
|
262 |
|
williamr@2
|
263 |
private:
|
williamr@2
|
264 |
IMPORT_C virtual void DoCancel();
|
williamr@2
|
265 |
|
williamr@2
|
266 |
/*
|
williamr@2
|
267 |
* RunL function inherited from CActive base class - carries out the actual parsing.
|
williamr@2
|
268 |
* @leave can Leave due to OOM
|
williamr@2
|
269 |
*/
|
williamr@2
|
270 |
virtual void RunL();
|
williamr@2
|
271 |
|
williamr@2
|
272 |
/*
|
williamr@2
|
273 |
* Helper function that does the parsing - called from inside RunL
|
williamr@2
|
274 |
*/
|
williamr@2
|
275 |
TBool DoParseLoopL();
|
williamr@2
|
276 |
|
williamr@2
|
277 |
/*
|
williamr@2
|
278 |
* RunError function inherited from CActive base class - intercepts any Leave from
|
williamr@2
|
279 |
* the RunL() function, sets an appropriate errorcode and calls ParseFileCompleteL
|
williamr@2
|
280 |
*/
|
williamr@2
|
281 |
IMPORT_C TInt RunError(TInt aError);
|
williamr@2
|
282 |
|
williamr@2
|
283 |
/*
|
williamr@2
|
284 |
* Constructors
|
williamr@2
|
285 |
*/
|
williamr@2
|
286 |
CMDXMLParser(MMDXMLParserObserver* aParserObserver);
|
williamr@2
|
287 |
|
williamr@2
|
288 |
CMDXMLParser(MMDXMLParserObserver* aParserObserver, MXMLDtd* aDtdRepresentation);
|
williamr@2
|
289 |
|
williamr@2
|
290 |
/*
|
williamr@2
|
291 |
* Called when a character is read in and found to bo outside of an element tag
|
williamr@2
|
292 |
*/
|
williamr@2
|
293 |
virtual void HandleTextL(TDes& aChar);
|
williamr@2
|
294 |
|
williamr@2
|
295 |
enum TGetCharReturn
|
williamr@2
|
296 |
{
|
williamr@2
|
297 |
KError = 0x00, // GetChar detected an error
|
williamr@2
|
298 |
KCharReturned, // GetChar returned a character
|
williamr@2
|
299 |
KWaitForChar // GetChar couldn't return a character this time, but might next time.
|
williamr@2
|
300 |
};
|
williamr@2
|
301 |
|
williamr@2
|
302 |
/*
|
williamr@2
|
303 |
* Fetch one character from the input file
|
williamr@2
|
304 |
* @param aChar the returned character.
|
williamr@2
|
305 |
* @return returns one of the values of TCharReturn
|
williamr@2
|
306 |
*/
|
williamr@2
|
307 |
TGetCharReturn GetChar(TDes& aChar);
|
williamr@2
|
308 |
|
williamr@2
|
309 |
/* utility functions, called from GetChar to deal with the
|
williamr@2
|
310 |
* 2 types of input stream
|
williamr@2
|
311 |
*/
|
williamr@2
|
312 |
TGetCharReturn GetDoubleByteChar(TDes& aChar);
|
williamr@2
|
313 |
TGetCharReturn GetSingleByteChar(TDes& aChar);
|
williamr@2
|
314 |
|
williamr@2
|
315 |
/*
|
williamr@2
|
316 |
* Fetch some more data from the data provider
|
williamr@2
|
317 |
* @return returns one of the values of TCharReturn
|
williamr@2
|
318 |
*/
|
williamr@2
|
319 |
void GetMoreData();
|
williamr@2
|
320 |
|
williamr@2
|
321 |
/*
|
williamr@2
|
322 |
* @return Returns true if the current tag is a doctype tag and sets the
|
williamr@2
|
323 |
* Document DocType member accordingly on the first pass of this function.
|
williamr@2
|
324 |
*/
|
williamr@2
|
325 |
TBool DocTypeL();
|
williamr@2
|
326 |
|
williamr@2
|
327 |
/*
|
williamr@2
|
328 |
* creates a new processing instruction if necessary and adds to document
|
williamr@2
|
329 |
* @return Returns true if the current tag is a processing instruction
|
williamr@2
|
330 |
*/
|
williamr@2
|
331 |
TBool ProcessingInstructionL(CMDXMLElement* aParentElement);
|
williamr@2
|
332 |
|
williamr@2
|
333 |
/*
|
williamr@2
|
334 |
* creates a new CDataSection if necessary and adds to document
|
williamr@2
|
335 |
* @return Returns true if the current tag is a processing instruction
|
williamr@2
|
336 |
*/
|
williamr@2
|
337 |
TBool CDataSectionL(CMDXMLElement* aParentElement);
|
williamr@2
|
338 |
TBool EndOfCDataSection();
|
williamr@2
|
339 |
|
williamr@2
|
340 |
/*
|
williamr@2
|
341 |
* @return returns true if the current tag is a version id tag and sets the
|
williamr@2
|
342 |
* Document Version member accordingly on the first pass of this function.
|
williamr@2
|
343 |
*/
|
williamr@2
|
344 |
TBool VersionIDL();
|
williamr@2
|
345 |
|
williamr@2
|
346 |
/*
|
williamr@2
|
347 |
* creates a new comment if necessary and adds to document
|
williamr@2
|
348 |
* @return returns true if the current tag is a comment tag
|
williamr@2
|
349 |
*/
|
williamr@2
|
350 |
TBool CommentL(CMDXMLElement* aParentElement);
|
williamr@2
|
351 |
|
williamr@2
|
352 |
/*
|
williamr@2
|
353 |
* Parse a start of element tag and create an element with attributes set.
|
williamr@2
|
354 |
* @return Returns a pointer to the created element
|
williamr@2
|
355 |
* @leave can Leave due to OOM
|
williamr@2
|
356 |
*/
|
williamr@2
|
357 |
virtual CMDXMLElement* ParseStartTagL();
|
williamr@2
|
358 |
|
williamr@2
|
359 |
/*
|
williamr@2
|
360 |
* Detects the type of a file - can be Unicode or UTF-8
|
williamr@2
|
361 |
*/
|
williamr@2
|
362 |
TBool DetectFileType();
|
williamr@2
|
363 |
|
williamr@2
|
364 |
/*
|
williamr@2
|
365 |
* Creates a generic or DTD-specific document object
|
williamr@2
|
366 |
* @leave can Leave due to OOM
|
williamr@2
|
367 |
*/
|
williamr@2
|
368 |
virtual void CreateDocumentL();
|
williamr@2
|
369 |
|
williamr@2
|
370 |
/*
|
williamr@2
|
371 |
* Sets iError to new errorcode if more serious than any error so far encountered
|
williamr@2
|
372 |
*/
|
williamr@2
|
373 |
IMPORT_C void SetError(const TInt aErrorCode, const TXMLErrorCodeSeverity aSeverity);
|
williamr@2
|
374 |
|
williamr@2
|
375 |
/*
|
williamr@2
|
376 |
* This function is used to parse the attributes.
|
williamr@2
|
377 |
* @param aElement The element to which the attributes belong
|
williamr@2
|
378 |
* @param aTagToParse The tag to be parsed
|
williamr@2
|
379 |
* @return Returns KErrNone if both attribute name & value are valid
|
williamr@2
|
380 |
* KErrXMLBadAttributeName if attribute name is invalid or KErrXMLBadAttributeValue is invalid
|
williamr@2
|
381 |
* @leave can Leave due to OOM
|
williamr@2
|
382 |
*/
|
williamr@2
|
383 |
TInt ParseElementAttributesL(CMDXMLElement& aElement, TDes& aTagToParse);
|
williamr@2
|
384 |
|
williamr@2
|
385 |
/**
|
williamr@2
|
386 |
This function locates the next attribute in the tag.
|
williamr@2
|
387 |
@param aTagToParse the tag to find the attribute in
|
williamr@2
|
388 |
@return the offset of the next attribute
|
williamr@2
|
389 |
*/
|
williamr@2
|
390 |
TInt LocateNextAttribute(const TDesC& aTagToParse);
|
williamr@2
|
391 |
|
williamr@2
|
392 |
/*
|
williamr@2
|
393 |
* Parses an end tag. In fact, at this point the end tag must match
|
williamr@2
|
394 |
* the tag name of the start tag.
|
williamr@2
|
395 |
* @param aTagToParse Text of the end tag.
|
williamr@2
|
396 |
* @return Returns KErrNone if the end tag matches the start tag or KErrNotFound if there is a mismatch.
|
williamr@2
|
397 |
*/
|
williamr@2
|
398 |
TInt ParseElementEndTag(CMDXMLElement& aElement, const TDesC& aTagToParse);
|
williamr@2
|
399 |
|
williamr@2
|
400 |
TInt CheckForStartCData(const TDesC& aTextToCheck);
|
williamr@2
|
401 |
TInt FindDelimiter(TDesC& aDataToSearch, TDesC& aDelimiterToFind);
|
williamr@2
|
402 |
|
williamr@2
|
403 |
/*
|
williamr@2
|
404 |
* Second stage constructor
|
williamr@2
|
405 |
*/
|
williamr@2
|
406 |
void ConstructL(MXMLDtd* aDtdRepresentation);
|
williamr@2
|
407 |
void AddTextL(CMDXMLElement* aParentElement);
|
williamr@2
|
408 |
|
williamr@2
|
409 |
/*
|
williamr@2
|
410 |
* Checks whether the end of this tag is in a CDataSection.
|
williamr@2
|
411 |
* @param aDataToSearch The data to check
|
williamr@2
|
412 |
* @return Returns ETrue if the tag contains an unclosed CDataSection
|
williamr@2
|
413 |
*/
|
williamr@2
|
414 |
TBool InCDataSection(TDesC& aDataToSearch);
|
williamr@2
|
415 |
|
williamr@2
|
416 |
/*
|
williamr@2
|
417 |
* Entity converts the sections of one attribute value that are not within a CDataSection.
|
williamr@2
|
418 |
* @param aAttributeValue one attribute value
|
williamr@2
|
419 |
* @return Returns an error if entity conversion did not successfully complete, otherwise KErrNone
|
williamr@2
|
420 |
*/
|
williamr@2
|
421 |
TInt ParseSingleAttributeL(TDes& aAttributeValue);
|
williamr@2
|
422 |
|
williamr@2
|
423 |
/*
|
williamr@2
|
424 |
* Prepares this class for use on another file.
|
williamr@2
|
425 |
*
|
williamr@2
|
426 |
*/
|
williamr@2
|
427 |
void PrepareForReuseL();
|
williamr@2
|
428 |
|
williamr@2
|
429 |
/**
|
williamr@2
|
430 |
This should be called when parsing has been completed, before calling ParseFileCompleteL().
|
williamr@2
|
431 |
It checks for errors that can only be determined at the end of parsing, eg missing doctype or
|
williamr@2
|
432 |
incomplete content.
|
williamr@2
|
433 |
*/
|
williamr@2
|
434 |
void CheckForErrors();
|
williamr@2
|
435 |
|
williamr@2
|
436 |
IMPORT_C void PlaceholderForRemovedExport1(MMDXMLParserObserver* aParserObserver);
|
williamr@2
|
437 |
IMPORT_C void PlaceholderForRemovedExport2(MMDXMLParserObserver* aParserObserver, MXMLDtd* aDtdRepresentation);
|
williamr@2
|
438 |
IMPORT_C void PlaceholderForRemovedExport3();
|
williamr@2
|
439 |
|
williamr@2
|
440 |
|
williamr@2
|
441 |
private:
|
williamr@2
|
442 |
enum TPanicCode { ENullMemVarDataSource,
|
williamr@2
|
443 |
ENullMemVarParserObserver,
|
williamr@2
|
444 |
ENullMemVarXMLDoc,
|
williamr@2
|
445 |
ENullMemVarElementTag,
|
williamr@2
|
446 |
ENullParameterParentElement };
|
williamr@2
|
447 |
void Panic(TPanicCode aReason) const;
|
williamr@2
|
448 |
|
williamr@2
|
449 |
private:
|
williamr@2
|
450 |
MMDXMLParserObserver* iParserObserver;
|
williamr@2
|
451 |
MXMLDtd* iDtdRepresentation;
|
williamr@2
|
452 |
TInt iError; // Current error
|
williamr@2
|
453 |
TXMLErrorCodeSeverity iSeverity; // ErrorCode severity
|
williamr@2
|
454 |
CMDXMLDocument* iXMLDoc; // Document created by the parser
|
williamr@2
|
455 |
CMDXMLEntityConverter* iEntityConverter; // Entity converter used by the parser
|
williamr@2
|
456 |
HBufC* iElementTag; // Currently processed element tag
|
williamr@2
|
457 |
TBool iDocTypeSet;
|
williamr@2
|
458 |
TBool iVersionSet;
|
williamr@2
|
459 |
TInt iBytesPerChar;
|
williamr@2
|
460 |
|
williamr@2
|
461 |
/* member variables dealing with access to source data */
|
williamr@2
|
462 |
TPtrC8 iInputBufferPtr; // set during a call to get more data
|
williamr@2
|
463 |
TInt iCurrentInputBufferLen; // current length of the data block available
|
williamr@2
|
464 |
TInt iNextChar; // read position in the data block
|
williamr@2
|
465 |
TInt iInputBytesRemaining; // number of bytes remaining to read.
|
williamr@2
|
466 |
HBufC8 *iUTF8EdgeBuffer; // buffer to hold up to 6 bytes so that UTF8 parsing can span edges of data blocks
|
williamr@2
|
467 |
HBufC8 *iBomBuffer; // buffer to hold data at the start of the stream so we may determine charset
|
williamr@2
|
468 |
TInt iRequiredUTF8Bytes; // number of bytes required to complete the character held in the edge buffer
|
williamr@2
|
469 |
TBool iUnicodeInputMisaligned; // Set to ETrue if the unicode input stream is not aligned to 16-bit boundaries
|
williamr@2
|
470 |
MMDXMLParserDataProvider* iDataSource; // XML Data Source being parsed.
|
williamr@2
|
471 |
CMDXMLParserFileDataSource* iFileSource; // We own this, and need to free it when we are done. Only used when we're providing the data source object to wrap a local file.
|
williamr@2
|
472 |
|
williamr@2
|
473 |
/* member variables dealing with chunked conversion into unicode output */
|
williamr@2
|
474 |
TBuf<32> iUnicodeConversion; // buffer to temporarily hold the results of conversion from UTF8 to Unicode
|
williamr@2
|
475 |
TInt iUnicodeConversionLen; // number of characters stored in our intermediate buffer
|
williamr@2
|
476 |
TInt iUnicodeReadPos; // next character to send from our intermediate buffer
|
williamr@2
|
477 |
TBuf<1> iSpareChar;
|
williamr@2
|
478 |
|
williamr@2
|
479 |
/* member variables used when parsing a local file */
|
williamr@2
|
480 |
TDesC *iFileToParse;
|
williamr@2
|
481 |
RFs iRFs;
|
williamr@2
|
482 |
RFile iFileHandleToParse;
|
williamr@2
|
483 |
|
williamr@2
|
484 |
TBool iEndOfTag;
|
williamr@2
|
485 |
|
williamr@2
|
486 |
/* member variables used in DoParseLoopL() */
|
williamr@2
|
487 |
TBool iOpened;
|
williamr@2
|
488 |
TBool iClosed;
|
williamr@2
|
489 |
CMDXMLElement* iNewElement;
|
williamr@2
|
490 |
CMDXMLElement* iParentElement;
|
williamr@2
|
491 |
HBufC* iText;
|
williamr@2
|
492 |
enum EParserStates
|
williamr@2
|
493 |
{
|
williamr@2
|
494 |
KInitFromFile,
|
williamr@2
|
495 |
KDetermineCharset,
|
williamr@2
|
496 |
KWaitingForData,
|
williamr@2
|
497 |
KParseData,
|
williamr@2
|
498 |
KSpanDataGap,
|
williamr@2
|
499 |
KFinished
|
williamr@2
|
500 |
};
|
williamr@2
|
501 |
|
williamr@2
|
502 |
EParserStates iState;
|
williamr@2
|
503 |
EParserStates iPreviousState;
|
williamr@2
|
504 |
TInt iSuspiciousCharacter;
|
williamr@2
|
505 |
TBool iStoreInvalid; // controls whether invalid elements and attributes are stored in the DOM.
|
williamr@2
|
506 |
TBool iPreserve;
|
williamr@2
|
507 |
|
williamr@2
|
508 |
};
|
williamr@2
|
509 |
|
williamr@2
|
510 |
#endif
|