List of usage examples for javax.script ScriptEngineManager getEngineFactories
public List<ScriptEngineFactory> getEngineFactories()
ScriptEngineFactory
classes found by the discovery mechanism. From source file:EnumerateScriptEngines.java
public static void main(String[] args) { ScriptEngineManager manager = new ScriptEngineManager(); List<ScriptEngineFactory> factories = manager.getEngineFactories(); for (ScriptEngineFactory factory : factories) { System.out.println("Engine name (full): " + factory.getEngineName()); System.out.println("Engine version: " + factory.getEngineVersion()); System.out.println("Supported extensions:"); List<String> extensions = factory.getExtensions(); for (String extension : extensions) System.out.println(" " + extension); System.out.println("Language name: " + factory.getLanguageName()); System.out.println("Language version: " + factory.getLanguageVersion()); System.out.println("Supported MIME types:"); List<String> mimetypes = factory.getMimeTypes(); for (String mimetype : mimetypes) System.out.println(" " + mimetype); System.out.println("Supported short names:"); List<String> shortnames = factory.getNames(); for (String shortname : shortnames) System.out.println(" " + shortname); System.out.println();/* w w w . ja va 2s.co m*/ } }
From source file:Main.java
public static void main(String[] args) { ScriptEngineManager manager = new ScriptEngineManager(); // Get the list of all available engines List<ScriptEngineFactory> list = manager.getEngineFactories(); // Print the details of each engine for (ScriptEngineFactory f : list) { System.out.println("Engine Name:" + f.getEngineName()); System.out.println("Engine Version:" + f.getEngineVersion()); System.out.println("Language Name:" + f.getLanguageName()); System.out.println("Language Version:" + f.getLanguageVersion()); System.out.println("Engine Short Names:" + f.getNames()); System.out.println("Mime Types:" + f.getMimeTypes()); System.out.println("==="); }//from w ww.jav a 2 s . c om }
From source file:com.xafero.vee.cmd.MainApp.java
private static void printLanguages() { ScriptEngineManager mgr = new ScriptEngineManager(); for (ScriptEngineFactory factory : mgr.getEngineFactories()) System.out.println(MoreObjects.toStringHelper("").add("name", factory.getEngineName()) .add("version", factory.getEngineVersion()) .add("extensions", "[ " + Strings.join(" | ", factory.getExtensions()) + " ]") .add("mimeTypes", "[ " + Strings.join(" | ", factory.getMimeTypes()) + " ]") .add("aliases", "[ " + Strings.join(" | ", factory.getNames()) + " ]") .add("language", factory.getLanguageName() + " " + factory.getLanguageVersion()) .omitNullValues().toString().replace(", ", String.format(", %n "))); }
From source file:org.mycontroller.standalone.scripts.McScriptEngineUtils.java
public static List<HashMap<String, Object>> getScriptEnginesDetail() { List<HashMap<String, Object>> engines = new ArrayList<HashMap<String, Object>>(); ScriptEngineManager mgr = McScriptEngineUtils.getScriptEngineManager(); List<ScriptEngineFactory> factories = mgr.getEngineFactories(); for (ScriptEngineFactory factory : factories) { HashMap<String, Object> engine = new HashMap<String, Object>(); engine.put("engineName", factory.getEngineName()); engine.put("engineVersion", factory.getEngineVersion()); engine.put("languageName", factory.getLanguageName()); engine.put("languageVersion", factory.getLanguageVersion()); engine.put("extensions", factory.getExtensions()); engine.put("alias", factory.getNames()); engines.add(engine);/*ww w . j av a 2s . c o m*/ } return engines; }
From source file:tools.httpserver.custom.ScriptList.java
/** * @return a vector containing Scriptengines names and associated languages *//*from ww w .j a v a2 s .com*/ public static Vector<String[]> getScriptEngines() { Vector<String[]> vector = new Vector<String[]>(); ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); for (ScriptEngineFactory factories : scriptEngineManager.getEngineFactories()) { boolean inserted = false; for (int i = 0; i < vector.size(); i++) { String[] s = vector.elementAt(i); if (s[0].compareToIgnoreCase(factories.getEngineName()) > 0) { vector.insertElementAt(new String[] { factories.getEngineName(), factories.getLanguageName() }, i); inserted = true; break; } } if (!inserted) vector.add(new String[] { factories.getEngineName(), factories.getLanguageName() }); } if (javax.tools.ToolProvider.getSystemJavaCompiler() != null) { vector.add(new String[] { "java", "java" }); } return vector; }
From source file:tools.httpserver.custom.ScriptList.java
/** * Create a new empty SpoonScript file using provided parameters * @param params_values parameters to use for file creation (table containing "param=value" strings) * @param type Set if script concerns REQMOD or RESPMOD * @param user User who generates the request * @return Action to do after: edit the new file if all is ok, return error otherwise *//*from ww w. ja va 2s . c om*/ public static String create(String[] params_values, Icap.TYPE type, User user) { String name = null; String language = null; for (String s : params_values) { String[] values = s.split("="); if (values.length != 2) continue; if (values[0].equals("script.name")) name = values[1].replace("+", " ").trim(); if (values[0].equals("script.language")) language = TextTools.hexToUTF8(values[1]).trim(); } if (name == null || language == null) { error = "Invalid script name or language"; return ""; } SpoonScript[] scripts = type == Icap.TYPE.REQMOD ? icap.services.GreasySpoon.reqSpoonScripts : icap.services.GreasySpoon.respSpoonScripts; for (SpoonScript script : scripts) { if (script.getScriptName().equalsIgnoreCase(name)) { error = "A script with this name already exists."; return ""; } } ScriptEngineFactory factory = null; ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); for (ScriptEngineFactory factories : scriptEngineManager.getEngineFactories()) { if (factories.getEngineName().equalsIgnoreCase(language)) { factory = factories; break; } } String factorylanguage; String extension; if (factory == null) { if (language.equals("java")) { factorylanguage = "java"; extension = "java"; } else { error = "Provided language cannot be founded."; return ""; } } else { factorylanguage = factory.getLanguageName(); extension = factory.getExtensions().get(0); } String scriptdirectory = icap.services.GreasySpoon.scriptsDirectory; String commentstring = icap.services.GreasySpoon.languageComments.getProperty(factorylanguage, "//").trim(); String tag; if (type == Icap.TYPE.REQMOD) { tag = icap.services.GreasySpoon.greasySpoonReqTag; } else { tag = icap.services.GreasySpoon.greasySpoonRespTag; } String filecomment = SpoonScript.getScriptSkeleton(type, extension, commentstring); String filename = scriptdirectory + File.separator + name.replace(" ", "_").replace("%20", "_") + tag + extension; SpoonScript.save(filename, filecomment.replace("%name%", name), user.getRights()); icap.services.GreasySpoon.forceReload(); return "edit=" + filename; }
From source file:org.apache.solr.update.processor.StatelessScriptUpdateProcessorFactory.java
/** * For error messages - returns null if there are any exceptions of any * kind building the string (or of the list is empty for some unknown reason). * @param ext - if true, list of extensions, otherwise a list of engine names *//*from ww w . j ava 2 s . c o m*/ private static String getSupportedEngines(ScriptEngineManager mgr, boolean ext) { String result = null; try { List<ScriptEngineFactory> factories = mgr.getEngineFactories(); if (null == factories) return result; Set<String> engines = new LinkedHashSet<>(factories.size()); for (ScriptEngineFactory f : factories) { if (ext) { engines.addAll(f.getExtensions()); } else { engines.addAll(f.getNames()); } } result = StringUtils.join(engines, ", "); } catch (RuntimeException e) { /* :NOOP: */ } return result; }
From source file:com.tc.websocket.scripts.Script.java
/** * Prints the engines./*from w ww. java2 s .co m*/ */ public static void printEngines() { ScriptEngineManager manager = new ScriptEngineManager(); List<ScriptEngineFactory> engines = manager.getEngineFactories(); for (ScriptEngineFactory engine : engines) { System.out.println(engine.getEngineName()); } }
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); }//from www.ja v a 2 s. c om System.out.printf("\tLanguage: %s (%s)\n", langName, langVersion); } }
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 ww . ja v a2 s . c o m*/ } assertNotNull("Can't find engine '" + engineName + "'", foundEngine); foundEngine.eval("print('Hello, World')"); }