messagingappbase/smilengine/engine/parser/smilparser_dom.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2003 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: smilparser_dom implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "smilparser.h"
       
    21 
       
    22 #include <gmxmldocument.h>
       
    23 #include <gmxmlelement.h>
       
    24 
       
    25 class DOMParserPrivate
       
    26 	{
       
    27 public:
       
    28 	DOMParserPrivate(CSmilParser* p) { parser=p; }
       
    29 	void OpenNodeL(CMDXMLNode* n);
       
    30 	void CloseNodeL(CMDXMLNode* n);
       
    31 	CSmilParser* parser;
       
    32 	};
       
    33 
       
    34 void DOMParserPrivate::OpenNodeL(CMDXMLNode* n)
       
    35 	{
       
    36 	if (n->NodeType()==CMDXMLNode::EElementNode)
       
    37 		{
       
    38 		CMDXMLElement* el = static_cast<CMDXMLElement*>(n);
       
    39 		parser->BeginElementL(el->NodeName());
       
    40 
       
    41 		for (TInt i = 0; i<el->NumAttributes(); ++i)
       
    42 			{
       
    43 			TPtrC name, value;
       
    44 			el->AttributeDetails(i,name,value);
       
    45 			parser->AttributeValueL(name,value);
       
    46 			}
       
    47 
       
    48 		parser->AttributesEndL(el->NumAttributes());
       
    49 		}			
       
    50 	return;
       
    51 	}
       
    52 
       
    53 
       
    54 void DOMParserPrivate::CloseNodeL(CMDXMLNode* n)
       
    55 	{
       
    56 	if (n->NodeType()==CMDXMLNode::EElementNode)
       
    57 		{
       
    58 		parser->EndElementL(n->NodeName());
       
    59 		}			
       
    60 	return;
       
    61 	}
       
    62 
       
    63 
       
    64 void ParseDomL(CSmilParser* parser, CMDXMLDocument* doc)
       
    65 	{
       
    66 
       
    67 	CMDXMLElement* root = doc->DocumentElement();
       
    68 
       
    69 	CMDXMLNode* n = root;
       
    70 
       
    71 	DOMParserPrivate* dp = new (ELeave) DOMParserPrivate(parser);
       
    72 	CleanupStack::PushL(dp);
       
    73 
       
    74 	while (n)
       
    75 		{
       
    76 		dp->OpenNodeL(n);
       
    77 
       
    78 		if (n->FirstChild())
       
    79 			n = n->FirstChild();
       
    80 		else if (n->NextSibling())
       
    81 			{
       
    82 			dp->CloseNodeL(n);
       
    83 			n = n->NextSibling();
       
    84 			}
       
    85 		else 
       
    86 			{
       
    87 			while (n)
       
    88 				{
       
    89 				dp->CloseNodeL(n);
       
    90 				if (n->NextSibling())
       
    91 					{
       
    92 					n=n->NextSibling();
       
    93 					break;
       
    94 					}				
       
    95 				n = n->ParentNode();			
       
    96 				}
       
    97 			}
       
    98 		}
       
    99 	CleanupStack::PopAndDestroy();
       
   100 	return;
       
   101 	}