diff --git a/src/main/java/org/lsc/utils/ScriptingEvaluator.java b/src/main/java/org/lsc/utils/ScriptingEvaluator.java index ca05f946..9913109c 100644 --- a/src/main/java/org/lsc/utils/ScriptingEvaluator.java +++ b/src/main/java/org/lsc/utils/ScriptingEvaluator.java @@ -5,6 +5,7 @@ import java.util.Map; import java.util.Optional; import java.util.function.Predicate; +import java.util.regex.Pattern; import javax.script.*; @@ -41,7 +42,7 @@ public class ScriptingEvaluator { } private ScriptingEvaluator() { - instancesTypeCache = new HashMap(); + instancesTypeCache = new HashMap<>(); List factories = mgr.getEngineFactories(); for (ScriptEngineFactory sef : factories) { boolean loaded = false; @@ -115,13 +116,33 @@ public static void contribute(String implementationName, private ScriptableEvaluator identifyScriptingEngine(String expression) throws LscServiceException { String[] parts = expression.split(":"); - if (parts != null && parts.length > 0 && parts[0].length() < 10 - && instancesTypeCache.containsKey(parts[0])) { - return instancesTypeCache.get(parts[0]); + String match = matchJScriptEvaluator(parts[0]); + if (!match.isEmpty()) { + return instancesTypeCache.get(match); } return defaultImplementation.orElseThrow(() -> new LscServiceException("Missing Script evaluator")); } + /** + * Matches the prefix specifying the jscript evaluator. + * + * @param jscript the prefix + * @return the matched jscript evaluator + */ + public String matchJScriptEvaluator(String jscript) { + for (String jscriptEngine : instancesTypeCache.keySet()) { + Pattern pattern = Pattern.compile("\\n.*" + jscriptEngine); + if (pattern.matcher(jscript).matches()) { + return jscriptEngine; + } + pattern = Pattern.compile(jscriptEngine); + if (pattern.matcher(jscript).matches()) { + return jscriptEngine; + } + } + return ""; + } + /** * Remove scripting engine prefix if required * @param expression the expression