Search in sources :

Example 31 with ScriptEngineManager

use of javax.script.ScriptEngineManager in project adempiere by adempiere.

the class MRule method getScriptEngine.

//	toString
/**
	 * 	Script Engine for this rule
	 *	@return ScriptEngine
	 */
public ScriptEngine getScriptEngine() {
    factory = new ScriptEngineManager();
    String engineName = getEngineName();
    if (engineName != null)
        engine = factory.getEngineByName(engineName);
    return engine;
}
Also used : ScriptEngineManager(javax.script.ScriptEngineManager)

Example 32 with ScriptEngineManager

use of javax.script.ScriptEngineManager in project lucene-solr by apache.

the class ScriptTransformer method initEngine.

private void initEngine(Context context) {
    String scriptText = context.getScript();
    String scriptLang = context.getScriptLanguage();
    if (scriptText == null) {
        throw new DataImportHandlerException(SEVERE, "<script> tag is not present under <dataConfig>");
    }
    ScriptEngineManager scriptEngineMgr = new ScriptEngineManager();
    ScriptEngine scriptEngine = scriptEngineMgr.getEngineByName(scriptLang);
    if (scriptEngine == null) {
        throw new DataImportHandlerException(SEVERE, "Cannot load Script Engine for language: " + scriptLang);
    }
    if (scriptEngine instanceof Invocable) {
        engine = (Invocable) scriptEngine;
    } else {
        throw new DataImportHandlerException(SEVERE, "The installed ScriptEngine for: " + scriptLang + " does not implement Invocable.  Class is " + scriptEngine.getClass().getName());
    }
    try {
        scriptEngine.eval(scriptText);
    } catch (ScriptException e) {
        wrapAndThrow(SEVERE, e, "'eval' failed with language: " + scriptLang + " and script: \n" + scriptText);
    }
}
Also used : Invocable(javax.script.Invocable) ScriptException(javax.script.ScriptException) ScriptEngineManager(javax.script.ScriptEngineManager) ScriptEngine(javax.script.ScriptEngine)

Example 33 with ScriptEngineManager

use of javax.script.ScriptEngineManager in project lucene-solr by apache.

the class ScriptEngineTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    manager = new ScriptEngineManager();
}
Also used : ScriptEngineManager(javax.script.ScriptEngineManager)

Example 34 with ScriptEngineManager

use of javax.script.ScriptEngineManager in project lucene-solr by apache.

the class TestBadConfig method testMissingScriptFile.

public void testMissingScriptFile() throws Exception {
    // sanity check
    Assume.assumeNotNull((new ScriptEngineManager()).getEngineByExtension("js"));
    assertConfigs("bad-solrconfig-missing-scriptfile.xml", "schema.xml", "a-file-name-that-does-not-exist.js");
}
Also used : ScriptEngineManager(javax.script.ScriptEngineManager)

Example 35 with ScriptEngineManager

use of javax.script.ScriptEngineManager in project lucene-solr by apache.

the class TestBadConfig method testInvalidScriptFile.

public void testInvalidScriptFile() throws Exception {
    // sanity check
    Assume.assumeNotNull((new ScriptEngineManager()).getEngineByName("javascript"));
    assertConfigs("bad-solrconfig-invalid-scriptfile.xml", "schema.xml", "currency.xml");
}
Also used : ScriptEngineManager(javax.script.ScriptEngineManager)

Aggregations

ScriptEngineManager (javax.script.ScriptEngineManager)109 ScriptEngine (javax.script.ScriptEngine)66 Test (org.junit.Test)23 ScriptException (javax.script.ScriptException)20 ScriptEngineFactory (javax.script.ScriptEngineFactory)14 File (java.io.File)12 Invocable (javax.script.Invocable)11 QuickTest (com.hazelcast.test.annotation.QuickTest)10 IOException (java.io.IOException)10 FileReader (java.io.FileReader)9 Bindings (javax.script.Bindings)9 Before (org.junit.Before)9 Map (java.util.Map)8 GroovyScriptEngineFactory (org.codehaus.groovy.jsr223.GroovyScriptEngineFactory)8 Reader (java.io.Reader)7 HashMap (java.util.HashMap)6 SimpleBindings (javax.script.SimpleBindings)6 PrintWriter (java.io.PrintWriter)4 StringWriter (java.io.StringWriter)4 InputStreamReader (java.io.InputStreamReader)3