|
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: CLocalDeletion |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDES |
|
22 #include "XdmXmlParser.h" |
|
23 #include "LocalProtocol.h" |
|
24 #include "LocalDocument.h" |
|
25 #include "LocalDeletion.h" |
|
26 #include "LocalDocumentNode.h" |
|
27 #include "LocalNodeAttribute.h" |
|
28 |
|
29 // --------------------------------------------------------- |
|
30 // C++ constructor can NOT contain any code, that |
|
31 // might leave. |
|
32 // --------------------------------------------------------- |
|
33 // |
|
34 CLocalDeletion::CLocalDeletion( CLocalDocument& aTargetDoc, |
|
35 CLocalDocumentNode* aDocumentSubset, |
|
36 CLocalOperationFactory& aOperationFactory ) : |
|
37 CLocalOperationBase( aTargetDoc, aOperationFactory ), |
|
38 iDocumentSubset( aDocumentSubset ), |
|
39 iOperationType( aDocumentSubset == NULL ? |
|
40 EXdmDocument : EXdmPartialDocument ) |
|
41 { |
|
42 } |
|
43 |
|
44 // --------------------------------------------------------- |
|
45 // CLocalDeletion::NewL |
|
46 // |
|
47 // --------------------------------------------------------- |
|
48 // |
|
49 CLocalDeletion* CLocalDeletion::NewL( CLocalDocument& aParentDoc, |
|
50 CLocalDocumentNode* aDocumentSubset, |
|
51 CLocalOperationFactory& aOperationFactory ) |
|
52 { |
|
53 CLocalDeletion* self = new ( ELeave ) CLocalDeletion( aParentDoc, aDocumentSubset, aOperationFactory ); |
|
54 CleanupStack::PushL( self ); |
|
55 self->BaseConstructL(); |
|
56 CleanupStack::Pop(); |
|
57 return self; |
|
58 } |
|
59 |
|
60 // --------------------------------------------------------- |
|
61 // CLocalDeletion::ExecuteL |
|
62 // |
|
63 // --------------------------------------------------------- |
|
64 // |
|
65 void CLocalDeletion::ExecuteL() |
|
66 { |
|
67 TPtrC fileName = iTargetDoc.XmlFilePath(); |
|
68 TInt size = OpenDataFileL( fileName ); |
|
69 if( size > 0 ) |
|
70 { |
|
71 //Only a subset of a document |
|
72 if( iTargetDoc.IsSubset() ) |
|
73 HandlePartialDeletionL( size ); |
|
74 else if( iDocumentSubset != NULL ) |
|
75 { |
|
76 iTargetDoc.RemoveData( ( CLocalDocumentNode* )iDocumentSubset ); |
|
77 iXmlFile.Close(); |
|
78 ReplaceDataFileL(); |
|
79 WriteFileL( iTargetDoc.DocumentRoot() ); |
|
80 } |
|
81 else |
|
82 { |
|
83 iXmlFile.Close(); |
|
84 DeleteDataFileL(); //Delete the whole document |
|
85 } |
|
86 } |
|
87 else User::Leave( KErrNotFound ); |
|
88 iXmlFile.Close(); |
|
89 } |
|
90 |
|
91 // --------------------------------------------------------- |
|
92 // CLocalAddition::HandlePartialUpdateL |
|
93 // |
|
94 // --------------------------------------------------------- |
|
95 // |
|
96 void CLocalDeletion::HandlePartialDeletionL( TInt aDataLength ) |
|
97 { |
|
98 TInt error = KErrNone; |
|
99 HBufC8* data = FetchXmlDataL( aDataLength ); |
|
100 CleanupStack::PushL( data ); |
|
101 TRAP( error, iXmlParser->ParseDocumentL( &iTargetDoc, *data ) ); |
|
102 CXdmDocumentNode* parent = iDocumentSubset->Parent(); |
|
103 RPointerArray<CXdmDocumentNode> parentResults; |
|
104 CleanupClosePushL( parentResults ); |
|
105 RPointerArray<SXdmAttribute16> parentAttributes; |
|
106 CleanupClosePushL( parentAttributes ); |
|
107 RPointerArray<CXdmDocumentNode> nodeResults; |
|
108 CleanupClosePushL( nodeResults ); |
|
109 RPointerArray<SXdmAttribute16> nodeAttributes; |
|
110 CleanupClosePushL( nodeAttributes ); |
|
111 TInt pAttrCount = parent->AttributeCount(); |
|
112 TInt dAttrCount = iDocumentSubset->AttributeCount(); |
|
113 if( pAttrCount > 0 ) |
|
114 { |
|
115 SXdmAttribute16 attribute; |
|
116 for( TInt i = 0;i < pAttrCount;i++ ) |
|
117 { |
|
118 attribute.iName.Set( parent->Attribute( i )->NodeName() ); |
|
119 attribute.iValue.Set( parent->Attribute( i )->AttributeValue() ); |
|
120 } |
|
121 User::LeaveIfError( parentAttributes.Append( &attribute ) ); |
|
122 } |
|
123 if( dAttrCount > 0 ) |
|
124 { |
|
125 SXdmAttribute16 attribute; |
|
126 for( TInt i = 0;i < dAttrCount;i++ ) |
|
127 { |
|
128 attribute.iName.Set( iDocumentSubset->Attribute( i )->NodeName() ); |
|
129 attribute.iValue.Set( iDocumentSubset->Attribute( i )->AttributeValue() ); |
|
130 } |
|
131 User::LeaveIfError( nodeAttributes.Append( &attribute ) ); |
|
132 } |
|
133 iTargetDoc.Find( parent->NodeName(), parentResults, parentAttributes ); |
|
134 iTargetDoc.Find( iDocumentSubset->NodeName(), nodeResults, nodeAttributes ); |
|
135 if( parentResults.Count() == 1 && nodeResults.Count() == 1 ) |
|
136 { |
|
137 iXmlFile.Close(); |
|
138 ReplaceDataFileL(); |
|
139 CLocalDocumentNode* p = ( CLocalDocumentNode* )parentResults[0]; |
|
140 CLocalDocumentNode* r = ( CLocalDocumentNode* )nodeResults[0]; |
|
141 p->RemoveLocalL( r ); |
|
142 WriteFileL( iTargetDoc.DocumentRoot() ); |
|
143 } |
|
144 else User::Leave( KErrGeneral ); |
|
145 CleanupStack::PopAndDestroy( 5 ); //nodeAttributes, nodeResults, |
|
146 //parentAttributes, parentResults, data |
|
147 } |
|
148 |
|
149 // --------------------------------------------------------- |
|
150 // Symbian OS default constructor may leave. |
|
151 // |
|
152 // --------------------------------------------------------- |
|
153 // |
|
154 void CLocalDeletion::Destroy() |
|
155 { |
|
156 delete this; |
|
157 } |
|
158 |
|
159 // --------------------------------------------------------- |
|
160 // Destructor |
|
161 // |
|
162 // --------------------------------------------------------- |
|
163 // |
|
164 CLocalDeletion::~CLocalDeletion() |
|
165 { |
|
166 |
|
167 } |
|
168 |
|
169 // End of File |
|
170 |