1 package org.sapia.gumby.tags.script; 2 3 import org.sapia.gumby.RenderContext; 4 import org.sapia.gumby.factory.ContextAware; 5 import org.sapia.gumby.script.EngineFactory; 6 import org.sapia.gumby.script.Script; 7 import org.sapia.util.xml.confix.ConfigurationException; 8 import org.sapia.util.xml.confix.ObjectCreationCallback; 9 10 25 public class Expr implements ObjectCreationCallback, ContextAware { 26 27 private static final Object [] EMPTY_ARGS = new Object [0]; 28 29 private String _text, _lang; 30 private RenderContext _context; 31 32 public void setText(String txt) { 33 _text = txt; 34 } 35 36 public void setLang(String lang) { 37 _lang = lang; 38 } 39 40 43 public void handleContext(RenderContext context) { 44 _context = context; 45 } 46 47 50 public Object onCreate() throws ConfigurationException { 51 if(_text == null) 52 throw new ConfigurationException("Script source not specified"); 53 54 Script script; 55 try { 56 if(_lang == null) { 57 script = EngineFactory.getDefaultEngine().parseScript(_text); 58 } else { 59 script = EngineFactory.getEngineFor(_lang).parseScript(_text); 60 } 61 } catch(Exception e) { 62 throw new ConfigurationException("Could not parse script", e); 63 } 64 try { 65 return script.execute(_context, EMPTY_ARGS); 66 } catch(Exception e) { 67 throw new ConfigurationException("Could not evaluate expression", e); 68 } 69 } 70 71 } 72 | Popular Tags |