code: 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 first short name
                      return engineFactory.getNames().get(0);
                  }
              }
          }
          logger.warn("Can't determine engine name based on filename and available script engines {}",filename);
          return null;
      }
docs: This method is static is available as utility for users that are passing the contents of a script
  and want to set the engineName property based on a filename.
  
  @param filename the filename
  @return script engine name