Coverage Report - net.sourceforge.jeuclid.elements.generic.MathImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
MathImpl
50%
9/18
50%
3/6
2
MathImpl$1
N/A
N/A
2
MathImpl$ChildContext
96%
24/25
75%
12/16
2
 
 1  
 /*
 2  
  * Copyright 2002 - 2007 JEuclid, http://jeuclid.sf.net
 3  
  * 
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 /* $Id: MathImpl.java,v c169040ef426 2009/10/28 08:55:31 max $ */
 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  
  * The root element for creating a MathElement tree.
 33  
  * 
 34  
  * @version $Revision: c169040ef426 $
 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  
             // old namespace
 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  
                 // Support deprecated attributes
 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  
     /** attribute for display. */
 97  
     public static final String ATTR_DISPLAY = "display";
 98  
 
 99  
     /** attribute for macros. */
 100  
     public static final String ATTR_MACROS = "macros";
 101  
 
 102  
     /**
 103  
      * The XML element from this class.
 104  
      */
 105  
     public static final String ELEMENT = "math";
 106  
 
 107  
     private static final long serialVersionUID = 1L;
 108  
 
 109  
     /** attribute for mode. */
 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  
     // Happens to be display as well.
 117  
     private static final String DEPRECATED_BLOCK_VALUE_FOR_MODE = MathImpl.ATTR_DISPLAY;
 118  
 
 119  
     /**
 120  
      * Default constructor. Sets MathML Namespace.
 121  
      * 
 122  
      * @param qname
 123  
      *            Qualified name.
 124  
      * @param odoc
 125  
      *            Owner Document.
 126  
      */
 127  
     public MathImpl(final String qname, final AbstractDocument odoc) {
 128  15581
         super(qname, odoc);
 129  15581
     }
 130  
 
 131  
     /** {@inheritDoc} */
 132  
     @Override
 133  
     protected Node newNode() {
 134  0
         return new MathImpl(this.nodeName, this.ownerDocument);
 135  
     }
 136  
 
 137  
     /**
 138  
      * Set the type of equation.
 139  
      * 
 140  
      * @param display
 141  
      *            INLINE|BLOCK
 142  
      */
 143  
     public void setDisplay(final String display) {
 144  0
         this.setAttribute(MathImpl.ATTR_DISPLAY, display);
 145  0
     }
 146  
 
 147  
     /**
 148  
      * Returns the display.
 149  
      * 
 150  
      * @return Display display
 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  
     /** {@inheritDoc} */
 173  
     @Override
 174  
     public LayoutContext getChildLayoutContext(final int childNum,
 175  
             final LayoutContext context) {
 176  9622
         return new ChildContext(context);
 177  
     }
 178  
 
 179  
     /** {@inheritDoc} */
 180  
     public String getMacros() {
 181  0
         return this.getMathAttribute(MathImpl.ATTR_MACROS);
 182  
     }
 183  
 
 184  
     /** {@inheritDoc} */
 185  
     public void setMacros(final String macros) {
 186  0
         this.setAttribute(MathImpl.ATTR_MACROS, macros);
 187  0
     }
 188  
 
 189  
 }