|
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: CLocalDocument |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <f32file.h> |
|
23 #include "XdmProtocol.h" |
|
24 #include "XdmNamespace.h" |
|
25 #include "XdmOperation.h" |
|
26 #include "XdmXmlParser.h" |
|
27 #include "LocalProtocol.h" |
|
28 #include "LocalDocument.h" |
|
29 #include "LocalDocumentNode.h" |
|
30 #include "XdmOperationFactory.h" |
|
31 |
|
32 // ---------------------------------------------------- |
|
33 // CLocalDocument::CLocalDocument |
|
34 // |
|
35 // ---------------------------------------------------- |
|
36 // |
|
37 CLocalDocument::CLocalDocument( CXdmEngine& aXdmEngine, |
|
38 CLocalProtocol& aLocalProtocol ) : |
|
39 CXdmDocument( aXdmEngine ), |
|
40 iLocalProtocol( aLocalProtocol ) |
|
41 { |
|
42 } |
|
43 |
|
44 |
|
45 // ---------------------------------------------------------- |
|
46 // CLocalDocument::NewL |
|
47 // |
|
48 // ---------------------------------------------------------- |
|
49 // |
|
50 CLocalDocument* CLocalDocument::NewL( CXdmEngine& aXdmEngine, |
|
51 const TDesC& aDocumentName, |
|
52 CLocalProtocol& aLocalProtocol ) |
|
53 { |
|
54 CLocalDocument* self = new ( ELeave ) CLocalDocument( aXdmEngine, aLocalProtocol ); |
|
55 CleanupStack::PushL( self ); |
|
56 self->BaseConstructL( KLocalOperationFactory, aDocumentName ); |
|
57 self->ConstructL(); |
|
58 CleanupStack::Pop(); |
|
59 return self; |
|
60 } |
|
61 |
|
62 // ---------------------------------------------------------- |
|
63 // CLocalDocument::ConstructL |
|
64 // |
|
65 // ---------------------------------------------------------- |
|
66 // |
|
67 void CLocalDocument::ConstructL() |
|
68 { |
|
69 #ifdef _DEBUG |
|
70 iLocalProtocol.WriteToLog( _L8( "CLocalDocument::ConstructL()" ) ); |
|
71 #endif |
|
72 TPtrC name = iDocumentName->Des(); |
|
73 TPtrC root = iLocalProtocol.RootFolder(); |
|
74 iFullPath = HBufC::NewL( name.Length() + root.Length() ); |
|
75 iFullPath->Des().Copy( root ); |
|
76 iFullPath->Des().Append( name ); |
|
77 FetchTimeStampL(); |
|
78 CActiveScheduler::Add( this ); |
|
79 } |
|
80 |
|
81 // ---------------------------------------------------------- |
|
82 // CLocalDocument::ResetContents |
|
83 // |
|
84 // ---------------------------------------------------------- |
|
85 // |
|
86 void CLocalDocument::ResetContents() |
|
87 { |
|
88 delete iDocumentRoot; |
|
89 iDocumentRoot = NULL; |
|
90 iNamespaces.ResetAndDestroy(); |
|
91 } |
|
92 |
|
93 // ---------------------------------------------------------- |
|
94 // CLocalDocument::FetchTimeStampL |
|
95 // |
|
96 // ---------------------------------------------------------- |
|
97 // |
|
98 void CLocalDocument::FetchTimeStampL() |
|
99 { |
|
100 #ifdef _DEBUG |
|
101 iLocalProtocol.WriteToLog( _L8( "CLocalDocument::FetchTimeStampL()" ) ); |
|
102 #endif |
|
103 RFile timeStamp; |
|
104 TBuf8<KDateTimeMaxSize> buf; |
|
105 TBuf<KDateTimeMaxSize> buf16; |
|
106 const TChar idSeparator = 46; |
|
107 TPtrC fullPath( iFullPath->Des() ); |
|
108 HBufC* path = HBufC::NewLC( fullPath.Length() + KTimeStampFileExt().Length() ); |
|
109 TInt index = fullPath.LocateReverse( idSeparator ); |
|
110 TPtrC tmspName( index > 0 ? fullPath.Left( index ) : fullPath ); |
|
111 path->Des().Copy( tmspName ); |
|
112 path->Des().Append( KTimeStampFileExt ); |
|
113 TInt error = timeStamp.Open( CLocalProtocol::FileSession(), path->Des(), EFileRead ); |
|
114 if( error == KErrNone ) |
|
115 { |
|
116 CleanupClosePushL( timeStamp ); |
|
117 User::LeaveIfError( timeStamp.Read( buf ) ); |
|
118 buf16.Copy( buf ); |
|
119 buf.Zero(); |
|
120 User::LeaveIfError( iLastModification.Parse( buf16 ) ); |
|
121 CleanupStack::PopAndDestroy(); //timeStamp |
|
122 } |
|
123 CleanupStack::PopAndDestroy(); //path |
|
124 } |
|
125 // ---------------------------------------------------- |
|
126 // CLocalDocument::~CLocalDocument |
|
127 // |
|
128 // ---------------------------------------------------- |
|
129 // |
|
130 CLocalDocument::~CLocalDocument() |
|
131 { |
|
132 #ifdef _DEBUG |
|
133 iLocalProtocol.WriteToLog( _L8( "CLocalDocument::~CLocalDocument()" ) ); |
|
134 #endif |
|
135 Cancel(); |
|
136 delete iFullPath; |
|
137 delete iDocumentRoot; |
|
138 iNamespaces.ResetAndDestroy(); |
|
139 } |
|
140 |
|
141 // ---------------------------------------------------- |
|
142 // CLocalDocument::CreateRootL |
|
143 // |
|
144 // ---------------------------------------------------- |
|
145 // |
|
146 CXdmDocumentNode* CLocalDocument::CreateRootL() |
|
147 { |
|
148 #ifdef _DEBUG |
|
149 iLocalProtocol.WriteToLog( _L8( "CLocalDocument::DocumentSubsetL()" ) ); |
|
150 #endif |
|
151 iDocumentRoot = CLocalDocumentNode::NewL( iXdmEngine, iLocalProtocol ); |
|
152 return iDocumentRoot; |
|
153 } |
|
154 |
|
155 // ---------------------------------------------------- |
|
156 // CLocalDocument::TempCopyL |
|
157 // |
|
158 // ---------------------------------------------------- |
|
159 // |
|
160 EXPORT_C CLocalDocument* CLocalDocument::TempCopyL() |
|
161 { |
|
162 return CLocalDocument::NewL( iXdmEngine, Name(), iLocalProtocol ); |
|
163 } |
|
164 |
|
165 // ---------------------------------------------------- |
|
166 // CLocalDocument::DocumentRoot |
|
167 // |
|
168 // ---------------------------------------------------- |
|
169 // |
|
170 CXdmDocumentNode* CLocalDocument::DocumentRoot() const |
|
171 { |
|
172 return iDocumentRoot; |
|
173 } |
|
174 |
|
175 // ---------------------------------------------------- |
|
176 // CLocalDocument::ErrorRoot |
|
177 // |
|
178 // ---------------------------------------------------- |
|
179 // |
|
180 CXdmDocumentNode* CLocalDocument::ErrorRoot() |
|
181 { |
|
182 return NULL; |
|
183 } |
|
184 |
|
185 // ---------------------------------------------------- |
|
186 // CLocalDocument::ErrorRoot |
|
187 // |
|
188 // ---------------------------------------------------- |
|
189 // |
|
190 TXdmDocType CLocalDocument::DocumentType() const |
|
191 { |
|
192 return EXdmDocGeneral; |
|
193 } |
|
194 |
|
195 // ---------------------------------------------------- |
|
196 // CLocalDocument::IsSubset |
|
197 // |
|
198 // ---------------------------------------------------- |
|
199 // |
|
200 EXPORT_C TBool CLocalDocument::IsSubset() const |
|
201 { |
|
202 return iDocSubset; |
|
203 } |
|
204 |
|
205 // ---------------------------------------------------- |
|
206 // CLocalDocument::ResetSubset |
|
207 // |
|
208 // ---------------------------------------------------- |
|
209 // |
|
210 EXPORT_C void CLocalDocument::ResetSubset() |
|
211 { |
|
212 CXdmDocument::ResetSubset(); |
|
213 delete iDocumentRoot; |
|
214 iDocumentRoot = NULL; |
|
215 } |
|
216 |
|
217 // ---------------------------------------------------- |
|
218 // CLocalDocument::XmlFilePath |
|
219 // |
|
220 // ------------------------------ ---------------------- |
|
221 // |
|
222 EXPORT_C TPtrC CLocalDocument::XmlFilePath() const |
|
223 { |
|
224 return iFullPath != NULL ? iFullPath->Des() : TPtrC(); |
|
225 } |
|
226 |
|
227 // ---------------------------------------------------- |
|
228 // CLocalDocument::RemoveData |
|
229 // |
|
230 // ---------------------------------------------------- |
|
231 // |
|
232 EXPORT_C void CLocalDocument::RemoveData( CLocalDocumentNode* /*aDocumentNode*/ ) |
|
233 { |
|
234 #ifdef _DEBUG |
|
235 iLocalProtocol.WriteToLog( _L8( "CLocalDocument::RemoveData()" ) ); |
|
236 #endif |
|
237 |
|
238 } |
|
239 |
|
240 // ---------------------------------------------------- |
|
241 // CLocalDocument::StartUpdateL |
|
242 // |
|
243 // ---------------------------------------------------- |
|
244 // |
|
245 void CLocalDocument::StartUpdateL() |
|
246 { |
|
247 #ifdef _DEBUG |
|
248 iLocalProtocol.WriteToLog( _L8( "CLocalDocument::StartUpdateL()" ) ); |
|
249 #endif |
|
250 TBool keepGoing = ETrue; |
|
251 TInt completion = KErrNone; |
|
252 TInt count = iChangeRequests.Count(); |
|
253 for( TInt i = 0;keepGoing && i < count;i++ ) |
|
254 { |
|
255 //"First in, first served" |
|
256 TRAPD( error, iChangeRequests[0]->ExecuteL() ); |
|
257 if( error == KErrNone ) |
|
258 { |
|
259 #ifdef _DEBUG |
|
260 iLocalProtocol.WriteToLog( _L8( " Execution of the operation no. %d was successful" ), i ); |
|
261 #endif |
|
262 } |
|
263 else |
|
264 { |
|
265 #ifdef _DEBUG |
|
266 iLocalProtocol.WriteToLog( _L8( " Execution of the operation no. %d failed with %d" ), i, error ); |
|
267 #endif |
|
268 completion = error; |
|
269 keepGoing = EFalse; |
|
270 } |
|
271 FinaliseOperation( 0 ); |
|
272 } |
|
273 User::RequestComplete( iClientStatus, completion ); |
|
274 } |
|
275 |
|
276 // ---------------------------------------------------- |
|
277 // CLocalProtocol::AppendPathPartL |
|
278 // |
|
279 // ---------------------------------------------------- |
|
280 // |
|
281 void CLocalDocument::AppendPathPartL( const TDesC& aString ) |
|
282 { |
|
283 #ifdef _DEBUG |
|
284 iLocalProtocol.WriteToLog( _L8( "CLocalDocument::PathPartL()" ) ); |
|
285 #endif |
|
286 if( iDocumentRoot != NULL ) |
|
287 { |
|
288 CXdmDocumentNode* node = NULL; |
|
289 CXdmDocumentNode* parent = iDocumentRoot; |
|
290 while( parent->NextNode() != NULL ) |
|
291 parent = parent->NextNode(); |
|
292 node = CLocalDocumentNode::NewL( iXdmEngine, aString, parent, iLocalProtocol ); |
|
293 parent->SetNextNode( node ); |
|
294 } |
|
295 else |
|
296 iDocumentRoot = CLocalDocumentNode::NewL( iXdmEngine, aString, iLocalProtocol ); |
|
297 } |
|
298 |
|
299 // ---------------------------------------------------- |
|
300 // CLocalProtocol::CurrentExtent |
|
301 // |
|
302 // ---------------------------------------------------- |
|
303 // |
|
304 CXdmDocumentNode* CLocalDocument::CurrentExtent() const |
|
305 { |
|
306 #ifdef _DEBUG |
|
307 iLocalProtocol.WriteToLog( _L8( "CLocalDocument::CurrentExtent()" ) ); |
|
308 #endif |
|
309 CXdmDocumentNode* ret = NULL; |
|
310 if( iDocumentRoot != NULL ) |
|
311 { |
|
312 CXdmDocumentNode* node = iDocumentRoot; |
|
313 while( node->NextNode() != NULL ) |
|
314 node = node->NextNode(); |
|
315 ret = node; |
|
316 } |
|
317 else |
|
318 { |
|
319 #ifdef _DEBUG |
|
320 iLocalProtocol.WriteToLog( _L8( " This document does not yet have a root, leave with KErrGeneral" ) ); |
|
321 #endif |
|
322 User::Leave( KErrGeneral ); |
|
323 } |
|
324 return ret; |
|
325 } |
|
326 |
|
327 // ---------------------------------------------------- |
|
328 // CLocalDocument::StartUpdateL |
|
329 // |
|
330 // ---------------------------------------------------- |
|
331 // |
|
332 void CLocalDocument::StartInternalL( TRequestStatus& aStatus ) |
|
333 { |
|
334 #ifdef _DEBUG |
|
335 iLocalProtocol.WriteToLog( _L8( "CLocalDocument::StartInternalL()" ) ); |
|
336 #endif |
|
337 aStatus = KRequestPending; |
|
338 iClientStatus = &aStatus; |
|
339 StartUpdateL(); |
|
340 } |
|
341 |
|
342 // ---------------------------------------------------- |
|
343 // CLocalDocument::CancelUpdate |
|
344 // |
|
345 // ---------------------------------------------------- |
|
346 // |
|
347 void CLocalDocument::CancelUpdate() |
|
348 { |
|
349 #ifdef _DEBUG |
|
350 iLocalProtocol.WriteToLog( _L8( "CLocalDocument::CancelUpdate()" ) ); |
|
351 #endif |
|
352 User::RequestComplete( iClientStatus, KErrCancel ); |
|
353 } |
|
354 |
|
355 // --------------------------------------------------------- |
|
356 // CLocalDocument::RunL() |
|
357 // |
|
358 // --------------------------------------------------------- |
|
359 // |
|
360 void CLocalDocument::RunL() |
|
361 { |
|
362 #ifdef _DEBUG |
|
363 iLocalProtocol.WriteToLog( _L8( "CLocalDocument::RunL()" ) ); |
|
364 #endif |
|
365 } |
|
366 |
|
367 // ---------------------------------------------------- |
|
368 // CLocalDocument::FinaliseOperation |
|
369 // |
|
370 // ---------------------------------------------------- |
|
371 // |
|
372 void CLocalDocument::FinaliseOperation( TInt aIndex ) |
|
373 { |
|
374 #ifdef _DEBUG |
|
375 iLocalProtocol.WriteToLog( _L8( "CLocalDocument::FinaliseOperation()" ) ); |
|
376 #endif |
|
377 TInt count = iChangeRequests.Count(); |
|
378 if( count > 0 && ( aIndex >= 0 && aIndex < count ) ) |
|
379 { |
|
380 MXdmOperation* operation = NULL; |
|
381 operation = iChangeRequests[aIndex]; |
|
382 iChangeRequests.Remove( aIndex ); |
|
383 operation->Destroy(); |
|
384 operation = NULL; |
|
385 } |
|
386 } |
|
387 |
|
388 // --------------------------------------------------------- |
|
389 // CLocalDocument::AppendNamespaceL |
|
390 // |
|
391 // --------------------------------------------------------- |
|
392 // |
|
393 void CLocalDocument::AppendNamespaceL( const TDesC8& aUri, const TDesC8& aPrefix ) |
|
394 { |
|
395 CXdmNamespace* ns = CXdmNamespace::NewL( aUri, aPrefix ); |
|
396 CleanupStack::PushL( ns ); |
|
397 User::LeaveIfError( iNamespaces.Append( ns ) ); |
|
398 CleanupStack::Pop(); //ns |
|
399 } |
|
400 |
|
401 // --------------------------------------------------------- |
|
402 // CXcapDocument::RemoveNamespace |
|
403 // |
|
404 // --------------------------------------------------------- |
|
405 // |
|
406 void CLocalDocument::RemoveNamespace( const TDesC8& aUri ) |
|
407 { |
|
408 TBool found = EFalse; |
|
409 CXdmNamespace* ns = NULL; |
|
410 TInt count = iNamespaces.Count(); |
|
411 for( TInt i = 0;!found && i < count;i++ ) |
|
412 { |
|
413 ns = iNamespaces[i]; |
|
414 if( ns->Uri().Compare( aUri ) == 0 ) |
|
415 { |
|
416 found = ETrue; |
|
417 iNamespaces.Remove( i ); |
|
418 delete ns; |
|
419 ns = NULL; |
|
420 } |
|
421 } |
|
422 } |
|
423 |
|
424 // --------------------------------------------------------- |
|
425 // CLocalDocument::Uri |
|
426 // |
|
427 // --------------------------------------------------------- |
|
428 // |
|
429 TPtrC8 CLocalDocument::Uri( const TDesC8& aPrefix ) const |
|
430 { |
|
431 TPtrC8 uri( _L8( "" ) ); |
|
432 TBool found = EFalse; |
|
433 TInt count = iNamespaces.Count(); |
|
434 for( TInt i = 0;i < count && !found;i++ ) |
|
435 { |
|
436 if( iNamespaces[i]->Prefix().Compare( aPrefix ) == 0 ) |
|
437 { |
|
438 uri.Set( iNamespaces[i]->Uri() ); |
|
439 found = ETrue; |
|
440 } |
|
441 } |
|
442 return uri; |
|
443 } |
|
444 |
|
445 // --------------------------------------------------------- |
|
446 // CLocalDocument::Count |
|
447 // |
|
448 // --------------------------------------------------------- |
|
449 // |
|
450 TInt CLocalDocument::Count() const |
|
451 { |
|
452 return iNamespaces.Count(); |
|
453 } |
|
454 |
|
455 // --------------------------------------------------------- |
|
456 // CLocalDocument::Prefix |
|
457 // |
|
458 // --------------------------------------------------------- |
|
459 // |
|
460 TPtrC8 CLocalDocument::Prefix( TInt aIndex ) const |
|
461 { |
|
462 TInt count = iNamespaces.Count(); |
|
463 if( count > 0 && ( aIndex >= 0 && aIndex < count ) ) |
|
464 return iNamespaces[aIndex]->Prefix(); |
|
465 else return TPtrC8(); |
|
466 } |
|
467 |
|
468 // --------------------------------------------------------- |
|
469 // CLocalDocument::Uri |
|
470 // |
|
471 // --------------------------------------------------------- |
|
472 // |
|
473 TPtrC8 CLocalDocument::Uri( TInt aIndex ) const |
|
474 { |
|
475 TInt count = iNamespaces.Count(); |
|
476 if( count > 0 && ( aIndex >= 0 && aIndex < count ) ) |
|
477 return iNamespaces[aIndex]->Uri(); |
|
478 else return TPtrC8(); |
|
479 } |
|
480 |
|
481 // --------------------------------------------------------- |
|
482 // CLocalDocument::ResetNamespaces |
|
483 // |
|
484 // --------------------------------------------------------- |
|
485 // |
|
486 void CLocalDocument::ResetNamespaces( ) |
|
487 { |
|
488 iNamespaces.ResetAndDestroy(); |
|
489 } |
|
490 |
|
491 // --------------------------------------------------------- |
|
492 // CLocalDocument::TimeStamp |
|
493 // |
|
494 // --------------------------------------------------------- |
|
495 // |
|
496 TTime CLocalDocument::TimeStamp() const |
|
497 { |
|
498 return iLastModification; |
|
499 } |
|
500 |
|
501 // --------------------------------------------------------- |
|
502 // CLocalDocument::SaveClientStatus |
|
503 // |
|
504 // --------------------------------------------------------- |
|
505 // |
|
506 void CLocalDocument::SaveClientStatus( TRequestStatus& aStatus ) |
|
507 { |
|
508 iClientStatus = &aStatus; |
|
509 } |
|
510 |
|
511 // --------------------------------------------------------- |
|
512 // CLocalDocument::DoCancel |
|
513 // |
|
514 // --------------------------------------------------------- |
|
515 // |
|
516 void CLocalDocument::DoCancel() |
|
517 { |
|
518 #ifdef _DEBUG |
|
519 iLocalProtocol.WriteToLog( _L8( "CLocalDocument::DoCancel()" ) ); |
|
520 #endif |
|
521 } |
|
522 |
|
523 |
|
524 |
|
525 |