本文整理了Java中javax.script.ScriptEngine.getContext()
方法的一些代码示例,展示了ScriptEngine.getContext()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ScriptEngine.getContext()
方法的具体详情如下:
包路径:javax.script.ScriptEngine
类名称:ScriptEngine
方法名:getContext
[英]Returns the default ScriptContext of the ScriptEngine whose Bindings, Readers and Writers are used for script executions when no ScriptContext is specified.
[中]返回ScriptEngine的默认ScriptContext,当未指定ScriptContext时,其绑定、读卡器和写卡器用于脚本执行。
代码示例来源:origin: looly/hutool
@Override
public ScriptContext getContext() {
return engine.getContext();
}
代码示例来源:origin: looly/hutool
@Override
public ScriptContext getContext() {
return engine.getContext();
}
代码示例来源:origin: looly/hutool
@Override
public ScriptContext getContext() {
return engine.getContext();
}
代码示例来源:origin: looly/hutool
@Override
public ScriptContext getContext() {
return engine.getContext();
}
代码示例来源:origin: plantuml/plantuml
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;
}
}
代码示例来源:origin: Activiti/Activiti
scriptEngine.getContext().setAttribute("#jsr223.groovy.engine.keep.globals", "weak", ScriptContext.ENGINE_SCOPE);
} catch (Exception ignore) {
代码示例来源:origin: jamesdbloom/mockserver
@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;
}
}
代码示例来源:origin: cbeust/testng
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);
}
}
代码示例来源:origin: code4craft/webmagic
ScriptEngine engine = enginePool.getEngine();
try {
ScriptContext context = engine.getContext();
context.setAttribute("page", page, ScriptContext.ENGINE_SCOPE);
context.setAttribute("config", site, ScriptContext.ENGINE_SCOPE);
代码示例来源:origin: cbeust/testng
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);
}
代码示例来源:origin: camunda/camunda-bpm-platform
/**
* 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);
}
代码示例来源:origin: camunda/camunda-bpm-platform
/**
* 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);
}
代码示例来源:origin: stackoverflow.com
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);
代码示例来源:origin: schemacrawler/SchemaCrawler
scriptEngine.getContext().setWriter(writer);
scriptEngine.put("catalog", catalog);
scriptEngine.put("connection", connection);
代码示例来源:origin: OpenNMS/opennms
@Override
public ScriptContext getContext() {
return engine.getContext();
}
@Override
代码示例来源:origin: stackoverflow.com
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);
代码示例来源:origin: org.apache.myfaces.extensions.cdi.bundles/myfaces-extcdi-bundle-jsf20
/**
* {@inheritDoc}
*/
public ScriptContext getContext()
{
return getScriptEngine().getContext();
}
代码示例来源:origin: org.cogchar/org.cogchar.lib.core.impl
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) {
代码示例来源:origin: org.jruby/jruby-complete
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;
}
代码示例来源:origin: org.jruby/jruby-complete
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;
}
内容来源于网络,如有侵权,请联系作者删除!