1 /** |
|
2 * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "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 * Symbian Foundation - initial contribution. |
|
11 * Contributors: |
|
12 * Description: |
|
13 * Overview: |
|
14 * Details: |
|
15 * Platforms/Drives/Compatibility: |
|
16 * Assumptions/Requirement/Pre-requisites: |
|
17 * Failures and causes: |
|
18 */ |
|
19 |
|
20 package org.symbian.tools.wrttools.core.deploy.emulator; |
|
21 |
|
22 import java.io.File; |
|
23 import java.io.FileInputStream; |
|
24 import java.io.IOException; |
|
25 import java.util.HashMap; |
|
26 |
|
27 import javax.xml.parsers.DocumentBuilder; |
|
28 import javax.xml.parsers.DocumentBuilderFactory; |
|
29 import javax.xml.parsers.ParserConfigurationException; |
|
30 |
|
31 import org.eclipse.core.runtime.IPath; |
|
32 import org.eclipse.core.runtime.Path; |
|
33 import org.symbian.tools.wrttools.core.IWRTConstants; |
|
34 import org.w3c.dom.Document; |
|
35 import org.w3c.dom.NamedNodeMap; |
|
36 import org.w3c.dom.Node; |
|
37 import org.w3c.dom.NodeList; |
|
38 import org.xml.sax.SAXException; |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 /** |
|
44 * The Content provider for the Emulators List displayed. |
|
45 * @author avraina |
|
46 * |
|
47 */ |
|
48 public class EmulatorListProvider{ |
|
49 |
|
50 /** |
|
51 * Map containing of the SDKS with the corresponding paths. |
|
52 */ |
|
53 private static HashMap<String, String> listofEmulators = new HashMap<String, String>(); |
|
54 |
|
55 public static HashMap<String, String> populateEmulators() { |
|
56 if (listofEmulators == null) { |
|
57 listofEmulators = new HashMap<String, String>(); |
|
58 } |
|
59 listofEmulators.clear(); |
|
60 initialize(); |
|
61 return listofEmulators; |
|
62 } |
|
63 |
|
64 // helper methods |
|
65 |
|
66 /** |
|
67 * This will parse the xml and create the nodes to be displayed on the table |
|
68 * viewer. The information will be used by content & label provider to get |
|
69 * the contents and display accordingly in the list of the projects in the view. |
|
70 */ |
|
71 public static HashMap<String, String> initialize() { |
|
72 |
|
73 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); |
|
74 // Parse the devices.xml and retrieve the list of the emulators from it |
|
75 // and build the list to be displayed in the view. |
|
76 |
|
77 try { |
|
78 DocumentBuilder builder = factory.newDocumentBuilder(); |
|
79 File file = new File(IWRTConstants.DEVICES_XML_PATH); |
|
80 if (!file.exists()) { |
|
81 IPath otherPath = new Path(System.getProperty("user.home")) |
|
82 .append(IWRTConstants.DEVICES_VISTA_XML_PATH); |
|
83 file = otherPath.toFile(); |
|
84 } |
|
85 if(file.exists()){ |
|
86 FileInputStream fin = new FileInputStream(file); |
|
87 Document document = builder.parse(fin); |
|
88 NodeList childNodes = document.getChildNodes(); |
|
89 |
|
90 |
|
91 |
|
92 for (int i = 0; i < childNodes.getLength(); i++) { |
|
93 |
|
94 Node node = childNodes.item(i); |
|
95 String nodeName = node.getNodeName(); |
|
96 // If the node name is "devices" it is the root node of the xml. |
|
97 if (nodeName.equals(IWRTConstants.DEVICES_TAG)) { |
|
98 // once we have the root node get the child information to |
|
99 // build the devices list. |
|
100 createDevicesList(node); |
|
101 |
|
102 } |
|
103 } |
|
104 if(listofEmulators.size() == 0){ |
|
105 listofEmulators.put("None",""); |
|
106 } |
|
107 |
|
108 |
|
109 |
|
110 } |
|
111 |
|
112 } catch (ParserConfigurationException e) { |
|
113 // WidgetUtils.getView().getLogger().severe(e.getMessage()); |
|
114 } catch (SAXException e) { |
|
115 // WidgetUtils.getView().getLogger().severe(e.getMessage()); |
|
116 } catch (IOException e) { |
|
117 // WidgetUtils.getView().getLogger().severe(e.getMessage()); |
|
118 } |
|
119 return listofEmulators; |
|
120 } |
|
121 |
|
122 /** |
|
123 * Creates the devices nodes in the table. |
|
124 * @param parentNode |
|
125 */ |
|
126 private static void createDevicesList(Node parentNode) { |
|
127 NodeList list = getChildNodes(parentNode); |
|
128 for (int i = 0; i < list.getLength(); i++) { |
|
129 Node node = list.item(i); |
|
130 String nodeName = node.getNodeName(); |
|
131 if (nodeName.equals(IWRTConstants.DEVICE_TAG)) { |
|
132 createDeviceChildNode(node); |
|
133 } |
|
134 } |
|
135 } |
|
136 |
|
137 /** |
|
138 * Gets the EPOC ROOT node and than finally the list of devices. |
|
139 * @param parentNode |
|
140 */ |
|
141 private static void createDeviceChildNode(Node parentNode) { |
|
142 NodeList list = getChildNodes(parentNode); |
|
143 for (int i = 0; i < list.getLength(); i++) { |
|
144 Node node = list.item(i); |
|
145 String nodeName = node.getNodeName(); |
|
146 if (nodeName.equals(IWRTConstants.EPOC_ROOT_TAG)) { |
|
147 addProject(node,parentNode); |
|
148 } |
|
149 } |
|
150 } |
|
151 |
|
152 /** |
|
153 * Adds the devices to the list to be displayed. |
|
154 * @param deviceNode the device node |
|
155 * @param epocNode the epoc root node. |
|
156 */ |
|
157 private static void addProject(Node epocNode, Node deviceNode) { |
|
158 NodeList list = getChildNodes(epocNode); |
|
159 NamedNodeMap attributes = deviceNode.getAttributes(); |
|
160 String sdkId=""; |
|
161 String sdkName=""; |
|
162 for (int i = 0; i < attributes.getLength(); i++) { |
|
163 Node item = attributes.item(i); |
|
164 if(item.getNodeName().equals(IWRTConstants.NAME_ATTR)){ |
|
165 sdkName = item.getNodeValue(); |
|
166 } |
|
167 if(item.getNodeName().equals(IWRTConstants.ID_ATTR)){ |
|
168 sdkId = item.getNodeValue(); |
|
169 } |
|
170 } |
|
171 for (int i = 0; i < list.getLength(); i++) { |
|
172 Node node = list.item(i); |
|
173 if(sdkName.equals(IWRTConstants.EMULATOR_NAME)){ |
|
174 listofEmulators.put(sdkId, node.getNodeValue()); |
|
175 } |
|
176 } |
|
177 } |
|
178 |
|
179 /** |
|
180 * Returns the child list of the particular Node. |
|
181 * @param parentNode |
|
182 */ |
|
183 private static NodeList getChildNodes(Node parentNode) { |
|
184 return parentNode.getChildNodes(); |
|
185 } |
|
186 } |
|