use of javax.script.ScriptException 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.ScriptException 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.ScriptException 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.ScriptException in project jqa-core-framework by buschmais.
the class AnalyzerVisitor method executeScript.
/**
* Execute an analysis script
*
* @param <T>
* The result type.
* @param scriptExecutable
* The script.
* @param ruleParameters
* @param severity
* The severity. @return The result.
* @throws RuleExecutorException
* If script execution fails.
*/
private <T extends ExecutableRule> Result<T> executeScript(T executable, ScriptExecutable scriptExecutable, Map<String, Object> ruleParameters, Severity severity) throws RuleExecutorException {
String language = scriptExecutable.getLanguage();
ScriptEngine scriptEngine = scriptEngineManager.getEngineByName(language);
if (scriptEngine == null) {
List<String> availableLanguages = new ArrayList<>();
for (ScriptEngineFactory factory : scriptEngineManager.getEngineFactories()) {
availableLanguages.addAll(factory.getNames());
}
throw new RuleExecutorException("Cannot resolve scripting engine for '" + language + "', available languages are " + availableLanguages);
}
// Set default variables
scriptEngine.put(ScriptVariable.STORE.getVariableName(), store);
scriptEngine.put(ScriptVariable.RULE.getVariableName(), executable);
scriptEngine.put(ScriptVariable.SEVERITY.getVariableName(), severity);
// Set rule parameters
for (Map.Entry<String, Object> entry : ruleParameters.entrySet()) {
scriptEngine.put(entry.getKey(), entry.getValue());
}
Object scriptResult;
try {
scriptResult = scriptEngine.eval(scriptExecutable.getSource());
} catch (ScriptException e) {
throw new RuleExecutorException("Cannot execute script.", e);
}
if (!(scriptResult instanceof Result)) {
throw new RuleExecutorException("Script returned an invalid result type, expected " + Result.class.getName() + " but got " + scriptResult);
}
return Result.class.cast(scriptResult);
}
use of javax.script.ScriptException in project sling by apache.
the class XProcScriptEngine method eval.
public Object eval(Reader reader, ScriptContext scriptContext) throws ScriptException {
Bindings bindings = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
SlingScriptHelper helper = (SlingScriptHelper) bindings.get(SlingBindings.SLING);
if (helper == null) {
throw new ScriptException("SlingScriptHelper missing from bindings");
}
String scriptName = helper.getScript().getScriptResource().getPath();
try {
XplBuilder xplBuilder = new XplBuilder();
Pipeline xpl = (Pipeline) xplBuilder.build(reader);
xpl.getEnv().setSling(helper);
xpl.eval();
} catch (Throwable t) {
log.error("Failure running XProc script.", t);
final ScriptException se = new ScriptException("Failure running XProc script " + scriptName);
se.initCause(t);
throw se;
}
return null;
}
Aggregations