Coverage Report - org.apache.commons.el.ExpressionString
 
Classes in this File Line Coverage Branch Coverage Complexity
ExpressionString
0%
0/31
0%
0/18
2.5
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *     http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.commons.el;
 18  
 
 19  
 import javax.servlet.jsp.el.ELException;
 20  
 import javax.servlet.jsp.el.FunctionMapper;
 21  
 import javax.servlet.jsp.el.VariableResolver;
 22  
 
 23  
 /**
 24  
  *
 25  
  * <p>Represents an expression String consisting of a mixture of
 26  
  * Strings and Expressions.
 27  
  * 
 28  
  * @author Nathan Abramson - Art Technology Group
 29  
  * @author Shawn Bayern
 30  
  * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author: bayard $
 31  
  **/
 32  
 
 33  
 public class ExpressionString extends Expression
 34  
 {
 35  
   //-------------------------------------
 36  
   // Properties
 37  
   //-------------------------------------
 38  
   // property elements
 39  
 
 40  
   Object [] mElements;
 41  
   public Object [] getElements ()
 42  0
   { return mElements; }
 43  
   public void setElements (Object [] pElements)
 44  0
   { mElements = pElements; }
 45  
 
 46  
   //-------------------------------------
 47  
   /**
 48  
    *
 49  
    * Constructor
 50  
    **/
 51  
   public ExpressionString (Object [] pElements)
 52  0
   {
 53  0
     mElements = pElements;
 54  0
   }
 55  
 
 56  
   //-------------------------------------
 57  
   /**
 58  
    *
 59  
    * Evaluates the expression string by evaluating each element,
 60  
    * converting it to a String (using toString, or "" for null values)
 61  
    * and concatenating the results into a single String.
 62  
    **/
 63  
   public Object evaluate (VariableResolver pResolver,
 64  
                           FunctionMapper functions)
 65  
     throws ELException
 66  
   {
 67  0
     StringBuffer buf = new StringBuffer ();
 68  0
     for (int i = 0; i < mElements.length; i++) {
 69  0
       Object elem = mElements [i];
 70  0
       if (elem instanceof String) {
 71  0
         buf.append ((String) elem);
 72  
       }
 73  0
       else if (elem instanceof Expression) {
 74  0
         Object val = 
 75  
           ((Expression) elem).evaluate (pResolver, functions);
 76  0
         if (val != null) {
 77  0
           buf.append (val.toString ());
 78  
         }
 79  
       }
 80  
     }
 81  0
     return buf.toString ();
 82  
   }
 83  
 
 84  
   //-------------------------------------
 85  
   /**
 86  
    *
 87  
    * Returns the expression in the expression language syntax
 88  
    **/
 89  
   public String getExpressionString ()
 90  
   {
 91  0
     StringBuffer buf = new StringBuffer ();
 92  0
     for (int i = 0; i < mElements.length; i++) {
 93  0
       Object elem = mElements [i];
 94  0
       if (elem instanceof String) {
 95  0
         buf.append ((String) elem);
 96  
       }
 97  0
       else if (elem instanceof Expression) {
 98  0
         buf.append ("${");
 99  0
         buf.append (((Expression) elem).getExpressionString ());
 100  0
         buf.append ("}");
 101  
       }
 102  
     }
 103  0
     return buf.toString ();
 104  
   }
 105  
 
 106  
   //-------------------------------------
 107  
 
 108  
   public Expression bindFunctions(FunctionMapper functions) throws ELException {
 109  0
       final Object[] boundElements = new Object[mElements.length];
 110  0
       for (int i = 0; i < mElements.length; i++) {
 111  0
           if (mElements[i] instanceof Expression) {
 112  0
               boundElements[i] = ((Expression)mElements[i]).bindFunctions(functions);
 113  
           } else {
 114  0
               boundElements[i] = mElements[i];
 115  
           }
 116  
       }
 117  0
       return new ExpressionString(boundElements);
 118  
   }
 119  
 }