Coverage report

  %line %branch
org.apache.commons.jelly.impl.ScriptBlock
91% 
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 java.util.ArrayList;
 19  
 import java.util.Iterator;
 20  
 import java.util.List;
 21  
 
 22  
 import org.apache.commons.jelly.JellyContext;
 23  
 import org.apache.commons.jelly.JellyException;
 24  
 import org.apache.commons.jelly.JellyTagException;
 25  
 import org.apache.commons.jelly.Script;
 26  
 import org.apache.commons.jelly.XMLOutput;
 27  
 
 28  
 /** <p><code>ScriptBlock</code> a block of scripts.</p>
 29  
   *
 30  
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
 31  
   * @version $Revision: 155420 $
 32  
   */
 33  
 public class ScriptBlock implements Script {
 34  
 
 35  
     /** The list of scripts */
 36  21203
     private List list = new ArrayList();
 37  
 
 38  
     /**
 39  
      * Create a new instance.
 40  
      */
 41  21203
     public ScriptBlock() {
 42  21203
     }
 43  
 
 44  
     /**
 45  
      * @see Object#toString()
 46  
      */
 47  
     public String toString() {
 48  0
         return super.toString() + "[scripts=" + list + "]";
 49  
     }
 50  
 
 51  
     /** Add a new script to the end of this block */
 52  
     public void addScript(Script script) {
 53  48373
         list.add(script);
 54  48373
     }
 55  
 
 56  
     /** Removes a script from this block */
 57  
     public void removeScript(Script script) {
 58  0
         list.remove(script);
 59  0
     }
 60  
 
 61  
     /**
 62  
      * Gets the child scripts that make up this block. This list is live
 63  
      * so that it can be modified if requried
 64  
      */
 65  
     public List getScriptList() {
 66  4290
         return list;
 67  
     }
 68  
 
 69  
     // Script interface
 70  
     //-------------------------------------------------------------------------
 71  
     public Script compile() throws JellyException {
 72  21086
         int size = list.size();
 73  21086
         if (size == 1) {
 74  3926
             Script script = (Script) list.get(0);
 75  3926
             return script.compile();
 76  
         }
 77  
         // now compile children
 78  61516
         for (int i = 0; i < size; i++) {
 79  44356
             Script script = (Script) list.get(i);
 80  44356
             list.set(i, script.compile());
 81  
         }
 82  17160
         return this;
 83  
     }
 84  
 
 85  
     /** Evaluates the body of a tag */
 86  
     public void run(JellyContext context, XMLOutput output) throws JellyTagException {
 87  
 /*
 88  
         for (int i = 0, size = scripts.length; i < size; i++) {
 89  
             Script script = scripts[i];
 90  
             script.run(context, output);
 91  
         }
 92  
 */
 93  5993
         for (Iterator iter = list.iterator(); iter.hasNext(); ) {
 94  12675
             Script script = (Script) iter.next();
 95  12675
             script.run(context, output);
 96  12129
         }
 97  5447
     }
 98  
     
 99  
     /**
 100  
      * Trim the body of the script.
 101  
      * In this case, trim all elements, removing any that are empty text.
 102  
      */
 103  
     public void trimWhitespace() {
 104  4225
         List list = getScriptList();
 105  24258
         for ( int i = list.size() - 1; i >= 0; i-- ) {
 106  20033
             Script script = (Script) list.get(i);
 107  20033
             if ( script instanceof TextScript ) {
 108  11401
                 TextScript textScript = (TextScript) script;
 109  11401
                 String text = textScript.getText();
 110  11401
                 text = text.trim();
 111  11401
                 if ( text.length() == 0 ) {
 112  11336
                     list.remove(i);
 113  11336
                 }
 114  
                 else {
 115  65
                     textScript.setText(text);
 116  
                 }
 117  
             }
 118  
         }
 119  4225
     }
 120  
 }

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