tmf: Switch tmf.core to Java 7 + fix warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / filter / xml / TmfFilterContentHandler.java
CommitLineData
be222f56 1/*******************************************************************************
11252342
AM
2 * Copyright (c) 2010, 2013 Ericsson
3 *
be222f56
PT
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
11252342 8 *
be222f56
PT
9 * Contributors:
10 * Yuriy Vashchuk (yvashchuk@gmail.com) - Initial API and implementation
11 * based on http://smeric.developpez.com/java/cours/xml/sax/
12 * Patrick Tasse - Refactoring
13 *******************************************************************************/
14
15package org.eclipse.linuxtools.tmf.core.filter.xml;
16
17import java.util.Stack;
18
19import org.eclipse.linuxtools.tmf.core.filter.model.ITmfFilterTreeNode;
20import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterAndNode;
21import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterCompareNode;
22import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterContainsNode;
23import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterEqualsNode;
24import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterEventTypeNode;
25import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterMatchesNode;
26import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterNode;
27import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterOrNode;
28import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterRootNode;
29import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterTreeNode;
30import org.eclipse.linuxtools.tmf.core.filter.model.TmfFilterCompareNode.Type;
31import org.xml.sax.Attributes;
32import org.xml.sax.SAXException;
33import org.xml.sax.helpers.DefaultHandler;
34
35/**
36 * The SAX Content Handler
11252342 37 *
be222f56
PT
38 * @version 1.0
39 * @author Yuriy Vashchuk
40 * @author Patrick Tasse
41 */
42public class TmfFilterContentHandler extends DefaultHandler {
11252342 43
be222f56
PT
44 private ITmfFilterTreeNode fRoot = null;
45 private Stack<ITmfFilterTreeNode> fFilterTreeStack = null;
46
47 /**
48 * The default constructor
11252342 49 */
be222f56
PT
50 public TmfFilterContentHandler() {
51 super();
a4524c1b 52 fFilterTreeStack = new Stack<>();
be222f56
PT
53 }
54
55 /**
56 * Getter of tree
11252342 57 *
be222f56 58 * @return The builded tree
11252342 59 */
be222f56
PT
60 public ITmfFilterTreeNode getTree() {
61 return fRoot;
62 }
11252342
AM
63
64
be222f56
PT
65 @Override
66 public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
67 ITmfFilterTreeNode node = null;
11252342 68
be222f56 69 if (localName.equalsIgnoreCase(TmfFilterRootNode.NODE_NAME)) {
11252342 70
be222f56 71 node = new TmfFilterRootNode();
11252342 72
be222f56 73 } else if (localName.equals(TmfFilterNode.NODE_NAME)) {
11252342 74
be222f56 75 node = new TmfFilterNode(atts.getValue(TmfFilterNode.NAME_ATTR));
11252342 76
be222f56 77 } else if (localName.equals(TmfFilterEventTypeNode.NODE_NAME)) {
11252342 78
be222f56
PT
79 node = new TmfFilterEventTypeNode(null);
80 ((TmfFilterEventTypeNode) node).setEventType(atts.getValue(TmfFilterEventTypeNode.TYPE_ATTR));
81 ((TmfFilterEventTypeNode) node).setName(atts.getValue(TmfFilterEventTypeNode.NAME_ATTR));
11252342 82
be222f56 83 } else if (localName.equals(TmfFilterAndNode.NODE_NAME)) {
11252342 84
be222f56
PT
85 node = new TmfFilterAndNode(null);
86 String value = atts.getValue(TmfFilterAndNode.NOT_ATTR);
87 if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) {
88 ((TmfFilterAndNode) node).setNot(true);
89 }
11252342 90
be222f56 91 } else if (localName.equals(TmfFilterOrNode.NODE_NAME)) {
11252342 92
be222f56
PT
93 node = new TmfFilterOrNode(null);
94 String value = atts.getValue(TmfFilterOrNode.NOT_ATTR);
95 if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) {
96 ((TmfFilterOrNode) node).setNot(true);
97 }
11252342 98
be222f56 99 } else if (localName.equals(TmfFilterContainsNode.NODE_NAME)) {
11252342 100
be222f56
PT
101 node = new TmfFilterContainsNode(null);
102 String value = atts.getValue(TmfFilterContainsNode.NOT_ATTR);
103 if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) {
104 ((TmfFilterContainsNode) node).setNot(true);
105 }
106 ((TmfFilterContainsNode) node).setField(atts.getValue(TmfFilterContainsNode.FIELD_ATTR));
107 ((TmfFilterContainsNode) node).setValue(atts.getValue(TmfFilterContainsNode.VALUE_ATTR));
108 value = atts.getValue(TmfFilterContainsNode.IGNORECASE_ATTR);
109 if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) {
110 ((TmfFilterContainsNode) node).setIgnoreCase(true);
111 }
11252342 112
be222f56 113 } else if (localName.equals(TmfFilterEqualsNode.NODE_NAME)) {
11252342 114
be222f56
PT
115 node = new TmfFilterEqualsNode(null);
116 String value = atts.getValue(TmfFilterEqualsNode.NOT_ATTR);
117 if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) {
118 ((TmfFilterEqualsNode) node).setNot(true);
119 }
120 ((TmfFilterEqualsNode) node).setField(atts.getValue(TmfFilterEqualsNode.FIELD_ATTR));
121 ((TmfFilterEqualsNode) node).setValue(atts.getValue(TmfFilterEqualsNode.VALUE_ATTR));
122 value = atts.getValue(TmfFilterEqualsNode.IGNORECASE_ATTR);
123 if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) {
124 ((TmfFilterEqualsNode) node).setIgnoreCase(true);
125 }
11252342 126
be222f56 127 } else if (localName.equals(TmfFilterMatchesNode.NODE_NAME)) {
11252342 128
be222f56
PT
129 node = new TmfFilterMatchesNode(null);
130 String value = atts.getValue(TmfFilterMatchesNode.NOT_ATTR);
131 if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) {
132 ((TmfFilterMatchesNode) node).setNot(true);
133 }
134 ((TmfFilterMatchesNode) node).setField(atts.getValue(TmfFilterMatchesNode.FIELD_ATTR));
135 ((TmfFilterMatchesNode) node).setRegex(atts.getValue(TmfFilterMatchesNode.REGEX_ATTR));
11252342 136
be222f56 137 } else if (localName.equals(TmfFilterCompareNode.NODE_NAME)) {
11252342 138
be222f56
PT
139 node = new TmfFilterCompareNode(null);
140 String value = atts.getValue(TmfFilterCompareNode.NOT_ATTR);
141 if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) {
142 ((TmfFilterCompareNode) node).setNot(true);
143 }
144 ((TmfFilterCompareNode) node).setField(atts.getValue(TmfFilterCompareNode.FIELD_ATTR));
145 value = atts.getValue(TmfFilterCompareNode.TYPE_ATTR);
146 if (value != null) {
147 ((TmfFilterCompareNode) node).setType(Type.valueOf(value));
148 }
149 value = atts.getValue(TmfFilterCompareNode.RESULT_ATTR);
150 if (value != null) {
151 if (value.equals(Integer.toString(-1))) {
152 ((TmfFilterCompareNode) node).setResult(-1);
153 } else if (value.equals(Integer.toString(1))) {
154 ((TmfFilterCompareNode) node).setResult(1);
155 } else {
156 ((TmfFilterCompareNode) node).setResult(0);
157 }
158 }
159 ((TmfFilterCompareNode) node).setValue(atts.getValue(TmfFilterCompareNode.VALUE_ATTR));
11252342 160
be222f56
PT
161 }
162
163 fFilterTreeStack.push(node);
164 }
165
be222f56
PT
166 @Override
167 public void endElement(String uri, String localName, String qName) throws SAXException {
168 ITmfFilterTreeNode node = fFilterTreeStack.pop();
169
170 if (fFilterTreeStack.isEmpty()) {
171 fRoot = node;
172 } else if (fFilterTreeStack.lastElement() instanceof TmfFilterTreeNode &&
173 node instanceof TmfFilterTreeNode) {
174 fFilterTreeStack.lastElement().addChild(node);
175 }
11252342 176
be222f56
PT
177 }
178
179}
This page took 0.037885 seconds and 5 git commands to generate.