ScriptEnginePersonAttributeDao extends AbstractDefaultAttributePersonAttributeDao { public static String getScriptEngineName(String filename) { String extension = FilenameUtils.getExtension(filename); if (StringUtils.isBlank(extension)) { logger.warn("Can't determine engine name based on filename without extension {}", filename); return null; } ScriptEngineManager manager = new ScriptEngineManager(); List<ScriptEngineFactory> engines = manager.getEngineFactories(); for (ScriptEngineFactory engineFactory : engines) { List<String> extensions = engineFactory.getExtensions(); for (String supportedExt : extensions) { if (extension.equals(supportedExt)) { return engineFactory.getNames().get(0); } } } logger.warn("Can't determine engine name based on filename and available script engines {}", filename); return null; } ScriptEnginePersonAttributeDao();  ScriptEnginePersonAttributeDao(String scriptFile);  ScriptEnginePersonAttributeDao(String scriptFile, String engineName);  ScriptEnginePersonAttributeDao(String scriptFile, String engineName, IUsernameAttributeProvider usernameAttributeProvider); String getScriptFile(); void setScriptFile(final String scriptFile); String getEngineName(); void setEngineName(final String engineName); boolean isCaseInsensitiveUsername(); void setCaseInsensitiveUsername(final boolean caseInsensitiveUsername); @Override IPersonAttributes getPerson(final String uid, final IPersonAttributeDaoFilter filter); @Override Set<IPersonAttributes> getPeopleWithMultivaluedAttributes(final Map<String, List<Object>> query,
                                                                     final IPersonAttributeDaoFilter filter); @Override @JsonIgnore Set<String> getPossibleUserAttributeNames(final IPersonAttributeDaoFilter filter); @Override @JsonIgnore Set<String> getAvailableQueryAttributes(final IPersonAttributeDaoFilter filter); static String getScriptEngineName(String filename);  }
@Test public void testGetScriptEngineName() { assertNull(ScriptEnginePersonAttributeDao.getScriptEngineName("not a filename = a script")); final String scriptEngineName = ScriptEnginePersonAttributeDao.getScriptEngineName("SampleScriptedJavascriptPersonAttributeDao.js"); assertTrue(scriptEngineName.equalsIgnoreCase("nashorn") || scriptEngineName.equalsIgnoreCase("Graal.js")); final String engineName2 = ScriptEnginePersonAttributeDao.getScriptEngineName("src/test/resources/SampleScriptedJavascriptPersonAttributeDao.js"); assertTrue(engineName2.equalsIgnoreCase("nashorn") || scriptEngineName.equalsIgnoreCase("Graal.js")); assertEquals("groovy", ScriptEnginePersonAttributeDao.getScriptEngineName("src/test/resources/SampleScriptedGroovyPersonAttributeDao.groovy")); assertNull(ScriptEnginePersonAttributeDao.getScriptEngineName("test.py") ); }