xdmprotocols/LocalProtocol/LocalOperations/src/LocalAddition.cpp
branchRCL_3
changeset 18 fbd2e7cec7ef
parent 0 c8caa15ef882
equal deleted inserted replaced
17:2669f8761a99 18:fbd2e7cec7ef
       
     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: CLocalAddition
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDES
       
    22 #include "LocalProtocol.h"
       
    23 #include "LocalDocument.h"
       
    24 #include "LocalAddition.h"
       
    25 #include "XdmXmlParser.h"
       
    26 #include "LocalDocumentNode.h"
       
    27 #include "LocalNodeAttribute.h"
       
    28 #include "LocalOperationFactory.h"
       
    29     
       
    30 // ---------------------------------------------------------
       
    31 // CLocalAddition::CLocalAddition
       
    32 //
       
    33 // ---------------------------------------------------------
       
    34 //
       
    35 CLocalAddition::CLocalAddition( CLocalDocument& aParentDoc,
       
    36                                 CLocalDocumentNode* aDocumentSubset,
       
    37                                 CLocalOperationFactory& aOperationFactory ) :
       
    38                                 CLocalOperationBase( aParentDoc, aOperationFactory ),
       
    39                                 iOperationType( aDocumentSubset == NULL ?
       
    40                                 EXdmDocument : EXdmPartialDocument ),         
       
    41                                 iDocumentSubset( aDocumentSubset )
       
    42                                                       
       
    43     {
       
    44     }
       
    45 
       
    46 // ---------------------------------------------------------
       
    47 // CLocalAddition::NewL
       
    48 //
       
    49 // ---------------------------------------------------------
       
    50 //
       
    51 CLocalAddition* CLocalAddition::NewL( CLocalDocument& aParentDoc,
       
    52                                       CLocalDocumentNode* aDocumentSubset,
       
    53                                       CLocalOperationFactory& aOperationFactory )
       
    54     {
       
    55     CLocalAddition* self = new ( ELeave ) CLocalAddition( aParentDoc, aDocumentSubset, aOperationFactory );
       
    56     CleanupStack::PushL( self );
       
    57     self->BaseConstructL();
       
    58     CleanupStack::Pop();
       
    59     return self;
       
    60     }
       
    61 
       
    62 // ---------------------------------------------------------
       
    63 // CLocalAddition::ExecuteL
       
    64 //
       
    65 // ---------------------------------------------------------
       
    66 //
       
    67 void CLocalAddition::ExecuteL()
       
    68     {
       
    69     TPtrC fileName = iTargetDoc.XmlFilePath();
       
    70     TInt size = OpenDataFileL( fileName );
       
    71     if( size > 0 )      //The document already exists
       
    72         {
       
    73         //Only a subset of a document
       
    74         if( iTargetDoc.IsSubset() && iDocumentSubset != NULL )  
       
    75             HandlePartialUpdateL( size );
       
    76         else WriteFileL( iTargetDoc.DocumentRoot() );
       
    77         }
       
    78     else WriteFileL( iTargetDoc.DocumentRoot() );
       
    79     iXmlFile.Close();
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------
       
    83 // CLocalAddition::HandlePartialUpdateL
       
    84 //
       
    85 // ---------------------------------------------------------
       
    86 //
       
    87 void CLocalAddition::HandlePartialUpdateL( TInt aDataLength )
       
    88     {
       
    89     HBufC8* data = FetchXmlDataL( aDataLength );
       
    90     CleanupStack::PushL( data );
       
    91     CLocalDocument* copy = iTargetDoc.TempCopyL();
       
    92     CleanupStack::PushL( copy );
       
    93     iXmlParser->ParseDocumentL( copy, *data );
       
    94     RPointerArray<CXdmDocumentNode> results;
       
    95     CleanupClosePushL( results );
       
    96     RPointerArray<SXdmAttribute16> attributes;
       
    97     CleanupClosePushL( attributes );
       
    98     TInt attrCount = iDocumentSubset->AttributeCount();
       
    99     if( attrCount > 0 )
       
   100         {
       
   101         SXdmAttribute16 attribute;
       
   102         for( TInt i = 0;i < attrCount;i++ )
       
   103             {
       
   104             attribute.iName.Set( iDocumentSubset->Attribute( i )->NodeName() );
       
   105             attribute.iValue.Set( iDocumentSubset->Attribute( i )->AttributeValue() );
       
   106             }
       
   107         User::LeaveIfError( attributes.Append( &attribute ) );
       
   108         }
       
   109     copy->Find( iDocumentSubset->NodeName(), results, attributes );
       
   110     if( results.Count() == 1 )
       
   111         {
       
   112         iXmlFile.Close();
       
   113         ReplaceDataFileL();
       
   114         CLocalDocumentNode* node = ( CLocalDocumentNode* )results[0];
       
   115         node->AppendLocalL( ( CLocalDocumentNode* )iDocumentSubset );
       
   116         WriteFileL( copy->DocumentRoot() );
       
   117         }
       
   118     else User::Leave( KErrGeneral );
       
   119     CleanupStack::PopAndDestroy( 4 );  //attributes, results, copy, data
       
   120     }
       
   121         
       
   122 // ---------------------------------------------------------
       
   123 // CLocalAddition::Destroy
       
   124 //
       
   125 // ---------------------------------------------------------
       
   126 //     
       
   127 void CLocalAddition::Destroy()
       
   128     {
       
   129     delete this;
       
   130     } 
       
   131 
       
   132 // ---------------------------------------------------------
       
   133 // Destructor
       
   134 //
       
   135 // ---------------------------------------------------------
       
   136 //
       
   137 CLocalAddition::~CLocalAddition()
       
   138     {
       
   139     
       
   140     }
       
   141 
       
   142 //  End of File  
       
   143