|
1 /* |
|
2 * Copyright (c) 2007-2010 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 * Imports general configuration from XML file |
|
17 * |
|
18 */ |
|
19 package com.nokia.traceviewer.engine.preferences; |
|
20 |
|
21 import java.io.File; |
|
22 |
|
23 import org.w3c.dom.Document; |
|
24 import org.w3c.dom.Element; |
|
25 import org.w3c.dom.Node; |
|
26 import org.w3c.dom.NodeList; |
|
27 |
|
28 import com.nokia.traceviewer.action.OpenDecodeFileAction; |
|
29 import com.nokia.traceviewer.engine.TraceViewerGlobals; |
|
30 |
|
31 /** |
|
32 * Imports general configuration from XML file |
|
33 */ |
|
34 public class XMLGeneralConfigurationImporter extends |
|
35 XMLBaseConfigurationImporter { |
|
36 |
|
37 /** |
|
38 * Constructor |
|
39 * |
|
40 * @param configurationFileName |
|
41 * file name where to import data from |
|
42 * @param pathRelative |
|
43 * tells is the path relative |
|
44 */ |
|
45 public XMLGeneralConfigurationImporter(String configurationFileName, |
|
46 boolean pathRelative) { |
|
47 super(null, configurationFileName, pathRelative); |
|
48 } |
|
49 |
|
50 /** |
|
51 * Imports data |
|
52 */ |
|
53 public void importData() { |
|
54 File file = new File(filePath); |
|
55 if (file.exists()) { |
|
56 Document doc = getDocument(); |
|
57 |
|
58 if (doc != null) { |
|
59 |
|
60 // Get lineCount node from the XML file |
|
61 NodeList list = doc.getElementsByTagName(GENERAL_TAG); |
|
62 Node parent = list.item(0); |
|
63 |
|
64 // Import configurations |
|
65 if (parent != null) { |
|
66 NodeList children = parent.getChildNodes(); |
|
67 for (int i = 0; i < children.getLength(); i++) { |
|
68 if (children.item(i) instanceof Element) { |
|
69 processItems(children.item(i)); |
|
70 } |
|
71 } |
|
72 } |
|
73 } |
|
74 } |
|
75 } |
|
76 |
|
77 /** |
|
78 * Import configurations |
|
79 * |
|
80 * @param node |
|
81 * Configuration node |
|
82 */ |
|
83 private void processItems(Node node) { |
|
84 // Decode file |
|
85 if (node.getNodeName().equals(DECODEFILE_TAG)) { |
|
86 processDecodeFile(node); |
|
87 } |
|
88 } |
|
89 |
|
90 /** |
|
91 * Processes decode file node |
|
92 * |
|
93 * @param node |
|
94 * node to be processed |
|
95 */ |
|
96 private void processDecodeFile(Node node) { |
|
97 String path = node.getTextContent(); |
|
98 if (path != null && !path.equals("")) { //$NON-NLS-1$ |
|
99 OpenDecodeFileAction action = (OpenDecodeFileAction) TraceViewerGlobals |
|
100 .getTraceViewer().getView().getActionFactory() |
|
101 .getOpenDecodeFileAction(); |
|
102 action.addOpenInStartupDictionary(path); |
|
103 } |
|
104 } |
|
105 } |