ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / filter / xml / TmfFilterXMLParser.java
1 /*******************************************************************************
2 * Copyright (c) 2010, 2012 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.core.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.core.filter.model.ITmfFilterTreeNode;
21 import org.xml.sax.SAXException;
22 import org.xml.sax.XMLReader;
23
24 /**
25 * The SAX based XML parser
26 *
27 * @version 1.0
28 * @author Yuriy Vashchuk
29 * @author Patrick Tasse
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 * @throws SAXException SAX exception
40 * @throws IOException IO exception
41 */
42 public TmfFilterXMLParser(final String uri) throws SAXException, IOException {
43
44 SAXParserFactory m_parserFactory = null;
45 m_parserFactory = SAXParserFactory.newInstance();
46 m_parserFactory.setNamespaceAware(true);
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.049017 seconds and 5 git commands to generate.