|
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.dto.module.RuleVo; |
|
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 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 |
27
| public RuleHandler(final AbstractSimpleHandler handler) {
|
|
50 |
27
| super(handler, "RULE");
|
|
51 |
27
| descriptionHandler = new LatexListHandler(this, "DESCRIPTION");
|
|
52 |
27
| proofHandler = new ProofHandler(this);
|
|
53 |
| } |
|
54 |
| |
|
55 |
6
| public final void init() {
|
|
56 |
6
| rule = null;
|
|
57 |
| } |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
6
| public final Rule getRule() {
|
|
65 |
6
| return rule;
|
|
66 |
| } |
|
67 |
| |
|
68 |
15
| public final void startElement(final String name, final SimpleAttributes attributes)
|
|
69 |
| throws SyntaxException { |
|
70 |
15
| if (getStartTag().equals(name)) {
|
|
71 |
6
| rule = new RuleVo();
|
|
72 |
6
| if (null != attributes.getString("name")) {
|
|
73 |
6
| rule.setName(attributes.getString("name"));
|
|
74 |
| } else { |
|
75 |
0
| throw SyntaxException.createMissingAttributeException(name, "name");
|
|
76 |
| } |
|
77 |
9
| } else if ("LINK".equals(name)) {
|
|
78 |
3
| if (null != attributes.getString("id")) {
|
|
79 |
3
| rule.addLink(attributes.getString("id"));
|
|
80 |
| } else { |
|
81 |
0
| throw SyntaxException.createMissingAttributeException(name, "id");
|
|
82 |
| } |
|
83 |
6
| } else if (descriptionHandler.getStartTag().equals(name)) {
|
|
84 |
6
| 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 |
15
| public final void endElement(final String name) throws SyntaxException {
|
|
93 |
15
| if (getStartTag().equals(name)) {
|
|
94 |
| |
|
95 |
9
| } else if ("LINK".equals(name)) {
|
|
96 |
| |
|
97 |
6
| } else if (descriptionHandler.getStartTag().equals(name)) {
|
|
98 |
6
| 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 |
| } |