1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sourceforge.jeuclid.elements.content.semantic;
20
21 import net.sourceforge.jeuclid.elements.presentation.AbstractContainer;
22
23 import org.apache.batik.dom.AbstractDocument;
24 import org.w3c.dom.Node;
25 import org.w3c.dom.mathml.MathMLElement;
26 import org.w3c.dom.mathml.MathMLSemanticsElement;
27
28
29
30
31
32
33 public final class Semantics extends AbstractContainer implements
34 MathMLSemanticsElement {
35
36
37
38
39 public static final String ELEMENT = "semantics";
40
41 private static final long serialVersionUID = 1L;
42
43
44
45
46
47
48
49
50
51 public Semantics(final String qname, final AbstractDocument odoc) {
52 super(qname, odoc);
53 }
54
55
56 @Override
57 protected Node newNode() {
58 return new Semantics(this.nodeName, this.ownerDocument);
59 }
60
61
62 public void deleteAnnotation(final int index) {
63 this.removeAnnotation(index);
64 }
65
66
67 public MathMLElement getAnnotation(final int index) {
68
69 return (MathMLElement) this.getChildNodes().item(index);
70 }
71
72
73 public MathMLElement getBody() {
74 return (MathMLElement) this.getFirstChild();
75 }
76
77
78 public int getNAnnotations() {
79 return Math.max(0, this.getChildNodes().getLength() - 1);
80 }
81
82
83 public MathMLElement insertAnnotation(final MathMLElement newAnnotation,
84 final int index) {
85 if (index == 0) {
86 if (this.getNAnnotations() == 0) {
87 this.setAnnotation(newAnnotation, 1);
88 } else {
89 this.addMathElement(newAnnotation);
90 }
91 } else {
92 final MathMLElement oldChild = this.getAnnotation(index);
93 if (oldChild == null) {
94 this.setAnnotation(newAnnotation, index);
95 } else {
96 this.insertBefore(newAnnotation, oldChild);
97 }
98 }
99 return newAnnotation;
100 }
101
102
103 public MathMLElement removeAnnotation(final int index) {
104 final MathMLElement oldChild = this.getAnnotation(index);
105 return (MathMLElement) this.removeChild(oldChild);
106 }
107
108
109 public MathMLElement setAnnotation(final MathMLElement newAnnotation,
110 final int index) {
111
112 this.setMathElement(index, newAnnotation);
113 return newAnnotation;
114 }
115
116
117 public void setBody(final MathMLElement body) {
118 this.setMathElement(0, body);
119 }
120
121 }