1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.tags.beanshell;
17
18 import bsh.EvalError;
19 import bsh.Interpreter;
20
21 import java.util.Iterator;
22
23 import org.apache.commons.jelly.JellyContext;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27
28 /*** Integrates BeanShell's interpreter with Jelly's JellyContext
29 *
30 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
31 * @version $Revision: 155420 $
32 */
33 public class JellyInterpreter extends Interpreter {
34
35 /*** The Log to which logging calls will be made. */
36 private static final Log log = LogFactory.getLog( JellyInterpreter.class );
37
38 private JellyContext context;
39
40 public JellyInterpreter() {
41 }
42
43 public JellyContext getJellyContext() {
44 return context;
45 }
46
47 public void setJellyContext(JellyContext context) throws EvalError {
48 this.context = context;
49
50
51 for ( Iterator iter = context.getVariableNames(); iter.hasNext(); ) {
52 String name = (String) iter.next();
53 Object value = context.getVariable(name);
54 name = convertVariableName(name);
55 if (name != null) {
56 set( name, value );
57 }
58 }
59
60
61 set( "context", context );
62 }
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81 /***
82 * Converts variables to a beanshell allowable format or hides names that
83 * can't be converted, by returning null.
84 * For now lets just turn '.' into '_'
85 */
86 protected String convertVariableName(String name) {
87 return name.replace('.', '_');
88 }
89 }