use of org.codelibs.fess.script.ScriptEngineFactory in project fess by codelibs.
the class DocBoostMatcherTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
ScriptEngineFactory scriptEngineFactory = new ScriptEngineFactory();
ComponentUtil.register(scriptEngineFactory, "scriptEngineFactory");
new AbstractScriptEngine() {
@Override
public Object evaluate(String template, Map<String, Object> paramMap) {
final Map<String, Object> bindingMap = new HashMap<>(paramMap);
bindingMap.put("container", SingletonLaContainerFactory.getContainer());
final GroovyShell groovyShell = new GroovyShell(new Binding(bindingMap));
try {
return groovyShell.evaluate(template);
} catch (final JobProcessingException e) {
throw e;
} catch (final Exception e) {
return null;
} finally {
final GroovyClassLoader loader = groovyShell.getClassLoader();
loader.clearCache();
}
}
@Override
protected String getName() {
return Constants.DEFAULT_SCRIPT;
}
}.register();
}
use of org.codelibs.fess.script.ScriptEngineFactory in project fess by codelibs.
the class AbstractDataStoreTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
dataStore = new AbstractDataStore() {
@Override
protected String getName() {
return "Test";
}
@Override
protected void storeData(DataConfig dataConfig, IndexUpdateCallback callback, Map<String, String> paramMap, Map<String, String> scriptMap, Map<String, Object> defaultDataMap) {
// TODO nothing
}
};
ScriptEngineFactory scriptEngineFactory = new ScriptEngineFactory();
ComponentUtil.register(scriptEngineFactory, "scriptEngineFactory");
new AbstractScriptEngine() {
@Override
public Object evaluate(String template, Map<String, Object> paramMap) {
final Map<String, Object> bindingMap = new HashMap<>(paramMap);
bindingMap.put("container", SingletonLaContainerFactory.getContainer());
final GroovyShell groovyShell = new GroovyShell(new Binding(bindingMap));
try {
return groovyShell.evaluate(template);
} catch (final JobProcessingException e) {
throw e;
} catch (final Exception e) {
return null;
} finally {
final GroovyClassLoader loader = groovyShell.getClassLoader();
loader.clearCache();
}
}
@Override
protected String getName() {
return Constants.DEFAULT_SCRIPT;
}
}.register();
}
Aggregations