| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2014 École Polytechnique de Montréal |
| 3 | * |
| 4 | * All rights reserved. This program and the accompanying materials are |
| 5 | * made available under the terms of the Eclipse Public License v1.0 which |
| 6 | * accompanies this distribution, and is available at |
| 7 | * http://www.eclipse.org/legal/epl-v10.html |
| 8 | * |
| 9 | * Contributors: |
| 10 | * Geneviève Bastien - Initial API and implementation |
| 11 | *******************************************************************************/ |
| 12 | |
| 13 | package org.eclipse.linuxtools.tmf.analysis.xml.ui.module; |
| 14 | |
| 15 | import java.io.File; |
| 16 | import java.io.IOException; |
| 17 | |
| 18 | import javax.xml.parsers.DocumentBuilder; |
| 19 | import javax.xml.parsers.DocumentBuilderFactory; |
| 20 | import javax.xml.parsers.ParserConfigurationException; |
| 21 | |
| 22 | import org.eclipse.core.runtime.IPath; |
| 23 | import org.eclipse.linuxtools.internal.tmf.analysis.xml.ui.Activator; |
| 24 | import org.eclipse.linuxtools.tmf.analysis.xml.core.module.XmlUtils; |
| 25 | import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModule; |
| 26 | import org.eclipse.linuxtools.tmf.core.analysis.ITmfNewAnalysisModuleListener; |
| 27 | import org.w3c.dom.Document; |
| 28 | import org.xml.sax.SAXException; |
| 29 | |
| 30 | /** |
| 31 | * This class searches all XML files to find outputs applicable to the newly |
| 32 | * created analysis |
| 33 | * |
| 34 | * @author Geneviève Bastien |
| 35 | */ |
| 36 | public class TmfXmlAnalysisOutputSource implements ITmfNewAnalysisModuleListener { |
| 37 | |
| 38 | /** String separating data elements for the output properties */ |
| 39 | public static final String DATA_SEPARATOR = ";;;"; //$NON-NLS-1$ |
| 40 | |
| 41 | @Override |
| 42 | public void moduleCreated(IAnalysisModule module) { |
| 43 | IPath pathToFiles = XmlUtils.getXmlFilesPath(); |
| 44 | File fFolder = pathToFiles.toFile(); |
| 45 | if (!(fFolder.isDirectory() && fFolder.exists())) { |
| 46 | return; |
| 47 | } |
| 48 | for (File xmlFile : fFolder.listFiles()) { |
| 49 | if (!XmlUtils.xmlValidate(xmlFile).isOK()) { |
| 50 | continue; |
| 51 | } |
| 52 | |
| 53 | try { |
| 54 | /* Load the XML File */ |
| 55 | DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); |
| 56 | DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); |
| 57 | Document doc = dBuilder.parse(xmlFile); |
| 58 | doc.getDocumentElement().normalize(); |
| 59 | |
| 60 | /* get state provider views if the analysis has state systems */ |
| 61 | /* TODO: Code here will come in later patch */ |
| 62 | |
| 63 | } catch (ParserConfigurationException | SAXException | IOException e) { |
| 64 | Activator.logError("Error opening XML file", e); //$NON-NLS-1$ |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | } |