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.Rule; |
21 |
| import org.qedeq.kernel.common.SyntaxException; |
22 |
| import org.qedeq.kernel.dto.module.RuleVo; |
23 |
| import org.qedeq.kernel.xml.parser.AbstractSimpleHandler; |
24 |
| import org.qedeq.kernel.xml.parser.SimpleAttributes; |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| public class RuleHandler extends AbstractSimpleHandler { |
34 |
| |
35 |
| |
36 |
| private final LatexListHandler descriptionHandler; |
37 |
| |
38 |
| |
39 |
| private final ProofHandler proofHandler; |
40 |
| |
41 |
| |
42 |
| private RuleVo rule; |
43 |
| |
44 |
| |
45 |
| |
46 |
| |
47 |
| |
48 |
| |
49 |
46
| public RuleHandler(final AbstractSimpleHandler handler) {
|
50 |
46
| super(handler, "RULE");
|
51 |
46
| descriptionHandler = new LatexListHandler(this, "DESCRIPTION");
|
52 |
46
| proofHandler = new ProofHandler(this);
|
53 |
| } |
54 |
| |
55 |
28
| public final void init() {
|
56 |
28
| rule = null;
|
57 |
| } |
58 |
| |
59 |
| |
60 |
| |
61 |
| |
62 |
| |
63 |
| |
64 |
28
| public final Rule getRule() {
|
65 |
28
| return rule;
|
66 |
| } |
67 |
| |
68 |
63
| public final void startElement(final String name, final SimpleAttributes attributes)
|
69 |
| throws SyntaxException { |
70 |
63
| if (getStartTag().equals(name)) {
|
71 |
28
| rule = new RuleVo();
|
72 |
28
| if (null != attributes.getString("name")) {
|
73 |
28
| rule.setName(attributes.getString("name"));
|
74 |
| } else { |
75 |
0
| throw SyntaxException.createMissingAttributeException(name, "name");
|
76 |
| } |
77 |
35
| } else if ("LINK".equals(name)) {
|
78 |
7
| if (null != attributes.getString("id")) {
|
79 |
7
| rule.addLink(attributes.getString("id"));
|
80 |
| } else { |
81 |
0
| throw SyntaxException.createMissingAttributeException(name, "id");
|
82 |
| } |
83 |
28
| } else if (descriptionHandler.getStartTag().equals(name)) {
|
84 |
28
| changeHandler(descriptionHandler, name, attributes);
|
85 |
0
| } else if (proofHandler.getStartTag().equals(name)) {
|
86 |
0
| changeHandler(proofHandler, name, attributes);
|
87 |
| } else { |
88 |
0
| throw SyntaxException.createUnexpectedTagException(name);
|
89 |
| } |
90 |
| } |
91 |
| |
92 |
63
| public final void endElement(final String name) throws SyntaxException {
|
93 |
63
| if (getStartTag().equals(name)) {
|
94 |
| |
95 |
35
| } else if ("LINK".equals(name)) {
|
96 |
| |
97 |
28
| } else if (descriptionHandler.getStartTag().equals(name)) {
|
98 |
28
| rule.setDescription(descriptionHandler.getLatexList());
|
99 |
0
| } else if (proofHandler.getStartTag().equals(name)) {
|
100 |
0
| rule.addProof(proofHandler.getProof());
|
101 |
| } else { |
102 |
0
| throw SyntaxException.createUnexpectedTagException(name);
|
103 |
| } |
104 |
| } |
105 |
| |
106 |
| |
107 |
| } |