Coverage report

  %line %branch
org.apache.commons.jelly.impl.ExpressionScript
56% 
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  
 import org.apache.commons.jelly.expression.Expression;
 23  
 
 24  
 import org.xml.sax.SAXException;
 25  
 
 26  
 /**
 27  
  * <p><code>ExpressionScript</code> outputs the value of an expression as text.</p>
 28  
  *
 29  
  * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
 30  
  * @version $Revision: 1.5 $
 31  
  */
 32  
 public class ExpressionScript implements Script {
 33  
 
 34  
     /** the expression evaluated as a String and output by this script */
 35  
     private Expression expression;
 36  
 
 37  0
     public ExpressionScript() {
 38  0
     }
 39  
 
 40  14
     public ExpressionScript(Expression expression) {
 41  14
         this.expression = expression;
 42  14
     }
 43  
 
 44  
     public String toString() {
 45  0
         return super.toString() + "[expression=" + expression + "]";
 46  
     }
 47  
 
 48  
     /** @return the expression evaluated as a String and output by this script */
 49  
     public Expression getExpression() {
 50  0
         return expression;
 51  
     }
 52  
 
 53  
     /** Sets the expression evaluated as a String and output by this script */
 54  
     public void setExpression(Expression expression) {
 55  0
         this.expression = expression;
 56  0
     }
 57  
 
 58  
     // Script interface
 59  
     //-------------------------------------------------------------------------
 60  
     public Script compile() {
 61  14
         return this;
 62  
     }
 63  
 
 64  
     /** Evaluates the body of a tag */
 65  
     public void run(JellyContext context, XMLOutput output) throws JellyTagException {
 66  30
         String text = expression.evaluateAsString(context);
 67  30
         if ( text != null ) {
 68  
 
 69  
             try {
 70  30
               output.write(text);
 71  30
             } catch (SAXException e) {
 72  0
                 throw new JellyTagException("Could not write to XMLOutput",e);
 73  
             }
 74  
 
 75  
         }
 76  30
     }
 77  
 }

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