Rename xxx.lttng to xxx.lttng.core
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf / src / org / eclipse / linuxtools / tmf / filter / xml / TmfFilterXMLParser.java
1 /*******************************************************************************
2 * Copyright (c) 2010 Ericsson
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 * Yuriy Vashchuk (yvashchuk@gmail.com) - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.filter.xml;
14
15 import java.io.IOException;
16
17 import javax.xml.parsers.ParserConfigurationException;
18 import javax.xml.parsers.SAXParserFactory;
19
20 import org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode;
21
22 import org.xml.sax.SAXException;
23 import org.xml.sax.XMLReader;
24
25 /**
26 * <b><u>FilterXMLParser</u></b>
27 * <p>
28 * This is SAX based XML parser
29 * <p>
30 */
31 public class TmfFilterXMLParser {
32
33 private static ITmfFilterTreeNode fRoot = null;
34
35 /**
36 * The XMLParser constructor
37 *
38 * @param uri The XML file to parse
39 */
40 public TmfFilterXMLParser(final String uri) throws SAXException, IOException {
41
42 SAXParserFactory m_parserFactory = null;
43 if (m_parserFactory == null) {
44 m_parserFactory = SAXParserFactory.newInstance();
45 m_parserFactory.setNamespaceAware(true);
46 }
47
48 XMLReader saxReader = null;
49 try {
50
51 saxReader = m_parserFactory.newSAXParser().getXMLReader();
52 saxReader.setContentHandler(new TmfFilterContentHandler());
53 saxReader.parse(uri);
54
55 fRoot = ((TmfFilterContentHandler) saxReader.getContentHandler()).getTree();
56
57 } catch (ParserConfigurationException e) {
58 e.printStackTrace();
59 }
60 }
61
62 /**
63 * Getter of tree
64 *
65 * @return The builded tree
66 */
67 public ITmfFilterTreeNode getTree() {
68 return fRoot;
69 }
70 }
This page took 0.034469 seconds and 5 git commands to generate.