xml/xmllibxml2parser/src/xmlengsaxplugin.h
changeset 0 e35f40988205
equal deleted inserted replaced
-1:000000000000 0:e35f40988205
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // SAX libxml2 parser plugin
       
    15 //
       
    16 
       
    17 
       
    18 
       
    19 /**
       
    20  @file
       
    21  @internalComponent
       
    22  @released
       
    23 */
       
    24 #ifndef XMLENGSAXPLUGIN_H
       
    25 #define XMLENGSAXPLUGIN_H
       
    26 
       
    27 #include <e32std.h>
       
    28 #include <stringpool.h>
       
    29 #include <stdlib.h>
       
    30 #include <badesca.h>
       
    31 
       
    32 #include <ecom/implementationproxy.h>
       
    33 #include <xml/xmlframeworkerrors.h>
       
    34 #include <xml/wbxmlextensionhandler.h>
       
    35 #include <xml/stringdictionarycollection.h>
       
    36 #include <xml/taginfo.h>
       
    37 #include <xml/parserfeature.h>
       
    38 #include <xml/attribute.h>
       
    39 #include <xml/documentparameters.h>
       
    40 #include <xml/contenthandler.h>
       
    41 #include <xml/plugins/parserinterface.h>
       
    42 #include <xml/plugins/parserinitparams.h>
       
    43 #include <xml/xmlparsererrors.h>
       
    44 
       
    45 #include <libxml2_parser.h>
       
    46 #include <libxml2_entities.h>
       
    47 #include <libxml2_sax2.h>
       
    48 
       
    49 #include <xml/utils/xmlengxestd.h>
       
    50 
       
    51 using namespace Xml;
       
    52 
       
    53 const TInt KFeatures  = EConvertTagsToLowerCase | EReportNamespaceMapping 
       
    54 						| EReportNamespaces | EReportNamespacePrefixes 
       
    55 						| EReplaceIntEntityFromExtSubsetByRef;
       
    56 
       
    57 const TInt KGranularityOfEntitiesArray = 8;						
       
    58 
       
    59 /**
       
    60  * GetLengthString:
       
    61  * @param   aString     the string 
       
    62  *
       
    63  * Return length of string.
       
    64  */	
       
    65 TInt GetLengthString(const xmlChar* aString);
       
    66 
       
    67 /**
       
    68  * EntityDecl:
       
    69  * @param aUserData the user data (XML parser context)
       
    70  * @param aName the entity name 
       
    71  * @param aType the entity type 
       
    72  * @param aPublicId The public ID of the entity
       
    73  * @param aSystemId The system ID of the entity
       
    74  * @param aContent the entity value (without processing).
       
    75  *
       
    76  * An entity definition has been parsed.
       
    77  */
       
    78 void EntityDeclaration(void *aUserData,
       
    79 				const xmlChar *aName,
       
    80 				int aType,
       
    81 				const xmlChar *aPublicId,
       
    82 				const xmlChar *aSystemId,
       
    83 				xmlChar *aContent);
       
    84 
       
    85 /**
       
    86  * ExternalSubset:
       
    87  * @param aUserData the user data (XML parser context)
       
    88  * @param aName the root element name
       
    89  * @param aExternalID the external ID
       
    90  * @param aSystemID the SYSTEM ID (e.g. filename or URL)
       
    91  *
       
    92  * Callback on external subset declaration.
       
    93  */	
       
    94 void ExternalSubset(void *aUserData,
       
    95 				const xmlChar *aName,
       
    96 				const xmlChar *aExternalID,
       
    97 				const xmlChar *aSystemID);
       
    98 
       
    99 /**
       
   100  * ResolveEntity:
       
   101  * @param aUserData the user data (XML parser context)
       
   102  * @param aPublicId The public ID of the entity
       
   103  * @param aSystemId The system ID of the entity
       
   104  *
       
   105  * Callback on resolve entity.
       
   106  */
       
   107 xmlParserInputPtr ResolveEntity(void *aUserData,
       
   108 				const xmlChar *aPublicId,
       
   109 				const xmlChar *aSystemId);			
       
   110 
       
   111 /**
       
   112  * StructuredError:
       
   113  * @param aUserData user provided data for the error callback
       
   114  * @param aError the error being raised.
       
   115  *
       
   116  * Signature of the function to use when there is an error and
       
   117  * the module handles the new error reporting mechanism.
       
   118  */
       
   119 void StructuredError(void *aUserData, 
       
   120 				xmlErrorPtr aError);
       
   121 
       
   122 /**
       
   123  * GetEntityL:
       
   124  * @param aUserData the user data (XML parser context)
       
   125  * @param aName The entity name
       
   126  *
       
   127  * Get an entity by name.
       
   128  *
       
   129  * Returns the xmlEntityPtr if found.
       
   130  */	
       
   131 xmlEntityPtr GetEntityL(void *aUserData,
       
   132 				const xmlChar *aName);
       
   133 
       
   134 /**
       
   135  * GetEntityCal:
       
   136  * @param aUserData the user data (XML parser context)
       
   137  * @param aName The entity name
       
   138  *
       
   139  * Get an entity by name.
       
   140  *
       
   141  * Returns the xmlEntityPtr if found.
       
   142  */	
       
   143 xmlEntityPtr GetEntityCal(void *aUserData,
       
   144 				const xmlChar *aName);
       
   145 
       
   146 /**
       
   147  * GetParameterEntityL:
       
   148  * @param aUserData the user data (XML parser context)
       
   149  * @param aName The entity name
       
   150  *
       
   151  * Get a parameter entity by name.
       
   152  *
       
   153  * Returns the xmlEntityPtr if found.
       
   154  */					
       
   155 xmlEntityPtr GetParameterEntity(void *aUserData,
       
   156 				const xmlChar *aName);
       
   157 
       
   158 /**
       
   159  * StartDocument:
       
   160  * @param aUserData the user data (XML parser context)
       
   161  *
       
   162  * Called when the document start being processed.
       
   163  */
       
   164 void StartDocument(void* aUserData);
       
   165 
       
   166 /**
       
   167  * EndDocument:
       
   168  * @param aUserData the user data (XML parser context)
       
   169  *
       
   170  * Called when the document end has been detected.
       
   171  */
       
   172 void EndDocument(void* aUserData);
       
   173 
       
   174 /**
       
   175  * Characters:
       
   176  * @param aUserData the user data (XML parser context)
       
   177  * @param aCharacter a xmlChar string
       
   178  * @param aLen the number of xmlChar
       
   179  *
       
   180  * Receiving some chars from the parser.
       
   181  */
       
   182 void Characters(void* aUserData, const xmlChar* aCharacter, int aLen);
       
   183 
       
   184 /**
       
   185  * IgnorableWhitespace:
       
   186  * @param aUserData the user data (XML parser context)
       
   187  * @param aCharacter a xmlChar string
       
   188  * @param aLen the number of xmlChar
       
   189  *
       
   190  * Receiving some ignorable whitespaces from the parser.
       
   191  * UNUSED: by default the DOM building will use characters.
       
   192  */
       
   193 void IgnorableWhitespace(void *aUserData, const xmlChar* aCharacter, int aLen);
       
   194 
       
   195 /**
       
   196  * ProcessingInstruction:
       
   197  * @param aUserData the user data (XML parser context)
       
   198  * @param aTarget the target name
       
   199  * @param aData the PI data's
       
   200  *
       
   201  * A processing instruction has been parsed.
       
   202  */
       
   203 void ProcessingInstruction(void *aUserData, const xmlChar* aTarget, const xmlChar* aData);
       
   204 
       
   205 /**
       
   206  * StartElementNsL:
       
   207  * @param aUserData the user data (XML parser context)
       
   208  * @param aLocalname the local name of the element
       
   209  * @param aPrefix the element namespace prefix if available
       
   210  * @param aURI the element namespace name if available
       
   211  * @param aNbNamespaces number of namespace definitions on that node
       
   212  * @param aNamespaces pointer to the array of prefix/URI pairs namespace definitions
       
   213  * @param aNbAttributes the number of attributes on that node
       
   214  * @param aNbDefaulted the number of defaulted attributes. The defaulted
       
   215  *                  ones are at the end of the array
       
   216  * @param aAttributes pointer to the array of (localname/prefix/URI/value/end)
       
   217  *               attribute values.
       
   218  *
       
   219  * SAX2 callback when an element start has been detected by the parser.
       
   220  * It provides the namespace informations for the element, as well as
       
   221  * the new namespace declarations on the element.
       
   222  */
       
   223 void StartElementNsL(
       
   224 					void *aUserData,
       
   225 					const xmlChar *aLocalname,
       
   226 					const xmlChar *aPrefix,
       
   227 					const xmlChar *aURI,
       
   228 					int aNbNamespaces,
       
   229 					const xmlChar **aNamespaces,
       
   230 					int aNbAttributes,
       
   231 					int aNbDefaulted,
       
   232 					const xmlChar **aAttributes);
       
   233 
       
   234 /**
       
   235  * StartElementNs:
       
   236  * @param aUserData the user data (XML parser context)
       
   237  * @param aLocalname the local name of the element
       
   238  * @param aPrefix the element namespace prefix if available
       
   239  * @param aURI the element namespace name if available
       
   240  * @param aNbNamespaces number of namespace definitions on that node
       
   241  * @param aNamespaces pointer to the array of prefix/URI pairs namespace definitions
       
   242  * @param aNbAttributes the number of attributes on that node
       
   243  * @param aNbDefaulted the number of defaulted attributes. The defaulted
       
   244  *                  ones are at the end of the array
       
   245  * @param aAttributes pointer to the array of (localname/prefix/URI/value/end)
       
   246  *               attribute values.
       
   247  *
       
   248  * SAX2 callback when an element start has been detected by the parser.
       
   249  * It provides the namespace informations for the element, as well as
       
   250  * the new namespace declarations on the element.
       
   251  */
       
   252 void StartElementNs(
       
   253 					void *aUserData,
       
   254 					const xmlChar *aLocalname,
       
   255 					const xmlChar *aPrefix,
       
   256 					const xmlChar *aURI,
       
   257 					int aNbNamespaces,
       
   258 					const xmlChar **aNamespaces,
       
   259 					int aNbAttributes,
       
   260 					int aNbDefaulted,
       
   261 					const xmlChar **aAttributes);
       
   262 
       
   263 /**
       
   264  * EndElementNsL:
       
   265  * @param aUserData the user data (XML parser context)
       
   266  * @param aLocalname the local name of the element
       
   267  * @param aPrefix the element namespace prefix if available
       
   268  * @param aURI the element namespace name if available
       
   269  *
       
   270  * SAX2 callback when an element end has been detected by the parser.
       
   271  * It provides the namespace informations for the element.
       
   272  */
       
   273 void EndElementNsL(
       
   274 					void *aUserData,
       
   275 					const xmlChar *aLocalname,
       
   276 					const xmlChar *aPrefix,
       
   277 					const xmlChar *aURI);
       
   278 
       
   279 /**
       
   280  * EndElementNs:
       
   281  * @param aUserData the user data (XML parser context)
       
   282  * @param aLocalname the local name of the element
       
   283  * @param aPrefix the element namespace prefix if available
       
   284  * @param aURI the element namespace name if available
       
   285  *
       
   286  * SAX2 callback when an element end has been detected by the parser.
       
   287  * It provides the namespace informations for the element.
       
   288  */
       
   289 void EndElementNs(
       
   290 					void *aUserData,
       
   291 					const xmlChar *aLocalname,
       
   292 					const xmlChar *aPrefix,
       
   293 					const xmlChar *aURI);
       
   294 
       
   295 /**
       
   296  * StartPrefixMappingL:
       
   297  * @param aUserData     the user data (XML parser context)
       
   298  * @param aPrefix  the element namespace prefix if available, NULL if default namespace
       
   299  * @param aURI     the element namespace name if available
       
   300  *
       
   301  * SAX2 callback when namespace prefix mapping is done.
       
   302  */
       
   303 void StartPrefixMappingL(
       
   304 		void* aUserData,
       
   305 		const xmlChar* aPrefix,
       
   306 		const xmlChar* aURI);
       
   307 
       
   308 /**
       
   309  * EndPrefixMappingL:
       
   310  * @param   aUserData     the user data (XML parser context)
       
   311  * @param   aPrefix  the element namespace prefix if available, NULL otherwise
       
   312  *
       
   313  * SAX2 callback when namespace prefix mapping is getting out of scope.
       
   314  */
       
   315 void EndPrefixMappingL(
       
   316 		void* aUserData,
       
   317 		const xmlChar* aPrefix);
       
   318 
       
   319 /**
       
   320  * StartPrefixMapping:
       
   321  * @param aUserData     the user data (XML parser context)
       
   322  * @param aPrefix  the element namespace prefix if available, NULL if default namespace
       
   323  * @param aURI     the element namespace name if available
       
   324  *
       
   325  * SAX2 callback when namespace prefix mapping is done.
       
   326  */
       
   327 void StartPrefixMapping(
       
   328 		void* aUserData,
       
   329 		const xmlChar* aPrefix,
       
   330 		const xmlChar* aURI);
       
   331 
       
   332 /**
       
   333  * EndPrefixMapping:
       
   334  * @param   aUserData     the user data (XML parser context)
       
   335  * @param   aPrefix  the element namespace prefix if available, NULL otherwise
       
   336  *
       
   337  * SAX2 callback when namespace prefix mapping is getting out of scope.
       
   338  */
       
   339 void EndPrefixMapping(
       
   340 		void* aUserData,
       
   341 		const xmlChar* aPrefix);
       
   342 
       
   343 /*
       
   344 
       
   345 CXMLEngineSAXPlugin class.
       
   346 
       
   347 This class encapsulates the LibXML2 parser. It is the engine behind CXMLEngineSAXPlugin.
       
   348 
       
   349 Handles construction and deletion of LibXML2 parser. Defines handlers required for LibXML2,
       
   350 transforms handler data to required types and passes this to the client by MContentHandler 
       
   351 callbacks.
       
   352 
       
   353 */
       
   354 
       
   355 class CXMLEngineSAXPlugin : public CBase, public MParser
       
   356 	{
       
   357 	
       
   358 	
       
   359 	public:
       
   360 
       
   361 		static MParser* NewL(TAny* aInitParams);
       
   362 		
       
   363 		virtual ~CXMLEngineSAXPlugin();
       
   364 
       
   365 		//From MParser
       
   366 		
       
   367 		/** 
       
   368 		 * Enable a feature. 
       
   369 		 */
       
   370 		TInt EnableFeature(TInt aParserFeature);
       
   371 		
       
   372 		/** 
       
   373 		 * Disable a feature. 
       
   374 		 */
       
   375 		TInt DisableFeature(TInt);
       
   376 
       
   377 		/** 
       
   378 		 * See if a feature is enabled. 
       
   379 		 */	
       
   380 		TBool IsFeatureEnabled(TInt) const;
       
   381 	
       
   382 		/** 
       
   383 		 * Parses a descriptor that contains part of a document. 
       
   384 		 */
       
   385 		void ParseChunkL (const TDesC8& aDescriptor);
       
   386 		
       
   387 		/** 
       
   388 		 * Parses a descriptor that contains the last  part of a document. 
       
   389 		 */
       
   390 		void ParseLastChunkL(const TDesC8& aDescriptor);
       
   391 
       
   392 		/** 
       
   393 		 * Interfaces don't have a destructor, so we have an explicit method instead. 
       
   394 		 */
       
   395 		void Release();
       
   396 
       
   397 		// From MContentSouce
       
   398 	
       
   399 		/** 
       
   400 		 * This method tells us what's the next content handler in the chain. 
       
   401 		 */	
       
   402 		void SetContentSink (MContentHandler& aContentHandler);
       
   403 
       
   404 		//Public getter and setter method
       
   405 		
       
   406 		/** 
       
   407 		 * This method returns pool object. 
       
   408 		 */
       
   409 		inline RStringPool& StringPool();
       
   410 
       
   411 		/** 
       
   412 		 * This method returns a user handler object. 
       
   413 		 */		
       
   414 		inline MContentHandler* getContentHandler() const;
       
   415 
       
   416 		/** 
       
   417 		 * This method returns a parser context object. 
       
   418 		 */	
       
   419 		xmlParserCtxtPtr getParserContext() const;
       
   420 		
       
   421 		/** 
       
   422 		 * This method return error status. 
       
   423 		 */			
       
   424 		inline TBool IsErrorStatus();
       
   425 		
       
   426 		/** 
       
   427 		 * This method set error status. 
       
   428 		 */			
       
   429 		inline void SetErrorStatus(TBool aStatus);
       
   430 		
       
   431 		/** 
       
   432 		 * This method stop parsing. 
       
   433 		 */			
       
   434 		void StopParsing(TInt aError);
       
   435 		
       
   436 		xmlEntity& GetEntity();
       
   437 		
       
   438 		/** 
       
   439 		 * This method releases context and leaves with aError code
       
   440 		 */			
       
   441 		 void CleanupAndLeaveL(TInt aError);
       
   442 		
       
   443 	private:
       
   444 
       
   445 		//constructor of CXMLEngineSAXPlugin
       
   446 		CXMLEngineSAXPlugin(TParserInitParams* aInitParams);		
       
   447 		void ConstructL();
       
   448 		
       
   449 	private:
       
   450 		
       
   451 		//user handler object 
       
   452 		MContentHandler* iContentHandler;
       
   453 		
       
   454 		RStringDictionaryCollection* iStringDictionaryCollection;
       
   455 		CCharSetConverter* iCharSetConverter;
       
   456 		RElementStack* iElementStack;
       
   457 		RStringPool iStringPool;
       
   458 		
       
   459 		//context to the libxml2 sax parser
       
   460 		xmlParserCtxtPtr iParserContext;
       
   461 		
       
   462 		//context to the libxml2 sax handler
       
   463 		xmlSAXHandler iParserEvents;
       
   464 		
       
   465 		//Features mode
       
   466 		TInt iParserMode;
       
   467 		
       
   468 		//flag which tells that in parsing process error occurs (TRUE if error was found)
       
   469 		TBool Flag_Error_Status; 
       
   470 		
       
   471 		xmlEntity iEntity;
       
   472 	};
       
   473 
       
   474 #include "xmlengsaxplugin.inl"
       
   475 
       
   476 #endif /* XMLENGSAXPLUGIN_H */
       
   477