syncmlfw/common/wbxml/src/syncml/WBXMLSyncMLParser.cpp
changeset 0 b497e44ab2fc
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     1 /*
       
     2 * Copyright (c) 2004 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:  SyncML document parser class implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // ------------------------------------------------------------------------------------------------
       
    20 // Includes
       
    21 // ------------------------------------------------------------------------------------------------
       
    22 #include "WBXMLSyncMLParser.h"
       
    23 #include "WBXMLParserError.h"
       
    24 
       
    25 #include "smlsyncmltags.h"
       
    26 #include "xmlelement.h"
       
    27 #include "smlmetinfdtd.h"
       
    28 #include "smldevinfdtd.h"
       
    29 
       
    30 // ------------------------------------------------------------------------------------------------
       
    31 // CWBXMLSyncMLDocHandler
       
    32 // ------------------------------------------------------------------------------------------------
       
    33 EXPORT_C CWBXMLSyncMLDocHandler* CWBXMLSyncMLDocHandler::NewL( MWBXMLSyncMLCallbacks* aCallbacks )
       
    34 	{
       
    35 	CWBXMLSyncMLDocHandler* self = new (ELeave) CWBXMLSyncMLDocHandler(aCallbacks);
       
    36 	CleanupStack::PushL(self);
       
    37 	self->ConstructL();
       
    38 	CleanupStack::Pop(); // self
       
    39 	return self;
       
    40 	}
       
    41 
       
    42 // ------------------------------------------------------------------------------------------------
       
    43 EXPORT_C CWBXMLSyncMLDocHandler::~CWBXMLSyncMLDocHandler()
       
    44 	{
       
    45 	if(iCmdStack)
       
    46 		{
       
    47 		iCmdStack->Reset();
       
    48 		}
       
    49 	delete iCmdStack;
       
    50 
       
    51 	if(iCleanupStack)
       
    52 		{
       
    53 		iCleanupStack->ResetAndDestroy();
       
    54 		}
       
    55 	delete iCleanupStack;
       
    56 	}
       
    57 
       
    58 // ------------------------------------------------------------------------------------------------
       
    59 void CWBXMLSyncMLDocHandler::StartDocumentL( TUint8 /*aVersion*/, TInt32 /*aPublicId*/, TUint32 /*aCharset*/ )
       
    60 	{
       
    61 	}
       
    62 
       
    63 // ------------------------------------------------------------------------------------------------
       
    64 void CWBXMLSyncMLDocHandler::StartDocumentL( TUint8 /*aVersion*/, const TDesC8& /*aPublicIdStr*/, TUint32 /*aCharset*/ )
       
    65 	{
       
    66 	}
       
    67 
       
    68 // ------------------------------------------------------------------------------------------------
       
    69 void CWBXMLSyncMLDocHandler::EndDocumentL()
       
    70 	{
       
    71 	}
       
    72 
       
    73 // ------------------------------------------------------------------------------------------------
       
    74 void CWBXMLSyncMLDocHandler::StartElementL( TWBXMLTag aTag, const CWBXMLAttributes& /*aAttributes*/ )
       
    75 	{
       
    76 	if( iCmdStack->Top() != 0 )
       
    77 		{
       
    78 		AddElementL(iCmdStack->Top()->BeginElementL(aTag, TXMLElementParams(iCallbacks)));
       
    79 		}
       
    80 	else
       
    81 		{
       
    82 		if( aTag == ESyncML )
       
    83 			{
       
    84 			AddElementL(new (ELeave) SmlSyncML_t());
       
    85 			}
       
    86 		else
       
    87 			{
       
    88 			User::Leave(KWBXMLParserErrorInvalidTag);
       
    89 			}
       
    90 		}
       
    91 	}
       
    92 
       
    93 // ------------------------------------------------------------------------------------------------
       
    94 void CWBXMLSyncMLDocHandler::AddElementL( CXMLElement* aElement )
       
    95 	{
       
    96 	if( aElement )
       
    97 		{
       
    98 		iCmdStack->Push(aElement);
       
    99 		if( aElement->NeedsCleanup() )
       
   100 			{
       
   101 			iCleanupStack->Push(aElement);
       
   102 			}
       
   103 		}
       
   104 	}
       
   105 
       
   106 // ------------------------------------------------------------------------------------------------
       
   107 void CWBXMLSyncMLDocHandler::EndElementL( TWBXMLTag aTag )
       
   108 	{
       
   109 	if( iCmdStack->Top() != 0 )
       
   110 		{
       
   111 		CXMLElement::TAction action = iCmdStack->Top()->EndElementL(iCallbacks, aTag);
       
   112 		if( action != CXMLElement::ENone )
       
   113 			{
       
   114 			CXMLElement* elem = iCmdStack->Pop();
       
   115 			if( iCleanupStack->Top() == elem )
       
   116 				{
       
   117 				iCleanupStack->Pop();
       
   118 				}
       
   119 			if( action == CXMLElement::EPopAndDestroy )
       
   120 				{
       
   121 				delete elem;
       
   122 				}
       
   123 			}
       
   124 		}
       
   125 	}
       
   126 
       
   127 // ------------------------------------------------------------------------------------------------
       
   128 void CWBXMLSyncMLDocHandler::CodePageSwitchL( TUint8 aPage )
       
   129 	{
       
   130 	switch( aPage )
       
   131 		{
       
   132 		// SyncML
       
   133 		case 0x00:
       
   134 			iCmdStack->Pop();
       
   135 			break;
       
   136 
       
   137 		// Meta Information
       
   138 		case 0x01:
       
   139 			{
       
   140 			SmlPcdataPtr_t top = (SmlPcdataPtr_t)iCmdStack->Top();
       
   141 			// If top element already contains content then push it into
       
   142 			// command stack, create new otherwise.
       
   143 			if( !top->content )
       
   144 				{
       
   145 				top->length = 0;
       
   146 				top->contentType = SML_PCDATA_EXTENSION;
       
   147 				top->extension = SML_EXT_METINF;
       
   148 				top->content = new (ELeave) SmlMetInfMetInf_t();
       
   149 				iCmdStack->Push(SmlMetInfMetInfPtr_t(top->content));
       
   150 				}
       
   151 			else
       
   152 				{
       
   153 				iCmdStack->Push(SmlMetInfMetInfPtr_t(top->content));
       
   154 				}
       
   155 			break;
       
   156 			}
       
   157 		case 0x02:	// 1.2 CHANGES: Properties
       
   158 			{
       
   159 			SmlPcdataPtr_t top = (SmlPcdataPtr_t)iCmdStack->Top();
       
   160 			// If top element already contains content then push it into
       
   161 			// command stack, create new otherwise.
       
   162 			if( !top->content )
       
   163 				{
       
   164 				top->length = 0;
       
   165 				top->contentType = SML_PCDATA_EXTENSION;
       
   166 				top->extension = SML_EXT_DEVINFPROP;
       
   167 				top->content = new (ELeave) SmlDevInfCtCap_t();
       
   168 				iCmdStack->Push((SmlDevInfCtCapPtr_t) top->content);
       
   169 				}
       
   170 			else
       
   171 				{
       
   172 				iCmdStack->Push((SmlDevInfCtCapPtr_t) top->content);
       
   173 				}
       
   174 			break;
       
   175 			} // Changes end
       
   176 		default: // 1.2 CHANGES: case default added
       
   177 			{
       
   178 			User::Leave(KErrParserErrorInvalidDocument);
       
   179 			}// changes end
       
   180 		}
       
   181 	}
       
   182 
       
   183 // ------------------------------------------------------------------------------------------------
       
   184 void CWBXMLSyncMLDocHandler::CharactersL( const TDesC8& aBuffer )
       
   185 	{
       
   186 	if( iCmdStack->Top() != 0 )
       
   187 		{
       
   188 		iCmdStack->Top()->SetDataL(aBuffer);
       
   189 		}
       
   190 	else
       
   191 		{
       
   192 		User::Leave(KWBXMLParserErrorInvalidTag);
       
   193 		}
       
   194 	}
       
   195 
       
   196 // ------------------------------------------------------------------------------------------------
       
   197 void CWBXMLSyncMLDocHandler::DocumentChangedL()
       
   198 	{
       
   199 	iCmdStack->Reset();
       
   200 	}
       
   201 
       
   202 // ------------------------------------------------------------------------------------------------
       
   203 void CWBXMLSyncMLDocHandler::Ext_IL( TWBXMLTag /*aTag*/, const TDesC8& /*aData*/ )
       
   204 	{
       
   205 	}
       
   206 
       
   207 // ------------------------------------------------------------------------------------------------
       
   208 void CWBXMLSyncMLDocHandler::Ext_TL( TWBXMLTag /*aTag*/, TUint32 /*aData*/ )
       
   209 	{
       
   210 	}
       
   211 
       
   212 // ------------------------------------------------------------------------------------------------
       
   213 void CWBXMLSyncMLDocHandler::ExtL( TWBXMLTag /*aTag*/ )
       
   214 	{
       
   215 	}
       
   216 
       
   217 // ------------------------------------------------------------------------------------------------
       
   218 void CWBXMLSyncMLDocHandler::OpaqueL( const TDesC8& aData )
       
   219 	{
       
   220 	CharactersL(aData);
       
   221 	}
       
   222 
       
   223 // ------------------------------------------------------------------------------------------------
       
   224 void CWBXMLSyncMLDocHandler::ConstructL()
       
   225 	{
       
   226 	iCmdStack = CNSmlStack<CXMLElement>::NewL();
       
   227 	iCleanupStack = CNSmlStack<CXMLElement>::NewL();
       
   228 	}
       
   229 
       
   230 // ------------------------------------------------------------------------------------------------
       
   231 CWBXMLSyncMLDocHandler::CWBXMLSyncMLDocHandler( MWBXMLSyncMLCallbacks* aCallbacks ) : iCallbacks(aCallbacks)
       
   232 	{
       
   233 	}
       
   234