1 senxmlreader.h |
1 /* |
|
2 * Copyright (c) 2002-2005 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 the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Class extends Symbian XML framework parser functionality |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 #ifndef SEN_XMLREADER_H |
|
26 #define SEN_XMLREADER_H |
|
27 |
|
28 // INCLUDES |
|
29 #include <Xml/Parser.h> |
|
30 #include <Xml/ParserFeature.h> // for TParserFeature enumeration |
|
31 #include <Xml/ContentHandler.h> |
|
32 #include <badesca.h> |
|
33 |
|
34 using namespace Xml; |
|
35 |
|
36 // CONSTANTS |
|
37 const TInt KSenDefaultParserFeature = (TInt)EReportNamespaceMapping; |
|
38 |
|
39 |
|
40 |
|
41 // FORWARD DECLARATIONS |
|
42 class MSenContentHandlerClient; |
|
43 class RFs; |
|
44 |
|
45 // CLASS DECLARATION |
|
46 |
|
47 /** |
|
48 * Class extends Symbian XML framework parser functionality |
|
49 * Callers of this class must register some handler which will |
|
50 * then receive XML callback events from underlying Symbian |
|
51 * XML framework. |
|
52 * @lib SenXML.dll |
|
53 * @since Series60 3.0 |
|
54 */ |
|
55 class CSenXmlReader : public CBase, public MContentHandler |
|
56 { |
|
57 public: // Constructors and destructor |
|
58 |
|
59 /** |
|
60 * Standard two-phase constructor. |
|
61 * Creates new parser instance using default |
|
62 * MIME type "text/xml" (KXmlParserMimeType). |
|
63 * @since Series60 3.0 |
|
64 * @return pointer to a new CSenXmlReader instance. |
|
65 */ |
|
66 IMPORT_C static CSenXmlReader* NewL(); |
|
67 |
|
68 /** |
|
69 * Standard two-phase constructor. |
|
70 * Creates new parser instance using default |
|
71 * MIME type "text/xml" (KXmlParserMimeType). |
|
72 * @since Series60 3.0 |
|
73 * @return pointer to a new CSenXmlReader instance |
|
74 * which is left on cleanup stack. |
|
75 */ |
|
76 IMPORT_C static CSenXmlReader* NewLC(); |
|
77 |
|
78 /** |
|
79 * A constructor with parser feature enabling. Uses default |
|
80 * parser MIME type "text/xml" (KXmlParserMimeType). |
|
81 * @since Series60 3.0 |
|
82 * @param aParserFeature is typically some enumeration introduced |
|
83 * in Xml::TParserFeature or some other feature introduced in |
|
84 * some XML parser implementation. |
|
85 * Leave codes: |
|
86 * KErrArgument if aParserFeature value is negative. |
|
87 */ |
|
88 IMPORT_C static CSenXmlReader* NewL(TInt aParserFeature); |
|
89 |
|
90 /** |
|
91 * A constructor with parser feature enabling. Uses default |
|
92 * parser MIME type "text/xml" (KXmlParserMimeType). |
|
93 * @since Series60 3.0 |
|
94 * @param aParserMimeType is the XML parser MIME type. |
|
95 * If descriptor is of zero-length, then default |
|
96 * MIME type KXmlParserMimeType is used ("text/xml"). |
|
97 * Availability of other MIME types depends on |
|
98 * underlying parser implementation. |
|
99 * @param aParserFeature is typically some enumeration introduced |
|
100 * in Xml::TParserFeature or some other feature introduced in |
|
101 * some XML parser implementation. |
|
102 * Leave codes: |
|
103 * KErrArgument if aParserFeature value is negative. |
|
104 */ |
|
105 IMPORT_C static CSenXmlReader* NewLC(TInt aParserFeature); |
|
106 |
|
107 /** |
|
108 * A constructor with parser MIME type. |
|
109 * Standard two-phase constructor. |
|
110 * @since Series60 3.0 |
|
111 * @param aParserMimeType is the XML parser MIME type. |
|
112 * If descriptor is of zero-length, then default |
|
113 * MIME type KXmlParserMimeType is used ("text/xml"). |
|
114 * Availability of other MIME types depends on |
|
115 * underlying parser implementation. |
|
116 * @return pointer to a new CSenXmlReader instance. |
|
117 */ |
|
118 IMPORT_C static CSenXmlReader* NewL(const TDesC8& aParserMimeType); |
|
119 |
|
120 /** |
|
121 * A constructor with parser MIME type. |
|
122 * @since Series60 3.0 |
|
123 * @param aParserMimeType is the XML parser MIME type. |
|
124 * If descriptor is of zero-length, then default |
|
125 * MIME type KXmlParserMimeType is used ("text/xml"). |
|
126 * Availability of other MIME types depends on |
|
127 * underlying parser implementation. |
|
128 * @return pointer to a new CSenXmlReader instance |
|
129 * which is left on cleanup stack. |
|
130 */ |
|
131 IMPORT_C static CSenXmlReader* NewLC(const TDesC8& aParserMimeType); |
|
132 |
|
133 /** |
|
134 * A constructor with parser MIME type and parser feature enabling. |
|
135 * @since Series60 3.0 |
|
136 * @param aParserFeature is typically some enumeration introduced |
|
137 * in Xml::TParserFeature or some other feature introduced in |
|
138 * some XML parser implementation. |
|
139 * Leave codes: |
|
140 * KErrArgument if aParserFeature value is negative. |
|
141 */ |
|
142 IMPORT_C static CSenXmlReader* NewL(const TDesC8& aParserMimeType, |
|
143 TInt aParserFeature); |
|
144 |
|
145 /** |
|
146 * A constructor with parser MIME type and parser feature enabling. |
|
147 * @since Series60 3.0 |
|
148 * @param aParserMimeType is the XML parser MIME type. |
|
149 * If descriptor is of zero-length, then default |
|
150 * MIME type KXmlParserMimeType is used ("text/xml"). |
|
151 * Availability of other MIME types depends on |
|
152 * underlying parser implementation. |
|
153 * @param aParserFeature is typically some enumeration introduced |
|
154 * in Xml::TParserFeature or some other feature introduced in |
|
155 * some XML parser implementation. |
|
156 * Leave codes: |
|
157 * KErrArgument if aParserFeature value is negative. |
|
158 */ |
|
159 IMPORT_C static CSenXmlReader* NewLC(const TDesC8& aParserMimeType, |
|
160 TInt aParserFeature); |
|
161 |
|
162 /** |
|
163 * Destructor. |
|
164 */ |
|
165 IMPORT_C virtual ~CSenXmlReader(); |
|
166 |
|
167 // New functions |
|
168 |
|
169 /** |
|
170 * Method to allow client to register a content event handler (for XML) for |
|
171 * the current reader. |
|
172 * @since Series60 3.0 |
|
173 * @param aContentHandler The new event handler. |
|
174 */ |
|
175 IMPORT_C virtual void SetContentHandler( |
|
176 MSenContentHandlerClient& aContentHandler); |
|
177 |
|
178 /** |
|
179 * Method for checking which feature has been enabled in the parser. |
|
180 * @since Series60 3.0 |
|
181 * @return the corresponding integer id of the feature |
|
182 */ |
|
183 IMPORT_C virtual TInt EnabledParserFeature(); |
|
184 |
|
185 /** |
|
186 * @deprecated - use EnabledParserFeature() instead. |
|
187 */ |
|
188 IMPORT_C virtual TInt ParserFeature(); |
|
189 |
|
190 /** |
|
191 * Method for enabling a parser feature. |
|
192 * @since Series60 3.0 |
|
193 * @param aParserFeature is typically some enumeration introduced |
|
194 * in Xml::TParserFeature or some other feature introduced in |
|
195 * some XML parser implementation. |
|
196 * @return KErrNone or some system-wide error code, if an error has |
|
197 * occurred. |
|
198 */ |
|
199 TInt SetParserFeature(TInt aParserFeature); |
|
200 |
|
201 /** |
|
202 * Parse an XML buffer. |
|
203 * @since Series60 3.0 |
|
204 * @param aBuff Buffer containing document to parse. |
|
205 * Note that this method will also leave, if an error |
|
206 * is returned from Symbian XML framework. Here are |
|
207 * the corresponding enums, and their respective |
|
208 * error code values (-1000, -999... and up) |
|
209 * (XML-specific errors returned by the XML parser) |
|
210 * [from XmlParserErrors.h] |
|
211 * EXmlParserError = -1000, |
|
212 * EXmlSyntax = 2+EXmlParserError, // -998 |
|
213 * EXmlNoElements, // -997 |
|
214 * EXmlInvalidToken, // -996 |
|
215 * EXmlUnclosedToken, // -995 |
|
216 * EXmlPartialChar, // -994 |
|
217 * EXmlTagMismatch, // -993 |
|
218 * EXmlDuplicateAttribute, // -992 |
|
219 * EXmlJunkAfterDocElement, // -991 |
|
220 * EXmlPeRef, // -990 |
|
221 * EXmlUndefinedEntity, // -989 |
|
222 * EXmlRecursiveEntity, // -988 |
|
223 * EXmlAsyncEntity, // -987 |
|
224 * EXmlBadCharRef, // -986 |
|
225 * EXmlBinaryEntityRef, // -985 |
|
226 * EXmlAttributeExternalEntityRef, // -984 |
|
227 * EXmlMisplacedPi, // -983 |
|
228 * EXmlUnknownEncoding, // -982 |
|
229 * EXmlIncorrectEncoding, // -981 |
|
230 * EXmlUnclosedCdata, // -980 |
|
231 * EXmlExternalEntityHandling, // -979 |
|
232 * EXmlNotStandalone, // -978 |
|
233 * EXmlUnexpectedState, // -977 |
|
234 * EXmlEntityDeclInPe, // -976 |
|
235 * EXmlDtdRequired, // -975 |
|
236 * EXmlFeatureLockedWhileParsing // -974 |
|
237 */ |
|
238 IMPORT_C void ParseL(const TDesC8& aBuff); |
|
239 |
|
240 /** |
|
241 * Parse an XML document. |
|
242 * @since Series60 3.0 |
|
243 * @param aRFs An open filesession. |
|
244 * @param aFileToParse Filename of file to parse. |
|
245 */ |
|
246 IMPORT_C void ParseL(RFs &aRFs, const TDesC& aFileToParse); |
|
247 |
|
248 // Functions from base classes |
|
249 |
|
250 // Callback functions implementing Symbian MContentHandler interface |
|
251 |
|
252 /** |
|
253 * @since Series60 3.0 |
|
254 * Leave codes: |
|
255 * KErrSenXmlContentHandlerNotSet if XML content handler |
|
256 * for this XML reader has not been set. This leave can |
|
257 * be avoided calling SetContentHandlerL() method prior |
|
258 * parsing some XML document. |
|
259 */ |
|
260 virtual void OnStartDocumentL(const RDocumentParameters& aDocParam, |
|
261 TInt aErrorCode); |
|
262 |
|
263 /** |
|
264 * @since Series60 3.0 |
|
265 * Leave codes: |
|
266 * KErrSenXmlContentHandlerNotSet if XML content handler |
|
267 * for this XML reader has not been set. This leave can |
|
268 * be avoided calling SetContentHandlerL() method prior |
|
269 * parsing some XML document. |
|
270 */ |
|
271 virtual void OnEndDocumentL(TInt aErrorCode); |
|
272 |
|
273 /** |
|
274 * @since Series60 3.0 |
|
275 * Leave codes: |
|
276 * KErrSenXmlContentHandlerNotSet if XML content handler |
|
277 * for this XML reader has not been set. This leave can |
|
278 * be avoided calling SetContentHandlerL() method prior |
|
279 * parsing some XML document. |
|
280 */ |
|
281 virtual void OnStartElementL(const RTagInfo& aElement, |
|
282 const RAttributeArray& aAttributes, |
|
283 TInt aErrorCode); |
|
284 |
|
285 /** |
|
286 * @since Series60 3.0 |
|
287 * Leave codes: |
|
288 * KErrSenXmlContentHandlerNotSet if XML content handler |
|
289 * for this XML reader has not been set. This leave can |
|
290 * be avoided calling SetContentHandlerL() method prior |
|
291 * parsing some XML document. |
|
292 */ |
|
293 virtual void OnEndElementL(const RTagInfo& aElement, TInt aErrorCode); |
|
294 |
|
295 /** |
|
296 * @since Series60 3.0 |
|
297 * @param aBytes is the actual XML data, content in UTF-8 form |
|
298 * @param aErrorCode KErrNone, or some system-wide error code |
|
299 * if an error has occured. |
|
300 */ |
|
301 virtual void OnContentL(const TDesC8& aBytes, TInt aErrorCode); |
|
302 |
|
303 /** |
|
304 * @since Series60 3.0 |
|
305 * Leave codes: |
|
306 * KErrSenXmlContentHandlerNotSet if XML content handler |
|
307 * for this XML reader has not been set. This leave can |
|
308 * be avoided calling SetContentHandlerL() method prior |
|
309 * parsing some XML document. |
|
310 */ |
|
311 virtual void OnStartPrefixMappingL(const RString& aPrefix, |
|
312 const RString& aUri, |
|
313 TInt aErrorCode); |
|
314 |
|
315 /** |
|
316 * @since Series60 3.0 |
|
317 * Leave codes: |
|
318 * KErrSenXmlContentHandlerNotSet if XML content handler |
|
319 * for this XML reader has not been set. This leave can |
|
320 * be avoided calling SetContentHandlerL() method prior |
|
321 * parsing some XML document. |
|
322 */ |
|
323 virtual void OnEndPrefixMappingL(const RString& aPrefix, TInt aErrorCode); |
|
324 |
|
325 /** |
|
326 * @since Series60 3.0 |
|
327 * Leave codes: |
|
328 * KErrSenXmlContentHandlerNotSet if XML content handler |
|
329 * for this XML reader has not been set. This leave can |
|
330 * be avoided calling SetContentHandlerL() method prior |
|
331 * parsing some XML document. |
|
332 */ |
|
333 virtual void OnIgnorableWhiteSpaceL(const TDesC8& aBytes, TInt aErrorCode); |
|
334 |
|
335 /** |
|
336 * @since Series60 3.0 |
|
337 * Leave codes: |
|
338 * KErrSenXmlContentHandlerNotSet if XML content handler |
|
339 * for this XML reader has not been set. This leave can |
|
340 * be avoided calling SetContentHandlerL() method prior |
|
341 * parsing some XML document. |
|
342 */ |
|
343 virtual void OnSkippedEntityL(const RString& aName, TInt aErrorCode); |
|
344 |
|
345 /** |
|
346 * @since Series60 3.0 |
|
347 * Leave codes: |
|
348 * KErrSenXmlContentHandlerNotSet if XML content handler |
|
349 * for this XML reader has not been set. This leave can |
|
350 * be avoided calling SetContentHandlerL() method prior |
|
351 * parsing some XML document. |
|
352 */ |
|
353 virtual void OnProcessingInstructionL(const TDesC8& aTarget, |
|
354 const TDesC8& aData, |
|
355 TInt aErrorCode); |
|
356 |
|
357 /** |
|
358 * OnError is a callback method signalled by Symbian XML |
|
359 * framework. Current implementation of this class issues |
|
360 * a leave in original ParseL() call on any received by |
|
361 * this callback implementation. Used leave code will be |
|
362 * the received error code. |
|
363 * |
|
364 * @since Series60 3.0 |
|
365 * @param aErrorCode is one of the Symbian XML framework |
|
366 * errors listed in XmlFrameworkErrors.h |
|
367 * |
|
368 * Currently any s |
|
369 * |
|
370 * If content handler was not set, ParseL will leaves with |
|
371 * KErrSenXmlContentHandlerNotSet. |
|
372 */ |
|
373 virtual void OnError(TInt aErrorCode); |
|
374 |
|
375 /** |
|
376 * This method obtains the interface matching the specified UID. |
|
377 * @since Series60 3.0 |
|
378 * @param aUid the UID identifying the required interface. |
|
379 * @return NULL if no interface matching the UID is found or |
|
380 * if content handler was not set. Otherwise, |
|
381 * returns pointer to the interface. |
|
382 */ |
|
383 virtual TAny* GetExtendedInterface(const TInt32 aUid); |
|
384 |
|
385 protected: |
|
386 |
|
387 /** |
|
388 * C++ constructor. |
|
389 */ |
|
390 IMPORT_C CSenXmlReader(TInt aParserFeature); |
|
391 |
|
392 /** |
|
393 * Symbian 2nd phase constructor. |
|
394 * @param aParserMimeType sets the MIME type of |
|
395 * this XML parser. |
|
396 */ |
|
397 void ConstructL(const TDesC8& aParserMimeType); |
|
398 |
|
399 // New functions |
|
400 |
|
401 /** |
|
402 * This method re-initializes encapsulated CParser class instance. |
|
403 * @since Series60 3.0 |
|
404 */ |
|
405 void RecreateParserL(); |
|
406 |
|
407 private: |
|
408 static void CleanupParser(TAny* apReader); |
|
409 |
|
410 void CleanUp(); |
|
411 |
|
412 private: // Data |
|
413 // Owned instance of Symbian XML framework (default) XML parser |
|
414 CParser* iParser; |
|
415 // Not owned pointer to XML content handler. |
|
416 MSenContentHandlerClient* iContentHandler; |
|
417 // Owned pointer to XML namespace prefix strings |
|
418 CDesC8Array* ipNsPrefixes; |
|
419 // Owned pointer to XML namespace URI strings |
|
420 CDesC8Array* ipNsUris; |
|
421 // Owned string pool for XML attribute handling. |
|
422 RStringPool iStringPool; |
|
423 // Integer indicating currently enabled features |
|
424 TInt iEnabledFeature; |
|
425 }; |
|
426 |
|
427 #endif // SEN_XMLREADER_H |
|
428 |
|
429 // End of File |
|
430 |