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

The following examples show how to use javax.script.ScriptEngineFactory#getEngineName() . 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: ScriptingTutorial.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public ScriptEngine listAll() {
    // BEGIN: org.netbeans.libs.graalsdk.ScriptingTutorial#listAll
    ScriptEngine found = null;
    final ScriptEngineManager manager = Scripting.createManager();
    for (ScriptEngineFactory factory : manager.getEngineFactories()) {
        final String name = factory.getEngineName();
        System.err.println("Found " + name);
        if (factory.getMimeTypes().contains("text/javascript")) {
            if (name.equals("GraalVM:js")) {
                found = factory.getScriptEngine();
            }
        }
    }
    // END: org.netbeans.libs.graalsdk.ScriptingTutorial#listAll
    return found;
}
 
Example 2
Source File: ScriptUtilities.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * getEngineFactoriesNames
 *
 * @return a map <name of the engine, alias>
 */
static public Map<String, String> getEngineFactoriesNames(){
	logger.debug("IN");
	ScriptEngineManager mgr = new ScriptEngineManager();
	List<ScriptEngineFactory> factories = mgr.getEngineFactories();

	Map<String,String> names=new HashMap<String,String>();
	for (ScriptEngineFactory factory: factories) {
		String engName1 = factory.getEngineName(); 
		String engVersion=factory.getEngineVersion();
		String engName=engName1+engVersion;
		List<String> engNames = factory.getNames();
		String alias=engName;
		if(engNames.size()>=1){
			alias=engNames.get(0);
		}
		names.put(engName, alias);
	}
	logger.debug("found "+names.keySet().size()+" engines");		
	logger.debug("OUT");
	return names;
}
 
Example 3
Source File: SpagoBIScriptManager.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
public void printInfo() {
	ScriptEngineManager mgr = new ScriptEngineManager();
	List<ScriptEngineFactory> factories = mgr.getEngineFactories();

	for (ScriptEngineFactory factory : factories) {
		logger.debug("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);
		}
		System.out.printf("\tLanguage: %s (%s)\n", langName, langVersion);
	}
}
 
Example 4
Source File: ScriptLanguageFixture.java    From hsac-fitnesse-fixtures with Apache License 2.0 6 votes vote down vote up
public Map<String, Map<String, Object>> availableEngines() {
    Map<String, Map<String, Object>> result = new LinkedHashMap<>();

    List<ScriptEngineFactory> factories = ENGINE_MANAGER.getEngineFactories();

    for (ScriptEngineFactory factory : factories) {
        Map<String, Object> f = new LinkedHashMap<>();
        String engName = factory.getEngineName();
        String engVersion = factory.getEngineVersion();
        List<String> engNames = factory.getNames();
        String langName = factory.getLanguageName();
        String langVersion = factory.getLanguageVersion();

        result.put(engName, f);
        f.put("language name", langName);
        f.put("language version", langVersion);
        f.put("aliases", engNames);
        f.put("version", engVersion);
    }
    return result;
}
 
Example 5
Source File: JavaScriptEnginesTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void fillArray(final ScriptEngineManager man, boolean allowAllAccess, List<Object[]> arr) {
    for (ScriptEngineFactory f : man.getEngineFactories()) {
        final String name = f.getEngineName();
        if (
                f.getMimeTypes().contains("text/javascript") ||
                name.contains("Nashorn")
                ) {
            final ScriptEngine eng = f.getScriptEngine();
            arr.add(new Object[] { name, "engineFactories", implName(eng), eng, allowAllAccess });
            for (String n : eng.getFactory().getNames()) {
                ScriptEngine byName = n == null ? null : man.getEngineByName(n);
                if (byName != null && eng.getClass() == byName.getClass()) {
                    arr.add(new Object[] { n, "name", implName(byName), byName, allowAllAccess });
                }
            }
            for (String t : eng.getFactory().getMimeTypes()) {
                ScriptEngine byType = t == null ? null : man.getEngineByMimeType(t);
                if (byType != null && eng.getClass() == byType.getClass()) {
                    arr.add(new Object[] { t, "type", implName(byType), byType, allowAllAccess });
                }
            }
            for (String e : eng.getFactory().getExtensions()) {
                ScriptEngine byExt = e == null ? null : man.getEngineByExtension(e);
                if (byExt != null && eng.getClass() == byExt.getClass()) {
                    arr.add(new Object[] { e, "ext", implName(byExt), byExt, allowAllAccess });
                }
            }
        }
    }
}
 
Example 6
Source File: BasicInfoSchemaTablesServiceImpl.java    From sql-layer with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Row next() {
    if (!it.hasNext())
        return null;
    ScriptEngineFactory factory = it.next();
    return new ValuesHolderRow(
            rowType,
            it.nextIndex(), // use nextIndex so that the IDs are 1-based
            factory.getEngineName(),
            factory.getEngineVersion(),
            factory.getLanguageName(),
            factory.getLanguageVersion(),
            ++rowCounter /*hidden pk*/);
}
 
Example 7
Source File: ScriptManager.java    From wandora with GNU General Public License v3.0 5 votes vote down vote up
public ScriptEngine getScriptEngine(String engineInfo){
    ScriptEngineFactory factory=engines.get(engineInfo);
    if(factory==null){
        javax.script.ScriptEngineManager manager=new javax.script.ScriptEngineManager();
        List<ScriptEngineFactory> fs=manager.getEngineFactories();
        int bestScore=0;
        for(ScriptEngineFactory f : fs){
            int s=matchEngine(engineInfo,f);
            if(s==10) {
                factory=f;
                break;
            }
            else if(s>bestScore){
                bestScore=s;
                factory=f;
            }
        }
        engines.put(engineInfo,factory);
    }
    if(factory==null) return null;
    
    ScriptEngine engine = factory.getScriptEngine();
    
    if(engine != null) {
        try {
            String engineName = factory.getEngineName();
            if(engineName != null && engineName.toLowerCase().contains("nashorn")) {
                // https://bugs.openjdk.java.net/browse/JDK-8025132
                engine.eval("load('nashorn:mozilla_compat.js');");
            }
        }
        catch(Exception e) {}
    }
    return engine;
}
 
Example 8
Source File: NbPacScriptEvaluator.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public String getEngineInfo() {
    ScriptEngineFactory factory = scriptEngine.getScriptEngine().getFactory();
    return factory.getEngineName() + " version " + factory.getEngineVersion();
}