|
1 /* |
|
2 * Copyright (c) 2009 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: Metadata import/export metadata and schema files |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef __MDSIMPORTEXPORT_H__ |
|
19 #define __MDSIMPORTEXPORT_H__ |
|
20 |
|
21 #include <e32base.h> |
|
22 #include <s32file.h> |
|
23 #include <flogger.h> |
|
24 |
|
25 #include "mdccommon.h" |
|
26 |
|
27 |
|
28 class CMdsNamespaceDef; |
|
29 class CMdsObjectDef; |
|
30 class CMdsRelationDef; |
|
31 class CMdsEventDef; |
|
32 class CCnvCharacterSetConverter; |
|
33 class CMdsClauseBuffer; |
|
34 class CMdsSchema; |
|
35 class CMdSSqlObjectManipulate; |
|
36 class CMdCSerializationBuffer; |
|
37 class CDesC16ArrayFlat; |
|
38 class RRowData; |
|
39 |
|
40 // declarations |
|
41 const TInt KMdsMaxLineLenght = 1024; |
|
42 const TInt KPropertyMinValue = 1; |
|
43 const TInt KPropertyMaxValue = 2; |
|
44 const TInt KPropertyDefValue = 3; |
|
45 |
|
46 /** |
|
47 * Metadata schema container within server |
|
48 * |
|
49 * This class is responsible for read MDE schema file and store all |
|
50 * information into one memory place. |
|
51 * |
|
52 */ |
|
53 class CMdsImportExport : public CBase |
|
54 { |
|
55 // friend class CMdsSchema; |
|
56 public: |
|
57 /** |
|
58 * Create new SchemaImport class |
|
59 * @return new created class |
|
60 */ |
|
61 static CMdsImportExport* NewL(); |
|
62 |
|
63 /** |
|
64 * Create new SchemaImport class |
|
65 * @return new created class |
|
66 */ |
|
67 static CMdsImportExport* NewLC(); |
|
68 |
|
69 /** |
|
70 * Destructor |
|
71 */ |
|
72 virtual ~CMdsImportExport(); |
|
73 |
|
74 /** |
|
75 * Reads and process schema file to classess hierarchy. |
|
76 * |
|
77 * @param aFileName filename to read from |
|
78 * @param aSchema schema where to read file ontology |
|
79 */ |
|
80 void ImportSchemaFromFileL( const TDesC& aFileName, CMdsSchema& aSchema, TUint32 aVendorId ); |
|
81 |
|
82 /** |
|
83 * Reads schema from DB |
|
84 * |
|
85 * @param aConnection connection to DB |
|
86 * @param aSchema returning schema |
|
87 */ |
|
88 void ImportSchemaFromDBL( CMdsSchema& aSchema ); |
|
89 |
|
90 /** |
|
91 * Checks for schema version information |
|
92 * @return ETrue if match, otherwise EFalse |
|
93 */ |
|
94 TBool ImportCheckVersionInfoL(); |
|
95 |
|
96 /** |
|
97 * Import items from file and add them do DB |
|
98 * |
|
99 * @return failed count |
|
100 */ |
|
101 TInt ImportMetadataL( CMdSSqlObjectManipulate& aManipulate, CMdsSchema& aSchemaNew, const TDesC16& aFileName ); |
|
102 |
|
103 /** |
|
104 * Export all (without confidential) items to file |
|
105 */ |
|
106 void ExportMetadataL( CMdsSchema& aSchemaNew, const TDesC16& aFileName, |
|
107 CMdCSerializationBuffer& aItems ); |
|
108 |
|
109 protected: |
|
110 |
|
111 |
|
112 /* |
|
113 IMPORT SCHEMA FILE |
|
114 */ |
|
115 |
|
116 /** |
|
117 * Imports a single schema file line |
|
118 * @param aParser a TLex8 object that parses a line of stream |
|
119 */ |
|
120 void ImportSchemaLineL( TLex8& aParser ); |
|
121 |
|
122 /** |
|
123 * imports a namespace |
|
124 * @param aParser the remaining parameters |
|
125 */ |
|
126 void ImportSchemaNamespaceL( TLex8& aParser ); |
|
127 |
|
128 /** |
|
129 * imports an object def |
|
130 * @param aParser the remaining parameters |
|
131 */ |
|
132 void ImportSchemaObjectDefL( TLex8& aParser ); |
|
133 |
|
134 /** |
|
135 * imports a property definition |
|
136 * @param aParser the remaining parameters |
|
137 */ |
|
138 void ImportSchemaPropertyDefL( TLex8& aParser ); |
|
139 |
|
140 /** |
|
141 * imports a relation definition |
|
142 * @param aParser the remaining parameters |
|
143 */ |
|
144 void ImportSchemaRelationDefL( TLex8& aParser ); |
|
145 |
|
146 /** |
|
147 * imports a event definition |
|
148 * @param aParser the remaining parameters |
|
149 */ |
|
150 void ImportSchemaEventDefL( TLex8& aParser ); |
|
151 |
|
152 /** |
|
153 * imports a version number |
|
154 * @param aParser the remaining parameters |
|
155 */ |
|
156 void ImportSchemaVersionL( TLex8& aParser ); |
|
157 |
|
158 /** |
|
159 * Checks that no more parameters are given in the current schema line. |
|
160 * @param aParser the remaining parameters |
|
161 */ |
|
162 void CheckNoMoreNumericParametersL( TLex8& aParser ); |
|
163 |
|
164 /* |
|
165 IMPORT METADATA FILE |
|
166 */ |
|
167 /** |
|
168 * Reads a single metadata file line |
|
169 * @return if reading is still possible (not end of file) |
|
170 */ |
|
171 TBool ReadMetadataFileLineL(); |
|
172 |
|
173 /** |
|
174 * add object to DB |
|
175 */ |
|
176 void AddObjectToDBL( CMdSSqlObjectManipulate& aManipulate, CMdsNamespaceDef* aNamespaceDef ); |
|
177 |
|
178 /** |
|
179 * Imports a single metadata item |
|
180 * @param aParser a TLex8 object that parses a line of stream |
|
181 */ |
|
182 void ImportMetadataItemL( TLex8& aParser, CMdSSqlObjectManipulate& aManipulate ); |
|
183 |
|
184 /** |
|
185 * imports an metadata file object |
|
186 * @param aParser the remaining parameters |
|
187 */ |
|
188 void ImportMetadataFileObjectL( TLex8& aParser, CMdSSqlObjectManipulate& aManipulate ); |
|
189 |
|
190 /** |
|
191 * imports an metadata file property |
|
192 * @param aParser the remaining parameters |
|
193 */ |
|
194 TMdCOffset ImportMetadataFilePropertyL( TLex8& aParser, TMdCOffset aFreespaceOffset ); |
|
195 |
|
196 /** |
|
197 * imports an metadata file freetext |
|
198 * @param aParser the remaining parameters |
|
199 */ |
|
200 void ImportMetadataFileFreeTextL( TLex8& aParser, CDesC16ArrayFlat& aFreeTextArray ); |
|
201 |
|
202 /** |
|
203 * imports an metadata file relation |
|
204 * @param aParser the remaining parameters |
|
205 */ |
|
206 void ImportMetadataFileRelationL( TLex8& aParser, CMdSSqlObjectManipulate& aManipulate ); |
|
207 |
|
208 /** |
|
209 * imports an metadata file event |
|
210 * @param aParser the remaining parameters |
|
211 */ |
|
212 void ImportMetadataFileEventL( TLex8& aParser, CMdSSqlObjectManipulate& aManipulate ); |
|
213 |
|
214 |
|
215 /* |
|
216 EXPORT MATADATA FILE |
|
217 */ |
|
218 // objects |
|
219 void ExportMetadataMakeSqlObjectClauseL( const CMdsNamespaceDef& aNamespaceDef, const CMdsObjectDef& aObjectDef, |
|
220 CMdsClauseBuffer& aClause, RRowData& aDataRow ); |
|
221 |
|
222 void ExportMetadataMakeFreeTextSqlClauseL( const CMdsNamespaceDef& aNamespaceDef, |
|
223 CMdsClauseBuffer& aFreeTextClause, RRowData& aFreeTextRow ); |
|
224 |
|
225 void ExportMetadataWriteObjectInfoL( const CMdsNamespaceDef& aNamespaceDef, const CMdsObjectDef& aObjectDef, |
|
226 CMdsClauseBuffer& aClause, RRowData& aDataRow, |
|
227 CMdsClauseBuffer& aFreeTextClause, RRowData& aFreeTextRow ); |
|
228 |
|
229 // relations |
|
230 void ExportMetadataMakeSqlRelationClauseL( const CMdsNamespaceDef& aNamespaceDef, |
|
231 CMdsClauseBuffer& aClause, RRowData& aDataRow ); |
|
232 |
|
233 void ExportMetadataWriteRelationInfoL( const CMdsNamespaceDef& aNamespaceDef, const CMdsRelationDef& aRelationDef, |
|
234 CMdsClauseBuffer& aClause, RRowData& aDataRow ); |
|
235 |
|
236 // events |
|
237 void ExportMetadataMakeSqlEventClauseL( const CMdsNamespaceDef& aNamespaceDef, |
|
238 CMdsClauseBuffer& aClause, RRowData& aDataRow ); |
|
239 |
|
240 void ExportMetadataWriteEventInfoL( const CMdsNamespaceDef& aNamespaceDef, const CMdsEventDef& aEventDef, |
|
241 CMdsClauseBuffer& aClause, RRowData& aDataRow ); |
|
242 |
|
243 |
|
244 // |
|
245 // Helpers |
|
246 // |
|
247 |
|
248 /** |
|
249 * Parses a safe TUint32 from the lexical parser. |
|
250 * The type is assumed to be decimal. |
|
251 * @param aValue parsed TUint32 value |
|
252 * @param aParser the remaining patameters |
|
253 * @return system wide error code |
|
254 */ |
|
255 TInt ImportUInt32( TUint32& aValue, TLex8& aParser ); |
|
256 |
|
257 /** |
|
258 * Parses mediaID from the lexical parser. |
|
259 * The type is assumed to be decimal. |
|
260 * @param aValue parsed TUint32 value |
|
261 * @param aParser the remaining patameters |
|
262 * @param aDriveLetter drive letter of the drive where the file under processing is located |
|
263 * @return system wide error code |
|
264 */ |
|
265 TInt ImportMediaId( TUint32& aValue, TLex8& aParser, TChar& aDriveLetter ); |
|
266 |
|
267 /** |
|
268 * Parses a safe TInt64 from the lexical parser. |
|
269 * The type is assumed to be decimal. |
|
270 * @param aValue parsed TInt64 value |
|
271 * @param aParser the remaining patameters |
|
272 * @return system wide error code |
|
273 */ |
|
274 TInt ImportInt64( TInt64& aValue, TLex8& aParser ); |
|
275 |
|
276 /** |
|
277 * Parses a safe TTime from the lexical parser. |
|
278 * implemented using GetNumericL template method. |
|
279 * @param aValue parsed TTime value |
|
280 * @param aParser the remaining patameters |
|
281 * @return system wide error code |
|
282 */ |
|
283 TInt ImportTime( TTime& aValue, TLex8& aParser ); |
|
284 |
|
285 /** |
|
286 * Parses a safe descriptor from the lexical parser. |
|
287 * @param aValue parsed descriptor |
|
288 * @param aParser the remaining patameters |
|
289 * @return system wide error code |
|
290 */ |
|
291 TInt ImportText( TDes16& aBuffer, TLex8& aParser ); |
|
292 |
|
293 /** |
|
294 * Parses a safe number type from given lexical parser. |
|
295 * The number type is given in a template parameter. |
|
296 * @param aValue parsed value of number type |
|
297 * @param aParser the remaining patameters |
|
298 * @return system wide error code |
|
299 */ |
|
300 template<class NumberType> |
|
301 TInt ImportNum( NumberType& aValue, TLex8& aParser ) |
|
302 { |
|
303 TLex8 tokenParser( aParser.NextToken() ); |
|
304 aParser.SkipSpace(); |
|
305 if ( tokenParser.Val( aValue ) != KErrNone ) |
|
306 { |
|
307 return KErrCorrupt; |
|
308 } |
|
309 return KErrNone; |
|
310 } |
|
311 |
|
312 TInt ImportNum( TReal32& aValue, TLex8& aParser ) |
|
313 { |
|
314 TLex8 tokenParser( aParser.NextToken() ); |
|
315 aParser.SkipSpace(); |
|
316 if ( tokenParser.Val( aValue,TChar(TUint('.')) ) != KErrNone ) |
|
317 { |
|
318 return KErrCorrupt; |
|
319 } |
|
320 return KErrNone; |
|
321 } |
|
322 |
|
323 TInt ImportNum( TReal64& aValue, TLex8& aParser ) |
|
324 { |
|
325 TLex8 tokenParser( aParser.NextToken() ); |
|
326 aParser.SkipSpace(); |
|
327 if ( tokenParser.Val( aValue,TChar(TUint('.')) ) != KErrNone ) |
|
328 { |
|
329 return KErrCorrupt; |
|
330 } |
|
331 return KErrNone; |
|
332 } |
|
333 /** |
|
334 * Converts from UTF8 -> Unicode |
|
335 * @param aUtf8 input descriptor |
|
336 * @param aBuffer result buffer |
|
337 * @return descriptor of TDesC16 type |
|
338 */ |
|
339 TDesC16& Conv8To16( const TDesC8& aUtf8, TDes16& aBuffer ); |
|
340 |
|
341 /** |
|
342 * Converts from Unicode -> UTF8 |
|
343 * @param aUnicode input descriptor |
|
344 * @param aBuffer result buffer |
|
345 * @return descriptor of TDesC8 type |
|
346 */ |
|
347 TDesC8& Conv16To8( const TDesC16& aUnicode, TDes8& aBuffer ); |
|
348 |
|
349 |
|
350 /** PROPERTY READING HELPER FUNCTIONS */ |
|
351 |
|
352 /** |
|
353 * Parses Uint32 value or check for one of min, max or def |
|
354 * constant value |
|
355 * @return depending on result: |
|
356 * 1 for min |
|
357 * 2 for max |
|
358 * 3 for default |
|
359 * -value for errors |
|
360 */ |
|
361 TInt CheckForConstant( TLex8& aParser ); |
|
362 |
|
363 /** |
|
364 * Parses Uint32 value or check for one of min, max or def |
|
365 * constant value |
|
366 */ |
|
367 TInt ImportPropertyUInt32( TUint32& aValue, TLex8& aParser ); |
|
368 |
|
369 /** |
|
370 * Parses a safe TInt64 from the lexical parser. |
|
371 * The type is assumed to be decimal. |
|
372 * @param aValue parsed TInt64 value |
|
373 * @param aParser parser |
|
374 */ |
|
375 TInt ImportPropertyInt64( TInt64& aValue, TLex8& aParser ); |
|
376 |
|
377 /** |
|
378 * Parses a safe TTime from the lexical parser. |
|
379 * implemented using GetNumericL template method. |
|
380 * @param aValue parsed TTime value |
|
381 * @param aParser the remaining patameters |
|
382 * @return system wide error code |
|
383 */ |
|
384 TInt ImportPropertyTime( TTime& aValue, TLex8& aParser ); |
|
385 |
|
386 /** |
|
387 * Parses a safe number type from given lexical parser. |
|
388 * The number type is given in a template parameter. |
|
389 * @param aValue parsed value of number type |
|
390 * @param aParser the remaining patameters |
|
391 * @return system wide error code |
|
392 */ |
|
393 template<class NumberType> |
|
394 TInt SetMinMaxDefValueL( TInt aError, NumberType& aValue, |
|
395 const NumberType& aMinValue, const NumberType& aMaxValue, |
|
396 const NumberType& aDefValue ) |
|
397 { |
|
398 if ( aError < KErrNone ) |
|
399 { |
|
400 return aError; |
|
401 } |
|
402 if ( aError == KPropertyMinValue) |
|
403 { |
|
404 aValue = aMinValue; |
|
405 return KErrNone; |
|
406 } |
|
407 else if ( aError == KPropertyMaxValue ) |
|
408 { |
|
409 aValue = aMaxValue; |
|
410 return KErrNone; |
|
411 } |
|
412 else if ( aError == KPropertyDefValue ) |
|
413 { |
|
414 aValue = aDefValue; |
|
415 return KErrNone; |
|
416 } |
|
417 return KErrArgument; |
|
418 } |
|
419 private: |
|
420 |
|
421 CMdsImportExport(); |
|
422 |
|
423 void ImportNamespaceFromDBL(); |
|
424 /* |
|
425 * 2nd phase constructor |
|
426 */ |
|
427 void ConstructL(); |
|
428 |
|
429 /** |
|
430 * Data import error logger |
|
431 * @param aMessage a message to be logged |
|
432 */ |
|
433 void LogError( const TDesC& aMessage ); |
|
434 |
|
435 private: |
|
436 /** |
|
437 * Store every namespace read from schema file. |
|
438 */ |
|
439 CMdsSchema* iSchema; |
|
440 |
|
441 /** |
|
442 * default schema |
|
443 * not own - do not delete |
|
444 */ |
|
445 CMdsSchema* iDefaultSchema; |
|
446 |
|
447 /** |
|
448 * Last read objectdef, where new properties should go. |
|
449 * Just for speed access to property add access time. |
|
450 * !! DO NOT DELETE !! - NOT OWN |
|
451 */ |
|
452 CMdsObjectDef* iLastObjectDef; |
|
453 |
|
454 /** |
|
455 * Unicode<->UTF8 converter |
|
456 */ |
|
457 CCnvCharacterSetConverter* iConverter; |
|
458 |
|
459 /** logs import errors to file */ |
|
460 RFileLogger iLog; |
|
461 |
|
462 /** |
|
463 * File stream used for reading the import file |
|
464 */ |
|
465 RFileReadStream iReadStream; |
|
466 |
|
467 /** |
|
468 * File stream used for reading the import file |
|
469 */ |
|
470 RFileWriteStream iWriteStream; |
|
471 |
|
472 |
|
473 /** |
|
474 * Handle to actual processing file |
|
475 */ |
|
476 RFs iFs; |
|
477 |
|
478 /** |
|
479 * current parsing filename |
|
480 */ |
|
481 TFileName iFileName; |
|
482 |
|
483 /** |
|
484 * current verdor id |
|
485 */ |
|
486 TUint32 iVendorId; |
|
487 |
|
488 /** |
|
489 * current parsing line buffer |
|
490 */ |
|
491 TBuf8<KMdsMaxLineLenght> iLine; |
|
492 |
|
493 /** |
|
494 * buffer for reading metadata file |
|
495 */ |
|
496 CMdCSerializationBuffer* iBuffer; |
|
497 |
|
498 /** |
|
499 * indicated if last line was processed |
|
500 */ |
|
501 TBool iLastLineProcessed; |
|
502 |
|
503 /** |
|
504 * current parsing line number |
|
505 */ |
|
506 TInt iLineNumber; |
|
507 |
|
508 /** |
|
509 * import failed count |
|
510 */ |
|
511 TUint32 iFailed; |
|
512 |
|
513 enum TImportVersionFlags |
|
514 { |
|
515 EVersionNone = 0x0000, |
|
516 EVersionAlreadyRead = 0x0001, |
|
517 }; |
|
518 TUint32 iVersionFlags; |
|
519 |
|
520 TInt iLastDriveNumber; |
|
521 |
|
522 TVolumeInfo iLastVolumeInfo; |
|
523 }; |
|
524 |
|
525 |
|
526 #endif // __MDSIMPORTEXPORT_H__ |