本文整理了Java中org.mozilla.javascript.Context.evaluateReader()
方法的一些代码示例,展示了Context.evaluateReader()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.evaluateReader()
方法的具体详情如下:
包路径:org.mozilla.javascript.Context
类名称:Context
方法名:evaluateReader
[英]Evaluate a reader as JavaScript source. All characters of the reader are consumed.
[中]将读卡器评估为JavaScript源。读卡器的所有字符都已使用。
代码示例来源:origin: galenframework/galen
public Object eval(Reader scriptFileReader, String javascriptPath) throws IOException {
File file = new File(javascriptPath);
loadFunction.putContextPath(file.getParent());
return context.evaluateReader(scope, scriptFileReader, javascriptPath, 1, null);
}
代码示例来源:origin: galenframework/galen
private void loadScript(Context cx, Scriptable scope, String fullPath) throws IOException {
InputStream is = retrieveScriptAsInputStream(fullPath);
String fileId = GalenUtils.calculateFileId(fullPath, is);
if (!loadedFileIds.contains(fileId)) {
File file = new File(fullPath);
String parentPath = file.getParent();
if (parentPath != null) {
contextPathStack.push(file.getParent());
}
cx.evaluateReader(scope, new InputStreamReader(is), file.getAbsolutePath(), 1, null);
loadedFileIds.add(fileId);
if (!contextPathStack.isEmpty()) {
contextPathStack.pop();
}
}
}
代码示例来源:origin: pentaho/pentaho-kettle
try {
inStream = new InputStreamReader( KettleVFS.getInputStream( fileName ) );
actualContext.evaluateReader( eval_scope, inStream, fileName, 1, null );
} catch ( FileNotFoundException Signal ) {
Context.reportError( "Unable to open file \"" + fileName + "\" (reason: \"" + Signal.getMessage() + "\")" );
代码示例来源:origin: EngineHub/WorldEdit
@Override
public Object eval(Reader reader, ScriptContext context)
throws ScriptException {
Scriptable scope = setupScope(cx, context);
String filename = (filename = (String) get(ScriptEngine.FILENAME)) == null
? "<unknown>" : filename;
try {
return cx.evaluateReader(scope, reader, filename, 1, null);
} catch (RhinoException e) {
String msg;
int line = (line = e.lineNumber()) == 0 ? -1 : line;
if (e instanceof JavaScriptException) {
msg = String.valueOf(((JavaScriptException) e).getValue());
} else {
msg = e.getMessage();
}
ScriptException scriptException =
new ScriptException(msg, e.sourceName(), line);
scriptException.initCause(e);
throw scriptException;
} catch (IOException e) {
throw new ScriptException(e);
} finally {
Context.exit();
}
}
代码示例来源:origin: stackoverflow.com
public class RJsDemo {
@Test
public void simpleRhinoTest() throws FileNotFoundException, IOException {
Context cx = Context.enter();
final JsRuntimeSupport browserSupport = new JsRuntimeSupport();
final ScriptableObject sharedScope = cx.initStandardObjects(browserSupport, true);
String[] names = { "print", "load" };
sharedScope.defineFunctionProperties(names, sharedScope.getClass(), ScriptableObject.DONTENUM);
Scriptable argsObj = cx.newArray(sharedScope, new Object[] {});
sharedScope.defineProperty("arguments", argsObj, ScriptableObject.DONTENUM);
cx.evaluateReader(sharedScope, new FileReader("./r.js"), "require", 1, null);
cx.evaluateReader(sharedScope, new FileReader("./loader.js"), "loader", 1, null);
Context.exit();
}
}
代码示例来源:origin: org.eclipse.ditto/ditto-services-connectivity-mapping
private void loadJavascriptLibrary(final Context cx, final Scriptable scope, final Reader reader,
final String libraryName) {
try {
cx.evaluateReader(scope, reader, libraryName, 1, null);
} catch (final IOException e) {
throw new IllegalStateException("Could not load script <" + libraryName + ">", e);
}
}
}
代码示例来源:origin: eclipse/ditto
private void loadJavascriptLibrary(final Context cx, final Scriptable scope, final Reader reader,
final String libraryName) {
try {
cx.evaluateReader(scope, reader, libraryName, 1, null);
} catch (final IOException e) {
throw new IllegalStateException("Could not load script <" + libraryName + ">", e);
}
}
}
代码示例来源:origin: stackoverflow.com
private void loadScript(Context cx, Scriptable scope, String name) {
FileReader readerJQ = null;
try {
readerJQ = new FileReader(name);
cx.evaluateReader(scope, readerJQ, name, 1, null);
readerJQ.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: com.atlassian.lesscss/lesscss-core
private void loadJs(Scriptable topScope, Context cx, String name) throws IOException {
final InputStream in = getClass().getResourceAsStream(name);
if (in == null) {
throw new FileNotFoundException("Could not find JS resource " + name);
}
InputStreamReader reader = new InputStreamReader(in, "UTF-8");
cx.evaluateReader(topScope, reader, name, 1, null);
}
代码示例来源:origin: org.bsc/jvm-npm-rhino
public static void loadModule(Context cx, Scriptable scope, Path modulePath) {
try (java.io.FileReader module = new java.io.FileReader( modulePath.toFile() ) ) {
cx.evaluateReader(scope, module, modulePath.toString(), 0, null);
} catch (IOException e) {
throw new RuntimeException(format("error evaluating [%s]!", modulePath.toString()), e);
}
}
代码示例来源:origin: viltgroup/minium
@SuppressWarnings("unchecked")
@Override
protected T doCall(Context cx, Scriptable scope) throws IOException {
Object val = cx.evaluateReader(scope, reader, sourceName, 1, null);
val = unwrappedValue(val);
return (T) val;
}
});
代码示例来源:origin: org.apache.pig/pig
/**
* evaluate javascript from a reader
* @param name the name of the script (for error messages)
* @param scriptReader the content of the script
* @return the result
*/
public Object jsEval(String name, Reader scriptReader) {
try {
return getContext().evaluateReader(scope, scriptReader, name, 1, null);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: com.galenframework/galen-core
public Object eval(Reader scriptFileReader, String javascriptPath) throws IOException {
File file = new File(javascriptPath);
loadFunction.putContextPath(file.getParent());
return context.evaluateReader(scope, scriptFileReader, javascriptPath, 1, null);
}
代码示例来源:origin: org.apache.xmlgraphics/batik-bridge
public Object run(Context cx) {
try {
return cx.evaluateReader(globalObject,
scriptReader,
description,
1, rhinoClassLoader);
} catch (IOException ioe) {
throw new WrappedException(ioe);
}
}
};
代码示例来源:origin: fr.avianey.apache-xmlgraphics/batik
public Object run(Context cx) {
try {
return cx.evaluateReader(globalObject,
scriptReader,
description,
1, rhinoClassLoader);
} catch (IOException ioe) {
throw new WrappedException(ioe);
}
}
};
代码示例来源:origin: apache/batik
public Object run(Context cx) {
try {
return cx.evaluateReader(globalObject,
scriptReader,
description,
1, rhinoClassLoader);
} catch (IOException ioe) {
throw new WrappedException(ioe);
}
}
};
代码示例来源:origin: viltgroup/minium
public MiniumBackend(ResourceLoader resourceLoader, Context cx, Scriptable scope) throws IOException {
try {
this.resourceLoader = resourceLoader;
this.cx = cx;
this.scope = scope;
this.scope.put("jsBackend", this.scope, this);
InputStreamReader dsl = new InputStreamReader(getClass().getResourceAsStream(JS_DSL), Charsets.UTF_8.toString());
this.cx.evaluateReader(this.scope, dsl, JS_DSL, 1, null);
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
代码示例来源:origin: stackoverflow.com
// Execution environment for Rhino
// there should be only one context in a giver thread
Context cx = Context.enter();
// Object.prototype, Function prototype, etc.
Scriptable scope = cx.initStandardObjects();
// Execute script from a given java.io.Reader
Object result = cx.evaluateReader(scope, reader, 0, null);
// If returning result isn't sufficient for your needs
// you can do something like this:
Object someVar = scope.get("someVar");
// Don't forget to close the context when you're done
Context.exit();
代码示例来源:origin: info.cukes/cucumber-rhino
private void runScript(Resource resource) {
try {
cx.evaluateReader(scope, new InputStreamReader(resource.getInputStream(), "UTF-8"), resource.getAbsolutePath(), 1, null);
} catch (IOException e) {
throw new CucumberException("Failed to evaluate JavaScript in " + resource.getAbsolutePath(), e);
}
}
代码示例来源:origin: viltgroup/minium
private void runScript(Resource resource) {
try {
cx.evaluateReader(scope, new InputStreamReader(resource.getInputStream(), "UTF-8"), resource.getAbsolutePath(), 1, null);
} catch (IOException e) {
throw new CucumberException("Failed to evaluate JavaScript in " + resource.getAbsolutePath(), e);
}
}
内容来源于网络,如有侵权,请联系作者删除!