01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: FilteredTagProcessorJanino.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.template;
09:
10: import java.util.Map;
11: import org.codehaus.janino.ExpressionEvaluator;
12:
13: public class FilteredTagProcessorJanino extends FilteredTagProcessor {
14: private static FilteredTagProcessor sInstance = null;
15:
16: public static FilteredTagProcessor getInstance() {
17: if (null == sInstance) {
18: sInstance = new FilteredTagProcessorJanino();
19: }
20:
21: return sInstance;
22: }
23:
24: public String getLanguage() {
25: return "JANINO";
26: }
27:
28: public Object processExpression(Template template, Class rootType,
29: String rootName, Object rootValue, String expression,
30: Map<String, Object> context) throws Exception {
31: ExpressionEvaluator evaluator = (ExpressionEvaluator) template
32: .getCacheObject(rootName + expression);
33:
34: if (null == evaluator) {
35: evaluator = new ExpressionEvaluator(expression,
36: Boolean.TYPE, new String[] { "context", rootName },
37: new Class[] { Map.class, rootType },
38: new Class[] { Exception.class }, getClass()
39: .getClassLoader());
40: template.cacheObject(rootName + expression, evaluator);
41: }
42:
43: Boolean result = (Boolean) evaluator.evaluate(new Object[] {
44: context, rootValue });
45:
46: return null != result && result.booleanValue();
47: }
48: }
|