Coverage Report - net.sourceforge.jeuclid.elements.support.text.TextContent
 
Classes in this File Line Coverage Branch Coverage Complexity
TextContent
75%
9/12
87%
7/8
3,5
 
 1  
 /*
 2  
  * Copyright 2009 - 2009 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: TextContent.java,v 8d5443ff84fe 2009/09/01 11:21:57 max $ */
 18  
 
 19  
 package net.sourceforge.jeuclid.elements.support.text;
 20  
 
 21  
 import net.sourceforge.jeuclid.elements.AbstractJEuclidElement;
 22  
 
 23  
 import org.w3c.dom.Node;
 24  
 
 25  
 /**
 26  
  * Helper class for handling Text Content.
 27  
  * 
 28  
  * @version $Revision: 8d5443ff84fe $
 29  
  */
 30  
 public final class TextContent {
 31  
 
 32  0
     private TextContent() {
 33  
         // do not instantiate.
 34  0
     }
 35  
 
 36  
     /**
 37  
      * Retrieve the text content for a given node according to MathML standards.
 38  
      * 
 39  
      * @param node
 40  
      *            Node
 41  
      * @return Text content. Always a valid String, never null.
 42  
      */
 43  
     public static String getText(final Node node) {
 44  22114413
         final String theText = node.getTextContent();
 45  22114413
         if (theText == null) {
 46  0
             return "";
 47  
         } else {
 48  
 
 49  22114413
             final StringBuilder newText = new StringBuilder();
 50  
 
 51  
             // As seen in 2.4.6
 52  22114413
             newText.append(theText.trim());
 53  
 
 54  22346859
             for (int i = 0; i < newText.length() - 1; i++) {
 55  232446
                 if ((newText.charAt(i) <= AbstractJEuclidElement.TRIVIAL_SPACE_MAX)
 56  
                         && (newText.charAt(i + 1) <= AbstractJEuclidElement.TRIVIAL_SPACE_MAX)) {
 57  627
                     newText.deleteCharAt(i);
 58  
                     // CHECKSTYLE:OFF
 59  
                     // This is intentional
 60  627
                     i--;
 61  
                     // CHECKSTYLE:ON
 62  
                 }
 63  
             }
 64  22114413
             return CharConverter.convertEarly(newText.toString());
 65  
         }
 66  
 
 67  
     }
 68  
 }