Search in sources :

Example 1 with ScriptEngineFactory

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();
}
Also used : Binding(groovy.lang.Binding) JobProcessingException(org.codelibs.fess.exception.JobProcessingException) GroovyShell(groovy.lang.GroovyShell) JobProcessingException(org.codelibs.fess.exception.JobProcessingException) GroovyClassLoader(groovy.lang.GroovyClassLoader) ScriptEngineFactory(org.codelibs.fess.script.ScriptEngineFactory) Map(java.util.Map) HashMap(java.util.HashMap) AbstractScriptEngine(org.codelibs.fess.script.AbstractScriptEngine)

Example 2 with ScriptEngineFactory

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();
}
Also used : Binding(groovy.lang.Binding) IndexUpdateCallback(org.codelibs.fess.ds.callback.IndexUpdateCallback) JobProcessingException(org.codelibs.fess.exception.JobProcessingException) GroovyShell(groovy.lang.GroovyShell) JobProcessingException(org.codelibs.fess.exception.JobProcessingException) GroovyClassLoader(groovy.lang.GroovyClassLoader) DataConfig(org.codelibs.fess.es.config.exentity.DataConfig) ScriptEngineFactory(org.codelibs.fess.script.ScriptEngineFactory) HashMap(java.util.HashMap) Map(java.util.Map) AbstractScriptEngine(org.codelibs.fess.script.AbstractScriptEngine)

Aggregations

Binding (groovy.lang.Binding)2 GroovyClassLoader (groovy.lang.GroovyClassLoader)2 GroovyShell (groovy.lang.GroovyShell)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 JobProcessingException (org.codelibs.fess.exception.JobProcessingException)2 AbstractScriptEngine (org.codelibs.fess.script.AbstractScriptEngine)2 ScriptEngineFactory (org.codelibs.fess.script.ScriptEngineFactory)2 IndexUpdateCallback (org.codelibs.fess.ds.callback.IndexUpdateCallback)1 DataConfig (org.codelibs.fess.es.config.exentity.DataConfig)1