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