protected Interpreter getInterpreter() { if (interpreter == null) { this.interpreter = new bsh.Interpreter(); interpreter.setNameSpace(null); // should always be set by context } return interpreter; }
protected Interpreter getInterpreter() { if (interpreter == null) { this.interpreter = new Interpreter(); interpreter.setNameSpace(null); // should always be set by context } return interpreter; }
public void destroy() { getOwner().removeAttribute(VAR_NSW); //bug 1814819 ,clear variable, dennis try { _bshns.clear(); _ip.setNameSpace(null); } catch (Throwable t) { //silently ignore (in case of upgrading to new bsh) } _ip = null; _bshns = null; super.destroy(); }
this.setNameSpace(namespace); this.setConsole(console);
public void init(Page owner, String zslang) { super.init(owner, zslang); _ip = new bsh.Interpreter(); _ip.setClassLoader(Classes.getContextClassLoader(BSHInterpreter.class)); _bshns = new GlobalNS(_ip.getClassManager(), "global"); _ip.setNameSpace(_bshns); }
BSHLogListener.ScriptInfo info = getScriptInfo(sources[i]); NameSpace ns = info!=null ?info.getNameSpace():null; if(ns!=null) bsh.setNameSpace(ns); bsh.set("event", ret); bsh.set("cfg", cfg);
private Object evalSource(Object source, ScriptContext scriptContext) throws ScriptException { try ( Interpreter bsh = getInterpreter() ) { NameSpace contextNameSpace = getEngineNameSpace(scriptContext); bsh.setNameSpace(contextNameSpace); bsh.setOut(toPrintStream(scriptContext.getWriter())); bsh.setErr(toPrintStream(scriptContext.getErrorWriter())); if (source instanceof Reader) { return bsh.eval((Reader) source); } else { return bsh.eval((String) source); } } catch (ParseException e) { // explicit parsing error throw new ScriptException(e.toString(), e.getErrorSourceFile(), e.getErrorLineNumber()); } catch (TargetError e) { // The script threw an application level exception ScriptException se = new ScriptException(e.toString(), e.getErrorSourceFile(), e.getErrorLineNumber()); se.initCause(e.getTarget()); throw se; } catch (EvalError e) { // The script couldn't be evaluated properly throw new ScriptException(e.toString(), e.getErrorSourceFile(), e.getErrorLineNumber()); } catch (IOException e) { throw new ScriptException(e.toString()); } }
private Object evalSource(Object source, ScriptContext scriptContext) throws ScriptException { bsh.NameSpace contextNameSpace = getEngineNameSpace(scriptContext); Interpreter bsh = getInterpreter(); bsh.setNameSpace(contextNameSpace); bsh.setOut(toPrintStream(scriptContext.getWriter())); bsh.setErr(toPrintStream(scriptContext.getErrorWriter())); try { if (source instanceof Reader) { return bsh.eval((Reader) source); } else { return bsh.eval((String) source); } //} catch (ParseException e) { // explicit parsing error TODO how to handle parse exception ? //throw new ScriptException(e.toString()); //e.getErrorSourceFile(), e.getErrorLineNumber()); } catch (TargetError e) { // The script threw an application level exception // set it as the cause ? ScriptException se = new ScriptException(e.toString(), e.getErrorSourceFile(), e.getErrorLineNumber()); se.initCause(e.getTarget()); throw se; } catch (EvalError e) { // The script couldn't be evaluated properly throw new ScriptException(e.toString(), e.getErrorSourceFile(), e.getErrorLineNumber()); } catch (InterpreterError e) { // The interpreter had a fatal problem throw new ScriptException(e.toString()); } }