1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| package org.qedeq.kernel.xml.handler.module; |
19 |
| |
20 |
| import org.qedeq.kernel.base.module.PredicateDefinition; |
21 |
| import org.qedeq.kernel.dto.module.PredicateDefinitionVo; |
22 |
| import org.qedeq.kernel.xml.parser.AbstractSimpleHandler; |
23 |
| import org.qedeq.kernel.xml.parser.SimpleAttributes; |
24 |
| import org.qedeq.kernel.xml.parser.SyntaxException; |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| public final class PredicateDefinitionHandler extends AbstractSimpleHandler { |
34 |
| |
35 |
| |
36 |
| private final VariableListHandler variableListHandler; |
37 |
| |
38 |
| |
39 |
| private final FormulaHandler formulaHandler; |
40 |
| |
41 |
| |
42 |
| private final LatexListHandler descriptionHandler; |
43 |
| |
44 |
| |
45 |
| private PredicateDefinitionVo definition; |
46 |
| |
47 |
| |
48 |
| private String latexPattern; |
49 |
| |
50 |
| |
51 |
| |
52 |
| |
53 |
| |
54 |
| |
55 |
| |
56 |
27
| public PredicateDefinitionHandler(final AbstractSimpleHandler handler) {
|
57 |
27
| super(handler, "DEFINITION_PREDICATE");
|
58 |
27
| variableListHandler = new VariableListHandler(this);
|
59 |
27
| formulaHandler = new FormulaHandler(this);
|
60 |
27
| descriptionHandler = new LatexListHandler(this, "DESCRIPTION");
|
61 |
| } |
62 |
| |
63 |
60
| public final void init() {
|
64 |
60
| definition = null;
|
65 |
60
| latexPattern = null;
|
66 |
| } |
67 |
| |
68 |
| |
69 |
| |
70 |
| |
71 |
| |
72 |
| |
73 |
60
| public final PredicateDefinition getDefinition() {
|
74 |
60
| return definition;
|
75 |
| } |
76 |
| |
77 |
222
| public final void startElement(final String name, final SimpleAttributes attributes)
|
78 |
| throws SyntaxException { |
79 |
222
| if (getStartTag().equals(name)) {
|
80 |
60
| definition = new PredicateDefinitionVo();
|
81 |
60
| definition.setArgumentNumber(attributes.getString("arguments"));
|
82 |
60
| definition.setName(attributes.getString("name"));
|
83 |
162
| } else if ("LATEXPATTERN".equals(name)) {
|
84 |
| |
85 |
102
| } else if (variableListHandler.getStartTag().equals(name)) {
|
86 |
60
| changeHandler(variableListHandler, name, attributes);
|
87 |
42
| } else if (formulaHandler.getStartTag().equals(name)) {
|
88 |
42
| changeHandler(formulaHandler, name, attributes);
|
89 |
0
| } else if (descriptionHandler.getStartTag().equals(name)) {
|
90 |
0
| changeHandler(descriptionHandler, name, attributes);
|
91 |
| } else { |
92 |
0
| throw SyntaxException.createUnexpectedTagException(name);
|
93 |
| } |
94 |
| } |
95 |
| |
96 |
222
| public final void endElement(final String name) throws SyntaxException {
|
97 |
222
| if (getStartTag().equals(name)) {
|
98 |
| |
99 |
162
| } else if ("LATEXPATTERN".equals(name)) {
|
100 |
60
| definition.setLatexPattern(latexPattern);
|
101 |
102
| } else if (variableListHandler.getStartTag().equals(name)) {
|
102 |
60
| definition.setVariableList(variableListHandler.getVariables());
|
103 |
42
| } else if (formulaHandler.getStartTag().equals(name)) {
|
104 |
42
| definition.setFormula(formulaHandler.getFormula());
|
105 |
0
| } else if (descriptionHandler.getStartTag().equals(name)) {
|
106 |
0
| definition.setDescription(descriptionHandler.getLatexList());
|
107 |
| } else { |
108 |
0
| throw SyntaxException.createUnexpectedTagException(name);
|
109 |
| } |
110 |
| } |
111 |
| |
112 |
60
| public final void characters(final String name, final String data) {
|
113 |
60
| if ("LATEXPATTERN".equals(name)) {
|
114 |
60
| latexPattern = data;
|
115 |
| } else { |
116 |
0
| throw new RuntimeException("Unexpected character data in tag: " + name);
|
117 |
| } |
118 |
| } |
119 |
| |
120 |
| |
121 |
| } |