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.dto.module.FunctionDefinitionVo; |
21 |
| import org.qedeq.kernel.xml.parser.AbstractSimpleHandler; |
22 |
| import org.qedeq.kernel.xml.parser.SimpleAttributes; |
23 |
| import org.qedeq.kernel.xml.parser.SyntaxException; |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| public final class FunctionDefinitionHandler extends AbstractSimpleHandler { |
33 |
| |
34 |
| |
35 |
| private final VariableListHandler variableListHandler; |
36 |
| |
37 |
| |
38 |
| private final TermHandler termHandler; |
39 |
| |
40 |
| |
41 |
| private final LatexListHandler descriptionHandler; |
42 |
| |
43 |
| |
44 |
| private FunctionDefinitionVo definition; |
45 |
| |
46 |
| |
47 |
| private String latexPattern; |
48 |
| |
49 |
| |
50 |
| |
51 |
| |
52 |
| |
53 |
| |
54 |
| |
55 |
27
| public FunctionDefinitionHandler(final AbstractSimpleHandler handler) {
|
56 |
27
| super(handler, "DEFINITION_FUNCTION");
|
57 |
27
| variableListHandler = new VariableListHandler(this);
|
58 |
27
| termHandler = new TermHandler(this);
|
59 |
27
| descriptionHandler = new LatexListHandler(this, "DESCRIPTION");
|
60 |
| } |
61 |
| |
62 |
48
| public final void init() {
|
63 |
48
| definition = null;
|
64 |
48
| latexPattern = null;
|
65 |
| } |
66 |
| |
67 |
| |
68 |
| |
69 |
| |
70 |
| |
71 |
| |
72 |
48
| public final FunctionDefinitionVo getDefinition() {
|
73 |
48
| return definition;
|
74 |
| } |
75 |
| |
76 |
183
| public final void startElement(final String name, final SimpleAttributes attributes)
|
77 |
| throws SyntaxException { |
78 |
183
| if (getStartTag().equals(name)) {
|
79 |
48
| definition = new FunctionDefinitionVo();
|
80 |
48
| definition.setArgumentNumber(attributes.getString("arguments"));
|
81 |
48
| definition.setName(attributes.getString("name"));
|
82 |
135
| } else if ("LATEXPATTERN".equals(name)) {
|
83 |
| |
84 |
87
| } else if (variableListHandler.getStartTag().equals(name)) {
|
85 |
39
| changeHandler(variableListHandler, name, attributes);
|
86 |
48
| } else if (termHandler.getStartTag().equals(name)) {
|
87 |
48
| changeHandler(termHandler, name, attributes);
|
88 |
0
| } else if (descriptionHandler.getStartTag().equals(name)) {
|
89 |
0
| changeHandler(descriptionHandler, name, attributes);
|
90 |
| } else { |
91 |
0
| throw SyntaxException.createUnexpectedTagException(name);
|
92 |
| } |
93 |
| } |
94 |
| |
95 |
183
| public final void endElement(final String name) throws SyntaxException {
|
96 |
183
| if (getStartTag().equals(name)) {
|
97 |
| |
98 |
135
| } else if ("LATEXPATTERN".equals(name)) {
|
99 |
48
| definition.setLatexPattern(latexPattern);
|
100 |
87
| } else if (variableListHandler.getStartTag().equals(name)) {
|
101 |
39
| definition.setVariableList(variableListHandler.getVariables());
|
102 |
48
| } else if (termHandler.getStartTag().equals(name)) {
|
103 |
48
| definition.setTerm(termHandler.getTerm());
|
104 |
0
| } else if (descriptionHandler.getStartTag().equals(name)) {
|
105 |
0
| definition.setDescription(descriptionHandler.getLatexList());
|
106 |
| } else { |
107 |
0
| throw SyntaxException.createUnexpectedTagException(name);
|
108 |
| } |
109 |
| } |
110 |
| |
111 |
48
| public final void characters(final String name, final String data) {
|
112 |
48
| if ("LATEXPATTERN".equals(name)) {
|
113 |
48
| latexPattern = data;
|
114 |
| } else { |
115 |
0
| throw new RuntimeException("Unexpected character data in tag: " + name);
|
116 |
| } |
117 |
| } |
118 |
| |
119 |
| |
120 |
| } |