xml/xmlparser/src/CXMLReader.cpp
branchRCL_3
changeset 33 604ca70b6235
parent 32 889504eac4fb
child 40 80a0ad972c63
equal deleted inserted replaced
32:889504eac4fb 33:604ca70b6235
     1 /*
       
     2 * Copyright (c) 2002 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 "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:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CXMLReader.h"
       
    22 
       
    23 
       
    24 /* Dictionar Public ID's */
       
    25 #define WML_1_1_PUBLIC_ID         4      
       
    26 #define WML_1_2_PUBLIC_ID         9     
       
    27 #define WML_1_3_PUBLIC_ID        10    
       
    28 #define XHTML_1_0_PUBLIC_ID      55    
       
    29 #define SYNCML_1_0_PUBLIC_ID  0xFD1
       
    30 #define WAP_PROV_1_0_PUBLIC_ID   11
       
    31 #define SI_1_0_PUBLIC_ID          5
       
    32 #define SL_1_0_PUBLIC_ID          6
       
    33 #define PUSH_PROV_1_0_PUBLIC_ID   1    
       
    34 extern "C" 
       
    35 { 
       
    36 	extern NW_WBXML_Dictionary_t NW_Wml_1_0_WBXMLDictionary;
       
    37 	extern NW_WBXML_Dictionary_t NW_Wml_1_1_WBXMLDictionary;
       
    38 	extern NW_WBXML_Dictionary_t NW_Wml_1_2_WBXMLDictionary;
       
    39 	extern NW_WBXML_Dictionary_t NW_Wml_1_3_WBXMLDictionary;
       
    40 	extern NW_WBXML_Dictionary_t NW_XHTML_WBXMLDictionary;
       
    41 	extern NW_WBXML_Dictionary_t NW_SyncML_1_0_WBXMLDictionary;
       
    42 	extern NW_WBXML_Dictionary_t NW_SL_WBXMLDictionary;
       
    43 //	extern NW_WBXML_Dictionary_t NW_wap_prov_doc_WBXMLDictionary;
       
    44 //	extern NW_WBXML_Dictionary_t SI_dictionary;
       
    45 //	extern NW_WBXML_Dictionary_t SL_dictionary;
       
    46 //	extern NW_WBXML_Dictionary_t push_nokprov_dictionary;
       
    47 }
       
    48 #define DICTIONARY_COUNT 7
       
    49 
       
    50 
       
    51 // ============================= LOCAL FUNCTIONS ===============================
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // BeginElementCB
       
    55 // BeginElement callback, stores elemntname in elemntlist
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 NW_Status_t BeginElementCB(NW_XML_Reader_t* aReader, 
       
    59 						 const NW_XML_Reader_Interval_t* aName, 
       
    60 						 void* aParser)
       
    61 {
       
    62 	CXMLObserver *wObserver = (CXMLObserver*)aParser;
       
    63 	TPtrC wElementName( (TUint16*)aReader->pBuf + aName->charStart, aName->charStop - aName->charStart );
       
    64 	TRAPD(error, wObserver->SetElementL(wElementName));
       
    65 	if(error)
       
    66 	{
       
    67 		(wObserver->GetAttributes())->Reset();
       
    68 		return NW_STAT_FAILURE;
       
    69 	}
       
    70 	// New element, reset attributes list
       
    71 	(wObserver->GetAttributes())->Reset();
       
    72 	return NW_STAT_SUCCESS;
       
    73 }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // EndElementCB. calls MXMLContentHandler::EndElement with elemntname, 
       
    77 // removes closed element from elemntlist. 
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 NW_Status_t EndElementCB(NW_XML_Reader_t* aReader, 
       
    81 					     const NW_XML_Reader_Interval_t* aName, 
       
    82 					     NW_Uint32 /*aEmpFlag*/,
       
    83 					     void* aParser)
       
    84 {
       
    85 	_LIT(KEmpty,"");
       
    86 	TPtrC wEmpty(KEmpty);
       
    87 	CXMLObserver* wObserver = (CXMLObserver*)aParser;
       
    88 	wObserver->RemoveElement();
       
    89 	MXMLContentHandler* aContentHandler = wObserver->GetContentHandler();
       
    90 	TPtrC aElementName( (TUint16*)aReader->pBuf + aName->charStart, aName->charStop - aName->charStart );
       
    91 	TInt result = aContentHandler->EndElement(wEmpty, wEmpty, aElementName);
       
    92 	aContentHandler->ReaderIndex( aReader->charIndex );
       
    93 	return  result ? NW_STAT_SUCCESS:NW_STAT_FAILURE;		
       
    94 }
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // AttributesStartCB 
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 NW_Status_t AttributeStartCB (NW_XML_Reader_t*,
       
   101                                const NW_XML_Reader_Interval_t* /*pI_name*/,
       
   102                                 void*)
       
   103 {
       
   104 	return NW_STAT_SUCCESS;	
       
   105 }
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // AttreibuteValueCB Adds new attribute to attributes list.
       
   109 // Adds URI to URI list if namespaces is used
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 NW_Status_t AttributeValueCB(NW_XML_Reader_t* aReader, 
       
   113 						   const NW_XML_Reader_Interval_t* aName,
       
   114                            const NW_XML_Reader_Interval_t* aValue,
       
   115                            void* aParser)
       
   116 {
       
   117 	_LIT(KNamespace,"xmlns:");
       
   118 	TPtrC wNamespace(KNamespace);
       
   119 	CXMLObserver* wObserver = (CXMLObserver*)aParser;
       
   120 	CXMLAttributes* wAttr = wObserver->GetAttributes();
       
   121 	
       
   122 	// Append new attribute to attributes list
       
   123 	TPtrC wAttributeName( (TUint16*)aReader->pBuf + aName->charStart, aName->charStop - aName->charStart );
       
   124 	TPtrC wAttributeValue( (TUint16*)aReader->pBuf + aValue->charStart, aValue->charStop - aValue->charStart );
       
   125 	TRAPD(error,wAttr->AppendL(wAttributeName, wAttributeValue));
       
   126 	if(error)
       
   127 	{
       
   128 		return NW_STAT_FAILURE;
       
   129 	}
       
   130 	// namespace declaration, store URI and extension
       
   131 	if(wAttributeName.Left(6).Match(wNamespace)!=KErrNotFound)
       
   132 	{
       
   133 		TPtrC wExtension = wAttributeName.Right(wAttributeName.Length()-6);
       
   134 		TRAP(error, wObserver->SetURIL(wAttributeValue, wExtension));
       
   135 		if(error)
       
   136 		{
       
   137 			return NW_STAT_FAILURE;
       
   138 		}
       
   139 	}
       
   140 	return NW_STAT_SUCCESS;		
       
   141 }
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // AttributesEndCB Calls MXMLContentHandler::StartElement with element name and
       
   145 // attributes list.
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 NW_Status_t AttributesEndCB(NW_XML_Reader_t* /*aReader*/, 
       
   149 						    NW_Uint32 /*aLength*/, 
       
   150 						    void* aParser)
       
   151 {
       
   152 	_LIT(KLocalName,"");
       
   153 	TPtrC wLocalName(KLocalName);
       
   154 	_LIT(KURI,"");
       
   155 	TPtrC wURI(KURI);
       
   156 	CXMLObserver* wObserver = (CXMLObserver*)aParser;
       
   157 	MXMLContentHandler* wContentHandler = wObserver->GetContentHandler();
       
   158 				
       
   159 	TPtrC wElementName = wObserver->GetElement();
       
   160 	CXMLAttributes* wAttributes = wObserver->GetAttributes();
       
   161 		
       
   162 	// if using namespace, get URI and localname
       
   163 	TInt wIndex = wElementName.Locate(':');
       
   164 	if(wIndex > 0)
       
   165 	{
       
   166 		wLocalName.Set(wElementName.Right(wElementName.Length()-wIndex-1));
       
   167 		TPtrC temp = wElementName.Left(wIndex);
       
   168 		wURI.Set(wObserver->GetURI(temp));
       
   169 	}
       
   170 	// Call StartElement, now that we have all the attributes
       
   171 	return wContentHandler->StartElement(wURI, wLocalName, wElementName, wAttributes) ? NW_STAT_SUCCESS:NW_STAT_FAILURE;	
       
   172 }
       
   173 
       
   174 // -----------------------------------------------------------------------------
       
   175 // CDataCB Reports actual CData as MXMLContentHandler::Characters (between 
       
   176 // MXMLContentHandler::StartCData and MXMLContentHandler::EndCData
       
   177 // -----------------------------------------------------------------------------
       
   178 //
       
   179 NW_Status_t CdataCB (NW_XML_Reader_t* aReader,
       
   180                      const NW_XML_Reader_Interval_t* aName,
       
   181                      void* aParser)
       
   182 {	
       
   183     CXMLObserver* wObserver = (CXMLObserver*)aParser;
       
   184 	MXMLContentHandler* aContentHandler = wObserver->GetContentHandler();
       
   185 	TPtrC wChar( (TUint16*)aReader->pBuf + aName->charStart, aName->charStop - aName->charStart );
       
   186 	
       
   187 	aContentHandler->StartCDATA();
       
   188 	aContentHandler->Charecters( wChar, aName->charStart, (aName->charStop - aName->charStart) ); 
       
   189 	return aContentHandler->EndCDATA()? NW_STAT_SUCCESS:NW_STAT_FAILURE;
       
   190 }
       
   191 
       
   192 // -----------------------------------------------------------------------------
       
   193 // ContentCB Content reported as MXMLContentHandler::Characters
       
   194 // -----------------------------------------------------------------------------
       
   195 //
       
   196 NW_Status_t ContentCB (NW_XML_Reader_t* aReader,
       
   197                              const NW_XML_Reader_Interval_t* aValue,
       
   198                              void* aParser)
       
   199 {
       
   200 
       
   201 	CXMLObserver* wObserver = (CXMLObserver*)aParser;
       
   202 	TPtrC wChar( (TUint16*)aReader->pBuf + aValue->charStart, aValue->charStop - aValue->charStart );
       
   203 	
       
   204 	MXMLContentHandler* aContentHandler = wObserver->GetContentHandler();
       
   205 	
       
   206 	return (aContentHandler->Charecters(wChar, aValue->charStart, (aValue->charStop - aValue->charStart)))?NW_STAT_SUCCESS:NW_STAT_FAILURE;
       
   207 }
       
   208 
       
   209 
       
   210 // -----------------------------------------------------------------------------
       
   211 // AttrEntityVarValCB Adds new attribute to attributes list.
       
   212 // Adds URI to URI list if namespaces is used
       
   213 // -----------------------------------------------------------------------------
       
   214 //
       
   215 NW_Status_t AttrEntityVarValCB (NW_XML_Reader_t* aReader,
       
   216 									const NW_XML_Reader_Interval_t* aName,
       
   217                                     NW_Uint8* aValue,
       
   218                                     NW_Uint32 aValueByteLength,
       
   219                                     void* aParser)
       
   220   {
       
   221         _LIT(KNamespace, "xmlns:");
       
   222         TPtrC wNamespace(KNamespace);
       
   223         CXMLObserver* wObserver = (CXMLObserver*)aParser;
       
   224         CXMLAttributes* wAttr = wObserver->GetAttributes();
       
   225 
       
   226         // Append new attribute to attributes list
       
   227         TPtrC wAttributeName( (TUint16*)aReader->pBuf + aName->charStart, aName->charStop - aName->charStart );
       
   228         TPtrC wAttributeValue( (TUint16*)aValue, aValueByteLength/2 );
       
   229 
       
   230         TRAPD(error,wAttr->AppendL(wAttributeName, wAttributeValue));
       
   231         if(error)
       
   232         {
       
   233                 return NW_STAT_FAILURE;
       
   234         }
       
   235 
       
   236         // namespace declaration, store URI and extension
       
   237         if(wAttributeName.Left(6).Match(wNamespace)!=KErrNotFound)
       
   238         {
       
   239                 TPtrC wExtension = wAttributeName.Right(wAttributeName.Length()-6);
       
   240                 TRAP(error, wObserver->SetURIL(wAttributeValue, wExtension));
       
   241                 if(error)
       
   242                 {
       
   243                         return NW_STAT_FAILURE;
       
   244                 }
       
   245         }
       
   246 	return NW_STAT_SUCCESS;
       
   247   }
       
   248 
       
   249 
       
   250 // -----------------------------------------------------------------------------
       
   251 // EntityCB Entity reported as MXMLContentHandler::StartEntity
       
   252 // -----------------------------------------------------------------------------
       
   253 //
       
   254 NW_Status_t EntityCB (NW_XML_Reader_t* aReader,
       
   255                              NW_Uint32 aNumEntity,
       
   256                              void* aParser, 
       
   257                              CXML_Uint8* aIntEntityValStr) 
       
   258 {
       
   259 
       
   260 	CXMLObserver *wObserver = (CXMLObserver*)aParser;
       
   261 
       
   262 	NW_String_t *tempString = NW_String_new();
       
   263 	// handle OOM
       
   264 	if(tempString == NULL)
       
   265 	{
       
   266 		return NW_STAT_FAILURE;
       
   267 	}
       
   268 
       
   269     if(aIntEntityValStr == NULL) 
       
   270     { 
       
   271      //It is character/predefined entities 
       
   272 	NW_String_entityToString(aNumEntity, tempString, aReader->encoding);
       
   273     } 
       
   274 	
       
   275     if(aIntEntityValStr != NULL) 
       
   276 	{
       
   277      //It is the internal entity 
       
   278       tempString->storage = aIntEntityValStr; 
       
   279 	}
       
   280 
       
   281     TPtrC wTmpEntityPtr((TUint16*)tempString->storage); 
       
   282         TInt result(wObserver->GetContentHandler()->StartEntity(wTmpEntityPtr)); 
       
   283 	
       
   284 	if (result == 0) 
       
   285 	{
       
   286 		NW_String_delete(tempString);
       
   287 		return NW_STAT_FAILURE;
       
   288 	}
       
   289         result = wObserver->GetContentHandler()->EndEntity(wTmpEntityPtr); 
       
   290 		NW_String_delete(tempString);
       
   291 
       
   292 	return (result?NW_STAT_SUCCESS:NW_STAT_FAILURE);
       
   293 	
       
   294 }
       
   295 
       
   296 // -----------------------------------------------------------------------------
       
   297 // CommentCB 
       
   298 // -----------------------------------------------------------------------------
       
   299 //
       
   300 NW_Status_t CommentCB (NW_XML_Reader_t* aReader,
       
   301                        const NW_XML_Reader_Interval_t* aName,
       
   302                        void* aParser )
       
   303 {
       
   304 	CXMLObserver* wObserver = (CXMLObserver*)aParser;
       
   305 	TPtrC wComment( (TUint16*)aReader->pBuf + aName->charStart, aName->charStop - aName->charStart );
       
   306 	return (wObserver->GetContentHandler())->Comment(wComment)?NW_STAT_SUCCESS:NW_STAT_FAILURE;		
       
   307 }
       
   308 
       
   309 // -----------------------------------------------------------------------------
       
   310 // StartDocumentCB 
       
   311 // -----------------------------------------------------------------------------
       
   312 //
       
   313 NW_Status_t StartDocumentCB (NW_XML_Reader_t* /*aReader*/,
       
   314                              void* aParser )
       
   315 
       
   316 {
       
   317 	CXMLObserver* wObserver = (CXMLObserver*)aParser;
       
   318 	return (wObserver->GetContentHandler())->StartDocument()?NW_STAT_SUCCESS:NW_STAT_FAILURE;		
       
   319 
       
   320 }
       
   321 
       
   322 // -----------------------------------------------------------------------------
       
   323 // EndDocumentCB 
       
   324 // -----------------------------------------------------------------------------
       
   325 //
       
   326 NW_Status_t EndDocumentCB (NW_XML_Reader_t* /*aReader*/,
       
   327                            void* aParser) 
       
   328 {
       
   329 	CXMLObserver* wObserver = (CXMLObserver*)aParser;
       
   330 	return (wObserver->GetContentHandler())->EndDocument()?NW_STAT_SUCCESS:NW_STAT_FAILURE;		
       
   331 }
       
   332 
       
   333 // -----------------------------------------------------------------------------
       
   334 // PiCB Report Processing Instruction with MXMLProcessingInstruction(Target, Data)
       
   335 // -----------------------------------------------------------------------------
       
   336 //
       
   337 NW_Status_t PiCB (NW_XML_Reader_t* aReader,
       
   338                   NW_PiFormTypeTag_t aTag,
       
   339                   const NW_XML_Reader_Interval_t* aName,
       
   340                   const NW_XML_Reader_Interval_t* aVersion,
       
   341                   const NW_XML_Reader_Interval_t* /*aEncoding*/,
       
   342                   const NW_XML_Reader_Interval_t* /*aStandalone*/,
       
   343                   const NW_XML_Reader_Interval_t* aContent,
       
   344                   void* aParser)
       
   345 {
       
   346 	CXMLObserver* wObserver = (CXMLObserver*)aParser;
       
   347 	TPtrC aTarget( (TUint16*)aReader->pBuf + aName->charStart, aName->charStop - aName->charStart );
       
   348 	if(aTag==XMLDECL)
       
   349 	{
       
   350 		TPtrC aData( (TUint16*)aReader->pBuf + aVersion->charStart, aVersion->charStop - aVersion->charStart );
       
   351 		return (wObserver->GetContentHandler())->ProcessingInstructions(aTarget, aData)?NW_STAT_SUCCESS:NW_STAT_FAILURE;	
       
   352 	}
       
   353 	else
       
   354 	{
       
   355 		TPtrC aData( (TUint16*)aReader->pBuf + aContent->charStart, aContent->charStop - aContent->charStart );
       
   356 		return (wObserver->GetContentHandler())->ProcessingInstructions(aTarget, aData)?NW_STAT_SUCCESS:NW_STAT_FAILURE;
       
   357 	}
       
   358 }
       
   359 
       
   360 
       
   361 // Binary Call backs
       
   362 
       
   363 // -----------------------------------------------------------------------------
       
   364 // Binary_StartDocument_CB 
       
   365 // -----------------------------------------------------------------------------
       
   366 //
       
   367 NW_Status_t Binary_StartDocument_CB (NW_WBXML_Parser_t* /*aParser*/, 
       
   368                                    NW_WBXML_Document_t* /*aDocument*/, 
       
   369                                    void * aContext)
       
   370 {
       
   371 	CXMLObserver* wObserver = (CXMLObserver*)aContext;
       
   372 	return (wObserver->GetBinaryContentHandler())->StartDocument()?NW_STAT_SUCCESS:NW_STAT_FAILURE;		
       
   373 }
       
   374 
       
   375 // -----------------------------------------------------------------------------
       
   376 // Binary_EndDocument_CB 
       
   377 // -----------------------------------------------------------------------------
       
   378 // 
       
   379 NW_Status_t Binary_EndDocument_CB(NW_WBXML_Parser_t* /*aParser*/, 
       
   380                                  void * aContext)
       
   381 {
       
   382 	CXMLObserver* wObserver = (CXMLObserver*)aContext;
       
   383 	return (wObserver->GetBinaryContentHandler())->EndDocument()?NW_STAT_SUCCESS:NW_STAT_FAILURE;
       
   384 }
       
   385 
       
   386 // -----------------------------------------------------------------------------
       
   387 // Binary_Pi_CB ?description.
       
   388 // -----------------------------------------------------------------------------
       
   389 //
       
   390 NW_Status_t Binary_Pi_CB (NW_WBXML_Parser_t* /*aParser*/, 
       
   391                         void * aContext)
       
   392 {
       
   393 	CXMLObserver* wObserver = (CXMLObserver*)aContext;
       
   394 	return (wObserver->GetBinaryContentHandler())->ProcessingInstruction()?NW_STAT_SUCCESS:NW_STAT_FAILURE;
       
   395 }
       
   396 
       
   397 // -----------------------------------------------------------------------------
       
   398 // Binary_Pi_End_CB 
       
   399 // -----------------------------------------------------------------------------
       
   400 //
       
   401 NW_Status_t Binary_Pi_End_CB (NW_WBXML_Parser_t* /*aParser*/, 
       
   402                             void* aContext)
       
   403 {
       
   404 	CXMLObserver *wObserver = (CXMLObserver*)aContext;
       
   405 	return (wObserver->GetBinaryContentHandler())->ProcessingInstructionEnd()?NW_STAT_SUCCESS:NW_STAT_FAILURE;
       
   406 }
       
   407 
       
   408 // -----------------------------------------------------------------------------
       
   409 // Binary_Tag_Start_CB 
       
   410 // -----------------------------------------------------------------------------
       
   411 //
       
   412 NW_Status_t Binary_Tag_Start_CB(NW_WBXML_Parser_t* /*aParser*/, 
       
   413                                void *aContext)
       
   414 {
       
   415 	
       
   416 	CXMLObserver *wObserver = (CXMLObserver*)aContext;
       
   417 	return (wObserver->GetBinaryContentHandler())->TagStart()?NW_STAT_SUCCESS:NW_STAT_FAILURE;
       
   418 }
       
   419 
       
   420 // -----------------------------------------------------------------------------
       
   421 // Binary_Tag_End_CB ?description.
       
   422 // -----------------------------------------------------------------------------
       
   423 //
       
   424 NW_Status_t Binary_Tag_End_CB(NW_WBXML_Parser_t* /*aParser*/, 
       
   425                              void *aContext)
       
   426 {
       
   427 	CXMLObserver *wObserver = (CXMLObserver*)aContext;	
       
   428 	return (wObserver->GetBinaryContentHandler())->TagEnd()?NW_STAT_SUCCESS:NW_STAT_FAILURE;
       
   429 }
       
   430 
       
   431 // -----------------------------------------------------------------------------
       
   432 // Binary_Attr_Start_CB 
       
   433 // -----------------------------------------------------------------------------
       
   434 //
       
   435 NW_Status_t Binary_Attr_Start_CB(NW_WBXML_Parser_t* /*aParser*/, 
       
   436                                 void *aContext)
       
   437 {
       
   438 	CXMLObserver *wObserver = (CXMLObserver*)aContext;
       
   439 	return (wObserver->GetBinaryContentHandler())->AttributeStart()?NW_STAT_SUCCESS:NW_STAT_FAILURE;
       
   440 }
       
   441 
       
   442 // -----------------------------------------------------------------------------
       
   443 // Binary_Attr_Val_CB 
       
   444 // -----------------------------------------------------------------------------
       
   445 //
       
   446 NW_Status_t Binary_Attr_Val_CB(NW_WBXML_Parser_t* /*aParser*/, 
       
   447                               void *aContext)
       
   448 {
       
   449 	CXMLObserver *wObserver = (CXMLObserver*)aContext;
       
   450 	return (wObserver->GetBinaryContentHandler())->AttributeValue()?NW_STAT_SUCCESS:NW_STAT_FAILURE;
       
   451 }
       
   452 
       
   453 // -----------------------------------------------------------------------------
       
   454 // Binary_Content_CB 
       
   455 // -----------------------------------------------------------------------------
       
   456 //
       
   457 NW_Status_t Binary_Content_CB(NW_WBXML_Parser_t* /*aParser*/, 
       
   458                              void *aContext)
       
   459 {
       
   460 	CXMLObserver *wObserver = (CXMLObserver*)aContext;
       
   461 	return (wObserver->GetBinaryContentHandler())->Content()?NW_STAT_SUCCESS:NW_STAT_FAILURE;
       
   462 }
       
   463 
       
   464 // -----------------------------------------------------------------------------
       
   465 // Binary_CodePage_CB 
       
   466 // -----------------------------------------------------------------------------
       
   467 //
       
   468 NW_Status_t Binary_CodePage_CB(NW_WBXML_Parser_t* /*aParser*/, 
       
   469                               void* aContext)
       
   470 {
       
   471 	// Code page switch in WBXML doc
       
   472 	CXMLObserver *wObserver = (CXMLObserver*)aContext;
       
   473 	return (wObserver->GetBinaryContentHandler())->CodePageSwitch()?NW_STAT_SUCCESS:NW_STAT_FAILURE;
       
   474 }
       
   475 
       
   476 // -----------------------------------------------------------------------------
       
   477 // Binary_Extension_CB 
       
   478 // -----------------------------------------------------------------------------
       
   479 //
       
   480 NW_Status_t Binary_Extension_CB(NW_WBXML_Parser_t* /*aParser*/, 
       
   481                                void* aContext)
       
   482 {
       
   483 	CXMLObserver *wObserver = (CXMLObserver*)aContext;
       
   484 	return (wObserver->GetBinaryContentHandler())->Extension()?NW_STAT_SUCCESS:NW_STAT_FAILURE;
       
   485 }
       
   486 
       
   487 // -----------------------------------------------------------------------------
       
   488 // Binary_Token_CB 
       
   489 // -----------------------------------------------------------------------------
       
   490 //  
       
   491 NW_Status_t Binary_Token_CB(NW_WBXML_Parser_t* /*aParser*/, 
       
   492                            NW_Uint8 aToken, 
       
   493                            void *aContext)
       
   494 {
       
   495 	CXMLObserver *wObserver = (CXMLObserver*)aContext;
       
   496 	NW_String_UCS2Buff_t *wTemp = NW_WBXML_Dictionary_getTagByFqToken (aToken);
       
   497 	TPtrC wString((TUint16*)wTemp);
       
   498 	return (wObserver->GetBinaryContentHandler())->Token(aToken, wString)?NW_STAT_SUCCESS:NW_STAT_FAILURE;
       
   499 }
       
   500 
       
   501 // -----------------------------------------------------------------------------
       
   502 // Binary_FQToken_CB 
       
   503 // -----------------------------------------------------------------------------
       
   504 //
       
   505 NW_Status_t Binary_FQToken_CB(NW_WBXML_Parser_t* /*aParser*/, 
       
   506                             NW_Uint32 aFQToken, 
       
   507                             void *aContext)
       
   508 {
       
   509 	CXMLObserver *wObserver = (CXMLObserver*)aContext;
       
   510 	NW_Byte aToken = (NW_Byte) (aFQToken & NW_WBXML_MASK_TOKEN);
       
   511 	if( (aToken & NW_WBXML_MASK_TAG_ID) != NW_WBXML_LITERAL)
       
   512 	{
       
   513 		NW_String_UCS2Buff_t *wTemp = NW_WBXML_Dictionary_getTagByFqToken(aFQToken); 
       
   514 		if(wTemp)
       
   515 		{
       
   516 			TPtrC wString((TUint16*)wTemp);
       
   517 			return (wObserver->GetBinaryContentHandler())->Token(aToken, wString)?NW_STAT_SUCCESS:NW_STAT_FAILURE;
       
   518 		}
       
   519 		return NW_STAT_FAILURE;
       
   520 	}
       
   521 	return NW_STAT_SUCCESS;
       
   522 }
       
   523 
       
   524 // -----------------------------------------------------------------------------
       
   525 // Binary_InlineString_CB 
       
   526 // -----------------------------------------------------------------------------
       
   527 //
       
   528 NW_Status_t Binary_InlineString_CB(NW_WBXML_Parser_t *aParser, 
       
   529                                   NW_Uint32 /*aIndex*/, 
       
   530                                   void *aContext)
       
   531 {
       
   532 	CXMLObserver *wObserver = (CXMLObserver*)aContext;
       
   533 	NW_String_t *tempString = NW_String_new();
       
   534 	// handle OOM
       
   535 	if(tempString == NULL)
       
   536 	{
       
   537 		return NW_STAT_FAILURE;
       
   538 	}
       
   539 	NW_WBXML_Document_t *doc = aParser->doc;
       
   540 
       
   541 	NW_WBXML_Parser_getStringInline(aParser, doc, tempString);
       
   542 
       
   543 	/**!
       
   544 	* This was changed because of MNUI-68TAZP - German umlauts were displayed wrong.
       
   545 	* This was caused by NW_String_byteToUCS2Char() function - this is not recognize utf-8 encoding and treats 
       
   546 	* all characters as a 1byte ASCII. In case of character encoded on more than 1 byte
       
   547 	* we get two or more separate symbols instead of one compound of these bytes.
       
   548 	* The CnvUtfConverter::ConvertToUnicodeFromUtf8() recognizes utf-8 properly.
       
   549 
       
   550 	NW_Ucs2 *ucs2;
       
   551     NW_String_byteToUCS2Char(tempString->storage, ((*tempString).length) & ~0x80000000, &ucs2); //VC, AM
       
   552 	// handle OOM
       
   553 	if(ucs2 == NULL)
       
   554 	{
       
   555 		NW_String_delete(tempString);
       
   556 		return NW_STAT_FAILURE;
       
   557 	}
       
   558 	TPtrC wString((TUint16*)ucs2);
       
   559 	NW_String_delete(tempString);
       
   560 	*/
       
   561 
       
   562 	TPtrC8 string8(tempString->storage);
       
   563 	HBufC *string16=NULL;
       
   564 	TRAPD(err, string16 = HBufC::NewL(string8.Length()));
       
   565 	if(err)
       
   566 	{
       
   567 		NW_String_delete(tempString);
       
   568 		return NW_STAT_FAILURE;
       
   569 	}
       
   570 	TPtr wString(string16->Des());
       
   571 
       
   572 #if defined(_UNICODE)
       
   573 	err = CnvUtfConverter::ConvertToUnicodeFromUtf8(wString,string8);
       
   574 	if(err != KErrNone)
       
   575 	{
       
   576 		NW_String_delete(tempString);
       
   577 		delete string16;
       
   578 		return NW_STAT_FAILURE;
       
   579 	}
       
   580 #else
       
   581 	wString.Copy(string8);
       
   582 #endif
       
   583 	
       
   584 	TInt result((wObserver->GetBinaryContentHandler())->InlineString(wString));
       
   585 
       
   586 	NW_String_delete(tempString);
       
   587 	delete string16;
       
   588 
       
   589 	return (result?NW_STAT_SUCCESS:NW_STAT_FAILURE);
       
   590 }
       
   591 
       
   592 // -----------------------------------------------------------------------------
       
   593 // Binary_TableString_CB
       
   594 // -----------------------------------------------------------------------------
       
   595 //
       
   596 NW_Status_t Binary_TableString_CB(NW_WBXML_Parser_t *aParser, 
       
   597                                  NW_Uint32 aIndex, 
       
   598                                  void *aContext)
       
   599 {
       
   600 	CXMLObserver *wObserver = (CXMLObserver*)aContext;
       
   601 	NW_String_t *tempString = NW_String_new();
       
   602 	// handle OOM
       
   603 	if(tempString == NULL)
       
   604 	{
       
   605 		return NW_STAT_FAILURE;
       
   606 	}
       
   607 	NW_WBXML_Document_t *doc = aParser->doc;
       
   608 	NW_WBXML_Document_getTableString(doc, aIndex, tempString);
       
   609 	/**!
       
   610 	* This was changed because of MNUI-68TAZP - German umlauts were displayed wrong.
       
   611 	* This was caused by NW_String_byteToUCS2Char() function - this is not recognize utf-8 encoding and treats 
       
   612 	* all characters as a 1byte ASCII. In case of character encoded on more than 1 byte
       
   613 	* we get two or more separate symbols instead of one compound of these bytes.
       
   614 	* The CnvUtfConverter::ConvertToUnicodeFromUtf8() recognizes utf-8 properly.
       
   615 
       
   616 	NW_Ucs2 *ucs2;
       
   617     NW_String_byteToUCS2Char(tempString->storage, ((*tempString).length) & ~0x80000000, &ucs2); //VC, AM
       
   618 	// handle OOM
       
   619 	if(ucs2 == NULL)
       
   620 	{
       
   621 		NW_String_delete(tempString);
       
   622 		return NW_STAT_FAILURE;
       
   623 	}
       
   624 	TPtrC wString((TUint16*)ucs2);
       
   625 	NW_String_delete(tempString);
       
   626 	*/
       
   627 
       
   628 	TPtrC8 string8(tempString->storage);
       
   629 	HBufC *string16=NULL;
       
   630 	TRAPD(err, string16 = HBufC::NewL(string8.Length()));
       
   631 	if(err)
       
   632 	{
       
   633 		NW_String_delete(tempString);
       
   634 		return NW_STAT_FAILURE;
       
   635 	}
       
   636 
       
   637 	TPtr wString(string16->Des());
       
   638 
       
   639 #if defined(_UNICODE)
       
   640 	err = CnvUtfConverter::ConvertToUnicodeFromUtf8(wString,string8);
       
   641 	if(err != KErrNone)
       
   642 	{
       
   643 		NW_String_delete(tempString);
       
   644 		delete string16;
       
   645 		return NW_STAT_FAILURE;
       
   646 	}
       
   647 #else
       
   648 	wString.Copy(string8);
       
   649 #endif
       
   650 	
       
   651 	TInt result((wObserver->GetBinaryContentHandler())->TableString(wString));
       
   652 
       
   653 	NW_String_delete(tempString);
       
   654 	delete string16;
       
   655 
       
   656 	return (result?NW_STAT_SUCCESS:NW_STAT_FAILURE);
       
   657 }
       
   658 
       
   659 // -----------------------------------------------------------------------------
       
   660 // Binary_Binary_CB 
       
   661 // -----------------------------------------------------------------------------
       
   662 //
       
   663 NW_Status_t Binary_Binary_CB(NW_WBXML_Parser_t* /*aParser*/, 
       
   664                             NW_Uint32 aIndex, 
       
   665                             void* aContext)
       
   666 {
       
   667 	CXMLObserver *wObserver = (CXMLObserver*)aContext;
       
   668 	return (wObserver->GetBinaryContentHandler())->Binary(aIndex)?NW_STAT_SUCCESS:NW_STAT_FAILURE; 
       
   669 }
       
   670 
       
   671 // -----------------------------------------------------------------------------
       
   672 // Binary_Opaque_CB 
       
   673 // -----------------------------------------------------------------------------
       
   674 //
       
   675 NW_Status_t Binary_Opaque_CB(NW_WBXML_Parser_t *aParser, 
       
   676                             NW_Uint32 aLength, 
       
   677                             void * aContext)
       
   678 {
       
   679 	CXMLObserver *wObserver = (CXMLObserver*)aContext;
       
   680 	TPtrC wString((TUint16*)aParser->p, aLength);
       
   681 	return (wObserver->GetBinaryContentHandler())->Opaque(aLength, wString)?NW_STAT_SUCCESS:NW_STAT_FAILURE;
       
   682 }
       
   683 
       
   684 // -----------------------------------------------------------------------------
       
   685 // Binary_Entity_CB 
       
   686 // -----------------------------------------------------------------------------
       
   687 //
       
   688 NW_Status_t Binary_Entity_CB(NW_WBXML_Parser_t *aParser, 
       
   689                             NW_Uint32 aIndex, 
       
   690                             void* aContext)
       
   691 {
       
   692 	NW_String_t *tempString = NW_String_new();
       
   693 	// handle OOM
       
   694 	if(tempString == NULL)
       
   695 	{
       
   696 		return NW_STAT_FAILURE;
       
   697 	}
       
   698 	NW_String_entityToString(aIndex, tempString, aParser->doc->charset);
       
   699 	NW_Ucs2 *ucs2;
       
   700     NW_String_byteToUCS2Char(tempString->storage, tempString->length, &ucs2);
       
   701 	// handle OOM
       
   702 	if(ucs2 == NULL)
       
   703 	{
       
   704 		NW_String_delete(tempString);
       
   705 		return NW_STAT_FAILURE;
       
   706 	}
       
   707 	TPtrC wString((TUint16*)ucs2);
       
   708 	NW_String_delete(tempString);
       
   709 	
       
   710 	CXMLObserver *wObserver = (CXMLObserver*)aContext;
       
   711 	TInt result((wObserver->GetBinaryContentHandler())->Entity(aIndex, wString));
       
   712 	delete (void*)wString.Ptr();
       
   713 	
       
   714 	return (result?NW_STAT_SUCCESS:NW_STAT_FAILURE);
       
   715 }
       
   716   
       
   717 // -----------------------------------------------------------------------------
       
   718 // Binary_Exception_CB For parse errors
       
   719 // -----------------------------------------------------------------------------
       
   720 //  
       
   721 NW_Status_t Binary_Exception_CB(NW_WBXML_Parser_t* /*aParser*/, 
       
   722                                NW_WBXML_Exception_t /*aException*/, 
       
   723                                void* aContext)
       
   724 {
       
   725 
       
   726 	CXMLObserver *wObserver = (CXMLObserver*)aContext;
       
   727 	return (wObserver->GetBinaryContentHandler())->Exception()?NW_STAT_SUCCESS:NW_STAT_FAILURE;
       
   728 }
       
   729 
       
   730 
       
   731 
       
   732 
       
   733 // ============================ MEMBER FUNCTIONS ===============================
       
   734 
       
   735 
       
   736 // -----------------------------------------------------------------------------
       
   737 // CXMLReader::CXMLReader
       
   738 // C++ default constructor can NOT contain any code, that
       
   739 // might leave.
       
   740 // -----------------------------------------------------------------------------
       
   741 //
       
   742 CXMLReader::CXMLReader() 
       
   743 {
       
   744 	
       
   745 }
       
   746 
       
   747 // -----------------------------------------------------------------------------
       
   748 // CXMLReader::ConstructL
       
   749 // Symbian 2nd phase constructor can leave.
       
   750 // -----------------------------------------------------------------------------
       
   751 //
       
   752 void CXMLReader::ConstructL()
       
   753 {
       
   754 	iParserObserver = CXMLObserver::NewL();
       
   755 	// Default parser = XML , not WBXML
       
   756 	iIsBinary = FALSE; 
       
   757 }
       
   758 
       
   759 // -----------------------------------------------------------------------------
       
   760 // ?classname::NewL
       
   761 // Two-phased constructor.
       
   762 // -----------------------------------------------------------------------------
       
   763 //
       
   764 CXMLReader* CXMLReader::NewL()
       
   765 {
       
   766 	CXMLReader* self = new( ELeave ) CXMLReader();
       
   767    
       
   768 	CleanupStack::PushL( self );
       
   769 	self->ConstructL();
       
   770 	CleanupStack::Pop();
       
   771 
       
   772 	return self;
       
   773 }
       
   774     
       
   775 // Destructor
       
   776 CXMLReader::~CXMLReader()
       
   777 {
       
   778 	if(iParserObserver)
       
   779 	{
       
   780 		delete iParserObserver;
       
   781 	}
       
   782 	
       
   783 }
       
   784 
       
   785 // -----------------------------------------------------------------------------
       
   786 // CXMLReader::SetFeature
       
   787 // (other items were commented in a header).
       
   788 // -----------------------------------------------------------------------------
       
   789 //
       
   790 TInt CXMLReader::SetFeature(TXMLFeature aFeature, TBool aStatus)
       
   791 {
       
   792 	TInt wReturn;
       
   793 	wReturn=0;
       
   794 
       
   795 	switch(aFeature)
       
   796 	{
       
   797 		case EXMLBinary:
       
   798 			iIsBinary = aStatus;
       
   799 			wReturn = KErrNone;
       
   800 		break;
       
   801 		case EXMLValidation:
       
   802 			wReturn = KErrNotSupported;
       
   803 		break;
       
   804 		default:
       
   805 			wReturn = KErrNotSupported;
       
   806 		break;
       
   807 	}
       
   808 	return wReturn;
       
   809 }
       
   810 
       
   811 // -----------------------------------------------------------------------------
       
   812 // CXMLReader::GetFeature
       
   813 // (other items were commented in a header).
       
   814 // -----------------------------------------------------------------------------
       
   815 //
       
   816 TInt CXMLReader::GetFeature(TXMLFeature aFeature, TBool &aStatus)
       
   817 {
       
   818 	TInt wReturn;
       
   819 	wReturn=0;
       
   820 
       
   821 	switch(aFeature)
       
   822 	{
       
   823 		case EXMLBinary:
       
   824 			aStatus = iIsBinary;
       
   825 			wReturn = KErrNone;
       
   826 		break;
       
   827 		case EXMLValidation:
       
   828 			aStatus = FALSE;
       
   829 			wReturn = KErrNotSupported;
       
   830 		break;
       
   831 		default:
       
   832 			wReturn = KErrNotSupported;
       
   833 		break;
       
   834 	}
       
   835 	return wReturn;
       
   836 }
       
   837 
       
   838 // -----------------------------------------------------------------------------
       
   839 // CXMLReader::SetContentHandler
       
   840 // (other items were commented in a header).
       
   841 // -----------------------------------------------------------------------------
       
   842 //
       
   843 TInt CXMLReader::SetContentHandler(MXMLContentHandler* aParserObserver)
       
   844 {
       
   845 	iParserObserver->SetContentHandler(aParserObserver);
       
   846 	return KErrNone;
       
   847 }
       
   848 
       
   849 // -----------------------------------------------------------------------------
       
   850 // CXMLReader::SetContentHandler
       
   851 // Set binary XML content handler
       
   852 // (other items were commented in a header).
       
   853 // -----------------------------------------------------------------------------
       
   854 //
       
   855 TInt CXMLReader::SetContentHandler(MWBXMLContentHandler* aParserObserver)
       
   856 {
       
   857 	iParserObserver->SetContentHandler(aParserObserver);
       
   858 	return KErrNone;
       
   859 }
       
   860 
       
   861 // -----------------------------------------------------------------------------
       
   862 // CXMLReader::Parse
       
   863 // Reades the input file, and calls ParseL(RFile&).
       
   864 // @ exception can Leave due to OOM
       
   865 // (other items were commented in a header).
       
   866 // -----------------------------------------------------------------------------
       
   867 //
       
   868 void CXMLReader::ParseL(RFs& aRFs, const TDesC& aFileToParse)
       
   869 {
       
   870 	RFile wXMLFile;
       
   871 		
       
   872 	//Open file
       
   873 	User::LeaveIfError(wXMLFile.Open(aRFs, aFileToParse, EFileRead | EFileShareReadersOnly));
       
   874 	CleanupClosePushL(wXMLFile);
       
   875 	ParseL(wXMLFile);
       
   876 	CleanupStack::PopAndDestroy(); // wXMLFile
       
   877 }
       
   878 
       
   879 // -----------------------------------------------------------------------------
       
   880 // CXMLReader::Parse
       
   881 // Reades the input from the opened file into buffer, and calls RunL.
       
   882 // @ exception can Leave due to OOM
       
   883 // (other items were commented in a header).
       
   884 // -----------------------------------------------------------------------------
       
   885 //
       
   886 void CXMLReader::ParseL(RFile& aOpenedFile)
       
   887 {
       
   888 	TInt wSize;
       
   889 	User::LeaveIfError(aOpenedFile.Size(wSize));
       
   890 		
       
   891 	HBufC8 * binaryBuffer = HBufC8::NewLC(wSize);
       
   892 	TPtr8 binaryBufferPtr = binaryBuffer->Des();
       
   893 	User::LeaveIfError(aOpenedFile.Read(binaryBufferPtr, wSize));
       
   894 
       
   895 	if(!iIsBinary)
       
   896 	{
       
   897 		TInt hichar = (CEditableText::EReversedByteOrderMark & 0xFF00)>>8;
       
   898 		TInt lochar = CEditableText::EReversedByteOrderMark & 0xFF;
       
   899 		TInt bytesPerChar = 1;
       
   900 		if(binaryBufferPtr.Ptr()[0] == hichar && binaryBufferPtr.Ptr()[1] == lochar)
       
   901 		{
       
   902 			bytesPerChar = 2;
       
   903 		}
       
   904 
       
   905 		HBufC * dataBuffer = HBufC::NewLC(wSize/bytesPerChar);
       
   906 		TPtr dataBufferPtr = dataBuffer->Des();
       
   907 		
       
   908 		if(bytesPerChar == 2)
       
   909 		{
       
   910 			dataBufferPtr.Set((TUint16*)binaryBufferPtr.Ptr()+1,
       
   911 							wSize/bytesPerChar-1, 
       
   912 							wSize/bytesPerChar-1);
       
   913 		}
       
   914 		else
       
   915 		{
       
   916 			CnvUtfConverter::ConvertToUnicodeFromUtf8(dataBufferPtr, binaryBuffer->Des());
       
   917 		}
       
   918 		User::LeaveIfError(ParseXML(dataBufferPtr));
       
   919 		CleanupStack::Pop(); // dataBuffer
       
   920 		CleanupStack::PopAndDestroy(); // binaryBuffer
       
   921 		delete dataBuffer;
       
   922 	}
       
   923 	else
       
   924 	{
       
   925 		User::LeaveIfError(ParseWBXML(binaryBufferPtr));
       
   926 		CleanupStack::PopAndDestroy(); // binaryBuffer
       
   927 	}
       
   928 }
       
   929 
       
   930 // -----------------------------------------------------------------------------
       
   931 // CXMLReader::ParseL
       
   932 // Copies aBuff into input buffer and calls RunL
       
   933 // @ exception can Leave due to OOM
       
   934 // (other items were commented in a header).
       
   935 // -----------------------------------------------------------------------------
       
   936 //
       
   937 void CXMLReader::ParseL(const TDesC8& aBuff) // change the allocations
       
   938 {
       
   939 	
       
   940 
       
   941 	if(!iIsBinary)
       
   942 	{
       
   943 		HBufC * dataBuffer = HBufC::NewLC(aBuff.Size());
       
   944 		TPtr dataBufferPtr = dataBuffer->Des();
       
   945 		CnvUtfConverter::ConvertToUnicodeFromUtf8(dataBufferPtr, aBuff);
       
   946 		User::LeaveIfError(ParseXML(dataBufferPtr));
       
   947 		CleanupStack::PopAndDestroy(); // dataBuffer
       
   948 	}
       
   949 	else
       
   950 	{
       
   951 		User::LeaveIfError(ParseWBXML(aBuff));
       
   952 	}
       
   953 }
       
   954 
       
   955 
       
   956 
       
   957 // -----------------------------------------------------------------------------
       
   958 // CXMLReader::ParseXML
       
   959 // 
       
   960 // (other items were commented in a header).
       
   961 // -----------------------------------------------------------------------------
       
   962 //
       
   963 TInt CXMLReader::ParseXML(const TDesC& aBuff)
       
   964 {
       
   965 	NW_Status_t status;
       
   966 	struct NW_XML_Parser_EventCallbacks_s cb;
       
   967 	struct NW_XML_Reader_s reader;
       
   968 
       
   969 	Mem::FillZ(&cb, sizeof(NW_XML_Parser_EventCallbacks_s));
       
   970 
       
   971 	// cXML callbacks
       
   972 	cb.StartDocument_CB = StartDocumentCB;
       
   973 	cb.EndDocument_CB = EndDocumentCB;
       
   974 	cb.Tag_Start_CB = BeginElementCB;
       
   975 	cb.Attr_Start_CB = AttributeStartCB;
       
   976 	cb.Attr_VarVal_CB = AttributeValueCB;
       
   977 	cb.Attributes_End_CB = AttributesEndCB;
       
   978 	cb.Tag_End_CB = EndElementCB;
       
   979 	cb.Content_CB = ContentCB;
       
   980 	cb.Cdata_CB = CdataCB; 
       
   981 	cb.Comment_CB = CommentCB;
       
   982 	cb.PiForm_CB = PiCB;
       
   983 	cb.pClientPointer = (void*)iParserObserver;
       
   984 	cb.Entity_CB = EntityCB;
       
   985 	cb.Attr_Entity_VarVal_CB = AttrEntityVarValCB;
       
   986 
       
   987 	// Remove whitespace from beginning	
       
   988 	TInt start(aBuff.Locate('<'));
       
   989 	
       
   990 	if (start == -1) 
       
   991 	{
       
   992 		return KErrParseFailed;
       
   993 	}
       
   994 
       
   995 	status = NW_XML_Reader_InitFromBuffer(&reader, aBuff.Right(aBuff.Length()-start).Size(), 
       
   996 										(unsigned char*)aBuff.Right(aBuff.Length()-start).Ptr());
       
   997 	NW_XML_Reader_SetEncoding(&reader, HTTP_iso_10646_ucs_2);
       
   998 		
       
   999 	// parse it!
       
  1000 	status = NW_XML_Parse(&reader, &cb);		
       
  1001 
       
  1002     ASSERT(!(reader.length % 2));
       
  1003     TPtrC16 wChar((const TUint16*)reader.pBuf, reader.length / 2);
       
  1004     MXMLContentHandler* aContentHandler = iParserObserver->GetContentHandler();
       
  1005     aContentHandler->DataBuffer(wChar);
       
  1006 
       
  1007 
       
  1008 	if (!NW_STAT_IS_SUCCESS(status))
       
  1009 	{
       
  1010 		return KErrParseFailed;
       
  1011 	}
       
  1012 	return KErrNone;
       
  1013 }
       
  1014 
       
  1015 // -----------------------------------------------------------------------------
       
  1016 // CXMLReader::ParseWBXML
       
  1017 // 
       
  1018 // (other items were commented in a header).
       
  1019 // -----------------------------------------------------------------------------
       
  1020 //
       
  1021 TInt CXMLReader::ParseWBXML(const TDesC8& aBuff)
       
  1022 {
       
  1023 	// WBXML CallBacks
       
  1024 	struct NW_WBXML_EventHandler_s binaryCB;
       
  1025 	
       
  1026 	Mem::FillZ(&binaryCB, sizeof(NW_WBXML_EventHandler_s));
       
  1027 
       
  1028 	// State change events
       
  1029 	binaryCB.StartDocument_CB = Binary_StartDocument_CB;
       
  1030 	binaryCB.EndDocument_CB = Binary_EndDocument_CB;
       
  1031 	binaryCB.Pi_CB = Binary_Pi_CB;
       
  1032 	binaryCB.Pi_End_CB = Binary_Pi_End_CB;
       
  1033 	binaryCB.Tag_Start_CB = Binary_Tag_Start_CB;
       
  1034 	binaryCB.Tag_End_CB = Binary_Tag_End_CB;
       
  1035 	binaryCB.Attr_Start_CB = Binary_Attr_Start_CB;
       
  1036 	binaryCB.Attr_Val_CB = Binary_Attr_Val_CB;
       
  1037 	binaryCB.Content_CB = Binary_Content_CB;
       
  1038 	binaryCB.CodePage_CB = Binary_CodePage_CB;
       
  1039 	binaryCB.Extension_CB = Binary_Extension_CB;
       
  1040 	// Handle data types 
       
  1041 	binaryCB.Token_CB = Binary_Token_CB;
       
  1042 	binaryCB.FQToken_CB = Binary_FQToken_CB;
       
  1043 	binaryCB.InlineString_CB = Binary_InlineString_CB;
       
  1044 	binaryCB.TableString_CB = Binary_TableString_CB;
       
  1045 	binaryCB.Binary_CB = Binary_Binary_CB;
       
  1046 	binaryCB.Opaque_CB = Binary_Opaque_CB;
       
  1047 	binaryCB.Entity_CB = Binary_Entity_CB;
       
  1048   	// For parse errors 
       
  1049 	binaryCB.Exception_CB = Binary_Exception_CB;
       
  1050 
       
  1051 	// init dictionarys
       
  1052 	NW_WBXML_Dictionary_t *dictionaries[DICTIONARY_COUNT];
       
  1053 	dictionaries[0] = (NW_WBXML_Dictionary_t *)&NW_SyncML_1_0_WBXMLDictionary;
       
  1054 	dictionaries[1] = (NW_WBXML_Dictionary_t *)&NW_Wml_1_0_WBXMLDictionary;
       
  1055 	dictionaries[2] = (NW_WBXML_Dictionary_t *)&NW_Wml_1_1_WBXMLDictionary;
       
  1056 	dictionaries[3] = (NW_WBXML_Dictionary_t *)&NW_Wml_1_2_WBXMLDictionary;
       
  1057 	dictionaries[4] = (NW_WBXML_Dictionary_t *)&NW_Wml_1_3_WBXMLDictionary;
       
  1058 	dictionaries[5] = (NW_WBXML_Dictionary_t *)&NW_XHTML_WBXMLDictionary;
       
  1059 	dictionaries[6] = (NW_WBXML_Dictionary_t *)&NW_SL_WBXMLDictionary;
       
  1060 //	dictionaries[7] = (NW_WBXML_Dictionary_t *)&SL_dictionary;
       
  1061 //	dictionaries[8] = (NW_WBXML_Dictionary_t *)&NW_wap_prov_doc_WBXMLDictionary;
       
  1062 //	dictionaries[9] = (NW_WBXML_Dictionary_t *)&push_nokprov_dictionary;
       
  1063 
       
  1064 	if ((NW_WBXML_Dictionary_initialize (DICTIONARY_COUNT, dictionaries)) != NW_STAT_SUCCESS)	
       
  1065 	{
       
  1066 		return KErrDictionaryInitFailed;
       
  1067 	} 
       
  1068 
       
  1069 	NW_Status_t status;
       
  1070     
       
  1071     // create parser
       
  1072 	NW_WBXML_Parser_t *parser = (NW_WBXML_Parser_t*)User::Alloc(sizeof(NW_WBXML_Parser_t));		
       
  1073 	if(parser == NULL)
       
  1074 	{
       
  1075 		NW_WBXML_Dictionary_destroy();
       
  1076 		return KErrParseFailed;
       
  1077 	}
       
  1078 	NW_WBXML_Parser_newInPlace(parser);
       
  1079 	
       
  1080 	// create document
       
  1081 	NW_WBXML_Document_t *doc = (NW_WBXML_Document_t*)User::Alloc(sizeof(NW_WBXML_Document_t));
       
  1082 	if(doc == NULL)
       
  1083 	{
       
  1084 		NW_WBXML_Dictionary_destroy();
       
  1085 		User::Free(parser);
       
  1086 		parser = NULL;
       
  1087 		return KErrParseFailed;
       
  1088 	}
       
  1089 	status = NW_WBXML_Document_construct(doc, SL_1_0_PUBLIC_ID);
       
  1090 	if(status != NW_STAT_SUCCESS)
       
  1091 	{
       
  1092 		NW_WBXML_Dictionary_destroy();
       
  1093 		User::Free(parser);
       
  1094 		parser = NULL;
       
  1095 		User::Free(doc);
       
  1096 		doc = NULL;
       
  1097 		return KErrParseFailed;
       
  1098 	}
       
  1099 	
       
  1100 	
       
  1101 	status =NW_WBXML_Parser_registerHandler(parser, &binaryCB, (void*)iParserObserver);
       
  1102 	
       
  1103   
       
  1104   	if (status == NW_STAT_SUCCESS)
       
  1105   	{
       
  1106 		status = NW_WBXML_Parser_parseBuffer(parser, doc, (NW_Byte*)aBuff.Ptr(), (NW_Uint32)aBuff.Length());
       
  1107 	}
       
  1108 
       
  1109 	NW_WBXML_Dictionary_destroy();
       
  1110 
       
  1111 	User::Free(parser);
       
  1112 	parser = NULL;
       
  1113 	NW_WBXML_Document_destruct(doc);
       
  1114 	User::Free(doc);
       
  1115 	doc = NULL;
       
  1116 	if(status != NW_STAT_SUCCESS)
       
  1117 	{
       
  1118 		return KErrParseFailed;
       
  1119 	}
       
  1120 	return KErrNone;
       
  1121 }
       
  1122 
       
  1123 //  End of File