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