Java Code Examples for javax.script.ScriptEngineFactory#getMimeTypes()

The following examples show how to use javax.script.ScriptEngineFactory#getMimeTypes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Scripting.java    From netbeans with Apache License 2.0 6 votes vote down vote up
EngineManager(boolean allowAllAccess, ClassLoader loader) {
    super(loader);
    this.allowAllAccess = allowAllAccess;
    if (allowAllAccess) {
        getBindings().put("allowAllAccess", true); // NOI18N
    }
    this.extra = populateExtras(this);
    for (ScriptEngineFactory f : extra) {
        registerEngineName(f.getEngineName(), f);
        for (String ext : f.getExtensions()) {
            registerEngineExtension(ext, f);
        }
        for (String mime : f.getMimeTypes()) {
            registerEngineMimeType(mime, f);
        }
    }
}
 
Example 2
Source File: GraalEnginesTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Test
public void invokeEngineViaGeneratedScriptEngine() {
    ScriptEngineManager man = Scripting.createManager();
    ScriptEngine llvm = man.getEngineByName("GraalVM:llvm");
    assertNotNull("llvm engine found: " + man.getEngineFactories(), llvm);

    ScriptEngineFactory jsFactory = null;
    ScriptEngineFactory graalvmJsFactory = null;
    ScriptEngineFactory llvmFactory = null;

    StringBuilder log = new StringBuilder();
    for (ScriptEngineFactory factory : man.getEngineFactories()) {
        final List<String> engineNames = factory.getNames();
        final List<String> types = factory.getMimeTypes();

        log.append("\nclass: ").append(factory.getClass().getSimpleName())
            .append("\nnames: ").append(engineNames)
            .append("\ntypes: ").append(types);

        if (engineNames.contains("LLVM")) {
            llvmFactory = factory;
        }
        if (types.contains("text/javascript")) {
            if (factory.getEngineName().startsWith("GraalVM:")) {
                assertNull("No previous generic GraalVM javascript factory: " + graalvmJsFactory, graalvmJsFactory);
                graalvmJsFactory = factory;
            } else {
                assertNull("No previous javascript factory: " + jsFactory, jsFactory);
                jsFactory = factory;
            }
        }
    }

    assertNotNull("llvm factory found: " + log, llvmFactory);
    assertNotNull("js factory found: " + log, jsFactory);
    assertNotNull("Generic GraalVM js factory found: " + log, graalvmJsFactory);
}
 
Example 3
Source File: NewAction.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private void showEngineDetails(JComponent parent, ScriptEngineFactory scriptEngineFactory) {
    StringBuilder out = new StringBuilder();

    out.append(String.format("Engine name: %s\n", scriptEngineFactory.getEngineName()));
    out.append(String.format("Engine version: %s\n", scriptEngineFactory.getEngineVersion()));
    out.append(String.format("Language name: %s\n", scriptEngineFactory.getLanguageName()));
    out.append(String.format("Language version: %s\n", scriptEngineFactory.getLanguageVersion()));

    out.append("File name extension(s):");
    final List<String> extensions = scriptEngineFactory.getExtensions();
    for (String extension : extensions) {
        out.append(" ");
        out.append(extension);
    }
    out.append("\n");

    out.append("File content type(s):");
    final List<String> mimeTypes = scriptEngineFactory.getMimeTypes();
    for (String mimeType : mimeTypes) {
        out.append(" ");
        out.append(mimeType);
    }
    out.append("\n");

    out.append("Engine factory name(s): ");
    final List<String> names = scriptEngineFactory.getNames();
    for (String name : names) {
        out.append(" ");
        out.append(name);
    }
    out.append("\n");

    JOptionPane.showMessageDialog(parent, out.toString(), "Script Engine Details", JOptionPane.INFORMATION_MESSAGE);
}
 
Example 4
Source File: ScriptEngineTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void factoryTests() {
    final ScriptEngineManager m = new ScriptEngineManager();
    final ScriptEngine e = m.getEngineByName("nashorn");
    assertNotNull(e);

    final ScriptEngineFactory fac = e.getFactory();

    assertEquals(fac.getLanguageName(), "ECMAScript");
    assertEquals(fac.getParameter(ScriptEngine.NAME), "javascript");
    assertEquals(fac.getLanguageVersion(), "ECMA - 262 Edition 5.1");
    assertEquals(fac.getEngineName(), "Oracle Nashorn");
    assertEquals(fac.getOutputStatement("context"), "print(context)");
    assertEquals(fac.getProgram("print('hello')", "print('world')"), "print('hello');print('world');");
    assertEquals(fac.getParameter(ScriptEngine.NAME), "javascript");

    boolean seenJS = false;
    for (final String ext : fac.getExtensions()) {
        if (ext.equals("js")) {
            seenJS = true;
        }
    }

    assertEquals(seenJS, true);
    final String str = fac.getMethodCallSyntax("obj", "foo", "x");
    assertEquals(str, "obj.foo(x)");

    boolean seenNashorn = false, seenJavaScript = false, seenECMAScript = false;
    for (final String name : fac.getNames()) {
        switch (name) {
            case "nashorn": seenNashorn = true; break;
            case "javascript": seenJavaScript = true; break;
            case "ECMAScript": seenECMAScript = true; break;
        default:
            break;
        }
    }

    assertTrue(seenNashorn);
    assertTrue(seenJavaScript);
    assertTrue(seenECMAScript);

    boolean seenAppJS = false, seenAppECMA = false, seenTextJS = false, seenTextECMA = false;
    for (final String mime : fac.getMimeTypes()) {
        switch (mime) {
            case "application/javascript": seenAppJS = true; break;
            case "application/ecmascript": seenAppECMA = true; break;
            case "text/javascript": seenTextJS = true; break;
            case "text/ecmascript": seenTextECMA = true; break;
        default:
            break;
        }
    }

    assertTrue(seenAppJS);
    assertTrue(seenAppECMA);
    assertTrue(seenTextJS);
    assertTrue(seenTextECMA);
}
 
Example 5
Source File: ScriptEngineTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void factoryTests() {
    final ScriptEngineManager m = new ScriptEngineManager();
    final ScriptEngine e = m.getEngineByName("nashorn");
    assertNotNull(e);

    final ScriptEngineFactory fac = e.getFactory();

    assertEquals(fac.getLanguageName(), "ECMAScript");
    assertEquals(fac.getParameter(ScriptEngine.NAME), "javascript");
    assertEquals(fac.getLanguageVersion(), "ECMA - 262 Edition 5.1");
    assertEquals(fac.getEngineName(), "Oracle Nashorn");
    assertEquals(fac.getOutputStatement("context"), "print(context)");
    assertEquals(fac.getProgram("print('hello')", "print('world')"), "print('hello');print('world');");
    assertEquals(fac.getParameter(ScriptEngine.NAME), "javascript");

    boolean seenJS = false;
    for (final String ext : fac.getExtensions()) {
        if (ext.equals("js")) {
            seenJS = true;
        }
    }

    assertEquals(seenJS, true);
    final String str = fac.getMethodCallSyntax("obj", "foo", "x");
    assertEquals(str, "obj.foo(x)");

    boolean seenNashorn = false, seenJavaScript = false, seenECMAScript = false;
    for (final String name : fac.getNames()) {
        switch (name) {
            case "nashorn": seenNashorn = true; break;
            case "javascript": seenJavaScript = true; break;
            case "ECMAScript": seenECMAScript = true; break;
        default:
            break;
        }
    }

    assertTrue(seenNashorn);
    assertTrue(seenJavaScript);
    assertTrue(seenECMAScript);

    boolean seenAppJS = false, seenAppECMA = false, seenTextJS = false, seenTextECMA = false;
    for (final String mime : fac.getMimeTypes()) {
        switch (mime) {
            case "application/javascript": seenAppJS = true; break;
            case "application/ecmascript": seenAppECMA = true; break;
            case "text/javascript": seenTextJS = true; break;
            case "text/ecmascript": seenTextECMA = true; break;
        default:
            break;
        }
    }

    assertTrue(seenAppJS);
    assertTrue(seenAppECMA);
    assertTrue(seenTextJS);
    assertTrue(seenTextECMA);
}
 
Example 6
Source File: ScriptEngineTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void factoryTests() {
    final ScriptEngineManager m = new ScriptEngineManager();
    final ScriptEngine e = m.getEngineByName("nashorn");
    assertNotNull(e);

    final ScriptEngineFactory fac = e.getFactory();

    assertEquals(fac.getLanguageName(), "ECMAScript");
    assertEquals(fac.getParameter(ScriptEngine.NAME), "javascript");
    assertEquals(fac.getLanguageVersion(), "ECMA - 262 Edition 5.1");
    assertEquals(fac.getEngineName(), "Oracle Nashorn");
    assertEquals(fac.getOutputStatement("context"), "print(context)");
    assertEquals(fac.getProgram("print('hello')", "print('world')"), "print('hello');print('world');");
    assertEquals(fac.getParameter(ScriptEngine.NAME), "javascript");

    boolean seenJS = false;
    for (final String ext : fac.getExtensions()) {
        if (ext.equals("js")) {
            seenJS = true;
        }
    }

    assertEquals(seenJS, true);
    final String str = fac.getMethodCallSyntax("obj", "foo", "x");
    assertEquals(str, "obj.foo(x)");

    boolean seenNashorn = false, seenJavaScript = false, seenECMAScript = false;
    for (final String name : fac.getNames()) {
        switch (name) {
            case "nashorn": seenNashorn = true; break;
            case "javascript": seenJavaScript = true; break;
            case "ECMAScript": seenECMAScript = true; break;
        default:
            break;
        }
    }

    assertTrue(seenNashorn);
    assertTrue(seenJavaScript);
    assertTrue(seenECMAScript);

    boolean seenAppJS = false, seenAppECMA = false, seenTextJS = false, seenTextECMA = false;
    for (final String mime : fac.getMimeTypes()) {
        switch (mime) {
            case "application/javascript": seenAppJS = true; break;
            case "application/ecmascript": seenAppECMA = true; break;
            case "text/javascript": seenTextJS = true; break;
            case "text/ecmascript": seenTextECMA = true; break;
        default:
            break;
        }
    }

    assertTrue(seenAppJS);
    assertTrue(seenAppECMA);
    assertTrue(seenTextJS);
    assertTrue(seenTextECMA);
}
 
Example 7
Source File: ScriptEngineTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void factoryTests() {
    final ScriptEngineManager m = new ScriptEngineManager();
    final ScriptEngine e = m.getEngineByName("nashorn");
    assertNotNull(e);

    final ScriptEngineFactory fac = e.getFactory();

    assertEquals(fac.getLanguageName(), "ECMAScript");
    assertEquals(fac.getParameter(ScriptEngine.NAME), "javascript");
    assertEquals(fac.getLanguageVersion(), "ECMA - 262 Edition 5.1");
    assertEquals(fac.getEngineName(), "Oracle Nashorn");
    assertEquals(fac.getOutputStatement("context"), "print(context)");
    assertEquals(fac.getProgram("print('hello')", "print('world')"), "print('hello');print('world');");
    assertEquals(fac.getParameter(ScriptEngine.NAME), "javascript");

    boolean seenJS = false;
    for (final String ext : fac.getExtensions()) {
        if (ext.equals("js")) {
            seenJS = true;
        }
    }

    assertEquals(seenJS, true);
    final String str = fac.getMethodCallSyntax("obj", "foo", "x");
    assertEquals(str, "obj.foo(x)");

    boolean seenNashorn = false, seenJavaScript = false, seenECMAScript = false;
    for (final String name : fac.getNames()) {
        switch (name) {
            case "nashorn": seenNashorn = true; break;
            case "javascript": seenJavaScript = true; break;
            case "ECMAScript": seenECMAScript = true; break;
        default:
            break;
        }
    }

    assertTrue(seenNashorn);
    assertTrue(seenJavaScript);
    assertTrue(seenECMAScript);

    boolean seenAppJS = false, seenAppECMA = false, seenTextJS = false, seenTextECMA = false;
    for (final String mime : fac.getMimeTypes()) {
        switch (mime) {
            case "application/javascript": seenAppJS = true; break;
            case "application/ecmascript": seenAppECMA = true; break;
            case "text/javascript": seenTextJS = true; break;
            case "text/ecmascript": seenTextECMA = true; break;
        default:
            break;
        }
    }

    assertTrue(seenAppJS);
    assertTrue(seenAppECMA);
    assertTrue(seenTextJS);
    assertTrue(seenTextECMA);
}
 
Example 8
Source File: ScriptEngineTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void factoryTests() {
    final ScriptEngineManager m = new ScriptEngineManager();
    final ScriptEngine e = m.getEngineByName("nashorn");
    assertNotNull(e);

    final ScriptEngineFactory fac = e.getFactory();

    assertEquals(fac.getLanguageName(), "ECMAScript");
    assertEquals(fac.getParameter(ScriptEngine.NAME), "javascript");
    assertEquals(fac.getLanguageVersion(), "ECMA - 262 Edition 5.1");
    assertEquals(fac.getEngineName(), "Oracle Nashorn");
    assertEquals(fac.getOutputStatement("context"), "print(context)");
    assertEquals(fac.getProgram("print('hello')", "print('world')"), "print('hello');print('world');");
    assertEquals(fac.getParameter(ScriptEngine.NAME), "javascript");

    boolean seenJS = false;
    for (final String ext : fac.getExtensions()) {
        if (ext.equals("js")) {
            seenJS = true;
        }
    }

    assertEquals(seenJS, true);
    final String str = fac.getMethodCallSyntax("obj", "foo", "x");
    assertEquals(str, "obj.foo(x)");

    boolean seenNashorn = false, seenJavaScript = false, seenECMAScript = false;
    for (final String name : fac.getNames()) {
        switch (name) {
            case "nashorn": seenNashorn = true; break;
            case "javascript": seenJavaScript = true; break;
            case "ECMAScript": seenECMAScript = true; break;
        default:
            break;
        }
    }

    assertTrue(seenNashorn);
    assertTrue(seenJavaScript);
    assertTrue(seenECMAScript);

    boolean seenAppJS = false, seenAppECMA = false, seenTextJS = false, seenTextECMA = false;
    for (final String mime : fac.getMimeTypes()) {
        switch (mime) {
            case "application/javascript": seenAppJS = true; break;
            case "application/ecmascript": seenAppECMA = true; break;
            case "text/javascript": seenTextJS = true; break;
            case "text/ecmascript": seenTextECMA = true; break;
        default:
            break;
        }
    }

    assertTrue(seenAppJS);
    assertTrue(seenAppECMA);
    assertTrue(seenTextJS);
    assertTrue(seenTextECMA);
}
 
Example 9
Source File: ScriptEngineTest.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void factoryTests() {
    final ScriptEngineManager m = new ScriptEngineManager();
    final ScriptEngine e = m.getEngineByName("nashorn");
    assertNotNull(e);

    final ScriptEngineFactory fac = e.getFactory();

    assertEquals(fac.getLanguageName(), "ECMAScript");
    assertEquals(fac.getParameter(ScriptEngine.NAME), "javascript");
    assertEquals(fac.getLanguageVersion(), "ECMA - 262 Edition 5.1");
    assertEquals(fac.getEngineName(), "Oracle Nashorn");
    assertEquals(fac.getOutputStatement("context"), "print(context)");
    assertEquals(fac.getProgram("print('hello')", "print('world')"), "print('hello');print('world');");
    assertEquals(fac.getParameter(ScriptEngine.NAME), "javascript");

    boolean seenJS = false;
    for (final String ext : fac.getExtensions()) {
        if (ext.equals("js")) {
            seenJS = true;
        }
    }

    assertEquals(seenJS, true);
    final String str = fac.getMethodCallSyntax("obj", "foo", "x");
    assertEquals(str, "obj.foo(x)");

    boolean seenNashorn = false, seenJavaScript = false, seenECMAScript = false;
    for (final String name : fac.getNames()) {
        switch (name) {
            case "nashorn": seenNashorn = true; break;
            case "javascript": seenJavaScript = true; break;
            case "ECMAScript": seenECMAScript = true; break;
        default:
            break;
        }
    }

    assertTrue(seenNashorn);
    assertTrue(seenJavaScript);
    assertTrue(seenECMAScript);

    boolean seenAppJS = false, seenAppECMA = false, seenTextJS = false, seenTextECMA = false;
    for (final String mime : fac.getMimeTypes()) {
        switch (mime) {
            case "application/javascript": seenAppJS = true; break;
            case "application/ecmascript": seenAppECMA = true; break;
            case "text/javascript": seenTextJS = true; break;
            case "text/ecmascript": seenTextECMA = true; break;
        default:
            break;
        }
    }

    assertTrue(seenAppJS);
    assertTrue(seenAppECMA);
    assertTrue(seenTextJS);
    assertTrue(seenTextECMA);
}
 
Example 10
Source File: ScriptEngineTest.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void factoryTests() {
    final ScriptEngineManager m = new ScriptEngineManager();
    final ScriptEngine e = m.getEngineByName("nashorn");
    assertNotNull(e);

    final ScriptEngineFactory fac = e.getFactory();

    assertEquals(fac.getLanguageName(), "ECMAScript");
    assertEquals(fac.getParameter(ScriptEngine.NAME), "javascript");
    assertEquals(fac.getLanguageVersion(), "ECMA - 262 Edition 5.1");
    assertEquals(fac.getEngineName(), "Oracle Nashorn");
    assertEquals(fac.getOutputStatement("context"), "print(context)");
    assertEquals(fac.getProgram("print('hello')", "print('world')"), "print('hello');print('world');");
    assertEquals(fac.getParameter(ScriptEngine.NAME), "javascript");

    boolean seenJS = false;
    for (String ext : fac.getExtensions()) {
        if (ext.equals("js")) {
            seenJS = true;
        }
    }

    assertEquals(seenJS, true);
    String str = fac.getMethodCallSyntax("obj", "foo", "x");
    assertEquals(str, "obj.foo(x)");

    boolean seenNashorn = false, seenJavaScript = false, seenECMAScript = false;
    for (String name : fac.getNames()) {
        switch (name) {
            case "nashorn": seenNashorn = true; break;
            case "javascript": seenJavaScript = true; break;
            case "ECMAScript": seenECMAScript = true; break;
        }
    }

    assertTrue(seenNashorn);
    assertTrue(seenJavaScript);
    assertTrue(seenECMAScript);

    boolean seenAppJS = false, seenAppECMA = false, seenTextJS = false, seenTextECMA = false;
    for (String mime : fac.getMimeTypes()) {
        switch (mime) {
            case "application/javascript": seenAppJS = true; break;
            case "application/ecmascript": seenAppECMA = true; break;
            case "text/javascript": seenTextJS = true; break;
            case "text/ecmascript": seenTextECMA = true; break;
        }
    }

    assertTrue(seenAppJS);
    assertTrue(seenAppECMA);
    assertTrue(seenTextJS);
    assertTrue(seenTextECMA);
}
 
Example 11
Source File: ScriptEngineTest.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void factoryTests() {
    final ScriptEngineManager m = new ScriptEngineManager();
    final ScriptEngine e = m.getEngineByName("nashorn");
    assertNotNull(e);

    final ScriptEngineFactory fac = e.getFactory();

    assertEquals(fac.getLanguageName(), "ECMAScript");
    assertEquals(fac.getParameter(ScriptEngine.NAME), "javascript");
    assertEquals(fac.getLanguageVersion(), "ECMA - 262 Edition 5.1");
    assertEquals(fac.getEngineName(), "Oracle Nashorn");
    assertEquals(fac.getOutputStatement("context"), "print(context)");
    assertEquals(fac.getProgram("print('hello')", "print('world')"), "print('hello');print('world');");
    assertEquals(fac.getParameter(ScriptEngine.NAME), "javascript");

    boolean seenJS = false;
    for (String ext : fac.getExtensions()) {
        if (ext.equals("js")) {
            seenJS = true;
        }
    }

    assertEquals(seenJS, true);
    String str = fac.getMethodCallSyntax("obj", "foo", "x");
    assertEquals(str, "obj.foo(x)");

    boolean seenNashorn = false, seenJavaScript = false, seenECMAScript = false;
    for (String name : fac.getNames()) {
        switch (name) {
            case "nashorn": seenNashorn = true; break;
            case "javascript": seenJavaScript = true; break;
            case "ECMAScript": seenECMAScript = true; break;
        }
    }

    assertTrue(seenNashorn);
    assertTrue(seenJavaScript);
    assertTrue(seenECMAScript);

    boolean seenAppJS = false, seenAppECMA = false, seenTextJS = false, seenTextECMA = false;
    for (String mime : fac.getMimeTypes()) {
        switch (mime) {
            case "application/javascript": seenAppJS = true; break;
            case "application/ecmascript": seenAppECMA = true; break;
            case "text/javascript": seenTextJS = true; break;
            case "text/ecmascript": seenTextECMA = true; break;
        }
    }

    assertTrue(seenAppJS);
    assertTrue(seenAppECMA);
    assertTrue(seenTextJS);
    assertTrue(seenTextECMA);
}
 
Example 12
Source File: ScriptEngineTest.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void factoryTests() {
    final ScriptEngineManager m = new ScriptEngineManager();
    final ScriptEngine e = m.getEngineByName("nashorn");
    assertNotNull(e);

    final ScriptEngineFactory fac = e.getFactory();

    assertEquals(fac.getLanguageName(), "ECMAScript");
    assertEquals(fac.getParameter(ScriptEngine.NAME), "javascript");
    assertEquals(fac.getLanguageVersion(), "ECMA - 262 Edition 5.1");
    assertEquals(fac.getEngineName(), "Oracle Nashorn");
    assertEquals(fac.getOutputStatement("context"), "print(context)");
    assertEquals(fac.getProgram("print('hello')", "print('world')"), "print('hello');print('world');");
    assertEquals(fac.getParameter(ScriptEngine.NAME), "javascript");

    boolean seenJS = false;
    for (final String ext : fac.getExtensions()) {
        if (ext.equals("js")) {
            seenJS = true;
        }
    }

    assertEquals(seenJS, true);
    final String str = fac.getMethodCallSyntax("obj", "foo", "x");
    assertEquals(str, "obj.foo(x)");

    boolean seenNashorn = false, seenJavaScript = false, seenECMAScript = false;
    for (final String name : fac.getNames()) {
        switch (name) {
            case "nashorn": seenNashorn = true; break;
            case "javascript": seenJavaScript = true; break;
            case "ECMAScript": seenECMAScript = true; break;
        default:
            break;
        }
    }

    assertTrue(seenNashorn);
    assertTrue(seenJavaScript);
    assertTrue(seenECMAScript);

    boolean seenAppJS = false, seenAppECMA = false, seenTextJS = false, seenTextECMA = false;
    for (final String mime : fac.getMimeTypes()) {
        switch (mime) {
            case "application/javascript": seenAppJS = true; break;
            case "application/ecmascript": seenAppECMA = true; break;
            case "text/javascript": seenTextJS = true; break;
            case "text/ecmascript": seenTextECMA = true; break;
        default:
            break;
        }
    }

    assertTrue(seenAppJS);
    assertTrue(seenAppECMA);
    assertTrue(seenTextJS);
    assertTrue(seenTextECMA);
}