Example usage for javax.script ScriptEngineFactory getNames

List of usage examples for javax.script ScriptEngineFactory getNames

Introduction

In this page you can find the example usage for javax.script ScriptEngineFactory getNames.

Prototype

public List<String> getNames();

Source Link

Document

Returns an immutable list of short names for the ScriptEngine, which may be used to identify the ScriptEngine by the ScriptEngineManager.

Usage

From source file:RegisteredNameDemo.java

public static void main(String[] args) {
    ScriptEngineManager manager = new ScriptEngineManager();
    List<ScriptEngineFactory> factories = manager.getEngineFactories();
    for (ScriptEngineFactory factory : factories) {
        List<String> regNames = factory.getNames();
        for (int i = 0; i < regNames.size(); i++) {
            System.out.printf("Registered name " + i + " " + (String) regNames.get(i) + "\n");
        }//from w  w w.  j  a  v a 2s  . co m
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    ScriptEngineManager mgr = new ScriptEngineManager();
    List<ScriptEngineFactory> engines = mgr.getEngineFactories();
    for (ScriptEngineFactory engine : engines) {
        System.out.println(engine.getEngineName());
        for (String n : engine.getNames()) {
            System.out.println("Short name : " + n);
        }/*from ww w  . j  a  v  a  2 s.c o  m*/
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    ScriptEngineManager mgr = new ScriptEngineManager();
    List<ScriptEngineFactory> engines = mgr.getEngineFactories();
    for (ScriptEngineFactory engine : engines) {
        System.out.println(engine.getEngineName());
        for (String n : engine.getNames()) {
            System.out.println("Short name : " + n);
        }/*from ww  w.  ja  v  a  2s  .  c o m*/
    }
    ScriptEngine engine = mgr.getEngineByName("JavaScript");
    String myJSCode = "function myFunction(){return (4+2);}myFunction();";
    System.out.println(engine.eval(myJSCode));
}

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("===");
    }//  ww  w. ja  va  2s. c  o  m
}

From source file:Main.java

public static void main(String args[]) {
    ScriptEngineManager manager = new ScriptEngineManager();
    List<ScriptEngineFactory> factories = manager.getEngineFactories();
    for (ScriptEngineFactory factory : factories) {
        System.out.println(factory.getEngineName());
        System.out.println(factory.getEngineVersion());
        System.out.println(factory.getLanguageName());
        System.out.println(factory.getLanguageVersion());
        System.out.println(factory.getExtensions());
        System.out.println(factory.getMimeTypes());
        System.out.println(factory.getNames());
    }// www.j  a  v  a2 s . c o m
}

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();//from   w ww .  ja  v  a 2  s .c o m
    }
}

From source file:com.galeoconsulting.leonardinius.api.LanguageUtils.java

public static String getLanguageName(ScriptEngineFactory factory) {
    String languageName = factory.getLanguageName();
    if ("ECMAScript".equals(languageName) && factory.getNames().contains("JavaScript")) {
        languageName = "JavaScript";
    }// w w w  .j  a v a 2  s  .  c om
    return StringUtils.capitalize(languageName);
}

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);/* w  w  w  . j  a va  2s. co  m*/
    }
    return engines;
}

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 a v  a2  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;
}