| 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 | 9622 | private final class ChildContext implements LayoutContext { |
| 40 | |
private final LayoutContext context; |
| 41 | |
|
| 42 | 9622 | private ChildContext(final LayoutContext myContext) { |
| 43 | 9622 | this.context = myContext; |
| 44 | 9622 | } |
| 45 | |
|
| 46 | |
public Object getParameter(final Parameter which) { |
| 47 | |
Object retVal; |
| 48 | 735752 | if (Parameter.DISPLAY.equals(which)) { |
| 49 | 12122 | if (MathImpl.DISPLAY_BLOCK.equals(MathImpl.this.getDisplay())) { |
| 50 | 11286 | retVal = Display.BLOCK; |
| 51 | |
} else { |
| 52 | 836 | retVal = Display.INLINE; |
| 53 | |
} |
| 54 | |
} else { |
| 55 | 723630 | retVal = MathImpl.this.applyLocalAttributesToContext( |
| 56 | |
this.context).getParameter(which); |
| 57 | |
} |
| 58 | 735752 | retVal = this.getParamValueFromJEuclidExt(which, retVal); |
| 59 | 735752 | return retVal; |
| 60 | |
} |
| 61 | |
|
| 62 | |
private Object getParamValueFromJEuclidExt(final Parameter which, |
| 63 | |
final Object currentValue) { |
| 64 | 735752 | Object retVal = currentValue; |
| 65 | 735752 | final String s0 = MathImpl.this.getAttributeNS( |
| 66 | |
Constants.NS_JEUCLID_EXT, which.getOptionName()); |
| 67 | 735752 | if ((s0 != null) && (s0.length() > 0)) { |
| 68 | 418 | retVal = which.fromString(s0); |
| 69 | |
} else { |
| 70 | 735334 | retVal = this.getDeprecatedParamValuesFromJEuclidExt(which, |
| 71 | |
retVal); |
| 72 | |
} |
| 73 | 735752 | return retVal; |
| 74 | |
} |
| 75 | |
|
| 76 | |
private Object getDeprecatedParamValuesFromJEuclidExt( |
| 77 | |
final Parameter which, final Object currentValue) { |
| 78 | |
|
| 79 | 735334 | Object retVal = currentValue; |
| 80 | 735334 | final String s = MathImpl.this.getAttributeNS( |
| 81 | |
Constants.NS_OLD_JEUCLID_EXT, which.getOptionName()); |
| 82 | 735334 | if ((s != null) && (s.length() > 0)) { |
| 83 | 418 | retVal = which.fromString(s); |
| 84 | |
} else { |
| 85 | |
|
| 86 | 734916 | final String s2 = MathImpl.this.getAttributeNS( |
| 87 | |
Constants.NS_OLD_JEUCLID_EXT, which.toString()); |
| 88 | 734916 | if ((s2 != null) && (s2.length() > 0)) { |
| 89 | 0 | retVal = which.fromString(s2); |
| 90 | |
} |
| 91 | |
} |
| 92 | 735334 | 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 | 15581 | super(qname, odoc); |
| 129 | 15581 | } |
| 130 | |
|
| 131 | |
|
| 132 | |
@Override |
| 133 | |
protected Node newNode() { |
| 134 | 0 | return new MathImpl(this.nodeName, this.ownerDocument); |
| 135 | |
} |
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
|
| 142 | |
|
| 143 | |
public void setDisplay(final String display) { |
| 144 | 0 | this.setAttribute(MathImpl.ATTR_DISPLAY, display); |
| 145 | 0 | } |
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
public String getDisplay() { |
| 153 | |
final String retVal; |
| 154 | 12331 | final String attrDisplay = this.getMathAttribute(MathImpl.ATTR_DISPLAY); |
| 155 | 12331 | if (attrDisplay == null) { |
| 156 | 12331 | if (MathImpl.DEPRECATED_BLOCK_VALUE_FOR_MODE.equalsIgnoreCase(this |
| 157 | |
.getMathAttribute(MathImpl.ATTR_MODE))) { |
| 158 | 11495 | retVal = MathImpl.DISPLAY_BLOCK; |
| 159 | |
} else { |
| 160 | 836 | retVal = MathImpl.DISPLAY_INLINE; |
| 161 | |
} |
| 162 | |
} else { |
| 163 | 0 | if (MathImpl.DISPLAY_BLOCK.equalsIgnoreCase(attrDisplay)) { |
| 164 | 0 | retVal = MathImpl.DISPLAY_BLOCK; |
| 165 | |
} else { |
| 166 | 0 | retVal = MathImpl.DISPLAY_INLINE; |
| 167 | |
} |
| 168 | |
} |
| 169 | 12331 | return retVal; |
| 170 | |
} |
| 171 | |
|
| 172 | |
|
| 173 | |
@Override |
| 174 | |
public LayoutContext getChildLayoutContext(final int childNum, |
| 175 | |
final LayoutContext context) { |
| 176 | 9622 | return new ChildContext(context); |
| 177 | |
} |
| 178 | |
|
| 179 | |
|
| 180 | |
public String getMacros() { |
| 181 | 0 | return this.getMathAttribute(MathImpl.ATTR_MACROS); |
| 182 | |
} |
| 183 | |
|
| 184 | |
|
| 185 | |
public void setMacros(final String macros) { |
| 186 | 0 | this.setAttribute(MathImpl.ATTR_MACROS, macros); |
| 187 | 0 | } |
| 188 | |
|
| 189 | |
} |