Example usage for javax.script ScriptEngineFactory getLanguageName

List of usage examples for javax.script ScriptEngineFactory getLanguageName

Introduction

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

Prototype

public String getLanguageName();

Source Link

Document

Returns the name of the scripting language supported by this ScriptEngine.

Usage

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;// w  w  w .j a  v  a2  s. c om
    }

    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:ca.hedlund.jiss.preprocessor.InfoPreprocessor.java

@Override
public boolean preprocessCommand(JissModel jissModel, String orig, StringBuffer cmd) {
    final String c = cmd.toString();
    if (c.equals(INFO_CMD)) {
        // clear string
        cmd.setLength(0);//  w  ww  .  j  a v  a2 s. c  o m

        final ScriptEngine se = jissModel.getScriptEngine();
        final ScriptEngineFactory seFactory = se.getFactory();

        final boolean incnl = !seFactory.getOutputStatement("").startsWith("println");

        final String infoCmd = seFactory.getOutputStatement(INFO_TXT + (incnl ? "\\n" : ""));
        final String langCmd = seFactory.getOutputStatement("Language:" + seFactory.getLanguageName() + " "
                + seFactory.getLanguageVersion() + (incnl ? "\\n" : ""));
        final String engineCmd = seFactory.getOutputStatement("Engine:" + seFactory.getEngineName() + " "
                + seFactory.getEngineVersion() + (incnl ? "\\n" : ""));
        final String program = seFactory.getProgram(infoCmd, langCmd, engineCmd);
        cmd.append(StringEscapeUtils.unescapeJava(program));
    }
    // we want the scripting engine to handle the replaced command
    return false;
}

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

From source file:com.galeoconsulting.leonardinius.api.impl.ScriptServiceImpl.java

@Override
public void defaultRegistration(ScriptEngineFactory engineFactory) {
    for (String extension : engineFactory.getExtensions()) {
        registerEngineExtension(extension, engineFactory);
    }//from w w w.  j  a va2 s.c  om

    for (String mime : engineFactory.getMimeTypes()) {
        registerEngineMime(mime, engineFactory);
    }

    registerEngineLanguage(engineFactory.getLanguageName(), engineFactory);
    registerEngineLanguage((String) engineFactory.getParameter(ScriptEngine.NAME), engineFactory);

    // do not rely on the other methods
    registeredEngines.put(engineFactory, DUMMY);
}

From source file:org.apache.sling.scripting.console.internal.ScriptConsolePlugin.java

private String getScriptConfig0() throws JSONException {
    StringWriter sw = new StringWriter();
    JSONWriter jw = new JSONWriter(sw);
    jw.setTidy(true);/*from w ww  .j a  v  a  2s .c o m*/
    jw.array();

    for (ScriptEngineFactory sef : scriptEngineManager.getEngineFactories()) {
        jw.object();
        if (sef.getExtensions().isEmpty()) {
            continue;
        }
        jw.key("langName").value(sef.getLanguageName());
        jw.key("langCode").value(sef.getExtensions().get(0));

        //Language mode as per CodeMirror names
        String mode = determineMode(sef.getExtensions());
        if (mode != null) {
            jw.key("mode").value(mode);
        }

        jw.endObject();
    }

    jw.endArray();
    return sw.toString();
}

From source file:org.apache.felix.webconsole.plugins.scriptconsole.internal.ScriptConsolePlugin.java

private String getScriptConfig0() throws JSONException {
    StringWriter sw = new StringWriter();
    JSONWriter jw = new JSONWriter(sw);
    jw.array();/* w ww  . j  a  va2  s .c om*/

    for (ScriptEngineFactory sef : scriptEngineManager.getEngineFactories()) {
        jw.object();
        if (sef.getExtensions().isEmpty()) {
            continue;
        }
        jw.key("langName").value(sef.getLanguageName());
        jw.key("langCode").value(sef.getExtensions().get(0));

        //Language mode as per CodeMirror names
        String mode = determineMode(sef.getExtensions());
        if (mode != null) {
            jw.key("mode").value(mode);
        }

        jw.endObject();
    }

    jw.endArray();
    return sw.toString();
}

From source file:org.apache.felix.webconsole.plugins.scriptconsole.internal.ScriptEngineManager.java

private Collection<?> registerFactory(final EngineManagerState mgr, final ScriptEngineFactory factory,
        final Map<Object, Object> props) {
    log.log(LogService.LOG_INFO,//from w ww . j av a2  s . c  o  m
            String.format("Adding ScriptEngine %s, %s for language %s, %s", factory.getEngineName(),
                    factory.getEngineVersion(), factory.getLanguageName(), factory.getLanguageVersion()));

    mgr.factories.add(factory);
    mgr.factoryProperties.put(factory, props);
    for (Object ext : factory.getExtensions()) {
        mgr.extensionAssociations.put((String) ext, factory);
    }
    return factory.getExtensions();
}

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 ww .ja va 2s  .  c om*/
        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 {/*from   w ww .  j  a  va 2s  .  c  om*/
        _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);
        }
    }
}

From source file:com.l2jfree.gameserver.scripting.L2ScriptEngineManager.java

private L2ScriptEngineManager() {
    ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
    List<ScriptEngineFactory> factories = scriptEngineManager.getEngineFactories();
    if (USE_COMPILED_CACHE) {
        _cache = loadCompiledScriptCache();
    } else {//from   w  w  w.j  a  v a 2s  . 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);
        }
    }

    preConfigure();
}