List of usage examples for org.apache.lucene.expressions.js JavascriptCompiler DEFAULT_FUNCTIONS
Map DEFAULT_FUNCTIONS
To view the source code for org.apache.lucene.expressions.js JavascriptCompiler DEFAULT_FUNCTIONS.
Click Source Link
From source file:com.o19s.es.ltr.utils.Scripting.java
License:Apache License
public static Object compile(String scriptSource) { // classloader created here final SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new SpecialPermission()); }// w w w . j a v a2s. com return AccessController.doPrivileged(new PrivilegedAction<Expression>() { @Override public Expression run() { try { // snapshot our context here, we check on behalf of the expression AccessControlContext engineContext = AccessController.getContext(); ClassLoader loader = getClass().getClassLoader(); if (sm != null) { loader = new ClassLoader(loader) { @Override protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { try { engineContext.checkPermission(new ClassPermission(name)); } catch (SecurityException e) { throw new ClassNotFoundException(name, e); } return super.loadClass(name, resolve); } }; } // NOTE: validation is delayed to allow runtime vars, and we don't have access to per index stuff here return JavascriptCompiler.compile(scriptSource, JavascriptCompiler.DEFAULT_FUNCTIONS, loader); } catch (ParseException e) { throw convertToScriptException("compile error", scriptSource, scriptSource, e); } } }); }
From source file:org.elasticsearch.script.expression.ExpressionScriptEngine.java
License:Apache License
@Override public <T> T compile(String scriptName, String scriptSource, ScriptContext<T> context, Map<String, String> params) { // classloader created here final SecurityManager sm = System.getSecurityManager(); SpecialPermission.check();/*from w w w.ja va2 s . c o m*/ Expression expr = AccessController.doPrivileged(new PrivilegedAction<Expression>() { @Override public Expression run() { try { // snapshot our context here, we check on behalf of the expression AccessControlContext engineContext = AccessController.getContext(); ClassLoader loader = getClass().getClassLoader(); if (sm != null) { loader = new ClassLoader(loader) { @Override protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { try { engineContext.checkPermission(new ClassPermission(name)); } catch (SecurityException e) { throw new ClassNotFoundException(name, e); } return super.loadClass(name, resolve); } }; } // NOTE: validation is delayed to allow runtime vars, and we don't have access to per index stuff here return JavascriptCompiler.compile(scriptSource, JavascriptCompiler.DEFAULT_FUNCTIONS, loader); } catch (ParseException e) { throw convertToScriptException("compile error", scriptSource, scriptSource, e); } } }); if (context.instanceClazz.equals(SearchScript.class)) { SearchScript.Factory factory = (p, lookup) -> newSearchScript(expr, lookup, p); return context.factoryClazz.cast(factory); } else if (context.instanceClazz.equals(ExecutableScript.class)) { ExecutableScript.Factory factory = (p) -> new ExpressionExecutableScript(expr, p); return context.factoryClazz.cast(factory); } else if (context.instanceClazz.equals(FilterScript.class)) { FilterScript.Factory factory = (p, lookup) -> newFilterScript(expr, lookup, p); return context.factoryClazz.cast(factory); } throw new IllegalArgumentException( "expression engine does not know how to handle script context [" + context.name + "]"); }
From source file:org.elasticsearch.script.expression.ExpressionScriptEngineService.java
License:Apache License
@Override public Object compile(final String script, Map<String, String> params) { // classloader created here final SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new SpecialPermission()); }//from w ww . jav a 2 s .c om return AccessController.doPrivileged(new PrivilegedAction<Expression>() { @Override public Expression run() { try { // snapshot our context here, we check on behalf of the expression final AccessControlContext engineContext = AccessController.getContext(); ClassLoader loader = getClass().getClassLoader(); if (sm != null) { loader = new ClassLoader(loader) { @Override protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { try { engineContext.checkPermission(new ClassPermission(name)); } catch (SecurityException e) { throw new ClassNotFoundException(name, e); } return super.loadClass(name, resolve); } }; } // NOTE: validation is delayed to allow runtime vars, and we don't have access to per index stuff here return JavascriptCompiler.compile(script, JavascriptCompiler.DEFAULT_FUNCTIONS, loader); } catch (ParseException e) { throw new ScriptException("Failed to parse expression: " + script, e); } } }); }