xdmprotocols/XcapProtocol/XcapAppUsage/src/XcapAppUsage.cpp
changeset 0 c8caa15ef882
equal deleted inserted replaced
-1:000000000000 0:c8caa15ef882
       
     1 /*
       
     2 * Copyright (c) 2005 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: CXcapAppUsage
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #ifdef _DEBUG
       
    24 #include <flogger.h>
       
    25 #endif
       
    26 
       
    27 #include <implementationproxy.h>
       
    28 
       
    29 #include "XcapAppUsageDef.h"
       
    30 
       
    31 #include "XcapDirectoryUsage.h"
       
    32 #include "XcapCapabilityUsage.h"
       
    33 #include "XcapPocGroupUsage.h"
       
    34 #include "XcapPocUserAccessUsage.h"
       
    35 #include "XcapSharedXDMUsage.h"
       
    36 #include "XcapRlsServicesUsage.h"
       
    37 #include "XcapResourceListsUsage.h"
       
    38 #include "XcapIetfCommonPolicyUsage.h"
       
    39 #include "XcapOmaCommonPolicyUsage.h"
       
    40 #include "XcapIetfPresRulesUsage.h"
       
    41 #include "XcapOmaPresRulesUsage.h"
       
    42 // Add the header of the new app usage here
       
    43 // #include "XcapTestAppUsage.h"
       
    44 // PRES-CONTENT STARTS
       
    45 #include "XcapC4.h"
       
    46 // PRES-CONTENT ENDS
       
    47 
       
    48 #include <XdmErrors.h>
       
    49 #include <XdmProtocolUidList.h>
       
    50 #include <XdmDocumentNode.h>
       
    51 #include <XdmNodeAttribute.h>
       
    52 #include "XcapUriInterface.h"
       
    53 
       
    54 
       
    55     
       
    56 // CONSTANTS
       
    57 // Map the interface UIDs to implementation factory functions
       
    58 const TImplementationProxy ImplementationTable[] = 
       
    59 	{
       
    60 #ifdef __EABI__  
       
    61 	IMPLEMENTATION_PROXY_ENTRY( KXdmCapabilityUsageUid, CXcapCapabilityUsage::NewL ),
       
    62 	IMPLEMENTATION_PROXY_ENTRY( KXdmDirectoryUsageUid,  CXcapDirectoryUsage::NewL ),
       
    63 	IMPLEMENTATION_PROXY_ENTRY( KXdmPocGroupUsageUid,   CXcapPocGroupUsage::NewL ),
       
    64 	IMPLEMENTATION_PROXY_ENTRY( KXdmPocUserAccessUsageUid,  CXcapPocUserAccessUsage::NewL ),
       
    65 	IMPLEMENTATION_PROXY_ENTRY( KXdmSharedXDMUsageUid,  CXcapSharedXDMUsage::NewL ),
       
    66 	IMPLEMENTATION_PROXY_ENTRY( KXdmRlsServicesUsageUid,    CXcapRlsServicesUsage::NewL ),
       
    67 	IMPLEMENTATION_PROXY_ENTRY( KXdmResourceListsUsageUid,  CXcapResourceListsUsage::NewL ),
       
    68 	IMPLEMENTATION_PROXY_ENTRY( KXdmIetfCommonPolicyUsageUid,   CXcapIetfCommonPolicyUsage::NewL ),
       
    69 	IMPLEMENTATION_PROXY_ENTRY( KXdmOmaCommonPolicyUsageUid,    CXcapOmaCommonPolicyUsage::NewL ),
       
    70 	IMPLEMENTATION_PROXY_ENTRY( KXdmIetfPresRulesUsageUid,  CXcapIetfPresRulesUsage::NewL ),
       
    71 	IMPLEMENTATION_PROXY_ENTRY( KXdmOmaPresRulesUsageUid,   CXcapOmaPresRulesUsage::NewL ),
       
    72     // add new usages here
       
    73     // IMPLEMENTATION_PROXY_ENTRY( KXdmTestAppUsageUid,    CXcapTestAppUsage::NewL ),
       
    74 // PRES-CONTENT STARTS
       
    75 	IMPLEMENTATION_PROXY_ENTRY( KXdmUsageUid, CXcapC4::NewL )
       
    76 // PRES-CONTENT ENDS
       
    77 #else  
       
    78     { { KXdmCapabilityUsageUid }, CXcapCapabilityUsage::NewL },
       
    79     { { KXdmDirectoryUsageUid }, CXcapDirectoryUsage::NewL },
       
    80     { { KXdmPocGroupUsageUid }, CXcapPocGroupUsage::NewL },
       
    81     { { KXdmPocUserAccessUsageUid }, CXcapPocUserAccessUsage::NewL },
       
    82     { { KXdmSharedXDMUsageUid }, CXcapSharedXDMUsage::NewL },
       
    83     { { KXdmRlsServicesUsageUid }, CXcapRlsServicesUsage::NewL },
       
    84     { { KXdmResourceListsUsageUid }, CXcapResourceListsUsage::NewL },
       
    85     { { KXdmIetfCommonPolicyUsageUid }, CXcapIetfCommonPolicyUsage::NewL },
       
    86     { { KXdmOmaCommonPolicyUsageUid }, CXcapOmaCommonPolicyUsage::NewL },
       
    87     { { KXdmIetfPresRulesUsageUid }, CXcapIetfPresRulesUsage::NewL },
       
    88     { { KXdmOmaPresRulesUsageUid }, CXcapOmaPresRulesUsage::NewL }, 
       
    89     // add new usages here
       
    90     // { { KXdmTestAppUsageUid }, CXcapTestAppUsage::NewL }, 
       
    91 // PRES-CONTENT STARTS
       
    92     { { KXdmUsageUid }, CXcapC4::NewL }
       
    93 // PRES-CONTENT ENDS
       
    94 #endif
       
    95     };
       
    96 
       
    97 // ----------------------------------------------------
       
    98 // ImplementationGroupProxy
       
    99 //
       
   100 // ----------------------------------------------------
       
   101 //
       
   102 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount )
       
   103     {
       
   104     aTableCount = sizeof( ImplementationTable ) / sizeof( TImplementationProxy );
       
   105     return ImplementationTable;
       
   106     }
       
   107 
       
   108 
       
   109 // ----------------------------------------------------
       
   110 // CXcapAppUsage::CXcapAppUsage
       
   111 // 
       
   112 // ----------------------------------------------------
       
   113 //
       
   114 CXcapAppUsage::CXcapAppUsage( const CXdmEngine& aXdmEngine ) :
       
   115 iXdmEngine( CONST_CAST( CXdmEngine&, aXdmEngine ) ),
       
   116 iAddNamespaces( EFalse ),
       
   117 iNsToNodeSelector( EFalse ),
       
   118 iAddNsAttributes( EFalse ),
       
   119 iIsGetOrDelete( EFalse )
       
   120     {
       
   121 #ifdef _NAMESPACES_TO_NODE_SELECTOR
       
   122     iNsToNodeSelector = ETrue;
       
   123 #endif   
       
   124 
       
   125 #ifdef _ADD_NAMESPACE_ATTRIBUTES
       
   126 	iAddNsAttributes = ETrue;
       
   127 #endif  
       
   128     }
       
   129 
       
   130 // ----------------------------------------------------
       
   131 // CXcapAppUsage::~CXcapAppUsage
       
   132 // 
       
   133 // ----------------------------------------------------
       
   134 //
       
   135 CXcapAppUsage::~CXcapAppUsage()
       
   136     {
       
   137     REComSession::DestroyedImplementation( iDestructorKey );
       
   138     }
       
   139 
       
   140 // ----------------------------------------------------
       
   141 // CXcapAppUsage::NewL
       
   142 // 
       
   143 // ----------------------------------------------------
       
   144 //
       
   145 EXPORT_C CXcapAppUsage* CXcapAppUsage::NewL( const CXdmEngine& aXdmEngine,
       
   146                                            const TInt aDocumentType )
       
   147     {
       
   148     TAny* ptr = NULL;
       
   149     TXcapAppUsageParams params( aXdmEngine );
       
   150     switch( aDocumentType )
       
   151         {
       
   152         case KXdmCapabilityUsageUid:
       
   153         case KXdmDirectoryUsageUid:
       
   154         case KXdmTestAppUsageUid:    
       
   155         case KXdmPocGroupUsageUid:   
       
   156         case KXdmPocUserAccessUsageUid:   
       
   157         case KXdmSharedXDMUsageUid:
       
   158         case KXdmRlsServicesUsageUid:   
       
   159         case KXdmResourceListsUsageUid:  
       
   160         case KXdmIetfCommonPolicyUsageUid:
       
   161         case KXdmOmaCommonPolicyUsageUid:     
       
   162         case KXdmIetfPresRulesUsageUid:     
       
   163         case KXdmOmaPresRulesUsageUid:
       
   164         case KXdmUsageUid:
       
   165             {
       
   166             TUid KImplementationUid = { aDocumentType };
       
   167             ptr = REComSession::CreateImplementationL( 
       
   168                    KImplementationUid,
       
   169                    _FOFF( CXcapAppUsage, iDestructorKey ),
       
   170                    ( TAny* )&params );
       
   171             }
       
   172             break;
       
   173      
       
   174         default:
       
   175             User::Leave( KErrNotSupported );
       
   176         }
       
   177     return reinterpret_cast<CXcapAppUsage*>( ptr );
       
   178     }
       
   179 
       
   180 // ----------------------------------------------------
       
   181 // CXcapAppUsage::Validate
       
   182 // 
       
   183 // ----------------------------------------------------
       
   184 //
       
   185 EXPORT_C TInt CXcapAppUsage::Validate( CXdmDocument& aXdmDocument, TBool aAddNamespaces ) 
       
   186     {    
       
   187     iAddNamespaces = aAddNamespaces;
       
   188     iIsGetOrDelete = EFalse;
       
   189     // catch leaves here and return the error code
       
   190     TInt error ( KErrNone );
       
   191     TRAP( error, DoValidateL( aXdmDocument ) );
       
   192     // add namespace information for outgoing document
       
   193     if ( error == KErrNone && iAddNamespaces )
       
   194         {
       
   195 	    aXdmDocument.ResetNamespaces();
       
   196 	    TRAP( error, AddNamespaceInformationL( aXdmDocument ) );	
       
   197 	    }
       
   198 #ifdef _DEBUG 
       
   199     WriteToLog( _L8( "CXcapAppUsage::Validate document returns %d" ), error );
       
   200 #endif
       
   201     return error;
       
   202     }
       
   203 
       
   204 // ----------------------------------------------------
       
   205 // CXcapAppUsage::Validate
       
   206 //
       
   207 // ----------------------------------------------------
       
   208 //	
       
   209 EXPORT_C TInt CXcapAppUsage::Validate( CXdmDocumentNode& aXdmNode, 
       
   210                                        MXcapUriInterface* aUriInterface,
       
   211                                        TBool aIsGetOrDelete ) 
       
   212     {
       
   213     iAddNamespaces = ETrue;  
       
   214     iIsGetOrDelete = aIsGetOrDelete;
       
   215     ResetUsedNamespaces();
       
   216     // catch leaves here and return the error code
       
   217     TInt error( KErrNone );
       
   218     TRAP( error, DoValidateL( aXdmNode ) );
       
   219 
       
   220     // add namespace if defined 
       
   221     if ( error == KErrNone && iAddNsAttributes )
       
   222     	{
       
   223     	TRAP( error, CreateNamespaceAttributesL( aXdmNode, aUriInterface ) );
       
   224     	}
       
   225     
       
   226 #ifdef _DEBUG 
       
   227     WriteToLog( _L8( "CXcapAppUsage::Validate node returns %d" ), error );
       
   228 #endif    
       
   229     return error;
       
   230     }
       
   231 	    
       
   232 			
       
   233 // ----------------------------------------------------
       
   234 // CXcapAppUsage::DoValidateL
       
   235 //
       
   236 // ----------------------------------------------------
       
   237 //
       
   238 void CXcapAppUsage::DoValidateL( CXdmDocumentNode& aXdmNode ) 
       
   239     {
       
   240     // call method from derived class
       
   241     ValidateNodeL( aXdmNode );
       
   242     
       
   243     // go through all attributes
       
   244     TInt attrCount( aXdmNode.AttributeCount() );
       
   245     for ( TInt i( 0 ); i < attrCount; i++ )
       
   246         {   
       
   247         CXdmNodeAttribute* attr = aXdmNode.Attribute( i );
       
   248         ValidateAttributeL( *attr ); 
       
   249         }
       
   250 		   
       
   251     // go through all descendants
       
   252     TInt count( aXdmNode.NodeCount( ) );
       
   253     for ( TInt i = 0; i < count; i++ )
       
   254         {
       
   255         DoValidateL ( *aXdmNode.ChileNode( i ) );
       
   256         }
       
   257     }
       
   258 	
       
   259 // ----------------------------------------------------
       
   260 // CXcapAppUsage::DoValidateL 
       
   261 // 
       
   262 // ----------------------------------------------------
       
   263 //  
       
   264 void CXcapAppUsage::DoValidateL ( CXdmDocument& aXdmDocument ) 
       
   265     {
       
   266     DoValidateL( *aXdmDocument.DocumentRoot() );
       
   267     }
       
   268 
       
   269 // ----------------------------------------------------
       
   270 // CXcapAppUsage::ValidateDataL
       
   271 // 
       
   272 // ----------------------------------------------------
       
   273 //
       
   274 void CXcapAppUsage::ValidateDataL ( TDataType aDataType, TDesC8& aData )
       
   275     {
       
   276     if ( iIsGetOrDelete )
       
   277         {
       
   278         return;
       
   279         }
       
   280     switch ( aDataType )
       
   281         {
       
   282         case EDataTypeString:
       
   283             {
       
   284             // TODO 
       
   285             }
       
   286         break;
       
   287         case EDataTypeNonNegativeInteger:
       
   288             {
       
   289             TInt value( 0 );
       
   290             TLex8 lex( aData );
       
   291             lex.Val( value );   
       
   292             if ( value < 0 )
       
   293                 {
       
   294                 User::Leave( KXcapErrorIllegalDataValue );
       
   295                 }
       
   296             }
       
   297             break;
       
   298         case EDataTypeAnyURI:
       
   299             {
       
   300             // TODO 
       
   301             }
       
   302             break;
       
   303         case EDataTypeDateTime:
       
   304             {
       
   305             // TODO 
       
   306             }
       
   307             break;
       
   308         case EDataTypeBoolean:
       
   309             {
       
   310             if ( aData.CompareF( KXdmTrue )
       
   311                 && aData.CompareF( KXdmFalse )
       
   312                 && aData.CompareF( KXdmZero )
       
   313                 && aData.CompareF( KXdmOneNbr )  )
       
   314                 {
       
   315                 User::Leave( KXcapErrorIllegalDataValue );  
       
   316                 }
       
   317             }
       
   318             break;
       
   319         case EDataTypeToken:
       
   320             {
       
   321             // elements that are using datatype token
       
   322             // scheme, class, occurence-id 
       
   323             }
       
   324             break;
       
   325         case EDataTypeEmpty:
       
   326             {
       
   327             if ( aData.Length() > 0 )
       
   328                 {
       
   329                 User::Leave( KXcapErrorIllegalDataValue );
       
   330                 } 
       
   331             }
       
   332             break;      
       
   333         default:    
       
   334         break;
       
   335         }
       
   336     }
       
   337     
       
   338 // ----------------------------------------------------
       
   339 // CXcapAppUsage::ValidateDataL
       
   340 // 
       
   341 // ----------------------------------------------------
       
   342 //
       
   343 void CXcapAppUsage::ValidateDataL ( TDataType aDataType, CXdmDocumentNode& aXdmNode )
       
   344     { 
       
   345     TPtrC8 data = aXdmNode.LeafNodeContent();
       
   346     ValidateDataL( aDataType, data );
       
   347     }
       
   348     
       
   349 // ----------------------------------------------------
       
   350 // CXcapAppUsage::ValidateDataL
       
   351 // 
       
   352 // ----------------------------------------------------
       
   353 //  
       
   354 void CXcapAppUsage::ValidateDataL ( TDataType aDataType, const CXdmNodeAttribute& aXdmNodeAttr )
       
   355     {
       
   356     HBufC8* dataBuf = aXdmNodeAttr.EightBitValueLC();   // << dataBuf
       
   357     TPtrC8 data = dataBuf->Des();
       
   358     ValidateDataL( aDataType, data );
       
   359     CleanupStack::PopAndDestroy( dataBuf );            // >>> dataBuf 
       
   360     }
       
   361 
       
   362 // ----------------------------------------------------
       
   363 // CXcapAppUsage::SetPrefixL
       
   364 // 
       
   365 // ----------------------------------------------------
       
   366 //
       
   367 void CXcapAppUsage::SetPrefixL( CXdmDocumentNode& aXdmNode, const TDesC8& aPrefix )
       
   368     {
       
   369     if ( iAddNamespaces )
       
   370         {
       
   371         aXdmNode.SetPrefixL( aPrefix ); 
       
   372         AddUsedNamespace( aPrefix );
       
   373         }
       
   374     }
       
   375     
       
   376 // ----------------------------------------------------
       
   377 // CXcapAppUsage::AddUsedNamespace
       
   378 // 
       
   379 // ----------------------------------------------------
       
   380 //
       
   381 void CXcapAppUsage::AddUsedNamespace( const TDesC8& aPrefix ) 
       
   382     {
       
   383     // rl
       
   384     if ( Match( aPrefix, KXdmResourceListsNsPrefix ) )
       
   385         {
       
   386         iRL = ETrue;
       
   387         }
       
   388     // cr
       
   389     else if ( Match( aPrefix, KXdmIetfCommonPolicyNsPrefix ) )
       
   390         {
       
   391         iCR = ETrue;
       
   392         }
       
   393     // cp
       
   394     else if ( Match( aPrefix, KXdmOmaCommonPolicyNsPrefix ) )
       
   395         {
       
   396         iCP = ETrue;
       
   397         }
       
   398     // pr
       
   399     else if ( Match( aPrefix, KXdmIetfPresRulesNsPrefix ) )
       
   400         {
       
   401         iPR = ETrue;
       
   402         }
       
   403     // ls
       
   404     else if ( Match( aPrefix, KXdmPocGroupNsPrefix ) )
       
   405         {
       
   406         iLS = ETrue;
       
   407         }
       
   408     // poc
       
   409     else if ( Match( aPrefix, KXdmPocUserAccessNsPrefix ) )
       
   410         {
       
   411         iPOC = ETrue;
       
   412         }
       
   413     // opr
       
   414     else if ( Match( aPrefix, KXdmOmaPresRulesNsPrefix ) )
       
   415         {
       
   416         iOPR = ETrue;
       
   417         }
       
   418     // rls
       
   419     else if ( Match( aPrefix, KXdmRlsServicesNsPrefix ) )
       
   420         {
       
   421         iRLS = ETrue;
       
   422         }
       
   423     // ou
       
   424     else if ( Match( aPrefix, KXdmSharedXDMUriUsageNsPrefix ) )
       
   425         {
       
   426         iOU = ETrue;
       
   427         }
       
   428     // add new prefix definitions here 
       
   429     }
       
   430     
       
   431 // ----------------------------------------------------
       
   432 // CXcapAppUsage::ResetUsedNamespaces
       
   433 // 
       
   434 // ----------------------------------------------------
       
   435 //
       
   436 void CXcapAppUsage::ResetUsedNamespaces() 
       
   437     {
       
   438     iRL = EFalse;
       
   439     iCR = EFalse;
       
   440     iCP = EFalse;
       
   441     iPR = EFalse;
       
   442     iLS = EFalse;
       
   443     iPOC = EFalse;
       
   444     iOPR = EFalse;
       
   445     iRLS = EFalse;
       
   446     iOU = EFalse;
       
   447     // add new prefix definitions here 
       
   448     }
       
   449     
       
   450 // ----------------------------------------------------
       
   451 // CXcapAppUsage::AppendUsedNamespacesL
       
   452 // 
       
   453 // ----------------------------------------------------
       
   454 //
       
   455 void CXcapAppUsage::AppendUsedNamespacesL( MXcapUriInterface* aUriInterface ) 
       
   456     {
       
   457     if( iRL )
       
   458         {
       
   459         aUriInterface->AddNamespaceMappingL( KXdmResourceListsNamespace, KXdmResourceListsNsPrefix );
       
   460         }
       
   461     if( iCR )
       
   462         {
       
   463         aUriInterface->AddNamespaceMappingL( KXdmIetfCommonPolicyNamespace, KXdmIetfCommonPolicyNsPrefix );
       
   464         }
       
   465     if( iCP )
       
   466         {
       
   467         aUriInterface->AddNamespaceMappingL( KXdmOmaCommonPolicyNamespace, KXdmOmaCommonPolicyNsPrefix );        
       
   468         }
       
   469     if( iPR )
       
   470         {
       
   471         aUriInterface->AddNamespaceMappingL( KXdmIetfPresRulesNamespace, KXdmIetfPresRulesNsPrefix );        
       
   472         }
       
   473     if( iLS )
       
   474         {
       
   475          aUriInterface->AddNamespaceMappingL( KXdmPocGroupNamespace, KXdmPocGroupNsPrefix );       
       
   476         }
       
   477     if( iPOC )
       
   478         {
       
   479         aUriInterface->AddNamespaceMappingL( KXdmPocUserAccessNamespace, KXdmPocUserAccessNsPrefix );       
       
   480         }
       
   481     if( iOPR )
       
   482         {
       
   483         aUriInterface->AddNamespaceMappingL( KXdmOmaPresRulesNamespace, KXdmOmaPresRulesNsPrefix );       
       
   484         }
       
   485     if( iRLS )
       
   486         {
       
   487         aUriInterface->AddNamespaceMappingL( KXdmRlsServicesNamespace, KXdmRlsServicesNsPrefix );        
       
   488         }
       
   489     if( iOU )
       
   490         {
       
   491         aUriInterface->AddNamespaceMappingL( KXdmSharedXDMUriUsageNamespace, KXdmSharedXDMUriUsageNsPrefix );
       
   492         }
       
   493     // add new prefix definitions here 
       
   494     }
       
   495     
       
   496 // ----------------------------------------------------
       
   497 // CXcapAppUsage::CreateNamespaceAttributesL
       
   498 // 
       
   499 // ----------------------------------------------------
       
   500 // 
       
   501 void CXcapAppUsage::CreateNamespaceAttributesL( CXdmDocumentNode& aXdmNode, MXcapUriInterface* aUriInterface )
       
   502 	{
       
   503 	// First remove all existing xmlns attributes
       
   504 	RemoveNamespaceAttributesL( aXdmNode );
       
   505 	
       
   506 	TPtrC8 nameSpace;
       
   507 	TPtrC8 prefix = aXdmNode.Prefix();
       
   508 	
       
   509     // if the root node belongs to the default namespace,
       
   510     // it's enough that we add attribute for it and also
       
   511     // attributes for all other used namespaces
       
   512     if ( Match( prefix, KNullDesC8 ) )
       
   513 			{
       
   514        	CXdmNodeAttribute* ns = aXdmNode.CreateAttributeL( KXdmDefaultNsAttrName );
       
   515         ns->SetAttributeValueL( DefaultNamespace() );
       
   516         AppendNamespaceAttributesL( aXdmNode ); 
       
   517         
       
   518         if ( iNsToNodeSelector )
       
   519             {
       
   520             //aUriInterface->AddNamespaceMappingL( DefaultNamespace(), KNullDesC8 );
       
   521             CXdmDocumentNode* parent = aXdmNode.Parent();
       
   522             while ( parent )
       
   523                 {
       
   524                 AddUsedNamespace ( parent->Prefix() );
       
   525                 parent = parent->Parent();
       
   526                 }
       
   527             AppendUsedNamespacesL( aUriInterface );   
       
   528             } 
       
   529         // we are done
       
   530 #ifdef _DEBUG 
       
   531     WriteToLog( _L8( "CXcapAppUsage::CreateNamespaceAttributesL root belongs to default" ) );
       
   532 #endif
       
   533         return;        
       
   534         }
       
   535 #ifdef _DEBUG 
       
   536     WriteToLog( _L8( "CXcapAppUsage::CreateNamespaceAttributesL root doesn't belong to default" ) );
       
   537 #endif   
       
   538     // if the default namespace is used in fragment,
       
   539     // the attribute for it has to be added
       
   540     if ( DefaultNamespaceUsed( aXdmNode ) )
       
   541         {
       
   542       	CXdmNodeAttribute* ns = aXdmNode.CreateAttributeL( KXdmDefaultNsAttrName );
       
   543         ns->SetAttributeValueL( DefaultNamespace() );
       
   544         }
       
   545 	// finally, create new xmlns attributes
       
   546     AppendNamespaceAttributesL( aXdmNode );
       
   547     if ( iNsToNodeSelector )
       
   548         {
       
   549         //aUriInterface->AddNamespaceMappingL( DefaultNamespace(), KNullDesC8 );
       
   550         CXdmDocumentNode* parent = aXdmNode.Parent();
       
   551         while ( parent )
       
   552             {
       
   553             AddUsedNamespace ( parent->Prefix() );
       
   554             parent = parent->Parent();
       
   555             }
       
   556         AppendUsedNamespacesL( aUriInterface );   
       
   557         } 
       
   558 	}	
       
   559 
       
   560 // ----------------------------------------------------
       
   561 // CXcapAppUsage::RemoveNamespaceAttributesL
       
   562 // 
       
   563 // ----------------------------------------------------
       
   564 // 
       
   565 void CXcapAppUsage::RemoveNamespaceAttributesL( CXdmDocumentNode& aXdmNode )
       
   566 	{
       
   567 #ifdef _DEBUG 
       
   568     WriteToLog( _L8( "CXcapAppUsage::RemoveNamespaceAttributesL begin" ) );
       
   569 #endif	
       
   570 	// go through all attributes
       
   571     for ( TInt i( aXdmNode.AttributeCount() - 1 ); i > KErrNotFound; i-- )
       
   572         {   
       
   573         CXdmNodeAttribute* attr = aXdmNode.Attribute( i );
       
   574        	if ( attr->NodeName().FindF( KXdmDefaultNsAttrName ) != KErrNotFound )
       
   575 			{
       
   576 #ifdef _DEBUG 
       
   577     WriteToLog( _L8( "CXcapAppUsage::RemoveNamespaceAttributesL AttrCount=%d i=%d" ), aXdmNode.AttributeCount(), i );
       
   578 #endif
       
   579 			aXdmNode.RemoveChileNodeL( attr );
       
   580 			}
       
   581         }
       
   582 		   
       
   583     // go through all descendants
       
   584     TInt count( aXdmNode.NodeCount( ) );
       
   585     for ( TInt i(0); i < count; i++ )
       
   586         {
       
   587         RemoveNamespaceAttributesL ( *aXdmNode.ChileNode( i ) );
       
   588         }
       
   589 #ifdef _DEBUG 
       
   590     WriteToLog( _L8( "CXcapAppUsage::RemoveNamespaceAttributesL done" ) );
       
   591 #endif	
       
   592 	}
       
   593 	
       
   594 // ----------------------------------------------------
       
   595 // CXcapAppUsage::DefaultNamespaceUsed
       
   596 // 
       
   597 // ----------------------------------------------------
       
   598 // 
       
   599 TBool CXcapAppUsage::DefaultNamespaceUsed( CXdmDocumentNode& aXdmNode )
       
   600 	{
       
   601 	if ( Match( aXdmNode.Prefix(), KNullDesC8 ) )
       
   602 		{
       
   603 #ifdef _DEBUG 
       
   604     WriteToLog( _L8( "CXcapAppUsage::DefaultNamespaceUsed returns true" ) );
       
   605 #endif
       
   606 		return ETrue;	
       
   607 		}
       
   608     // go through all descendants
       
   609     TInt count( aXdmNode.NodeCount( ) );
       
   610     for ( TInt i = 0; i < count; i++ )
       
   611         {
       
   612         if ( DefaultNamespaceUsed ( *aXdmNode.ChileNode( i ) ) )
       
   613             {
       
   614 #ifdef _DEBUG 
       
   615     WriteToLog( _L8( "CXcapAppUsage::DefaultNamespaceUsed returns true" ) );
       
   616 #endif
       
   617             return ETrue;
       
   618             }
       
   619         }
       
   620 #ifdef _DEBUG 
       
   621     WriteToLog( _L8( "CXcapAppUsage::DefaultNamespaceUsed returns false" ) );
       
   622 #endif
       
   623     return EFalse;	
       
   624 	}
       
   625 // ----------------------------------------------------
       
   626 // CXcapAppUsage::AppendNamespaceAttributesL
       
   627 // 
       
   628 // ----------------------------------------------------
       
   629 //
       
   630 void CXcapAppUsage::AppendNamespaceAttributesL( CXdmDocumentNode& aXdmNode ) 
       
   631     {
       
   632     if( iRL )
       
   633         {
       
   634 		CreateNamespaceAttributeL( aXdmNode, KXdmResourceListsNsPrefix, KXdmResourceListsNamespace );
       
   635         }
       
   636     if( iCR )
       
   637         {
       
   638         CreateNamespaceAttributeL( aXdmNode, KXdmIetfCommonPolicyNsPrefix, KXdmIetfCommonPolicyNamespace );
       
   639         }
       
   640     if( iCP )
       
   641         {
       
   642        	CreateNamespaceAttributeL( aXdmNode, KXdmOmaCommonPolicyNsPrefix, KXdmOmaCommonPolicyNamespace );        
       
   643         }
       
   644     if( iPR )
       
   645         {
       
   646         CreateNamespaceAttributeL( aXdmNode, KXdmIetfPresRulesNsPrefix, KXdmIetfPresRulesNamespace );        
       
   647         }
       
   648     if( iLS )
       
   649         {
       
   650        	CreateNamespaceAttributeL( aXdmNode, KXdmPocGroupNsPrefix, KXdmPocGroupNamespace );      
       
   651         }
       
   652     if( iPOC )
       
   653         {
       
   654        	CreateNamespaceAttributeL( aXdmNode, KXdmPocUserAccessNsPrefix, KXdmPocUserAccessNamespace );   
       
   655         }
       
   656     if( iOPR )
       
   657         {
       
   658        	CreateNamespaceAttributeL( aXdmNode, KXdmOmaPresRulesNsPrefix, KXdmOmaPresRulesNamespace );       
       
   659         }
       
   660     if( iRLS )
       
   661         {
       
   662         CreateNamespaceAttributeL( aXdmNode, KXdmRlsServicesNsPrefix, KXdmRlsServicesNamespace );  
       
   663         }
       
   664     if( iOU )
       
   665         {
       
   666        	CreateNamespaceAttributeL( aXdmNode, KXdmSharedXDMUriUsageNsPrefix, KXdmSharedXDMUriUsageNamespace );
       
   667         }
       
   668     // add new prefix definitions here 
       
   669 #ifdef _DEBUG 
       
   670     WriteToLog( _L8( "CXcapAppUsage::AppendNamespaceAttributesL done" ) );
       
   671 #endif
       
   672     }
       
   673     
       
   674 // ----------------------------------------------------
       
   675 // CXcapAppUsage::CreateNamespaceAttributeL
       
   676 // 
       
   677 // ----------------------------------------------------
       
   678 // 
       
   679 void CXcapAppUsage::CreateNamespaceAttributeL( CXdmDocumentNode& aXdmNode, const TDesC8& aPrefix, const TDesC8& aNamespace )
       
   680     {
       
   681 	TBuf8<KXdmMaxPrefixLength> name;
       
   682     name.Copy( KXdmNonDefaultNsAttrName );
       
   683     name.Append( aPrefix );
       
   684     HBufC8* attrName = name.AllocLC();	// << attrName
       
   685     CXdmNodeAttribute* ns = aXdmNode.CreateAttributeL(  );
       
   686     CleanupStack::PushL( ns );	// << ns
       
   687     ns->SetNameL( *attrName );
       
   688     ns->SetAttributeValueL( aNamespace );
       
   689     CleanupStack::Pop( ns );	// >> ns
       
   690     CleanupStack::PopAndDestroy();	// >>> attrName
       
   691 #ifdef _DEBUG 
       
   692     WriteToLog( _L8( "CXcapAppUsage::CreateNamespaceAttributeL done" ) );
       
   693 #endif
       
   694 	}
       
   695     
       
   696 // ----------------------------------------------------
       
   697 // CXcapAppUsage::Match
       
   698 // 
       
   699 // ----------------------------------------------------
       
   700 // 
       
   701 TBool CXcapAppUsage::Match( const TDesC& aLeft, const TDesC& aRight )
       
   702     {
       
   703     if ( !aLeft.CompareF( aRight ) )
       
   704         {
       
   705         return ETrue;
       
   706         }
       
   707     return EFalse;
       
   708     }
       
   709     
       
   710 // ----------------------------------------------------
       
   711 // CXcapAppUsage::Match
       
   712 // 
       
   713 // ----------------------------------------------------
       
   714 // 
       
   715 TBool CXcapAppUsage::Match( const TDesC8& aLeft, const TDesC8& aRight )
       
   716     {
       
   717     if ( !aLeft.CompareF( aRight ) )
       
   718         {
       
   719         return ETrue;
       
   720         }
       
   721     return EFalse;
       
   722     }    
       
   723     
       
   724 // ----------------------------------------------------
       
   725 // CXcapAppUsage::LeaveWithErrorL
       
   726 // 
       
   727 // ----------------------------------------------------
       
   728 //
       
   729 void CXcapAppUsage::LeaveWithErrorL( TInt aErrorCode )
       
   730     {
       
   731     if ( !iIsGetOrDelete )
       
   732         {
       
   733         User::Leave( aErrorCode );
       
   734         }
       
   735     }    
       
   736     
       
   737 
       
   738 // ----------------------------------------------------
       
   739 // CXcapAppUsage::WriteToLog
       
   740 // _DEBUG only
       
   741 // ----------------------------------------------------
       
   742 //
       
   743 #ifdef _DEBUG
       
   744 void CXcapAppUsage::WriteToLog( TRefByValue<const TDesC8> aFmt,... )                                 
       
   745     {
       
   746     VA_LIST list;
       
   747     VA_START( list, aFmt );
       
   748     TBuf8<KAppUsageLogBufferMaxSize> buf;
       
   749     buf.FormatList( aFmt, list );
       
   750     RFileLogger::Write( KXdmAppUsageLogDir, KXdmAppUsageLogFile, EFileLoggingModeAppend, buf );
       
   751     }
       
   752 #endif
       
   753     
       
   754 //  End of File  
       
   755 
       
   756