public Object findTemplateSource(String name) throws IOException { FreeMarkerTemplateLoader freeMarkerTemplateLoader = _freeMarkerTemplateLoadersMap.get(name); if (freeMarkerTemplateLoader != null) { Object templateSource = freeMarkerTemplateLoader.findTemplateSource(name); if (templateSource != null) { return new LiferayTemplateSource(freeMarkerTemplateLoader, templateSource); } } for (int i = 0; i < _freeMarkerTemplateLoaders.length; i++) { freeMarkerTemplateLoader = _freeMarkerTemplateLoaders[i]; Object templateSource = freeMarkerTemplateLoader.findTemplateSource(name); if (templateSource != null) { _freeMarkerTemplateLoadersMap.put(name, freeMarkerTemplateLoader); return new LiferayTemplateSource(freeMarkerTemplateLoader, templateSource); } } return null; }
@Override public void render( RoutingContext context, String templateFileName, Handler<AsyncResult<Buffer>> handler) { try { Template template = cache.get(templateFileName); if (template == null) { // real compile synchronized (this) { loader.setVertx(context.vertx()); // Compile template = config.getTemplate(adjustLocation(templateFileName)); } cache.put(templateFileName, template); } Map<String, RoutingContext> variables = new HashMap<>(1); variables.put("context", context); try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { template.process(variables, new OutputStreamWriter(baos)); handler.handle(Future.succeededFuture(Buffer.buffer(baos.toByteArray()))); } } catch (Exception ex) { handler.handle(Future.failedFuture(ex)); } }