List of usage examples for javax.script ScriptEngineFactory getNames
public List<String> getNames();
ScriptEngine
, which may be used to identify the ScriptEngine
by the ScriptEngineManager
. From source file:org.gatherdata.alert.detect.bsf.internal.BsfEventDetector.java
public BsfEventDetector() { this.scriptEngineManager = new ScriptEngineManager(); List<ScriptEngineFactory> engineFactories = scriptEngineManager.getEngineFactories(); log.info("Available ScriptEngineFactories..."); for (ScriptEngineFactory factory : engineFactories) { log.info("\t" + factory.getEngineName() + " - " + factory.getLanguageName() + " " + "ext:" + factory.getExtensions() + " " + "names:" + factory.getNames()); }/*from w w w . j ava2s .co m*/ }
From source file:it.geosolutions.geobatch.action.scripting.ScriptingTest.java
@Test public void testLoop() throws ScriptException { String engineName = "groovy"; ScriptEngine foundEngine = null; // create a script engine manager ScriptEngineManager mgr = new ScriptEngineManager(); List<ScriptEngineFactory> factories = mgr.getEngineFactories(); System.out.println("FOUND " + factories.size() + " factories"); for (ScriptEngineFactory sef : factories) { System.out.println("FACTORY: " + "'" + sef.getEngineName() + "' " + "'" + sef.getLanguageName() + "' " + "'" + sef.getExtensions() + "' " + "'" + sef.getNames() + "' "); if (sef.getEngineName().contains(engineName)) { foundEngine = sef.getScriptEngine(); }/* w w w.j a v a 2s . c o m*/ } assertNotNull("Can't find engine '" + engineName + "'", foundEngine); foundEngine.eval("print('Hello, World')"); }
From source file:org.archive.crawler.restlet.ScriptResource.java
protected Collection<Map<String, String>> getAvailableScriptEngines() { List<Map<String, String>> engines = new LinkedList<Map<String, String>>(); for (ScriptEngineFactory f : FACTORIES) { Map<String, String> engine = new LinkedHashMap<String, String>(); engine.put("engine", f.getNames().get(0)); engine.put("language", f.getLanguageName()); engines.add(engine);/* w w w . jav a2 s. c o m*/ } return engines; }
From source file:it.geosolutions.geobatch.action.scripting.ScriptingTest.java
@Test public void testGetEngineByExt() throws ScriptException { String engineExt = "js"; ScriptEngineManager mgr = new ScriptEngineManager(); // create a JavaScript engine ScriptEngine engine = mgr.getEngineByExtension(engineExt); assertNotNull("Can't find engine '" + engineExt + "'", engine); ScriptEngineFactory sef = engine.getFactory(); System.out.println("FACTORY for " + engineExt + ": " + "'" + sef.getEngineName() + "' " + "'" + sef.getLanguageName() + "' " + "'" + sef.getExtensions() + "' " + "'" + sef.getNames() + "' "); // evaluate JavaScript code from String engine.eval("print('Hello, World')"); }
From source file:it.geosolutions.geobatch.action.scripting.ScriptingTest.java
@Test public void testGroovy() throws ScriptException { String engineName = "groovy"; ScriptEngineManager mgr = new ScriptEngineManager(); // create a JavaScript engine ScriptEngine engine = mgr.getEngineByName(engineName); assertNotNull("Can't find engine '" + engineName + "'", engine); ScriptEngineFactory sef = engine.getFactory(); System.out.println("FACTORY for " + engineName + ": " + "'" + sef.getEngineName() + "' " + "'" + sef.getLanguageName() + "' " + "'" + sef.getExtensions() + "' " + "'" + sef.getNames() + "' "); // evaluate code from String engine.eval("println \"hello, groovy\""); }
From source file:org.pentaho.platform.plugin.condition.scriptable.ScriptableCondition.java
public void setListAvailableEngines(final boolean value) { this.listAvailableEngines = value; if (value) {/*from w ww .jav a 2 s . co m*/ System.out.println("*** DEBUG - Display Script Engine List ***"); ScriptEngineManager manager = new ScriptEngineManager(); List<ScriptEngineFactory> factories = manager.getEngineFactories(); for (ScriptEngineFactory factory : factories) { System.out.println(String.format("Engine %s, Version %s, Language %s, Registered Names: %s", factory.getEngineName(), factory.getEngineVersion(), factory.getLanguageName(), factory.getNames().toString())); } } }
From source file:cc.osint.graphd.script.GScriptEngine.java
public void dumpScriptEngines() throws Exception { ScriptEngineManager mgr = new ScriptEngineManager(); List<ScriptEngineFactory> factories = mgr.getEngineFactories(); for (ScriptEngineFactory factory : factories) { log.info("ScriptEngineFactory Info"); String engName = factory.getEngineName(); String engVersion = factory.getEngineVersion(); String langName = factory.getLanguageName(); String langVersion = factory.getLanguageVersion(); System.out.printf("\tScript Engine: %s (%s)\n", engName, engVersion); List<String> engNames = factory.getNames(); for (String name : engNames) { System.out.printf("\tEngine Alias: %s\n", name); }/*ww w.j a va 2s. co m*/ System.out.printf("\tLanguage: %s (%s)\n", langName, langVersion); } }
From source file:org.trafodion.rest.script.ScriptManager.java
private ScriptManager() { List<ScriptEngineFactory> engines = manager.getEngineFactories(); if (engines.isEmpty()) { LOG.warn("No scripting engines were found"); return;//from w ww. jav a 2 s .co m } StringBuffer sb = new StringBuffer(); sb.append("\nThe following " + engines.size() + " scripting engine(s) were found"); for (ScriptEngineFactory engine : engines) { sb.append("\nEngine name: " + engine.getEngineName() + "\nVersion: " + engine.getEngineVersion() + "\nLanguage: " + engine.getLanguageName()); List<String> extensions = engine.getExtensions(); if (extensions.size() > 0) { sb.append("\n\tEngine supports the following extensions:"); for (String e : extensions) { sb.append("\n\t\t" + e); } } List<String> shortNames = engine.getNames(); if (shortNames.size() > 0) { sb.append("\n\tEngine has the following short names:"); for (String n : engine.getNames()) { sb.append("\n\t\t" + n); } } String[] params = { ScriptEngine.ENGINE, ScriptEngine.ENGINE_VERSION, ScriptEngine.LANGUAGE, ScriptEngine.LANGUAGE_VERSION, ScriptEngine.NAME, "THREADING" }; sb.append("\n\tEngine has the following parameters:"); for (String param : params) { sb.append("\n\t\t" + param + " = " + engine.getParameter(param)); } sb.append("\n========================="); } LOG.debug(sb.toString()); //Get -Drest.home.dir restHome = System.getProperty("rest.home.dir"); //Start the scripts directory watcher watcherWorker = new ScriptManagerWatcher("ScriptManagerWatcher", restHome + "/bin/scripts"); }
From source file:org.apache.accumulo.core.util.shell.commands.ScriptCommand.java
private void listJSREngineInfo(ScriptEngineManager mgr, Shell shellState) throws IOException { List<ScriptEngineFactory> factories = mgr.getEngineFactories(); Set<String> lines = new TreeSet<String>(); for (ScriptEngineFactory factory : factories) { lines.add("ScriptEngineFactory Info"); String engName = factory.getEngineName(); String engVersion = factory.getEngineVersion(); String langName = factory.getLanguageName(); String langVersion = factory.getLanguageVersion(); lines.add("\tScript Engine: " + engName + " (" + engVersion + ")"); List<String> engNames = factory.getNames(); for (String name : engNames) { lines.add("\tEngine Alias: " + name); }/*from w w w .j a v a 2 s .com*/ lines.add("\tLanguage: " + langName + " (" + langVersion + ")"); } shellState.printLines(lines.iterator(), true); }
From source file:com.aionemu.commons.scripting.AionScriptEngineManager.java
private AionScriptEngineManager() { ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); List<ScriptEngineFactory> factories = scriptEngineManager.getEngineFactories(); if (USE_COMPILED_CACHE) { _cache = loadCompiledScriptCache(); } else {/*www . j av a2s. co m*/ _cache = null; } log.info("Initializing Script Engine Manager"); for (ScriptEngineFactory factory : factories) { try { log.info("Script Engine: " + factory.getEngineName() + " " + factory.getEngineVersion() + " - Language: " + factory.getLanguageName() + " " + factory.getLanguageVersion()); ScriptEngine engine = factory.getScriptEngine(); for (String name : factory.getNames()) { if (_nameEngines.containsKey(name)) throw new IllegalStateException("Multiple script engines for the same name!"); _nameEngines.put(name, engine); } for (String ext : factory.getExtensions()) { if (_extEngines.containsKey(ext)) throw new IllegalStateException("Multiple script engines for the same extension!"); _extEngines.put(ext, engine); } } catch (Exception e) { log.warn("Failed initializing factory.", e); } } }