1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
26
27
28
29
30
31
32
33 public class ExpressionString extends Expression
34 {
35
36
37
38
39
40 Object [] mElements;
41 public Object [] getElements ()
42 { return mElements; }
43 public void setElements (Object [] pElements)
44 { mElements = pElements; }
45
46
47
48
49
50
51 public ExpressionString (Object [] pElements)
52 {
53 mElements = pElements;
54 }
55
56
57
58
59
60
61
62
63 public Object evaluate (VariableResolver pResolver,
64 FunctionMapper functions)
65 throws ELException
66 {
67 StringBuffer buf = new StringBuffer ();
68 for (int i = 0; i < mElements.length; i++) {
69 Object elem = mElements [i];
70 if (elem instanceof String) {
71 buf.append ((String) elem);
72 }
73 else if (elem instanceof Expression) {
74 Object val =
75 ((Expression) elem).evaluate (pResolver, functions);
76 if (val != null) {
77 buf.append (val.toString ());
78 }
79 }
80 }
81 return buf.toString ();
82 }
83
84
85
86
87
88
89 public String getExpressionString ()
90 {
91 StringBuffer buf = new StringBuffer ();
92 for (int i = 0; i < mElements.length; i++) {
93 Object elem = mElements [i];
94 if (elem instanceof String) {
95 buf.append ((String) elem);
96 }
97 else if (elem instanceof Expression) {
98 buf.append ("${");
99 buf.append (((Expression) elem).getExpressionString ());
100 buf.append ("}");
101 }
102 }
103 return buf.toString ();
104 }
105
106
107
108 public Expression bindFunctions(FunctionMapper functions) throws ELException {
109 final Object[] boundElements = new Object[mElements.length];
110 for (int i = 0; i < mElements.length; i++) {
111 if (mElements[i] instanceof Expression) {
112 boundElements[i] = ((Expression)mElements[i]).bindFunctions(functions);
113 } else {
114 boundElements[i] = mElements[i];
115 }
116 }
117 return new ExpressionString(boundElements);
118 }
119 }