Use shared Groovy script engine

This commit is contained in:
Reinhard Pointner 2016-02-08 22:40:05 +00:00
parent 1ebece8d19
commit 25f6edd065
2 changed files with 7 additions and 8 deletions

View File

@ -10,11 +10,11 @@ import java.util.logging.Logger;
public class ExpressionFileFilter implements FileFilter { public class ExpressionFileFilter implements FileFilter {
private final ExpressionFilter filter; private final ExpressionFilter filter;
private final boolean errorResult; private final boolean error;
public ExpressionFileFilter(ExpressionFilter filter, boolean errorResult) { public ExpressionFileFilter(ExpressionFilter filter, boolean error) {
this.filter = filter; this.filter = filter;
this.errorResult = errorResult; this.error = error;
} }
public ExpressionFilter getExpressionFilter() { public ExpressionFilter getExpressionFilter() {
@ -27,7 +27,7 @@ public class ExpressionFileFilter implements FileFilter {
return filter.matches(new MediaBindingBean(readMetaInfo(f), f, null)); return filter.matches(new MediaBindingBean(readMetaInfo(f), f, null));
} catch (Exception e) { } catch (Exception e) {
Logger.getLogger(ExpressionFileFilter.class.getName()).log(Level.WARNING, e.toString()); Logger.getLogger(ExpressionFileFilter.class.getName()).log(Level.WARNING, e.toString());
return errorResult; return error;
} }
} }

View File

@ -1,9 +1,10 @@
package net.filebot.format; package net.filebot.format;
import static net.filebot.format.ExpressionFormat.*;
import java.security.AccessController; import java.security.AccessController;
import javax.script.Bindings; import javax.script.Bindings;
import javax.script.Compilable;
import javax.script.CompiledScript; import javax.script.CompiledScript;
import javax.script.ScriptContext; import javax.script.ScriptContext;
import javax.script.ScriptException; import javax.script.ScriptException;
@ -20,9 +21,7 @@ public class ExpressionFilter {
public ExpressionFilter(String expression) throws ScriptException { public ExpressionFilter(String expression) throws ScriptException {
this.expression = expression; this.expression = expression;
this.compiledExpression = new SecureCompiledScript(compileScriptlet(expression));
Compilable engine = (Compilable) ExpressionFormat.getGroovyScriptEngine();
this.compiledExpression = new SecureCompiledScript(engine.compile(expression)); // sandboxed script
} }
public String getExpression() { public String getExpression() {