static { ServiceLoader<Engine> ldr = ServiceLoader.load(Engine.class); String tmpDefaultEngineExtension = null; for (Engine engine : ldr) { ENGINE.put(engine.getExtension(), engine); tmpDefaultEngineExtension = engine.getExtension(); } if (ENGINE.size() == 1) { DEFAULT_ENGINE = tmpDefaultEngineExtension; } else { DEFAULT_ENGINE = null; } }
@Override public void render(@NotNull final String template) { int sep = template.lastIndexOf('.'); if (sep != -1) { String extension = template.substring(sep); final Engine renderEngine = ENGINE.get(extension); if (renderEngine == null) { ctx.fail("No engine registered for extension: " + extension); } else { renderEngine.render(template, ctx); } } else { // when no extension is provided but only 1 engine is available assume that one if (DEFAULT_ENGINE != null) { final Engine renderEngine = ENGINE.get(DEFAULT_ENGINE); renderEngine.render(template, ctx); } else { ctx.fail("Cannot determine the extension of the template"); } } }