epoc32/include/xml/dom/xmlengdeserializer.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
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@4
     1
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
williamr@4
     2
// All rights reserved.
williamr@4
     3
// This component and the accompanying materials are made available
williamr@4
     4
// under the terms of "Eclipse Public License v1.0"
williamr@4
     5
// which accompanies this distribution, and is available
williamr@4
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
williamr@4
     7
//
williamr@4
     8
// Initial Contributors:
williamr@4
     9
// Nokia Corporation - initial contribution.
williamr@4
    10
//
williamr@4
    11
// Contributors:
williamr@4
    12
//
williamr@4
    13
// Description:
williamr@4
    14
// XML Deserializer
williamr@4
    15
//
williamr@4
    16
williamr@4
    17
williamr@4
    18
williamr@4
    19
/**
williamr@4
    20
 @file
williamr@4
    21
 @publishedAll
williamr@4
    22
 @released
williamr@4
    23
*/
williamr@4
    24
#ifndef XMLENGDESERIALIZER_H
williamr@4
    25
#define XMLENGDESERIALIZER_H
williamr@4
    26
williamr@4
    27
#include <e32base.h>
williamr@4
    28
#include <xml/dom/xmlengparsingoptions.h>
williamr@4
    29
williamr@4
    30
#include <xml/contenthandler.h>
williamr@4
    31
#include <xml/parser.h>
williamr@4
    32
#include <e32std.h>
williamr@4
    33
williamr@4
    34
class RFs;
williamr@4
    35
class TXmlEngDataContainer;
williamr@4
    36
williamr@4
    37
/** Controls the format of deserialization */
williamr@4
    38
enum TXmlEngDeserializerType
williamr@4
    39
	{
williamr@4
    40
	/** Default deserialization (XML) */
williamr@4
    41
	EDeserializerDefault,
williamr@4
    42
	/** Deserialization from MIME Multipart containing XOP */
williamr@4
    43
	EDeserializerXOP,
williamr@4
    44
	/** Deserialization from XOP Infoset */
williamr@4
    45
	EDeserializerXOPInfoset,
williamr@4
    46
	/** Deserialization from GZip */
williamr@4
    47
	EDeserializerGZip
williamr@4
    48
	};
williamr@4
    49
williamr@4
    50
/** Controls the source of the deserialization */
williamr@4
    51
enum TXmlEngDeserializationSource
williamr@4
    52
	{
williamr@4
    53
	EDeserializeFromFile,
williamr@4
    54
	EDeserializeFromBuffer,
williamr@4
    55
	EDeserializeFromStream
williamr@4
    56
	};
williamr@4
    57
williamr@4
    58
/**
williamr@4
    59
Provides deserialization and parsing for XML content using a SAX callback
williamr@4
    60
interface.  Derived classes provide deserialization for specific formats,
williamr@4
    61
whereas this class defines the interface and provides default (plain XML)
williamr@4
    62
deserialization.
williamr@4
    63
williamr@4
    64
@see TXmlEngDeserializerType
williamr@4
    65
williamr@4
    66
Deserialization generates SAX events that are passed to a MContentHandler. 
williamr@4
    67
williamr@4
    68
@see Xml::MContentHandler
williamr@4
    69
williamr@4
    70
For deserialization to a DOM tree, see CXmlEngDeserializerDOM.
williamr@4
    71
@see CXmlEngDeserializerDOM
williamr@4
    72
williamr@4
    73
Support for data stored outside the DOM tree, such as data linked by
williamr@4
    74
xop:include references, is provided.  The external data must be set with
williamr@4
    75
UseExternalDataL() prior to deserialization.  The data is then returned through
williamr@4
    76
the MContentHandler interface.
williamr@4
    77
*/
williamr@4
    78
class CXmlEngDeserializer: public CBase
williamr@4
    79
{
williamr@4
    80
	friend class CXmlEngDeserializerXOP;
williamr@4
    81
	friend class CXmlEngDeserializerGZIP;
williamr@4
    82
williamr@4
    83
 public:
williamr@4
    84
    /**
williamr@4
    85
	Creates a deserializer of the given type.  Returns an instance of this
williamr@4
    86
	class or a derived class.
williamr@4
    87
williamr@4
    88
    @param aHandler Content handler for SAX events triggered by deserialization
williamr@4
    89
    @param aType Deserializer type    
williamr@4
    90
    @return The deserializer
williamr@4
    91
	@leave - One of the system-wide error codes
williamr@4
    92
    */
williamr@4
    93
	IMPORT_C static CXmlEngDeserializer* NewL( Xml::MContentHandler& aContentHandler, TXmlEngDeserializerType aType = EDeserializerDefault);
williamr@4
    94
												 
williamr@4
    95
	/**
williamr@4
    96
	Sets the input type to file and saves the file name for later
williamr@4
    97
	deserialization.
williamr@4
    98
	@param aFileName The file name of the file to deserialize
williamr@4
    99
	@leave - One of the system-wide error codes
williamr@4
   100
    */
williamr@4
   101
	IMPORT_C void SetInputFileL(const TDesC& aFileName);
williamr@4
   102
williamr@4
   103
	/**
williamr@4
   104
	Sets the input type to buffer and saves the buffer for later deserialization.
williamr@4
   105
	@param aBuffer The buffer to deserialize
williamr@4
   106
    */
williamr@4
   107
	IMPORT_C void SetInputBuffer(const TDesC8& aBuffer);
williamr@4
   108
williamr@4
   109
	/**
williamr@4
   110
	Sets the content handler which handles SAX events raised during
williamr@4
   111
	deserialization.  Clients must derive from Xml::MContentHandler in order to
williamr@4
   112
	receive SAX callbacks.
williamr@4
   113
williamr@4
   114
	@param aContentHandler The content handler
williamr@4
   115
	@leave - One of the system-wide error codes
williamr@4
   116
    */
williamr@4
   117
	IMPORT_C virtual void SetContentHandlerL(Xml::MContentHandler& aContentHandler);
williamr@4
   118
	
williamr@4
   119
    /**
williamr@4
   120
	Sets parsing options used for deserialization.
williamr@4
   121
	@param aOptions Parsing options to set.  A copy of the options is stored.
williamr@4
   122
    */	
williamr@4
   123
	IMPORT_C virtual void SetParsingOptions(TXmlEngParsingOptions& aOptions);
williamr@4
   124
williamr@4
   125
    /**
williamr@4
   126
	Gets the parsing options
williamr@4
   127
	@return The parsing options
williamr@4
   128
    */	
williamr@4
   129
	IMPORT_C virtual const TXmlEngParsingOptions& ParsingOptions();
williamr@4
   130
williamr@4
   131
	/**
williamr@4
   132
	Sets a list of data containers and indicates that the XML to be
williamr@4
   133
	deserialized contains references (such as xop:include) to data stored
williamr@4
   134
	outside the DOM tree.  
williamr@4
   135
williamr@4
   136
	Upon deserialization, the references are substituted with the matching data
williamr@4
   137
	containers and returned via the content handler.
williamr@4
   138
williamr@4
   139
	This often occurs when a multipart MIME message is received.  The text XML
williamr@4
   140
	content may be in one part, while the binary content is in another part.
williamr@4
   141
	Each part containing binary content must be placed into a data container using
williamr@4
   142
	RXmlEngDocument::CreateBinaryContainerL() or similar.  When deserialization
williamr@4
   143
	of the XML occurs, the data containers are retrieved by content-id.
williamr@4
   144
williamr@4
   145
	Ownership is not transferred and the list must stay in scope for the
williamr@4
   146
	lifetime of the deserializer.
williamr@4
   147
	
williamr@4
   148
	@param aList The list of data containers
williamr@4
   149
	@leave - Any system-wide error code
williamr@4
   150
    */
williamr@4
   151
	IMPORT_C void UseExternalDataL(RArray<TXmlEngDataContainer>& aList);
williamr@4
   152
williamr@4
   153
    /**
williamr@4
   154
	Gets the list of external data containers.
williamr@4
   155
	@return The list of data containers or NULL if no external data is registered
williamr@4
   156
    */
williamr@4
   157
	IMPORT_C RArray<TXmlEngDataContainer>* ExternalData();  
williamr@4
   158
williamr@4
   159
    /**
williamr@4
   160
	Enables parser features.
williamr@4
   161
williamr@4
   162
	@see Xml::CParser::EnableFeature()
williamr@4
   163
	@see Xml::CParser::TParserFeature
williamr@4
   164
	@param aParserFeature The parser feature to enable
williamr@4
   165
	@return KErrNone if successful, otherwise one of the system-wide error codes
williamr@4
   166
    */	
williamr@4
   167
	IMPORT_C virtual TInt EnableFeature(TInt aParserFeature);
williamr@4
   168
	
williamr@4
   169
    /**
williamr@4
   170
	Disables parser features.
williamr@4
   171
williamr@4
   172
	@see Xml::CParser::DisableFeature()
williamr@4
   173
	@see Xml::CParser::TParserFeature
williamr@4
   174
	@param aParserFeature The parser feature to disable
williamr@4
   175
	@return KErrNone if successful, otherwise one of the system-wide error codes
williamr@4
   176
    */	
williamr@4
   177
	IMPORT_C virtual TInt DisableFeature(TInt aParserFeature);
williamr@4
   178
williamr@4
   179
    /**
williamr@4
   180
	Checks if a parser feature is enabled.
williamr@4
   181
williamr@4
   182
	@see Xml::CParser::IsFeatureEnabled()
williamr@4
   183
	@see Xml::CParser::TParserFeature
williamr@4
   184
	@param aParserFeature The parser feature to check
williamr@4
   185
	@return ETrue if feature is enabled, otherwise EFalse
williamr@4
   186
    */	
williamr@4
   187
	IMPORT_C virtual TBool IsFeatureEnabled(TInt aParserFeature) const;
williamr@4
   188
williamr@4
   189
	/**
williamr@4
   190
	Deserializes the file or buffer previously set by SetInputFileL() or
williamr@4
   191
	SetInputBuffer().
williamr@4
   192
williamr@4
   193
	The result of deserialization is passed to the content handler as SAX
williamr@4
   194
	events.
williamr@4
   195
williamr@4
   196
	@leave KXmlEngErrNoParameters No file or buffer has been previously set
williamr@4
   197
	@leave - One of the system wide error codes or one of the Xml specific
williamr@4
   198
	ones defined in XmlFrameworkErrors.h
williamr@4
   199
    */
williamr@4
   200
	IMPORT_C virtual void DeserializeL();     
williamr@4
   201
williamr@4
   202
    /**
williamr@4
   203
	Deserializes the given file.  Any filename previously set with
williamr@4
   204
	SetInputFileL() is ignored. 
williamr@4
   205
williamr@4
   206
	The result of deserialization is passed to the content handler as SAX
williamr@4
   207
	events.
williamr@4
   208
williamr@4
   209
	@param aFileName The file to be parsed
williamr@4
   210
	@param aOptions Parsing options
williamr@4
   211
	@leave - One of the system wide error codes or one of the Xml specific
williamr@4
   212
	ones defined in XmlFrameworkErrors.h
williamr@4
   213
    */
williamr@4
   214
	IMPORT_C virtual void DeserializeL( const TDesC& aFileName,
williamr@4
   215
										const TXmlEngParsingOptions& aOptions = 
williamr@4
   216
											TXmlEngParsingOptions()); 
williamr@4
   217
williamr@4
   218
    /**
williamr@4
   219
	Deserializes the given file.  Any filename previously set with
williamr@4
   220
	SetInputFileL() is ignored.  
williamr@4
   221
williamr@4
   222
	The result of deserialization is passed to the content handler as SAX
williamr@4
   223
	events.
williamr@4
   224
williamr@4
   225
    @param aRFs File Server session
williamr@4
   226
	@param aFileName The file to be parsed
williamr@4
   227
	@param aOptions Parsing options
williamr@4
   228
	@leave - One of the system wide error codes or one of the Xml specific
williamr@4
   229
	ones defined in XmlFrameworkErrors.h
williamr@4
   230
    */
williamr@4
   231
	IMPORT_C virtual void DeserializeL( RFs& aRFs, 
williamr@4
   232
										const TDesC& aFileName,
williamr@4
   233
										const TXmlEngParsingOptions& aOptions = 
williamr@4
   234
											TXmlEngParsingOptions()); 
williamr@4
   235
	
williamr@4
   236
    /**
williamr@4
   237
	Deserializes the given buffer.  Any buffer previously set with
williamr@4
   238
	SetInputBuffer() is ignored. 
williamr@4
   239
williamr@4
   240
	The result of deserialization is passed to the content handler as SAX
williamr@4
   241
	events.
williamr@4
   242
williamr@4
   243
    @param aBuffer The buffer to be parsed 
williamr@4
   244
	@param aOptions Parsing options
williamr@4
   245
	@leave - One of the system wide error codes or one of the Xml specific
williamr@4
   246
	ones defined in XmlFrameworkErrors.h
williamr@4
   247
    */
williamr@4
   248
    IMPORT_C virtual void DeserializeL( const TDesC8& aBuffer,
williamr@4
   249
    									const TXmlEngParsingOptions& aOptions = 
williamr@4
   250
											TXmlEngParsingOptions()); 
williamr@4
   251
williamr@4
   252
    /** Destructor */
williamr@4
   253
    virtual ~CXmlEngDeserializer();
williamr@4
   254
williamr@4
   255
    /**
williamr@4
   256
    Retrieves a pointer to the data container referenced by CID.
williamr@4
   257
	@param aCid The aCid corresponding to the data container required
williamr@4
   258
	@return The data container or NULL if no matching container is found
williamr@4
   259
    */
williamr@4
   260
	TXmlEngDataContainer* GetDataContainer(const TDesC8& aCid);
williamr@4
   261
williamr@4
   262
private:
williamr@4
   263
    /** Default constructor */
williamr@4
   264
    CXmlEngDeserializer( );
williamr@4
   265
  
williamr@4
   266
    /** 2nd phase constructor */
williamr@4
   267
	virtual void ConstructL( Xml::MContentHandler& aContentHandler );
williamr@4
   268
	
williamr@4
   269
private:
williamr@4
   270
	/** SAX Parser */
williamr@4
   271
	Xml::CParser* iParser;
williamr@4
   272
	
williamr@4
   273
	/** File to be parsed */
williamr@4
   274
	HBufC*	iInputFileName;	
williamr@4
   275
	
williamr@4
   276
	/** Buffer to be parsed */
williamr@4
   277
	TPtrC8 iBuffer;
williamr@4
   278
	
williamr@4
   279
	/** Deserialization format */
williamr@4
   280
	TXmlEngDeserializationSource iSerializationOutput;
williamr@4
   281
	
williamr@4
   282
	/** Array of external data */
williamr@4
   283
	RArray<TXmlEngDataContainer>* iDataList;
williamr@4
   284
williamr@4
   285
	/** Features */
williamr@4
   286
	TUint iFeatures;
williamr@4
   287
williamr@4
   288
	/** Parsing options */
williamr@4
   289
	TXmlEngParsingOptions iParsingOptions;
williamr@4
   290
	
williamr@4
   291
}; //class CXmlEngDeserializer
williamr@4
   292
williamr@4
   293
williamr@4
   294
williamr@4
   295
#endif /* XMLENGDESERIALIZER_H */
williamr@4
   296