1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sourceforge.jeuclid.elements.generic;
20
21 import net.sourceforge.jeuclid.Constants;
22 import net.sourceforge.jeuclid.LayoutContext;
23 import net.sourceforge.jeuclid.context.Display;
24 import net.sourceforge.jeuclid.context.Parameter;
25 import net.sourceforge.jeuclid.elements.presentation.AbstractContainer;
26
27 import org.apache.batik.dom.AbstractDocument;
28 import org.w3c.dom.Node;
29 import org.w3c.dom.mathml.MathMLMathElement;
30
31
32
33
34
35
36 public final class MathImpl extends AbstractContainer implements
37 MathMLMathElement {
38
39 private final class ChildContext implements LayoutContext {
40 private final LayoutContext context;
41
42 private ChildContext(final LayoutContext myContext) {
43 this.context = myContext;
44 }
45
46 public Object getParameter(final Parameter which) {
47 Object retVal;
48 if (Parameter.DISPLAY.equals(which)) {
49 if (MathImpl.DISPLAY_BLOCK.equals(MathImpl.this.getDisplay())) {
50 retVal = Display.BLOCK;
51 } else {
52 retVal = Display.INLINE;
53 }
54 } else {
55 retVal = MathImpl.this.applyLocalAttributesToContext(
56 this.context).getParameter(which);
57 }
58 retVal = this.getParamValueFromJEuclidExt(which, retVal);
59 return retVal;
60 }
61
62 private Object getParamValueFromJEuclidExt(final Parameter which,
63 final Object currentValue) {
64 Object retVal = currentValue;
65 final String s0 = MathImpl.this.getAttributeNS(
66 Constants.NS_JEUCLID_EXT, which.getOptionName());
67 if ((s0 != null) && (s0.length() > 0)) {
68 retVal = which.fromString(s0);
69 } else {
70 retVal = this.getDeprecatedParamValuesFromJEuclidExt(which,
71 retVal);
72 }
73 return retVal;
74 }
75
76 private Object getDeprecatedParamValuesFromJEuclidExt(
77 final Parameter which, final Object currentValue) {
78
79 Object retVal = currentValue;
80 final String s = MathImpl.this.getAttributeNS(
81 Constants.NS_OLD_JEUCLID_EXT, which.getOptionName());
82 if ((s != null) && (s.length() > 0)) {
83 retVal = which.fromString(s);
84 } else {
85
86 final String s2 = MathImpl.this.getAttributeNS(
87 Constants.NS_OLD_JEUCLID_EXT, which.toString());
88 if ((s2 != null) && (s2.length() > 0)) {
89 retVal = which.fromString(s2);
90 }
91 }
92 return retVal;
93 }
94 }
95
96
97 public static final String ATTR_DISPLAY = "display";
98
99
100 public static final String ATTR_MACROS = "macros";
101
102
103
104
105 public static final String ELEMENT = "math";
106
107 private static final long serialVersionUID = 1L;
108
109
110 private static final String ATTR_MODE = "mode";
111
112 private static final String DISPLAY_INLINE = "inline";
113
114 private static final String DISPLAY_BLOCK = "block";
115
116
117 private static final String DEPRECATED_BLOCK_VALUE_FOR_MODE = MathImpl.ATTR_DISPLAY;
118
119
120
121
122
123
124
125
126
127 public MathImpl(final String qname, final AbstractDocument odoc) {
128 super(qname, odoc);
129 }
130
131
132 @Override
133 protected Node newNode() {
134 return new MathImpl(this.nodeName, this.ownerDocument);
135 }
136
137
138
139
140
141
142
143 public void setDisplay(final String display) {
144 this.setAttribute(MathImpl.ATTR_DISPLAY, display);
145 }
146
147
148
149
150
151
152 public String getDisplay() {
153 final String retVal;
154 final String attrDisplay = this.getMathAttribute(MathImpl.ATTR_DISPLAY);
155 if (attrDisplay == null) {
156 if (MathImpl.DEPRECATED_BLOCK_VALUE_FOR_MODE.equalsIgnoreCase(this
157 .getMathAttribute(MathImpl.ATTR_MODE))) {
158 retVal = MathImpl.DISPLAY_BLOCK;
159 } else {
160 retVal = MathImpl.DISPLAY_INLINE;
161 }
162 } else {
163 if (MathImpl.DISPLAY_BLOCK.equalsIgnoreCase(attrDisplay)) {
164 retVal = MathImpl.DISPLAY_BLOCK;
165 } else {
166 retVal = MathImpl.DISPLAY_INLINE;
167 }
168 }
169 return retVal;
170 }
171
172
173 @Override
174 public LayoutContext getChildLayoutContext(final int childNum,
175 final LayoutContext context) {
176 return new ChildContext(context);
177 }
178
179
180 public String getMacros() {
181 return this.getMathAttribute(MathImpl.ATTR_MACROS);
182 }
183
184
185 public void setMacros(final String macros) {
186 this.setAttribute(MathImpl.ATTR_MACROS, macros);
187 }
188
189 }