1 55 56 package org.apache.commons.el; 57 58 import javax.servlet.jsp.el.ELException ; 59 import javax.servlet.jsp.el.VariableResolver ; 60 import javax.servlet.jsp.el.FunctionMapper ; 61 62 71 72 public class ExpressionString 73 { 74 79 Object [] mElements; 80 public Object [] getElements () 81 { return mElements; } 82 public void setElements (Object [] pElements) 83 { mElements = pElements; } 84 85 90 public ExpressionString (Object [] pElements) 91 { 92 mElements = pElements; 93 } 94 95 102 public String evaluate (VariableResolver pResolver, 103 FunctionMapper functions, 104 Logger pLogger) 105 throws ELException 106 { 107 StringBuffer buf = new StringBuffer (); 108 for (int i = 0; i < mElements.length; i++) { 109 Object elem = mElements [i]; 110 if (elem instanceof String ) { 111 buf.append ((String ) elem); 112 } 113 else if (elem instanceof Expression) { 114 Object val = 115 ((Expression) elem).evaluate (pResolver, 116 functions, 117 pLogger); 118 if (val != null) { 119 buf.append (val.toString ()); 120 } 121 } 122 } 123 return buf.toString (); 124 } 125 126 131 public String getExpressionString () 132 { 133 StringBuffer buf = new StringBuffer (); 134 for (int i = 0; i < mElements.length; i++) { 135 Object elem = mElements [i]; 136 if (elem instanceof String ) { 137 buf.append ((String ) elem); 138 } 139 else if (elem instanceof Expression) { 140 buf.append ("${"); 141 buf.append (((Expression) elem).getExpressionString ()); 142 buf.append ("}"); 143 } 144 } 145 return buf.toString (); 146 } 147 148 } 150 | Popular Tags |