|
1 /* |
|
2 * Copyright (c) 2008 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: |
|
15 * |
|
16 * Exporter for dictionary file |
|
17 * |
|
18 */ |
|
19 package com.nokia.tracecompiler.decodeplugins.dictionary; |
|
20 |
|
21 import java.io.File; |
|
22 |
|
23 import com.nokia.tracecompiler.engine.TraceCompilerEngineConfiguration; |
|
24 import com.nokia.tracecompiler.engine.TraceCompilerEngineGlobals; |
|
25 import com.nokia.tracecompiler.file.FileUtils; |
|
26 import com.nokia.tracecompiler.model.TraceModel; |
|
27 import com.nokia.tracecompiler.source.SourceConstants; |
|
28 |
|
29 /** |
|
30 * Exporter for dictionary file |
|
31 * |
|
32 */ |
|
33 final class DictionaryFileExport { |
|
34 |
|
35 /** |
|
36 * The dictionary file properties |
|
37 */ |
|
38 private DictionaryFile dictionaryFile; |
|
39 |
|
40 /** |
|
41 * Constructor |
|
42 * |
|
43 * @param dictionary |
|
44 * the dictionary file |
|
45 */ |
|
46 DictionaryFileExport(DictionaryFile dictionary) { |
|
47 this.dictionaryFile = dictionary; |
|
48 } |
|
49 |
|
50 /** |
|
51 * Exports the dictionary file |
|
52 */ |
|
53 void exportDictionary() { |
|
54 String exportPath = getExportPath(File.separatorChar); |
|
55 String exportFile = dictionaryFile.getFileName(); |
|
56 String envRoot = TraceCompilerEngineGlobals.getConfiguration().getText( |
|
57 TraceCompilerEngineConfiguration.ENVIRONMENT_ROOT); |
|
58 if (envRoot != null) { |
|
59 File target = new File(envRoot + exportPath + exportFile); |
|
60 // The dictionary file is updated with the new environment root |
|
61 dictionaryFile.updatePath(target.getAbsolutePath()); |
|
62 DictionaryFileWriter writer = new DictionaryFileWriter( |
|
63 dictionaryFile); |
|
64 writer.write(); |
|
65 dictionaryFile.postFileWrittenEvent(dictionaryFile |
|
66 .getAbsolutePathWithID()); |
|
67 } |
|
68 } |
|
69 |
|
70 /** |
|
71 * Returns the export path for dictionary files |
|
72 * |
|
73 * @param separator |
|
74 * the file separator to use |
|
75 * @return the export path |
|
76 */ |
|
77 private static String getExportPath(char separator) { |
|
78 String exportPath = DictionaryPreferences.DEFAULT_EXPORT_PATH; |
|
79 |
|
80 // Accepts both types of separators, ends with separator |
|
81 exportPath = FileUtils.convertSeparators(separator, exportPath, true); |
|
82 return exportPath; |
|
83 } |
|
84 |
|
85 /** |
|
86 * Gets the default path to the dictionary file |
|
87 * |
|
88 * @param model |
|
89 * trace model |
|
90 * @return the file |
|
91 */ |
|
92 static String getPathForDictionary(TraceModel model) { |
|
93 String fileName = model.getName() |
|
94 + DictionaryFileConstants.DICTIONARY_FILE_EXTENSION; |
|
95 String exportPath = getExportPath(File.separatorChar); |
|
96 String envRoot = TraceCompilerEngineGlobals.getConfiguration().getText( |
|
97 TraceCompilerEngineConfiguration.ENVIRONMENT_ROOT); |
|
98 return FileUtils.convertSeparators(SourceConstants.FORWARD_SLASH_CHAR, |
|
99 envRoot + exportPath + fileName, false); |
|
100 } |
|
101 |
|
102 } |