TMF: Add support for XML-defined analysis outputs
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.analysis.xml.ui / src / org / eclipse / linuxtools / tmf / analysis / xml / ui / module / TmfXmlAnalysisOutputSource.java
CommitLineData
048bde85
GB
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
13package org.eclipse.linuxtools.tmf.analysis.xml.ui.module;
14
15import java.io.File;
16import java.io.IOException;
17
18import javax.xml.parsers.DocumentBuilder;
19import javax.xml.parsers.DocumentBuilderFactory;
20import javax.xml.parsers.ParserConfigurationException;
21
22import org.eclipse.core.runtime.IPath;
23import org.eclipse.linuxtools.internal.tmf.analysis.xml.ui.Activator;
24import org.eclipse.linuxtools.tmf.analysis.xml.core.module.XmlUtils;
25import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModule;
26import org.eclipse.linuxtools.tmf.core.analysis.ITmfNewAnalysisModuleListener;
27import org.w3c.dom.Document;
28import 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 */
36public 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}
This page took 0.034596 seconds and 5 git commands to generate.