01: ///////////////////////////////
02: // Makumba, Makumba tag library
03: // Copyright (C) 2000-2003 http://www.makumba.org
04: //
05: // This library is free software; you can redistribute it and/or
06: // modify it under the terms of the GNU Lesser General Public
07: // License as published by the Free Software Foundation; either
08: // version 2.1 of the License, or (at your option) any later version.
09: //
10: // This library is distributed in the hope that it will be useful,
11: // but WITHOUT ANY WARRANTY; without even the implied warranty of
12: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: // Lesser General Public License for more details.
14: //
15: // You should have received a copy of the GNU Lesser General Public
16: // License along with this library; if not, write to the Free Software
17: // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: //
19: // -------------
20: // $Id: Evaluator.java 2048 2007-11-14 11:49:19Z manuel_gay $
21: // $Name$
22: /////////////////////////////////////
23:
24: package org.makumba.list.engine;
25:
26: import javax.servlet.jsp.PageContext;
27:
28: /**
29: * An evaluator using the EL engine to evaluate all occurences of #{...} in a string
30: *
31: * @author Cristian Bogdan
32: * @version $Id: Evaluator.java 2048 2007-11-14 11:49:19Z manuel_gay $
33: */
34: public class Evaluator implements ComposedQuery.Evaluator {
35: PageContext pc;
36:
37: public Evaluator(PageContext pc) {
38: this .pc = pc;
39: }
40:
41: public String evaluate(String s) {
42: // FIXME: looking for #{....} may have to be rewritten
43: StringBuffer ret = new StringBuffer();
44: int begin, end;
45: int last = 0;
46: while (true) {
47: begin = s.indexOf("#{", last);
48: if (begin == -1)
49: return ret.append(s.substring(last)).toString();
50: ret.append(s.substring(last, begin));
51: end = s.indexOf("}", begin + 2);
52: if (end == -1)
53: throw new org.makumba.ProgrammerError("unpaired #{ in "
54: + s);
55: try {
56: ret.append(pc.getExpressionEvaluator().evaluate(
57: "$" + s.substring(begin + 1, end + 1),
58: Object.class, pc.getVariableResolver(), null)); // a:b() functions not supported yet
59: } catch (javax.servlet.jsp.el.ELException ele) {
60: throw new org.makumba.ProgrammerError(ele.toString());
61: }
62: last = end + 1;
63: }
64: }
65: }
|