1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.qedeq.kernel.xml.handler.parser; |
17 |
|
|
18 |
|
import java.util.ArrayList; |
19 |
|
import java.util.List; |
20 |
|
|
21 |
|
import org.qedeq.kernel.bo.parser.Operator; |
22 |
|
import org.qedeq.kernel.xml.common.XmlSyntaxException; |
23 |
|
import org.qedeq.kernel.xml.handler.common.AbstractSimpleHandler; |
24 |
|
import org.qedeq.kernel.xml.handler.common.SaxDefaultHandler; |
25 |
|
import org.qedeq.kernel.xml.handler.common.SimpleAttributes; |
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
@author |
32 |
|
|
|
|
| 0% |
Uncovered Elements: 107 (107) |
Complexity: 30 |
Complexity Density: 0.54 |
|
33 |
|
public final class ParserHandler extends AbstractSimpleHandler { |
34 |
|
|
35 |
|
|
36 |
|
private List operators = new ArrayList(); |
37 |
|
|
38 |
|
|
39 |
|
private String startSymbol; |
40 |
|
|
41 |
|
|
42 |
|
private String qedeq; |
43 |
|
|
44 |
|
|
45 |
|
private String qedeqArgument; |
46 |
|
|
47 |
|
|
48 |
|
private Integer priority; |
49 |
|
|
50 |
|
|
51 |
|
private Integer min; |
52 |
|
|
53 |
|
|
54 |
|
private Integer max; |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
@param |
61 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
62 |
0
|
public ParserHandler(final SaxDefaultHandler defaultHandler) {... |
63 |
0
|
super(defaultHandler, "parser"); |
64 |
|
} |
65 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
66 |
0
|
public final void init() {... |
67 |
0
|
operators.clear(); |
68 |
|
} |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
@return |
74 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
75 |
0
|
public final List getOperators() {... |
76 |
0
|
return operators; |
77 |
|
} |
78 |
|
|
|
|
| 0% |
Uncovered Elements: 46 (46) |
Complexity: 11 |
Complexity Density: 0.42 |
|
79 |
0
|
public final void startElement(final String name, final SimpleAttributes attributes)... |
80 |
|
throws XmlSyntaxException { |
81 |
0
|
if (getStartTag().equals(name)) { |
82 |
|
|
83 |
0
|
} else if ("prefixOperator".equals(name)) { |
84 |
0
|
setBasisAttributes(name, attributes); |
85 |
0
|
addOperator(Operator.SIMPLE_PREFIX); |
86 |
0
|
} else if ("infixOperator".equals(name)) { |
87 |
0
|
setBasisAttributes(name, attributes); |
88 |
0
|
addOperator(Operator.INFIX); |
89 |
0
|
} else if ("functionOperator".equals(name)) { |
90 |
0
|
setBasisAttributes(name, attributes); |
91 |
0
|
addOperator(Operator.FUNCTION); |
92 |
0
|
} else if ("complexOperator".equals(name)) { |
93 |
0
|
setBasisAttributes(name, attributes); |
94 |
0
|
final String separatorSymbol = attributes.getString("separatorSymbol"); |
95 |
0
|
if (separatorSymbol == null) { |
96 |
0
|
throw XmlSyntaxException.createEmptyAttributeException(name, "separatorSymbol"); |
97 |
|
} |
98 |
0
|
if (separatorSymbol.length() == 0) { |
99 |
0
|
throw XmlSyntaxException.createMissingAttributeException(name, "separatorSymbol"); |
100 |
|
} |
101 |
0
|
final String endSymbol = attributes.getString("endSymbol"); |
102 |
0
|
if (endSymbol == null) { |
103 |
0
|
throw XmlSyntaxException.createEmptyAttributeException(name, "endSymbol"); |
104 |
|
} |
105 |
0
|
if (endSymbol.length() == 0) { |
106 |
0
|
throw XmlSyntaxException.createMissingAttributeException(name, "endSymbol"); |
107 |
|
} |
108 |
0
|
if (max == null) { |
109 |
0
|
operators.add(new Operator(startSymbol, separatorSymbol, endSymbol, qedeq, |
110 |
|
qedeqArgument, priority.intValue(), min.intValue())); |
111 |
|
} else { |
112 |
0
|
operators.add(new Operator(startSymbol, separatorSymbol, endSymbol, qedeq, |
113 |
|
qedeqArgument, priority.intValue(), min.intValue(), max.intValue())); |
114 |
|
} |
115 |
|
} else { |
116 |
0
|
throw XmlSyntaxException.createUnexpectedTagException(name); |
117 |
|
} |
118 |
|
} |
119 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
120 |
0
|
private void addOperator(final int type) {... |
121 |
0
|
if (max == null) { |
122 |
0
|
operators.add(new Operator(startSymbol, qedeq, qedeqArgument, priority.intValue(), |
123 |
|
type, min.intValue())); |
124 |
|
} else { |
125 |
0
|
operators.add(new Operator(startSymbol, qedeq, qedeqArgument, priority.intValue(), |
126 |
|
type, min.intValue(), max.intValue())); |
127 |
|
} |
128 |
|
} |
129 |
|
|
|
|
| 0% |
Uncovered Elements: 30 (30) |
Complexity: 8 |
Complexity Density: 0.44 |
|
130 |
0
|
private void setBasisAttributes(final String element, final SimpleAttributes attributes)... |
131 |
|
throws XmlSyntaxException { |
132 |
0
|
startSymbol = attributes.getString("startSymbol"); |
133 |
0
|
if (startSymbol == null) { |
134 |
0
|
throw XmlSyntaxException.createMissingAttributeException(element, "startSymbol"); |
135 |
|
} |
136 |
0
|
if (startSymbol.length() == 0) { |
137 |
0
|
throw XmlSyntaxException.createEmptyAttributeException(element, "startSymbol"); |
138 |
|
} |
139 |
0
|
qedeq = attributes.getString("qedeq"); |
140 |
0
|
if (qedeq == null) { |
141 |
0
|
throw XmlSyntaxException.createMissingAttributeException(element, "qedeq"); |
142 |
|
} |
143 |
0
|
if (qedeq.length() == 0) { |
144 |
0
|
throw XmlSyntaxException.createEmptyAttributeException(element, "qedeq"); |
145 |
|
} |
146 |
0
|
qedeqArgument = attributes.getString("qedeqArgument"); |
147 |
0
|
priority = attributes.getInteger("priority"); |
148 |
0
|
if (priority == null || priority.intValue() < 0) { |
149 |
0
|
throw XmlSyntaxException.createMissingAttributeException(element, "priority"); |
150 |
|
} |
151 |
0
|
min = attributes.getInteger("min"); |
152 |
0
|
if (min == null) { |
153 |
0
|
min = new Integer(0); |
154 |
|
} |
155 |
0
|
max = attributes.getInteger("max"); |
156 |
|
} |
157 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 6 |
Complexity Density: 1 |
|
158 |
0
|
public final void endElement(final String name) throws XmlSyntaxException {... |
159 |
0
|
if (getStartTag().equals(name)) { |
160 |
|
|
161 |
0
|
} else if ("prefixOperator".equals(name)) { |
162 |
|
|
163 |
0
|
} else if ("infixOperator".equals(name)) { |
164 |
|
|
165 |
0
|
} else if ("functionOperator".equals(name)) { |
166 |
|
|
167 |
0
|
} else if ("complexOperator".equals(name)) { |
168 |
|
|
169 |
|
} else { |
170 |
0
|
throw XmlSyntaxException.createUnexpectedTagException(name); |
171 |
|
} |
172 |
|
} |
173 |
|
|
174 |
|
} |