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: FilteredTagProcessorOgnl.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.template;
09:
10: import ognl.*;
11:
12: import java.util.Map;
13:
14: public class FilteredTagProcessorOgnl extends FilteredTagProcessor {
15: private static final ClassResolver RESOLVER = new RifeResolver();
16:
17: private static FilteredTagProcessor sInstance = null;
18:
19: public static FilteredTagProcessor getInstance() {
20: if (null == sInstance) {
21: sInstance = new FilteredTagProcessorOgnl();
22: }
23:
24: return sInstance;
25: }
26:
27: public String getLanguage() {
28: return "OGNL";
29: }
30:
31: public Object processExpression(Template template, Class rootType,
32: String rootName, Object rootValue, String expression,
33: Map<String, Object> context) throws Exception {
34: Node tree = (Node) template.getCacheObject(expression);
35: if (null == tree) {
36: tree = (Node) Ognl.parseExpression(expression);
37: template.cacheObject(expression, tree);
38: }
39: TypeConverter converter = new DefaultTypeConverter();
40: OgnlContext ognl_context = new OgnlContext(RESOLVER, converter,
41: new DefaultMemberAccess(false, false, false), context);
42:
43: return tree.getValue(ognl_context, rootValue);
44: }
45:
46: public static class RifeResolver implements ClassResolver {
47: RifeResolver() {
48: }
49:
50: public Class classForName(String classname, Map context)
51: throws ClassNotFoundException {
52: return getClass().getClassLoader().loadClass(classname);
53: }
54: }
55: }
|