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