use of javax.script.Invocable in project jgnash by ccavanaugh.
the class ImportFilter method getDescription.
public String getDescription() {
try (final Reader reader = getReader()) {
engine.eval(reader);
final Invocable invocable = (Invocable) engine;
final Object result = invocable.invokeFunction("getDescription", Locale.getDefault());
return result.toString();
} catch (final ScriptException | IOException | NoSuchMethodException e) {
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
return "";
}
use of javax.script.Invocable in project jgnash by ccavanaugh.
the class ImportFilter method processMemo.
public String processMemo(final String memo) {
try (final Reader reader = getReader()) {
engine.eval(reader);
final Invocable invocable = (Invocable) engine;
final Object result = invocable.invokeFunction("processMemo", memo);
return result.toString();
} catch (final ScriptException | IOException | NoSuchMethodException e) {
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
return memo;
}
use of javax.script.Invocable in project jgnash by ccavanaugh.
the class ImportFilter method processPayee.
public String processPayee(final String payee) {
try (final Reader reader = getReader()) {
engine.eval(reader);
final Invocable invocable = (Invocable) engine;
final Object result = invocable.invokeFunction("processPayee", payee);
return result.toString();
} catch (final ScriptException | IOException | NoSuchMethodException e) {
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
return payee;
}
use of javax.script.Invocable in project sling by apache.
the class Module method loadAsDirectory.
/**
*
* @param module
* @param path
* @param currentResource
* @return
* @throws ScriptException
*/
public ModuleScript loadAsDirectory(String module, String path, Resource currentResource, String loader) throws ScriptException {
ResourceResolver resolver = currentResource.getResourceResolver();
Resource packageJson = resolver.getResource(path + "/package.json");
if (packageJson != null) {
Node jsonFile = packageJson.adaptTo(Node.class);
try {
boolean isFile = (jsonFile.isNodeType(NodeType.NT_FILE) || jsonFile.isNodeType(NodeType.NT_RESOURCE));
if (isFile) {
InputStream is = packageJson.getChild("jcr:content").adaptTo(InputStream.class);
try {
String jsonData = IOUtils.toString(is);
Invocable invocable = (Invocable) factory.getNashornEngine();
JSObject jsonprop = null;
try {
jsonprop = (JSObject) invocable.invokeMethod(factory.getNashornEngine().eval("JSON"), "parse", jsonData);
} catch (NoSuchMethodException ex) {
throw new ScriptException(ex);
}
Object main = jsonprop.getMember("main");
if (main != null) {
String packageModule = (String) main;
String mainpath = normalizePath(packageModule, path);
return loadAsFile(packageModule, mainpath, currentResource, loader);
}
} catch (IOException ex) {
throw new ScriptException(ex);
}
}
} catch (RepositoryException ex) {
throw new ScriptException(ex);
}
}
Resource indexjs = resolver.getResource(path + "/index.js");
if (indexjs != null) {
return createModuleScript(indexjs, ModuleScript.JS_FILE);
}
Resource indexjson = resolver.getResource(path + "/index.json");
if (indexjson != null) {
return createModuleScript(indexjson, ModuleScript.JSON_FILE);
}
Resource indexnode = resolver.getResource(path + "/index.node");
if (indexnode != null) {
throw new ScriptException("Node module .node (binary) loading is currently not supported");
}
return null;
}
use of javax.script.Invocable in project sling by apache.
the class ScriptSandboxServiceImpl method compileSource.
@Override
public String compileSource(String source) throws ScriptException {
Invocable inv = (Invocable) scriptEngine;
JSObject rs;
try {
rs = (JSObject) inv.invokeMethod(babel, "transform", source, babelOptions);
return rs.getMember("code").toString();
} catch (ScriptException ex) {
throw new ScriptException(ex);
} catch (NoSuchMethodException ex) {
throw new ScriptException(ex);
}
}
Aggregations