webservices/wsstar/wsstarmessagehandlers/src/wsstarmessageutils.cpp
changeset 0 62f9d29f7211
child 23 a1df79fa35b4
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     1 /*
       
     2 * Copyright (c) 2006-2006 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:           
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 
       
    27 #include "wsstarmessageutils.h"
       
    28 #include <xmlengnodelist.h> 
       
    29 
       
    30 CSenElement* CWSStarMessageUtils::GetMarkedElementL(CSenElement& aParent, 
       
    31                                                     const TDesC8& aValue, TBool aAttribute)
       
    32     {
       
    33      CSenElement* markedEl = NULL;
       
    34 
       
    35 //1.flat choose 
       
    36     RPointerArray<CSenElement>& elements = aParent.ElementsL();
       
    37     TInt count(elements.Count());
       
    38     TInt i=0;
       
    39     while (i<count && !markedEl)
       
    40         {
       
    41         markedEl = elements[i];
       
    42         if (aAttribute)
       
    43             {
       
    44             if (!markedEl->AttrValue(aValue))
       
    45                 {
       
    46                 markedEl = NULL;
       
    47                 }    
       
    48             }
       
    49         else
       
    50             {
       
    51             if (markedEl->LocalName() != aValue)
       
    52                 {
       
    53                 markedEl = NULL;
       
    54                 }    
       
    55             }
       
    56         
       
    57         i++;
       
    58         }
       
    59 
       
    60 //2.go deeper 
       
    61     if (!markedEl)
       
    62         {
       
    63         elements = aParent.ElementsL();
       
    64         TInt count(elements.Count());
       
    65         TInt i=0;
       
    66         while (i<count && !markedEl)
       
    67             {
       
    68             markedEl = CWSStarMessageUtils::GetMarkedElementL(*elements[i], aValue, aAttribute);
       
    69             i++;
       
    70             }
       
    71         }
       
    72     return markedEl;
       
    73     }
       
    74 
       
    75 void CWSStarMessageUtils::FindElementL(const TDesC8& aElementName, 
       
    76                                         const TDesC8& aNamespace, 
       
    77                                         const TXmlEngElement& aParent, 
       
    78                                         RArrayElements* aElements)
       
    79 {
       
    80     RXmlEngNodeList<TXmlEngElement> nodeList;
       
    81     TXmlEngElement parent;
       
    82     aParent.GetElementsByTagNameL( nodeList, aElementName , aNamespace );
       
    83     if( nodeList.Count() )
       
    84     {
       
    85         parent = nodeList.Next();
       
    86         aElements->AppendL(parent);
       
    87     }
       
    88     
       
    89     RXmlEngNodeList<TXmlEngElement> nodeChildList;
       
    90     aParent.GetChildElements(nodeChildList);
       
    91     
       
    92     TInt count( nodeChildList.Count() );
       
    93     for(TInt i(0) ; i<count ; i++)
       
    94     {
       
    95         if( nodeChildList.HasNext() )
       
    96         {
       
    97             CWSStarMessageUtils::FindElementL(aElementName , 
       
    98                                                 aNamespace , 
       
    99                                                 nodeChildList.Next() ,
       
   100                                                 aElements);
       
   101         }
       
   102     }
       
   103     nodeList.Close();
       
   104     nodeChildList.Close(); 
       
   105 }
       
   106 
       
   107 CSenElement* CWSStarMessageUtils::FindElementL(const TDesC8& aLocalName, CSenElement& aParent)
       
   108     {
       
   109      CSenElement* elem = NULL;
       
   110 
       
   111     RPointerArray<CSenElement>& elements = aParent.ElementsL();
       
   112     TInt count(elements.Count());
       
   113     TInt i=0;
       
   114     while (i<count && !elem)
       
   115         {
       
   116         elem = elements[i];
       
   117         if (elem->LocalName() != aLocalName)
       
   118             {
       
   119             elem = NULL;
       
   120             }    
       
   121         i++;
       
   122         }
       
   123 
       
   124     if (!elem)
       
   125         {
       
   126         elements = aParent.ElementsL();
       
   127         TInt count(elements.Count());
       
   128         TInt i=0;
       
   129         while (i<count && !elem)
       
   130             {
       
   131             elem = CWSStarMessageUtils::FindElementL(aLocalName, *elements[i]);
       
   132             i++;
       
   133             }
       
   134         }
       
   135     return elem;
       
   136     
       
   137     }
       
   138 void CWSStarMessageUtils::FindElementL(
       
   139                                 const TDesC8& aLocalName,
       
   140                                 CSenElement& aParent,
       
   141                                 RArraySenElements& aElements)
       
   142     {
       
   143     CSenElement* elem = NULL;
       
   144 
       
   145     RPointerArray<CSenElement>& elements = aParent.ElementsL();
       
   146     TInt count(elements.Count());
       
   147     TInt i=0;
       
   148     while (i<count)
       
   149         {
       
   150         elem = elements[i];
       
   151         if (elem->LocalName() == aLocalName)
       
   152         {
       
   153             aElements.Append(elem);
       
   154         }
       
   155         CWSStarMessageUtils::FindElementL(aLocalName, *elem,aElements);
       
   156         elem = NULL;
       
   157         i++;
       
   158         }
       
   159     }