Coverage report

  %line %branch
org.apache.commons.jelly.impl.TextScript
86% 
100% 

 1  
 /*
 2  
  * Copyright 2002,2004 The Apache Software Foundation.
 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  
 package org.apache.commons.jelly.impl;
 17  
 
 18  
 import org.apache.commons.jelly.JellyContext;
 19  
 import org.apache.commons.jelly.JellyTagException;
 20  
 import org.apache.commons.jelly.Script;
 21  
 import org.apache.commons.jelly.XMLOutput;
 22  
 
 23  
 import org.xml.sax.SAXException;
 24  
 
 25  
 /** <p><code>TextScript</code> outputs some static text.</p>
 26  
   *
 27  
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
 28  
   * @version $Revision: 155420 $
 29  
   */
 30  
 public class TextScript implements Script {
 31  
 
 32  
     /** the text output by this script */
 33  
     private String text;
 34  
 
 35  0
     public TextScript() {
 36  0
     }
 37  
 
 38  28006
     public TextScript(String text) {
 39  28006
         this.text = text;
 40  28006
     }
 41  
 
 42  
     public String toString() {
 43  0
         return super.toString() + "[text=" + text + "]";
 44  
     }
 45  
 
 46  
     /**
 47  
      * Trims whitespace from the start and end of the text in this script
 48  
      */
 49  
     public void trimWhitespace() {
 50  341
         this.text = text.trim();
 51  341
     }
 52  
 
 53  
     /**
 54  
      * Trims whitespace from the start of the text
 55  
      */
 56  
     public void trimStartWhitespace() {
 57  163
         int index = 0;
 58  663
         for ( int length = text.length(); index < length; index++ ) {
 59  622
             char ch = text.class="keyword">charAt(index);
 60  622
             if (!Character.isWhitespace(ch)) {
 61  122
                 break;
 62  
             }
 63  
         }
 64  163
         if ( index > 0 ) {
 65  121
             this.text = text.substring(index);
 66  
         }
 67  163
     }
 68  
 
 69  
     /**
 70  
      * Trims whitespace from the end of the text
 71  
      */
 72  
     public void trimEndWhitespace() {
 73  163
         int index = text.length();
 74  586
         while (--index >= 0) {
 75  532
             char ch = text.class="keyword">charAt(index);
 76  532
             if (!Character.isWhitespace(ch)) {
 77  109
                 break;
 78  
             }
 79  423
         }
 80  163
         index++;
 81  163
         if ( index < text.length() ) {
 82  121
             this.text = text.substring(0,index);
 83  
         }
 84  163
     }
 85  
 
 86  
     /** @return the text output by this script */
 87  
     public String getText() {
 88  11639
         return text;
 89  
     }
 90  
 
 91  
     /** Sets the text output by this script */
 92  
     public void setText(String text) {
 93  65
         this.text = text;
 94  65
     }
 95  
 
 96  
     // Script interface
 97  
     //-------------------------------------------------------------------------
 98  
     public Script compile() {
 99  27742
         return this;
 100  
     }
 101  
 
 102  
     /** Evaluates the body of a tag */
 103  
     public void run(JellyContext context, XMLOutput output) throws JellyTagException {
 104  1235
         if ( text != null ) {
 105  
             try {
 106  1235
               output.write(text);
 107  0
             } catch (SAXException e) {
 108  0
                 throw new JellyTagException("could not write to XMLOutput",e);
 109  1235
             }
 110  
         }
 111  1235
     }
 112  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.