simpleengine/xdmrlspres/src/crlsxdm.cpp
changeset 0 c8caa15ef882
child 25 e53c01f160bc
equal deleted inserted replaced
-1:000000000000 0:c8caa15ef882
       
     1 /*
       
     2 * Copyright (c) 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:    RLS and Presence XDM, This is class for RLS XDM
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // Includes
       
    22 #include <utf.h>
       
    23 #include <XdmProtocolInfo.h>
       
    24 #include <XdmEngine.h>
       
    25 #include <XdmDocument.h>
       
    26 #include <XdmDocumentNode.h>
       
    27 #include <XdmNodeAttribute.h>
       
    28 #include <XdmErrors.h>
       
    29 #include <xcapappusagedef.h>
       
    30 
       
    31 #include "crlsxdm.h"
       
    32 #include "mrlspresxdmasynchandler.h"
       
    33 #include "rlspresxdmlogger.h"
       
    34 #include "rlspresxdmconstsint.h"
       
    35 
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // CRLSXDM::NewL()
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 EXPORT_C CRLSXDM* CRLSXDM::NewL( const TInt aSettingId )
       
    42 	{
       
    43   OPENG_DP(D_OPENG_LIT( "CRLSXDM::NewL" ));
       
    44 	CRLSXDM* self = CRLSXDM::NewLC(aSettingId);
       
    45 	CleanupStack::Pop(self);
       
    46 	return self;		
       
    47 	}
       
    48 	
       
    49 // ---------------------------------------------------------------------------
       
    50 // CRLSXDM::NewLC()
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 EXPORT_C CRLSXDM* CRLSXDM::NewLC( const TInt aSettingId )
       
    54 	{
       
    55     OPENG_DP(D_OPENG_LIT( "CRLSXDM::NewLC" ));
       
    56     CRLSXDM* self = new (ELeave) CRLSXDM();
       
    57     CleanupStack::PushL( self );
       
    58     self->ConstructL( aSettingId );
       
    59     return self;
       
    60 	}
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // CRLSXDM::ConstructL()
       
    64 // ---------------------------------------------------------------------------
       
    65 //	
       
    66 void CRLSXDM::ConstructL(const TInt aSettingId)
       
    67     {
       
    68     OPENG_DP(D_OPENG_LIT( "CRLSXDM::ConstructL(%d)" ), aSettingId);
       
    69     iXDMProtocolInfo = CXdmProtocolInfo::NewL(aSettingId);
       
    70     iXDMEngine = CXdmEngine::NewL( *iXDMProtocolInfo);
       
    71     iRLSDocument = iXDMEngine->CreateDocumentModelL(KRLSDocumentName,
       
    72                                                     EXdmRlsServices);
       
    73                                                     
       
    74     CreateRootIfNeededL();
       
    75     
       
    76     iListPath = new(ELeave)CDesCArraySeg(KPresRLSDesArrayInitlVal);
       
    77     CActiveScheduler::Add( this );
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // CRLSXDM::CreateRootIfNeededL()
       
    82 // ---------------------------------------------------------------------------
       
    83 //    
       
    84 void CRLSXDM::CreateRootIfNeededL()
       
    85     {
       
    86     OPENG_DP(D_OPENG_LIT( "CRLSXDM::CreateRootIfNeededL" ));
       
    87     CXdmDocumentNode* myRootNode = iRLSDocument->DocumentRoot();
       
    88     if (myRootNode)
       
    89         {
       
    90         myRootNode->SetEmptyNode(EFalse);// allow new data to be created, for xdmengine bug
       
    91         return;
       
    92         }
       
    93     myRootNode = iRLSDocument->CreateRootL();
       
    94     myRootNode->SetNameL( KXdmRlsServices );
       
    95     }
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // CRLSXDM::CRLSXDM()
       
    99 // ---------------------------------------------------------------------------
       
   100 //    
       
   101 CRLSXDM::CRLSXDM() : CActive( EPriorityStandard ), 
       
   102                                             iAsyncReq(ERLSXDMNoRequestMade)
       
   103     {
       
   104     OPENG_DP(D_OPENG_LIT( "CRLSXDM::CRLSXDM" ));
       
   105     }
       
   106     
       
   107 // ---------------------------------------------------------------------------
       
   108 // CRLSXDM::~CRLSXDM()
       
   109 // ---------------------------------------------------------------------------
       
   110 //
       
   111 CRLSXDM::~CRLSXDM()
       
   112     {
       
   113     OPENG_DP(D_OPENG_LIT( "CRLSXDM::~CRLSXDM()" ));
       
   114     if(IsActive())
       
   115         Cancel();
       
   116     
       
   117     delete iRLSDocument;
       
   118     delete iXDMEngine;
       
   119     delete iXDMProtocolInfo;
       
   120     iRLSDocument = NULL;
       
   121     
       
   122     if(iListPath)
       
   123         iListPath->Reset();
       
   124     delete iListPath;
       
   125     
       
   126     iListPointerPath.Reset();
       
   127     
       
   128     delete iNegotiatedServiceUri;
       
   129     }
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // CRLSXDM::UpdateToServerL()
       
   133 // ---------------------------------------------------------------------------
       
   134 //    
       
   135 EXPORT_C TInt CRLSXDM::UpdateToServerL(MRLSPresXDMAsyncHandler* const aHandler)
       
   136 	{
       
   137     OPENG_DP(D_OPENG_LIT( "CRLSXDM::UpdateToServerL(%d)" ), aHandler);
       
   138     __ASSERT_ALWAYS(aHandler, User::Leave(KErrArgument));
       
   139     if (IsActive())
       
   140         return KErrAlreadyExists;
       
   141     iAsyncReq = ERLSXDMUpdateToServer;
       
   142     iAsyncHandler = aHandler;
       
   143     iRLSDocument->AppendL();
       
   144     iXDMEngine->UpdateL(iRLSDocument, iStatus);
       
   145     SetActive();
       
   146     return KErrNone;
       
   147 	}
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // CRLSXDM::CancelUpdateL()
       
   151 // ---------------------------------------------------------------------------
       
   152 //	
       
   153 EXPORT_C void CRLSXDM::CancelUpdateL()
       
   154     {
       
   155     OPENG_DP(D_OPENG_LIT( "CRLSXDM::CancelUpdateL" ));
       
   156     if (IsActive())
       
   157         {
       
   158         DoCancel();
       
   159         }
       
   160     }
       
   161 
       
   162 // ---------------------------------------------------------------------------
       
   163 // CRLSXDM::UpdateAllFromServerL()
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 EXPORT_C TInt CRLSXDM::UpdateAllFromServerL(MRLSPresXDMAsyncHandler* const aHandler)
       
   167     {
       
   168     OPENG_DP(D_OPENG_LIT( "CRLSXDM::UpdateAllFromServerL(%d)" ));
       
   169     __ASSERT_ALWAYS(aHandler, User::Leave(KErrArgument));
       
   170     if (IsActive())
       
   171         return KErrAlreadyExists;
       
   172     
       
   173     iAsyncHandler = aHandler;
       
   174     iRLSDocument->ResetContents();
       
   175     iRLSDocument->FetchDataL();
       
   176     iAsyncReq = ERLSXDMUpdateFromServer;
       
   177     
       
   178     iXDMEngine->UpdateL(iRLSDocument, iStatus);
       
   179    
       
   180     SetActive();
       
   181     return KErrNone;
       
   182     }
       
   183 
       
   184 // ---------------------------------------------------------------------------
       
   185 // CRLSXDM::DeleteAll()
       
   186 // ---------------------------------------------------------------------------
       
   187 //    
       
   188 EXPORT_C void CRLSXDM::DeleteAll()
       
   189     {
       
   190     OPENG_DP(D_OPENG_LIT( "CRLSXDM::DeleteAllL"));
       
   191     
       
   192     // resetting current path
       
   193     iListPath->Reset();
       
   194     iListPointerPath.Reset();
       
   195 
       
   196     CXdmDocumentNode* myRootNode = iRLSDocument->DocumentRoot();
       
   197     if (myRootNode==NULL)
       
   198         return;
       
   199     
       
   200     myRootNode->SetEmptyNode(ETrue); // delete all data
       
   201     myRootNode->SetEmptyNode(EFalse);// allow new data to be created
       
   202     }
       
   203 
       
   204 // ---------------------------------------------------------------------------
       
   205 // CRLSXDM::AddServiceURIL()
       
   206 // ---------------------------------------------------------------------------
       
   207 //
       
   208 EXPORT_C TInt CRLSXDM::AddServiceURIL(const TDesC& aServiceURI)
       
   209 	{
       
   210     OPENG_DP(D_OPENG_LIT( "CRLSXDM::AddServiceURIL(%S)" ),&aServiceURI);
       
   211     CXdmDocumentNode* myRootNode = iRLSDocument->DocumentRoot();
       
   212     if (myRootNode==NULL)
       
   213         return KErrNotFound;
       
   214     
       
   215     //check if already exist    
       
   216     if (IsServiceUriExist(aServiceURI, myRootNode) != NULL)
       
   217         return KErrAlreadyExists;
       
   218     
       
   219     //workaround
       
   220     myRootNode->SetEmptyNode(EFalse);// allow new data to be created
       
   221     
       
   222     CXdmDocumentNode* listServNode = myRootNode->CreateChileNodeL(KXdmService);
       
   223     CXdmNodeAttribute* attributeUri = listServNode->CreateAttributeL(KXdmUri);
       
   224     attributeUri->SetAttributeValueL(aServiceURI);
       
   225     
       
   226     // now add the packages
       
   227     CXdmDocumentNode* packagesNode = listServNode->CreateChileNodeL(KXdmPackages);
       
   228     CXdmDocumentNode* packageNode = packagesNode->CreateChileNodeL(KXdmPackage);
       
   229     packageNode->SetLeafNode(ETrue);
       
   230     packageNode->SetLeafNodeContentL(KXdmPresence);
       
   231     return KErrNone;
       
   232     }
       
   233 
       
   234 // ---------------------------------------------------------------------------
       
   235 // CRLSXDM::RemoveServiceURIL()
       
   236 // ---------------------------------------------------------------------------
       
   237 //
       
   238 EXPORT_C TInt CRLSXDM::RemoveServiceURIL(const TDesC& aServiceURI)
       
   239 	{
       
   240     OPENG_DP(D_OPENG_LIT( "CRLSXDM::RemoveServiceURIL(%S)" ),&aServiceURI);
       
   241     CXdmDocumentNode* myRootNode = iRLSDocument->DocumentRoot();
       
   242     TInt err(KErrNotFound);
       
   243     if (myRootNode!=NULL)
       
   244         {
       
   245         CXdmDocumentNode* serviceNode = IsServiceUriExist(aServiceURI, myRootNode);
       
   246         if(serviceNode) // if exist
       
   247             {
       
   248             iRLSDocument->RemoveFromModelL(serviceNode);
       
   249             err = KErrNone;
       
   250             }
       
   251         }
       
   252     // check valdity of path if operation is successful
       
   253     if(iListPath->Count() && (err==KErrNone))
       
   254         {
       
   255         if( (iListPath->MdcaPoint(0)) == aServiceURI)
       
   256             {
       
   257             // resetting current path
       
   258             iListPath->Reset();
       
   259             iListPointerPath.Reset();
       
   260             }
       
   261         }
       
   262         
       
   263     OPENG_DP(D_OPENG_LIT( "     returned: %d" ),err);
       
   264     return err;
       
   265 	}
       
   266 
       
   267 // ---------------------------------------------------------------------------
       
   268 // CRLSXDM::IsExistServiceURI()
       
   269 // ---------------------------------------------------------------------------
       
   270 //
       
   271 EXPORT_C TBool CRLSXDM::IsExistServiceURI(const TDesC& aServiceURI)
       
   272 	{
       
   273     OPENG_DP(D_OPENG_LIT( "CRLSXDM::IsExistServiceURI(%S)" ),&aServiceURI);
       
   274     CXdmDocumentNode* myRootNode = iRLSDocument->DocumentRoot();
       
   275     TBool isExist(EFalse);
       
   276     if (myRootNode!=NULL)
       
   277         {
       
   278         CXdmDocumentNode* serviceNode = IsServiceUriExist(aServiceURI, myRootNode);
       
   279         if(serviceNode) // if exist
       
   280             {
       
   281             isExist = ETrue;
       
   282             }
       
   283         }
       
   284 
       
   285     OPENG_DP(D_OPENG_LIT( "     returned: %d" ),isExist);
       
   286     return isExist;
       
   287 	}
       
   288 
       
   289 // ---------------------------------------------------------------------------
       
   290 // CRLSXDM::GetServiceUris()
       
   291 // ---------------------------------------------------------------------------
       
   292 //
       
   293 EXPORT_C void CRLSXDM::GetServiceUrisL(CDesCArray& aServiceUris)
       
   294     {
       
   295     OPENG_DP(D_OPENG_LIT( "CRLSXDM::GetServiceUris" ));
       
   296     CXdmDocumentNode* myRootNode = iRLSDocument->DocumentRoot();
       
   297     RPointerArray<CXdmDocumentNode> nodes;
       
   298     CXdmNodeAttribute* uriAttribute(NULL);
       
   299 
       
   300     if (myRootNode!=NULL)
       
   301         {
       
   302         // Find all Service Uris under root Node
       
   303         if ((myRootNode->Find(KXdmService, nodes)) == KErrNone)
       
   304             { // go through all found Uris
       
   305             TInt uriCountInNode = nodes.Count();
       
   306             OPENG_DP(D_OPENG_LIT( "     uriCountInNode(%d)" ),uriCountInNode);
       
   307             for (TInt k=0;k<uriCountInNode;k++)
       
   308                 { // get the uri attribute
       
   309                 uriAttribute = (nodes[k])->Attribute(KXdmUri);
       
   310                 // push it to given discriptor array
       
   311                 aServiceUris.AppendL(uriAttribute->AttributeValue());
       
   312                 }
       
   313             }
       
   314         }
       
   315     nodes.Close();
       
   316     }
       
   317 
       
   318 // ---------------------------------------------------------------------------
       
   319 // CRLSXDM::DeleteAllEmptyServiceUrisL()
       
   320 // ---------------------------------------------------------------------------
       
   321 //	
       
   322 EXPORT_C void CRLSXDM::DeleteAllEmptyServiceUrisL()
       
   323     {
       
   324     OPENG_DP(D_OPENG_LIT( "CRLSXDM::DeleteAllEmptyServiceUrisL" ));
       
   325     RPointerArray<CXdmDocumentNode> uriNodes;
       
   326     
       
   327     // resetting current path
       
   328     iListPath->Reset();
       
   329     iListPointerPath.Reset();
       
   330 
       
   331     TInt found = iRLSDocument->Find( KXdmService, uriNodes);
       
   332     OPENG_DP(D_OPENG_LIT( "     total Uris: %d" ), found);
       
   333     
       
   334     for (TInt i=0;i<found;i++)
       
   335         {
       
   336         if ( ((uriNodes[i])->NodeCount()) <= 1)// if Uri have only package node
       
   337             {
       
   338             iRLSDocument->RemoveFromModelL(uriNodes[i]);
       
   339             OPENG_DP(D_OPENG_LIT( "     delete at i = %d" ), i);
       
   340             }
       
   341         }
       
   342     uriNodes.Close();    
       
   343     }
       
   344 
       
   345 // ---------------------------------------------------------------------------
       
   346 // CRLSXDM::RenameListL()
       
   347 // ---------------------------------------------------------------------------
       
   348 //	
       
   349 EXPORT_C TInt CRLSXDM::RenameListL(const TDesC& aListName, 
       
   350                                                     const TDesC& aListNewName)
       
   351 	{
       
   352 	OPENG_DP(D_OPENG_LIT( "CRLSXDM::RenameListL(%S)" ),&aListName);
       
   353 	TInt err(KErrNotFound);
       
   354 	TInt count = iListPointerPath.Count();
       
   355 	if (count)
       
   356 	    {
       
   357 	    CXdmDocumentNode* list = GetNonLeafChild(KXdmList,aListName,
       
   358                                                     iListPointerPath[count-1]);
       
   359 	    if (list!=NULL) // if found
       
   360             { // if new name already exist
       
   361             CXdmDocumentNode* newList = GetNonLeafChild(KXdmList, aListNewName,
       
   362                                                         iListPointerPath[count-1]);
       
   363             if (newList)
       
   364                 err = KErrAlreadyExists;
       
   365             else
       
   366                 {
       
   367          	    CXdmNodeAttribute* myAttribute = list->Attribute(KXdmName);
       
   368         	    myAttribute->SetAttributeValueL(aListNewName);
       
   369         	    err = KErrNone;
       
   370                 }
       
   371             }
       
   372         }
       
   373     OPENG_DP(D_OPENG_LIT( "     returned: %d" ),err);
       
   374     return err;
       
   375 	}
       
   376 
       
   377 // ---------------------------------------------------------------------------
       
   378 // CRLSXDM::DeleteAllEmptyLists()
       
   379 // ---------------------------------------------------------------------------
       
   380 //
       
   381 EXPORT_C TInt CRLSXDM::DeleteAllEmptyLists(MRLSPresXDMAsyncHandler* const aHandler)
       
   382     {
       
   383     OPENG_DP(D_OPENG_LIT( "CRLSXDM::DeleteAllEmptyListsL(%d)" ), aHandler);
       
   384 
       
   385     if(aHandler==NULL)
       
   386         return KErrArgument;
       
   387     
       
   388     if (IsActive())
       
   389         return KErrAlreadyExists;
       
   390     
       
   391     // resetting current path
       
   392     iListPath->Reset();
       
   393     iListPointerPath.Reset();
       
   394 
       
   395     iAsyncReq = ERLSXDMDeletingEmptyLists;
       
   396     iAsyncHandler = aHandler;
       
   397     TRequestStatus* status = &iStatus;
       
   398     User::RequestComplete(status,KErrNone);
       
   399     SetActive();
       
   400     return KErrNone;
       
   401     }
       
   402 
       
   403 // ---------------------------------------------------------------------------
       
   404 // CRLSXDM::AddElementL()
       
   405 // ---------------------------------------------------------------------------
       
   406 //
       
   407 EXPORT_C TInt CRLSXDM::AddElementL(const TDesC& aElementType,
       
   408                         const TDesC& aData, const TDesC& aDisplayName)
       
   409     {
       
   410 	OPENG_DP(D_OPENG_LIT( "CRLSXDM::AddElementL" ));
       
   411 	OPENG_DP(D_OPENG_LIT( "     aElementType(%S), aData(%S), aDisplayName(%S)"),
       
   412 	                                &aElementType, &aData, &aDisplayName);
       
   413 	TInt err(KErrNone);
       
   414     TInt count = iListPointerPath.Count();
       
   415 
       
   416 	if(aElementType==KXdmResourceList)
       
   417 	    {
       
   418     	if (count) // should be atleast 1, so that resource-list reside inside serviceUri
       
   419     	    {
       
   420     	    CXdmDocumentNode* list = GetLeafChild(aElementType, aData,
       
   421                                                         iListPointerPath[count-1]);
       
   422     	    if (!list) // if not found
       
   423 	            {
       
   424         	    if(count==1)// if the package on same level
       
   425         	        RemovePackageL();
       
   426                 AddLeafElementL(KXdmResourceList, aData, iListPointerPath[count-1]);	    
       
   427                 if(count==1)// if the package on same level
       
   428         	        AddPackageL(); // so that package is the last element on service-uri
       
   429         	    err = KErrNone;
       
   430 	            }
       
   431 	        else
       
   432                 err = KErrAlreadyExists;
       
   433             }
       
   434         else
       
   435             err = KErrPermissionDenied; // path is not suitable
       
   436 	    }
       
   437 	else if(IsNonLeafElementValid(aElementType))
       
   438 	    {
       
   439 	    if( (count>1) || ((aElementType==KXdmList)&&(count)) )
       
   440 	        {
       
   441 	        CXdmDocumentNode* element = GetNonLeafChild(aElementType, aData,
       
   442                                                         iListPointerPath[count-1]);
       
   443             if(!element) // if element doesnt exist
       
   444 	            {
       
   445         	    if(count==1)// if the package on same level
       
   446         	        RemovePackageL();
       
   447                 AddNonLeafElementL(aElementType, aData, aDisplayName, iListPointerPath[count-1]);	    
       
   448                 if(count==1)// if the package on same level
       
   449         	        AddPackageL(); // so that package is the last element on service-uri
       
   450         	    err = KErrNone;
       
   451 	            }
       
   452             else
       
   453                 err = KErrAlreadyExists;
       
   454 	        }
       
   455         else
       
   456             err = KErrPermissionDenied; // path is not suitable
       
   457 	    }
       
   458 	else
       
   459 	    err = KErrArgument;
       
   460 	
       
   461 	OPENG_DP(D_OPENG_LIT( " return: err(%d)" ), err);
       
   462 	return err;
       
   463     }
       
   464 
       
   465 // ---------------------------------------------------------------------------
       
   466 // CRLSXDM::GetDisplayName()
       
   467 // ---------------------------------------------------------------------------
       
   468 //
       
   469 EXPORT_C TInt CRLSXDM::GetDisplayName(const TDesC& aElementType,
       
   470                                 const TDesC& aData, TPtrC8& aDisplayName)
       
   471     {
       
   472 	OPENG_DP(D_OPENG_LIT( "CRLSXDM::GetDisplayName" ));
       
   473 	OPENG_DP(D_OPENG_LIT( "     aElementType(%S), aData(%S)"),
       
   474 	                                    &aElementType, &aData);
       
   475 	
       
   476 	TInt err(KErrNotFound);
       
   477 	
       
   478 	TInt count = iListPointerPath.Count();
       
   479 	if (count) // if there is atleast service uri
       
   480 	    {
       
   481 	    if(IsNonLeafElementValid(aElementType))
       
   482 	        {
       
   483 	        err = GetDisplayNameInt(aElementType, aData, aDisplayName,
       
   484                                             iListPointerPath[count-1]);
       
   485 	        }
       
   486 	    else
       
   487 	        err = KErrArgument;
       
   488         }
       
   489     return err;     
       
   490     }
       
   491 
       
   492 // ---------------------------------------------------------------------------
       
   493 // CRLSXDM::UpdateDisplayNameL()
       
   494 // ---------------------------------------------------------------------------
       
   495 //
       
   496 EXPORT_C TInt CRLSXDM::UpdateDisplayNameL(const TDesC& aElementType,  
       
   497                         const TDesC& aData, const TDesC& aDisplayName)
       
   498     {
       
   499 	OPENG_DP(D_OPENG_LIT( "CRLSXDM::UpdateDisplayNameL" ));
       
   500 	OPENG_DP(D_OPENG_LIT( "     aElementType(%S), aData(%S), aDisplayName(%S)"),
       
   501 	                                    &aElementType, &aData, &aDisplayName);
       
   502 	
       
   503 	TInt err(KErrNotFound);
       
   504 	
       
   505 	TInt count = iListPointerPath.Count();
       
   506 	if (count) // if there is atleast service uri
       
   507 	    {
       
   508 	    if(IsNonLeafElementValid(aElementType))
       
   509 	        {
       
   510 	        err = UpdateDisplayNameIntL(aElementType, aData, aDisplayName,
       
   511                                             iListPointerPath[count-1]);
       
   512 	        }
       
   513 	    else
       
   514 	        err = KErrArgument;
       
   515         }
       
   516     return err;     
       
   517     }
       
   518 
       
   519 // ---------------------------------------------------------------------------
       
   520 // CRLSXDM::GetElementsL()
       
   521 // ---------------------------------------------------------------------------
       
   522 //
       
   523 EXPORT_C void CRLSXDM::GetElementsL(const TDesC& aElementType, 
       
   524                                                     CDesCArray& aValues)
       
   525     {
       
   526 	OPENG_DP(D_OPENG_LIT( "CRLSXDM::GetElementsL" ));
       
   527 	OPENG_DP(D_OPENG_LIT( "     aElementType(%S)"),&aElementType);
       
   528 	
       
   529 	TInt count = iListPointerPath.Count();
       
   530 	if (count) // if there is atleast service uri
       
   531 	    {
       
   532 	    if(IsNonLeafElementValid(aElementType))
       
   533 	        GetNonLeafElementsL(aElementType, aValues, iListPointerPath[count-1]);
       
   534 	    else if(aElementType==KXdmResourceList)
       
   535 	        GetLeafElementsL(aElementType, aValues, iListPointerPath[count-1]);
       
   536         }
       
   537     }
       
   538             
       
   539 // ---------------------------------------------------------------------------
       
   540 // CRLSXDM::RemoveElementL()
       
   541 // ---------------------------------------------------------------------------
       
   542 //
       
   543 EXPORT_C TInt CRLSXDM::RemoveElementL(const TDesC& aElementType, 
       
   544                                                     const TDesC& aData)
       
   545     {
       
   546 	OPENG_DP(D_OPENG_LIT( "CRLSXDM::RemoveElementL" ));
       
   547 	OPENG_DP(D_OPENG_LIT( "     aElementType(%S), aData(%S)"),
       
   548 	                                            &aElementType, &aData);
       
   549 	TInt err(KErrNotFound);
       
   550     TInt count = iListPointerPath.Count();
       
   551     CXdmDocumentNode* myNode(NULL);
       
   552     
       
   553     if(count)
       
   554         {
       
   555       	if(aElementType==KXdmResourceList)
       
   556       	    myNode = GetLeafChild(aElementType,aData,iListPointerPath[count-1]);
       
   557       	else if(IsNonLeafElementValid(aElementType))
       
   558       	    myNode = GetNonLeafChild(aElementType,aData,iListPointerPath[count-1]);
       
   559       	else
       
   560       	    err = KErrArgument;
       
   561         }
       
   562 
       
   563     if (myNode) // if found
       
   564         {
       
   565         iRLSDocument->RemoveFromModelL(myNode);
       
   566         err = KErrNone;
       
   567         }
       
   568 	
       
   569 	OPENG_DP(D_OPENG_LIT( " return: err(%d)" ), err);
       
   570 	return err;
       
   571     }
       
   572 
       
   573 // ---------------------------------------------------------------------------
       
   574 // CRLSXDM::IsElementExist()
       
   575 // ---------------------------------------------------------------------------
       
   576 //
       
   577 EXPORT_C TBool CRLSXDM::IsElementExist(const TDesC& aElementType, 
       
   578                                                     const TDesC& aData)
       
   579     {
       
   580 	OPENG_DP(D_OPENG_LIT( "CRLSXDM::IsElementExist" ));
       
   581 	OPENG_DP(D_OPENG_LIT( "     aElementType(%S), aData(%S)"),
       
   582 	                                            &aElementType, &aData);
       
   583 	TBool ret(EFalse);
       
   584     TInt count = iListPointerPath.Count();
       
   585     CXdmDocumentNode* myNode(NULL);
       
   586     
       
   587     if(count)
       
   588         {
       
   589       	if(aElementType==KXdmResourceList)
       
   590       	    myNode = GetLeafChild(aElementType,aData,iListPointerPath[count-1]);
       
   591       	else if(IsNonLeafElementValid(aElementType))
       
   592       	    myNode = GetNonLeafChild(aElementType,aData,iListPointerPath[count-1]);
       
   593         }
       
   594 
       
   595     if (myNode) // if found
       
   596         {
       
   597         ret = ETrue;
       
   598         }
       
   599 	
       
   600 	OPENG_DP(D_OPENG_LIT( " return: err(%d)" ), ret);
       
   601 	return ret;
       
   602     }
       
   603 	
       
   604 // ---------------------------------------------------------------------------
       
   605 // CRLSXDM::SwitchToServiceURI()
       
   606 // ---------------------------------------------------------------------------
       
   607 //	
       
   608 EXPORT_C TInt CRLSXDM::SwitchToServiceURIL(const TDesC& aServiceURI)
       
   609 	{
       
   610 	OPENG_DP(D_OPENG_LIT( "CRLSXDM::SwitchToServiceURI(%S)" ),&aServiceURI);
       
   611 	TInt err(KErrNotFound);
       
   612     CXdmDocumentNode* myRootNode = iRLSDocument->DocumentRoot();
       
   613     if (myRootNode==NULL)
       
   614         return err;
       
   615     
       
   616     CXdmDocumentNode* serviceUriNode = IsServiceUriExist( aServiceURI, myRootNode);
       
   617     if (serviceUriNode==NULL)
       
   618         return KErrNotFound;
       
   619     
       
   620     iListPointerPath.Reset();
       
   621     iListPath->Reset();
       
   622     
       
   623     iListPointerPath.Append(serviceUriNode); // append pointer to node
       
   624     iListPath->AppendL(aServiceURI); // append new list path
       
   625     return KErrNone;		
       
   626 	}
       
   627 
       
   628 // ---------------------------------------------------------------------------
       
   629 // CRLSXDM::SwitchToList()
       
   630 // ---------------------------------------------------------------------------
       
   631 //	
       
   632 EXPORT_C TInt CRLSXDM::SwitchToListL(const TDesC& aListName)
       
   633 	{
       
   634 	OPENG_DP(D_OPENG_LIT( "CRLSXDM::SwitchToList(%S)" ),&aListName);
       
   635 	TInt err(KErrNotFound);
       
   636 	TInt count = iListPointerPath.Count();
       
   637 	if (count)
       
   638 	    {
       
   639 	    CXdmDocumentNode* list = GetNonLeafChild(KXdmList,aListName,
       
   640                                                     iListPointerPath[count-1]);
       
   641 	    if (list) // if found
       
   642 	        {
       
   643     	    iListPointerPath.Append(list); // append pointer to node
       
   644             iListPath->AppendL(aListName); // append new list path
       
   645             err = KErrNone;
       
   646 	        }
       
   647         }
       
   648     OPENG_DP(D_OPENG_LIT( "     returned: %d" ),err);    
       
   649     return err;        
       
   650 	}
       
   651 
       
   652 // ---------------------------------------------------------------------------
       
   653 // CRLSXDM::SwitchOutFromList()
       
   654 // ---------------------------------------------------------------------------
       
   655 //	
       
   656 EXPORT_C void CRLSXDM::SwitchOutFromList()
       
   657 	{
       
   658 	OPENG_DP(D_OPENG_LIT( "CRLSXDM::SwitchOutFromList" ));
       
   659 	TInt count = iListPath->Count();
       
   660 	if(count) // if some path exist
       
   661         {
       
   662         iListPath->Delete(count-1); // remove last list name
       
   663         iListPointerPath.Remove(count-1); // remove last node pointer
       
   664         OPENG_DP(D_OPENG_LIT( "     switched out" ));
       
   665         }
       
   666 	}
       
   667 
       
   668 // ---------------------------------------------------------------------------
       
   669 // CRLSXDM::GetCurrentPathL()
       
   670 // ---------------------------------------------------------------------------
       
   671 //	
       
   672 EXPORT_C void CRLSXDM::GetCurrentPathL(CDesCArray& aPath)
       
   673 	{
       
   674 	OPENG_DP(D_OPENG_LIT( "CRLSXDM::GetCurrentPath" ));
       
   675 	aPath.Reset();
       
   676 	TInt count = iListPath->Count();
       
   677     for (TInt i=0;i<count;i++)
       
   678         {
       
   679         aPath.AppendL(iListPath->MdcaPoint(i));
       
   680         }
       
   681     OPENG_DP(D_OPENG_LIT( "     aPathCount = %d" ),aPath.Count());
       
   682 	}
       
   683 	
       
   684 // ---------------------------------------------------------------------------
       
   685 // CRLSXDM::SetCurrentpath()
       
   686 // ---------------------------------------------------------------------------
       
   687 //
       
   688 EXPORT_C TInt CRLSXDM::SetCurrentpathL(const MDesCArray& aLists)
       
   689 	{
       
   690 	OPENG_DP(D_OPENG_LIT( "CRLSXDM::SetCurrentpath" ));
       
   691     CXdmDocumentNode* myRootNode = iRLSDocument->DocumentRoot();
       
   692     if (myRootNode==NULL)
       
   693         return KErrNotFound;
       
   694     
       
   695     CXdmDocumentNode* serviceUriNode(NULL);
       
   696     
       
   697     TInt count = aLists.MdcaCount();
       
   698 
       
   699     if(count) // if there is atleast one element(service-uri) in path info
       
   700         {
       
   701         serviceUriNode = IsServiceUriExist( aLists.MdcaPoint(0), myRootNode);
       
   702         if (serviceUriNode==NULL)
       
   703             {
       
   704             OPENG_DP(D_OPENG_LIT( "     service-uri doesnt exist:%d" ),KErrNotFound);
       
   705             return KErrNotFound;
       
   706             }
       
   707         }
       
   708     
       
   709     RPointerArray<CXdmDocumentNode> confirmedNodes;
       
   710     
       
   711     CXdmDocumentNode* currentNode = serviceUriNode;
       
   712     confirmedNodes.Append(currentNode);
       
   713     
       
   714     if(count>1) // if some list(s) exist in path info
       
   715         {
       
   716         for (TInt i=1; i<count; i++)
       
   717             {
       
   718             currentNode = GetNonLeafChild(KXdmList, aLists.MdcaPoint(i),
       
   719                                                                      currentNode);
       
   720             if (currentNode==NULL)
       
   721                 {
       
   722                 confirmedNodes.Close();
       
   723                 OPENG_DP(D_OPENG_LIT( "     path incorrect at i:%d" ),i);
       
   724                 return KErrNotFound;
       
   725                 }
       
   726             confirmedNodes.Append(currentNode);
       
   727             }
       
   728         }
       
   729     
       
   730     // since path is verified, update local path variables
       
   731     OPENG_DP(D_OPENG_LIT( "     pathFound" ));
       
   732     iListPath->Reset();
       
   733     iListPointerPath.Reset();
       
   734     for (TInt j=0;j<count;j++)
       
   735         {
       
   736         iListPath->AppendL(aLists.MdcaPoint(j));
       
   737         iListPointerPath.Append(confirmedNodes[j]);
       
   738         }
       
   739     
       
   740     confirmedNodes.Close();    
       
   741     return KErrNone;
       
   742 	}
       
   743 
       
   744 // ---------------------------------------------------------------------------
       
   745 // CRLSXDM::IsServiceUriExist()
       
   746 // ---------------------------------------------------------------------------
       
   747 //	
       
   748 CXdmDocumentNode* CRLSXDM::IsServiceUriExist(const TDesC& uriAttr,
       
   749                                             CXdmDocumentNode* aRootNode)
       
   750     {
       
   751     OPENG_DP(D_OPENG_LIT( " CRLSXDM::IsServiceUriExist" ));
       
   752     // Find all service nodes in this root
       
   753     RPointerArray<CXdmDocumentNode> serviceNodes;
       
   754     TInt err= aRootNode->Find( KXdmService, serviceNodes);
       
   755     if (err != KErrNone) // return if no service nodes found
       
   756         {
       
   757         serviceNodes.Close();
       
   758         return NULL;    
       
   759         }
       
   760         
       
   761     TInt serviceNodesCounts = serviceNodes.Count();
       
   762     CXdmDocumentNode* desiredNode(NULL);
       
   763     // Go through all service nodes
       
   764     for(TInt i=0; i<serviceNodesCounts;i++)
       
   765         {
       
   766         CXdmNodeAttribute* UriAttr = (serviceNodes[i])->Attribute(KXdmUri);
       
   767         // if URI value is same
       
   768         if (UriAttr->AttributeValue() == uriAttr)
       
   769             {
       
   770             desiredNode = serviceNodes[i];
       
   771             OPENG_DP(D_OPENG_LIT( " CRLSXDM: Found" ));              
       
   772             break;
       
   773             }
       
   774         }
       
   775     serviceNodes.Close();
       
   776     return desiredNode;
       
   777     }
       
   778     
       
   779 // ---------------------------------------------------------------------------
       
   780 // CRLSXDM::GetNonLeafChild()
       
   781 // ---------------------------------------------------------------------------
       
   782 //
       
   783 CXdmDocumentNode* CRLSXDM::GetNonLeafChild(const TDesC& aChildName,
       
   784                                     const TDesC& aAttrValue,
       
   785                                     CXdmDocumentNode* const aTargetNode)
       
   786     {
       
   787     OPENG_DP(D_OPENG_LIT( " CRLSXDM::GetNonLeafChild" ));
       
   788     OPENG_DP(D_OPENG_LIT( "  aChildName:%S, aAttrValue:%S"),
       
   789                                        &aChildName, &aAttrValue);
       
   790     CXdmDocumentNode* currentNode = aTargetNode;
       
   791     RPointerArray<CXdmDocumentNode> nodes;
       
   792     CXdmDocumentNode* desiredNode(NULL);
       
   793     CXdmNodeAttribute* attr(NULL);
       
   794     TBuf<KPresRLSElemAttrNameLen> attrName;
       
   795     
       
   796     GetNonLeafElementAttrName(aChildName, attrName);
       
   797     
       
   798     // Find all childs under currentNode
       
   799     if ((currentNode->Find(aChildName, nodes)) == KErrNone)
       
   800         { // go through all found childs
       
   801         TInt givenChildCountInNode = nodes.Count();
       
   802         OPENG_DP(D_OPENG_LIT( " GetNonLeafChild: givenChildCountInNode = %d" ),
       
   803                                                          givenChildCountInNode);
       
   804         for (TInt k=0;k<givenChildCountInNode;k++)
       
   805             { // get the attribute
       
   806             attr = (nodes[k])->Attribute(attrName);
       
   807             // match it with given attr
       
   808             if (attr->AttributeValue() == aAttrValue)
       
   809                 {
       
   810                 desiredNode = nodes[k];
       
   811                 break;
       
   812                 }
       
   813             }
       
   814         }
       
   815     nodes.Close();
       
   816     return desiredNode;        
       
   817     }
       
   818     
       
   819 
       
   820 // ---------------------------------------------------------------------------
       
   821 // CRLSXDM::GetLeafChild()
       
   822 // ---------------------------------------------------------------------------
       
   823 //    
       
   824 CXdmDocumentNode* CRLSXDM::GetLeafChild(const TDesC& aChildName,
       
   825                 const TDesC& aValue, CXdmDocumentNode* const aTargetNode)
       
   826     {
       
   827     OPENG_DP(D_OPENG_LIT( " CRLSXDM::IsResListExist" ));
       
   828     OPENG_DP(D_OPENG_LIT( " aChildName:%S, aValue:%S" ), &aChildName, &aValue);
       
   829     CXdmDocumentNode* currentNode = aTargetNode;
       
   830     RPointerArray<CXdmDocumentNode> nodes;
       
   831     CXdmDocumentNode* desiredNode(NULL);
       
   832     HBufC* nodeContents(NULL);
       
   833     
       
   834     // Find all leaf children under currentNode
       
   835     if ((currentNode->Find(aChildName, nodes)) == KErrNone)
       
   836         { // go through all found children
       
   837         TInt childCountInNode = nodes.Count();
       
   838         OPENG_DP(D_OPENG_LIT( " GetLeafChild: childCountInNode = %d" ), 
       
   839                                                         childCountInNode);
       
   840         for (TInt k=0;k<childCountInNode;k++)
       
   841             { // get the leaf node content
       
   842             nodeContents = CnvUtfConverter::ConvertToUnicodeFromUtf8L
       
   843                                             ((nodes[k])->LeafNodeContent());
       
   844             // match it with given contents
       
   845             if (nodeContents->Des() == aValue)
       
   846                 {
       
   847                 desiredNode = nodes[k];
       
   848                 delete nodeContents;
       
   849                 break;
       
   850                 }
       
   851             delete nodeContents;    
       
   852             }
       
   853         }
       
   854     nodes.Close();
       
   855     return desiredNode;        
       
   856     }
       
   857     
       
   858 // ---------------------------------------------------------------------------
       
   859 // CRLSXDM::AddNonLeafElementL()
       
   860 // ---------------------------------------------------------------------------
       
   861 // 
       
   862 void CRLSXDM::AddNonLeafElementL(const TDesC& aElementType, 
       
   863                         const TDesC& aData, const TDesC& aDisplayName,
       
   864                                 CXdmDocumentNode* const aTargetNode)
       
   865     {
       
   866 	OPENG_DP(D_OPENG_LIT( " CRLSXDM::AddNonLeafElementL" ));
       
   867 	OPENG_DP(D_OPENG_LIT( "     aElementType(%S), aData(%S), aDisplayName(%S)"),
       
   868 	                                &aElementType,&aData,&aDisplayName);
       
   869 	                                
       
   870     TBuf<KPresRLSElemAttrNameLen> attrName;
       
   871     
       
   872     GetNonLeafElementAttrName(aElementType, attrName);
       
   873                                 
       
   874 	
       
   875     CXdmDocumentNode* myNode = aTargetNode->CreateChileNodeL(aElementType);
       
   876     CXdmNodeAttribute* myAttribute = myNode->CreateAttributeL(attrName);
       
   877     myAttribute->SetAttributeValueL(aData);
       
   878     
       
   879     if (aDisplayName!=KNullDesC) // if a display name is provided
       
   880         {
       
   881         CXdmDocumentNode* myDispName = myNode->CreateChileNodeL(KXdmDisplayName);
       
   882         myDispName->SetLeafNode(ETrue);
       
   883         myDispName->SetLeafNodeContentL(aDisplayName);
       
   884         }
       
   885     OPENG_DP(D_OPENG_LIT( "     NonLeafElement added" ));
       
   886     }
       
   887    
       
   888 // ---------------------------------------------------------------------------
       
   889 // CRLSXDM::AddLeafElementL()
       
   890 // ---------------------------------------------------------------------------
       
   891 // 
       
   892 void CRLSXDM::AddLeafElementL(const TDesC& aElementType, const TDesC& aData,
       
   893                                     CXdmDocumentNode* const aTargetNode)
       
   894     {
       
   895 	OPENG_DP(D_OPENG_LIT( " CRLSXDM::AddLeafElementL" ));
       
   896 	OPENG_DP(D_OPENG_LIT( "     aElementType(%S), aData(%S)"),
       
   897 	                                            &aElementType, &aData);
       
   898 	
       
   899     CXdmDocumentNode* myNode = aTargetNode->CreateChileNodeL(aElementType);
       
   900     myNode->SetLeafNode(ETrue);
       
   901     myNode->SetLeafNodeContentL(aData);
       
   902     OPENG_DP(D_OPENG_LIT( "     AddLeafElementL added" ));
       
   903     }
       
   904 
       
   905 // ---------------------------------------------------------------------------
       
   906 // CRLSXDM::GetDisplayNameInt()
       
   907 // ---------------------------------------------------------------------------
       
   908 // 
       
   909 TInt CRLSXDM::GetDisplayNameInt(const TDesC& aElementType,
       
   910                         const TDesC& aData, TPtrC8& aDisplayName,
       
   911                                 CXdmDocumentNode* const aTargetNode)
       
   912     {
       
   913 	OPENG_DP(D_OPENG_LIT( " CRLSXDM::GetDisplayName" ));
       
   914 	OPENG_DP(D_OPENG_LIT( "     aElementType(%S),aData(%S)" )
       
   915 	                                    ,&aElementType, &aData);
       
   916 	
       
   917 	TInt err(KErrNotFound);
       
   918 	
       
   919 	RPointerArray<CXdmDocumentNode> nodes;
       
   920     TBuf<KPresRLSElemAttrNameLen> attrName;
       
   921     
       
   922     GetNonLeafElementAttrName(aElementType, attrName);
       
   923 
       
   924     CXdmDocumentNode* myNode = GetNonLeafChild(aElementType, aData,
       
   925                                                             aTargetNode);
       
   926     if (myNode) // if found
       
   927         {
       
   928         // Find display name node
       
   929         if ( (myNode->Find(KXdmDisplayName, nodes)) == KErrNone)
       
   930             {
       
   931             TInt nodeCountInNode = nodes.Count();
       
   932             OPENG_DP(D_OPENG_LIT( "     nodeCountInNode(%d)" ),nodeCountInNode);
       
   933             if(nodeCountInNode==1)// should be one node that of dispname
       
   934                 {
       
   935                 CXdmDocumentNode* dispNameNode = myNode->ChileNode(0);
       
   936                 dispNameNode->SetLeafNode(ETrue);
       
   937                 aDisplayName.Set(dispNameNode->LeafNodeContent());
       
   938                 err = KErrNone;
       
   939                 }    
       
   940             }
       
   941         }    
       
   942     
       
   943     nodes.Close();
       
   944     return err;     
       
   945     }
       
   946 
       
   947 // ---------------------------------------------------------------------------
       
   948 // CRLSXDM::UpdateDisplayNameIntL()
       
   949 // ---------------------------------------------------------------------------
       
   950 // 
       
   951 TInt CRLSXDM::UpdateDisplayNameIntL(const TDesC& aElementType, 
       
   952                         const TDesC& aData, const TDesC& aDisplayName,
       
   953                                 CXdmDocumentNode* const aTargetNode)
       
   954     {
       
   955 	OPENG_DP(D_OPENG_LIT( " CRLSXDM::UpdateDisplayNameL" ));
       
   956 	OPENG_DP(D_OPENG_LIT( "     aElementType(%S),aData(%S),aDisplayName(%S)" )
       
   957 	                                    ,&aElementType,&aData, &aDisplayName);
       
   958 	                                    
       
   959     TBuf<KPresRLSElemAttrNameLen> attrName;
       
   960     
       
   961     GetNonLeafElementAttrName(aElementType, attrName);
       
   962 
       
   963     CXdmDocumentNode* myNode = GetNonLeafChild(aElementType, aData, aTargetNode);
       
   964     if (myNode==NULL) // if found
       
   965         return KErrNotFound;
       
   966     
       
   967     
       
   968     myNode->SetEmptyNode(ETrue); // delete all children from this
       
   969     myNode->SetEmptyNode(EFalse);
       
   970     CXdmDocumentNode* myDispName = myNode->CreateChileNodeL(KXdmDisplayName);
       
   971     myDispName->SetLeafNode(ETrue);
       
   972     myDispName->SetLeafNodeContentL(aDisplayName);
       
   973     OPENG_DP(D_OPENG_LIT( "     updated" ));
       
   974     return KErrNone;
       
   975     }
       
   976 
       
   977 // ---------------------------------------------------------------------------
       
   978 // CRLSXDM::GetNonLeafElementsL()
       
   979 // ---------------------------------------------------------------------------
       
   980 // 
       
   981 void CRLSXDM::GetNonLeafElementsL(const TDesC& aElementType,
       
   982             CDesCArray& aValues, CXdmDocumentNode* const aTargetNode)
       
   983     {
       
   984 	OPENG_DP(D_OPENG_LIT( " CRLSXDM::GetNonLeafElementsL" ));
       
   985 	OPENG_DP(D_OPENG_LIT( "     aElementType(%S)"),&aElementType);
       
   986 
       
   987     RPointerArray<CXdmDocumentNode> nodes;
       
   988     CXdmNodeAttribute* attribute(NULL);
       
   989     
       
   990     TBuf<KPresRLSElemAttrNameLen> attrName;
       
   991     GetNonLeafElementAttrName(aElementType, attrName);
       
   992     
       
   993     // Find all elements under currentNode
       
   994     if ((aTargetNode->Find(aElementType, nodes)) == KErrNone)
       
   995         { // go through all found nodes
       
   996         TInt nodeCountInNode = nodes.Count();
       
   997         OPENG_DP(D_OPENG_LIT( "     nodeCountInNode(%d)" ),nodeCountInNode);
       
   998         for (TInt k=0;k<nodeCountInNode;k++)
       
   999             { // get the aAttr attribute
       
  1000             attribute = (nodes[k])->Attribute(attrName);
       
  1001             // push it to given discriptor array
       
  1002             aValues.AppendL(attribute->AttributeValue());
       
  1003             }
       
  1004         }
       
  1005         
       
  1006     nodes.Close();
       
  1007     }
       
  1008             
       
  1009 // ---------------------------------------------------------------------------
       
  1010 // CRLSXDM::GetLeafElementsL()
       
  1011 // ---------------------------------------------------------------------------
       
  1012 // 
       
  1013 void CRLSXDM::GetLeafElementsL(const TDesC& aElementType, CDesCArray& aValues, 
       
  1014                                 CXdmDocumentNode* const aTargetNode)
       
  1015     {
       
  1016     OPENG_DP(D_OPENG_LIT( " CRLSXDM::GetLeafElementsL(%S)" ), &aElementType);
       
  1017 
       
  1018     RPointerArray<CXdmDocumentNode> nodes;
       
  1019     HBufC* nodeContents(NULL);
       
  1020     
       
  1021     // Find all leaf children under currentNode
       
  1022     if ((aTargetNode->Find(aElementType, nodes)) == KErrNone)
       
  1023         { // go through all found children
       
  1024         TInt childCountInNode = nodes.Count();
       
  1025         OPENG_DP(D_OPENG_LIT( " GetLeafElementsL: childCountInNode = %d" ), 
       
  1026                                                         childCountInNode);
       
  1027         for (TInt k=0;k<childCountInNode;k++)
       
  1028             { // get the leaf node content
       
  1029             nodeContents = CnvUtfConverter::ConvertToUnicodeFromUtf8L
       
  1030                                             ((nodes[k])->LeafNodeContent());
       
  1031             CleanupStack::PushL(nodeContents);
       
  1032             aValues.AppendL(nodeContents->Des());
       
  1033             CleanupStack::PopAndDestroy(nodeContents);                                
       
  1034             }
       
  1035         }
       
  1036     nodes.Close();
       
  1037     }
       
  1038     
       
  1039     
       
  1040 // ---------------------------------------------------------------------------
       
  1041 // CRLSXDM::ValidateAndGetAttrName()
       
  1042 // ---------------------------------------------------------------------------
       
  1043 //    
       
  1044 void CRLSXDM::GetNonLeafElementAttrName(const TDesC& aElementName,
       
  1045                                                             TDes& aAttrName)
       
  1046     {
       
  1047     OPENG_DP(D_OPENG_LIT( " CRLSXDM::ValidateAndGetAttrName" ));
       
  1048     OPENG_DP(D_OPENG_LIT( " aElementName:%S, aAttrName:%S" ), 
       
  1049                                                     &aElementName, &aAttrName);
       
  1050     if (aElementName == KPresList)
       
  1051         {
       
  1052         aAttrName.Copy(KXdmName);
       
  1053         }
       
  1054     else if (aElementName == KPresEntry)
       
  1055         {
       
  1056         aAttrName.Copy(KXdmUri);
       
  1057         }
       
  1058     else if (aElementName == KPresExternal)
       
  1059         {
       
  1060         aAttrName.Copy(KXdmAnchor);
       
  1061         }
       
  1062     else if (aElementName == KPresEntryRef)
       
  1063         {
       
  1064         aAttrName.Copy(KXdmRef);
       
  1065         }
       
  1066     }
       
  1067     
       
  1068 // ---------------------------------------------------------------------------
       
  1069 // CRLSXDM::IsNonLeafElementValid()
       
  1070 // ---------------------------------------------------------------------------
       
  1071 //    
       
  1072 TBool CRLSXDM::IsNonLeafElementValid(const TDesC& aElementName)
       
  1073     {
       
  1074     OPENG_DP(D_OPENG_LIT( " CRLSXDM::IsNonLeafElementValid" ));
       
  1075     OPENG_DP(D_OPENG_LIT( " aElementName:%S"), &aElementName);
       
  1076     TBool err(EFalse);
       
  1077     
       
  1078     if ( (aElementName == KPresList)||(aElementName == KPresEntry)||
       
  1079             (aElementName == KPresExternal)||(aElementName == KPresEntryRef))
       
  1080         err = ETrue;
       
  1081 
       
  1082     OPENG_DP(D_OPENG_LIT( "     return: %d" ), err);
       
  1083     return err;    
       
  1084     }
       
  1085     
       
  1086 // ---------------------------------------------------------------------------
       
  1087 // CRLSXDM::AddPackageL()
       
  1088 // ---------------------------------------------------------------------------
       
  1089 //    
       
  1090 void CRLSXDM::AddPackageL()
       
  1091     {
       
  1092     OPENG_DP(D_OPENG_LIT( " CRLSXDM::AddPackage()" ));
       
  1093     RPointerArray<CXdmDocumentNode> nodes;
       
  1094 	TInt count = iListPointerPath.Count();
       
  1095 	if (count)
       
  1096 	    {
       
  1097         // now add the packages
       
  1098         CXdmDocumentNode* packagesNode = iListPointerPath[0]->CreateChileNodeL(KXdmPackages);
       
  1099         CXdmDocumentNode* packageNode = packagesNode->CreateChileNodeL(KXdmPackage);
       
  1100         packageNode->SetLeafNode(ETrue);
       
  1101         packageNode->SetLeafNodeContentL(KXdmPresence);
       
  1102         }
       
  1103     }
       
  1104 
       
  1105 // ---------------------------------------------------------------------------
       
  1106 // CRLSXDM::RemovePackageL()
       
  1107 // ---------------------------------------------------------------------------
       
  1108 //    
       
  1109 void CRLSXDM::RemovePackageL()
       
  1110     {
       
  1111     OPENG_DP(D_OPENG_LIT( " CRLSXDM::RemovePackage()" ));
       
  1112     RPointerArray<CXdmDocumentNode> nodes;
       
  1113 	TInt count = iListPointerPath.Count();
       
  1114 	if (count)
       
  1115 	    {
       
  1116         if (((iListPointerPath[0])->Find(KXdmPackages, nodes)) == KErrNone)
       
  1117             {
       
  1118             TInt nodeCount = nodes.Count();
       
  1119             OPENG_DP(D_OPENG_LIT( "     RemovePackage: nodeCount = %d" ), nodeCount);
       
  1120             if(nodeCount) //if package found
       
  1121                 {
       
  1122                 iRLSDocument->RemoveFromModelL(nodes[0]);
       
  1123                 OPENG_DP(D_OPENG_LIT( "     removed" ));                
       
  1124                 }
       
  1125             }
       
  1126         }
       
  1127     nodes.Close();
       
  1128     }
       
  1129     
       
  1130 // ---------------------------------------------------------------------------
       
  1131 // CRLSXDM::DeleteEmptyListsL()
       
  1132 // ---------------------------------------------------------------------------
       
  1133 //    
       
  1134 void CRLSXDM::DeleteEmptyListsL()
       
  1135     {
       
  1136     OPENG_DP(D_OPENG_LIT( " CRLSXDM::DeleteEmptyLists" ));
       
  1137     RPointerArray<CXdmDocumentNode> listNodes;
       
  1138     
       
  1139     TInt found = iRLSDocument->Find( KXdmList, listNodes);
       
  1140     OPENG_DP(D_OPENG_LIT( "     total Uris: %d" ), found);
       
  1141     for (TInt i=0;i<found;i++)
       
  1142         {
       
  1143         if ( ((listNodes[i])->NodeCount()) < 2)// one child can be of display-name
       
  1144                                                // otherwise list is empty
       
  1145             {
       
  1146             if ( ((listNodes[i])->NodeCount()) == 1) // if possibly disp-name present
       
  1147                 {
       
  1148                 if (((listNodes[i])->ChileNode(0)->NodeName()) != KXdmDisplayName)
       
  1149                     continue; // if the one found node is not display name
       
  1150                               // then the list is not empty
       
  1151                 }
       
  1152             iRLSDocument->RemoveFromModelL(listNodes[i]);
       
  1153             OPENG_DP(D_OPENG_LIT( "     delete at i = %d" ), i);
       
  1154             listNodes.Close();
       
  1155             return; // we are deleting one by one because we dont know
       
  1156                     // the hirarchy
       
  1157             }
       
  1158         }
       
  1159     listNodes.Close();    
       
  1160     iAsyncReq = ERLSXDMDeletedEmptyLists;
       
  1161     }
       
  1162 
       
  1163 // ---------------------------------------------------------------------------
       
  1164 // CRLSXDM::DoCancel()
       
  1165 // ---------------------------------------------------------------------------
       
  1166 //    
       
  1167 void CRLSXDM::DoCancel()
       
  1168     {
       
  1169     OPENG_DP(D_OPENG_LIT( " CRLSXDM::DoCancel" ));
       
  1170     iXDMEngine->CancelUpdate(iRLSDocument);
       
  1171     iAsyncReq = ERLSXDMRequestCancelling;      
       
  1172     }
       
  1173 
       
  1174 // ---------------------------------------------------------------------------
       
  1175 // CRLSXDM::RunL()
       
  1176 // ---------------------------------------------------------------------------
       
  1177 //    
       
  1178 void CRLSXDM::RunL()
       
  1179     {
       
  1180     OPENG_DP(D_OPENG_LIT( " CRLSXDM::RunL" ));
       
  1181     OPENG_DP(D_OPENG_LIT( "     RunL iAsyncReq(%d), iStatus(%d)" ),iAsyncReq,
       
  1182                                                                  iStatus.Int());
       
  1183                                                                                      
       
  1184     TRequestStatus* status = &iStatus;
       
  1185     TInt origStatus = iStatus.Int();
       
  1186                                                                  
       
  1187     switch (iAsyncReq)
       
  1188         {
       
  1189         case ERLSXDMUpdateToServer:
       
  1190             
       
  1191             if ( origStatus == KXcapErrorHttpConflict )
       
  1192                 {
       
  1193                 TRAP_IGNORE( DoParseNegotiatedServiceUriL( iRLSDocument->ErrorRoot() ));
       
  1194                 }
       
  1195             else
       
  1196                 {
       
  1197                 delete iNegotiatedServiceUri;
       
  1198                 iNegotiatedServiceUri = NULL;
       
  1199                 }                           
       
  1200                         
       
  1201             iAsyncReq = ERLSXDMNoRequestMade;                        
       
  1202             TRAP_IGNORE( iAsyncHandler->HandleRLSUpdateDocumentL( origStatus ));
       
  1203             break;
       
  1204         case ERLSXDMUpdateFromServer:
       
  1205             CreateRootIfNeededL();
       
  1206             iAsyncReq = ERLSXDMNoRequestMade;               
       
  1207             if( origStatus == KXcapErrorHttpNotFound) // if doc not on server
       
  1208                 {                                
       
  1209                 TRAP_IGNORE (iAsyncHandler->HandleRLSUpdateDocumentL(KErrNotFound));
       
  1210                 }
       
  1211             else
       
  1212                 {                                
       
  1213                 TRAP_IGNORE( iAsyncHandler->HandleRLSUpdateDocumentL( origStatus ));
       
  1214                 }
       
  1215             break;
       
  1216             
       
  1217         case ERLSXDMDeletingEmptyLists:
       
  1218             DeleteEmptyListsL();
       
  1219             User::RequestComplete(status,KErrNone);
       
  1220             SetActive();
       
  1221             break;
       
  1222                 
       
  1223         case ERLSXDMDeletedEmptyLists:
       
  1224             iAsyncReq = ERLSXDMNoRequestMade;        
       
  1225             TRAP_IGNORE( iAsyncHandler->HandleRLSDeleteAllEmptyListsL( origStatus ));
       
  1226             break;
       
  1227             
       
  1228         case ERLSXDMRequestCancelling:
       
  1229             iAsyncReq = ERLSXDMNoRequestMade;         
       
  1230             TRAP_IGNORE( iAsyncHandler->HandleRLSUpdateCancelL( origStatus ));  
       
  1231             break;
       
  1232 
       
  1233         case ERLSXDMNoRequestMade:
       
  1234         default:
       
  1235             break;
       
  1236         }
       
  1237     }
       
  1238 
       
  1239 // ---------------------------------------------------------------------------
       
  1240 // CRLSXDM::RunError()
       
  1241 // ---------------------------------------------------------------------------
       
  1242 //    
       
  1243 TInt CRLSXDM::RunError(TInt aError)
       
  1244     {
       
  1245     OPENG_DP(D_OPENG_LIT( " CRLSXDM::RunError" ));
       
  1246     OPENG_DP(D_OPENG_LIT( "     RunError iAsyncReq(%d), aError(%d)" ),iAsyncReq,
       
  1247                                                                         aError);
       
  1248     // A show must go on, we coomplete the failed current client request. 
       
  1249     TRequestStatus* status = &iStatus;                                                                       
       
  1250     iAsyncReq = ERLSXDMNoRequestMade;                                                                        
       
  1251     User::RequestComplete( status, aError );                                                                        
       
  1252     
       
  1253     return KErrNone;
       
  1254     }
       
  1255     
       
  1256 // ---------------------------------------------------------------------------
       
  1257 // CRLSXDM::NegotiatedServiceUri()
       
  1258 // ---------------------------------------------------------------------------
       
  1259 //     
       
  1260 EXPORT_C TPtrC CRLSXDM::NegotiatedServiceUri()
       
  1261     {
       
  1262     return iNegotiatedServiceUri ? iNegotiatedServiceUri->Des() : TPtrC();
       
  1263     }    
       
  1264 	
       
  1265 // ---------------------------------------------------------------------------
       
  1266 // CRLSXDM::DoParseNegotiatedServiceUriL
       
  1267 // ---------------------------------------------------------------------------
       
  1268 //	
       
  1269 void CRLSXDM::DoParseNegotiatedServiceUriL( CXdmDocumentNode* aErrorBody )
       
  1270     {
       
  1271     _LIT( KMyXcapError, "xcap-error");        
       
  1272     _LIT( KMyUniquenessFailure, "uniqueness-failure");
       
  1273     _LIT( KMyExists, "exists");  
       
  1274     _LIT( KMyField, "field"); 
       
  1275     _LIT( KMyAltValue, "alt-value");  
       
  1276         
       
  1277     delete iNegotiatedServiceUri;
       
  1278     iNegotiatedServiceUri = NULL;
       
  1279 
       
  1280     if ( !aErrorBody )
       
  1281         {
       
  1282         return;
       
  1283         } 
       
  1284         
       
  1285     // Parse the content
       
  1286     // For example
       
  1287     // ------------    
       
  1288     /*
       
  1289     <?xml version="1.0" encoding="UTF-8"?>
       
  1290     <xcap-error xmlns="urn:oma:xml:xdm:xcap-error">
       
  1291         <uniqueness-failure>
       
  1292             <exists field="rls-services/service%5b1%5d/@uri">
       
  1293                 <alt-value>sip:tu30@poc.nokia.com;omapresencer1rls=5425</alt-value>
       
  1294             </exists>
       
  1295         </uniqueness-failure>
       
  1296     </xcap-error>
       
  1297     // ------------  
       
  1298     */         
       
  1299         
       
  1300     if ( aErrorBody->NodeName().Compare( KMyXcapError ))
       
  1301         {
       
  1302         return;
       
  1303         }
       
  1304     
       
  1305     RPointerArray<CXdmDocumentNode> resultArray;
       
  1306     CleanupClosePushL( resultArray );           // <<< resultArray
       
  1307             
       
  1308     CXdmDocumentNode* currNode = aErrorBody;
       
  1309     resultArray.Reset();
       
  1310     
       
  1311     resultArray.Reset();        
       
  1312     currNode->Find( KMyUniquenessFailure, resultArray );
       
  1313     if ( resultArray.Count() > 0)
       
  1314         {
       
  1315         currNode = resultArray[0];            
       
  1316         }
       
  1317     else
       
  1318         {
       
  1319         User::Leave( KErrNotFound );
       
  1320         }     
       
  1321             
       
  1322     resultArray.Reset();        
       
  1323     currNode->Find( KMyExists, resultArray );
       
  1324     if ( resultArray.Count() > 0)
       
  1325         {
       
  1326         currNode = resultArray[0];
       
  1327         if ( !(currNode->HasAttribute( KMyField ) )) 
       
  1328             {
       
  1329             // notice: We do not check the content of "field" attribute, 
       
  1330             // we trust that it is ok and refers to the last modified data.
       
  1331             User::Leave( KErrNotFound );
       
  1332             }             
       
  1333         }
       
  1334     else
       
  1335         {
       
  1336         User::Leave( KErrNotFound );
       
  1337         }    
       
  1338         
       
  1339     resultArray.Reset();        
       
  1340     currNode->Find( KMyAltValue, resultArray );
       
  1341     if ( resultArray.Count() > 0)
       
  1342         {
       
  1343         currNode = resultArray[0];    
       
  1344         }
       
  1345     else
       
  1346         {
       
  1347         User::Leave( KErrNotFound );
       
  1348         }     
       
  1349        
       
  1350     TPtrC8 pCon = currNode->LeafNodeContent();
       
  1351        
       
  1352     // Convert <alt-value> value to Unicode.
       
  1353     iNegotiatedServiceUri = CnvUtfConverter::ConvertToUnicodeFromUtf8L( pCon );           
       
  1354 
       
  1355     CleanupStack::PopAndDestroy( &resultArray );   // >>> resultArray   
       
  1356                 
       
  1357     }    
       
  1358 
       
  1359 // end of file