@Override public ScriptContext getContext() { return engine.getContext(); }
@Override public ScriptContext getContext() { return engine.getContext(); }
@Override public ScriptContext getContext() { return engine.getContext(); }
@Override public ScriptContext getContext() { return engine.getContext(); }
public String eval(String line) throws ScriptException { final ScriptContext context = engine.getContext(); final StringWriter sw = new StringWriter(); context.setWriter(new PrintWriter(sw)); engine.eval(line, context); final String result = sw.toString(); return result; } }
scriptEngine.getContext().setAttribute("#jsr223.groovy.engine.keep.globals", "weak", ScriptContext.ENGINE_SCOPE); } catch (Exception ignore) {
@Override public <T> T executeTemplate(String template, HttpRequest request, Class<? extends DTO<T>> dtoClass) { T result = null; try { Writer writer = new StringWriter(); ScriptContext context = engine.getContext(); context.setWriter(writer); context.setAttribute("request", new HttpRequestTemplateObject(request), ScriptContext.ENGINE_SCOPE); engine.eval(template); logFormatter.info(TEMPLATE_GENERATED, request, "generated output:{}from template:{}for request:{}", writer.toString(), template, request); result = httpTemplateOutputDeserializer.deserializer(request, writer.toString(), dtoClass); } catch (Exception e) { throw new RuntimeException(formatLogMessage("Exception transforming template:{}for request:{}", template, request), e); } return result; } }
private static void resetContext(ScriptEngine engine) { ScriptContext context = engine.getContext(); context.removeAttribute("method", ScriptContext.ENGINE_SCOPE); context.removeAttribute("groups", ScriptContext.ENGINE_SCOPE); context.removeAttribute("testngMethod", ScriptContext.ENGINE_SCOPE); } }
ScriptEngine engine = enginePool.getEngine(); try { ScriptContext context = engine.getContext(); context.setAttribute("page", page, ScriptContext.ENGINE_SCOPE); context.setAttribute("config", site, ScriptContext.ENGINE_SCOPE);
private static void setContext(ScriptEngine engine, Map<String, String> groups, ITestNGMethod tm) { ScriptContext context = engine.getContext(); Method method = tm.getConstructorOrMethod().getMethod(); context.setAttribute("method", method, ScriptContext.ENGINE_SCOPE); context.setAttribute("groups", groups, ScriptContext.ENGINE_SCOPE); context.setAttribute("testngMethod", tm, ScriptContext.ENGINE_SCOPE); }
/** * Allows providing custom configuration for the groovy script engine. * @param scriptEngine the groovy script engine to configure. */ protected void configureGroovyScriptEngine(ScriptEngine scriptEngine) { // make sure Groovy compiled scripts only hold weak references to java methods scriptEngine.getContext().setAttribute("#jsr223.groovy.engine.keep.globals", "weak", ScriptContext.ENGINE_SCOPE); }
/** * Allows providing custom configuration for the groovy script engine. * @param scriptEngine the groovy script engine to configure. */ protected void configureGroovyScriptEngine(ScriptEngine scriptEngine) { // make sure Groovy compiled scripts only hold weak references to java methods scriptEngine.getContext().setAttribute("#jsr223.groovy.engine.keep.globals", "weak", ScriptContext.ENGINE_SCOPE); }
String javaScriptExpression = "sayHello(name);"; Reader javaScriptFile = new StringReader( "function sayHello(name) {\n" + " println('Hello, '+name+'!');\n" + "}"); ScriptEngineManager factory = new ScriptEngineManager(); ScriptEngine engine = factory .getEngineByName("JavaScript"); ScriptContext context = engine.getContext(); context.setAttribute("name", "JavaScript", ScriptContext.ENGINE_SCOPE); engine.eval(javaScriptFile); engine.eval(javaScriptExpression);
scriptEngine.getContext().setWriter(writer); scriptEngine.put("catalog", catalog); scriptEngine.put("connection", connection);
@Override public ScriptContext getContext() { return engine.getContext(); } @Override
ScriptEngine engine = new ScriptEngineManager().getEngineByName("javascript"); ScriptContext context = engine.getContext(); StringWriter writer = new StringWriter(); context.setWriter(writer); engine.eval("print('Welocme to java worldddd')"); String output = writer.toString(); System.out.println("Script output: " + output);
/** * {@inheritDoc} */ public ScriptContext getContext() { return getScriptEngine().getContext(); }
public void enableTreeResults() { ScriptContext context = myMathEng.getContext(); // If we do this, an AST is returned. Otherwise a String is returned. context.setAttribute(MathScriptEngine.RETURN_OBJECT, Boolean.TRUE, ScriptContext.ENGINE_SCOPE); } @Override public IExpr parseAndEvalExprToIExpr(String expr) {
public ScriptEngine getEngineByName(String shortName) { if (shortName == null) { throw new NullPointerException("Null symbolicName"); } ScriptEngineFactory factory = nameMap.get(shortName); if (factory == null) { throw new IllegalArgumentException("No engine for " + shortName); } ScriptEngine engine = factory.getScriptEngine(); engine.getContext().setBindings(globalMap, ScriptContext.GLOBAL_SCOPE); return engine; }
public ScriptEngine getEngineByExtension(String extension) { if (extension == null) { throw new NullPointerException("Null extension"); } ScriptEngineFactory factory = extensionMap.get(extension); if (factory == null) { throw new IllegalArgumentException("No engine for " + extension); } ScriptEngine engine = factory.getScriptEngine(); engine.getContext().setBindings(globalMap, ScriptContext.GLOBAL_SCOPE); return engine; }