All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.arangodb.shaded.vertx.ext.web.common.template.TemplateEngine Maven / Gradle / Ivy

There is a newer version: 7.9.0
Show newest version
/*
 * Copyright 2014 Red Hat, Inc.
 *
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  and Apache License v2.0 which accompanies this distribution.
 *
 *  The Eclipse Public License is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *
 *  The Apache License v2.0 is available at
 *  http://www.opensource.org/licenses/apache2.0.php
 *
 *  You may elect to redistribute this code under either of these licenses.
 */

package com.arangodb.shaded.vertx.ext.web.common.template;

import com.arangodb.shaded.vertx.codegen.annotations.GenIgnore;
import com.arangodb.shaded.vertx.codegen.annotations.VertxGen;
import com.arangodb.shaded.vertx.core.AsyncResult;
import com.arangodb.shaded.vertx.core.Future;
import com.arangodb.shaded.vertx.core.Handler;
import com.arangodb.shaded.vertx.core.Promise;
import com.arangodb.shaded.vertx.core.buffer.Buffer;
import com.arangodb.shaded.vertx.core.json.JsonObject;

import java.util.Map;

/**
 * A template template uses a specific template and the data in a routing context to render a resource into a buffer.
 * 

* Concrete implementations exist for several well-known template engines. * * @author Tim Fox */ @VertxGen public interface TemplateEngine { /** * Render the template. Template engines that support partials/fragments should extract the template base path from * the template filename up to the last file separator. * * Some engines support localization, for these engines, there is a predefined key "lang" to specify the language to * be used in the localization, the format should follow the standard locale formats e.g.: "en-gb", "pt-br", "en". * * @param context the routing context * @param templateFileName the template file name to use * @param handler the handler that will be called with a result containing the buffer or a failure. */ default void render(JsonObject context, String templateFileName, Handler> handler) { render(context.getMap(), templateFileName, handler); } /** * @see TemplateEngine#render(JsonObject, String, Handler) * @param context the routing context * @param templateFileName the template file name to use */ default Future render(JsonObject context, String templateFileName) { Promise promise = Promise.promise(); render(context, templateFileName, promise); return promise.future(); } /** * Render the template. Template engines that support partials/fragments should extract the template base path from * the template filename up to the last file separator. * * Some engines support localization, for these engines, there is a predefined key "lang" to specify the language to * be used in the localization, the format should follow the standard locale formats e.g.: "en-gb", "pt-br", "en". * * @param context the routing context * @param templateFileName the template file name to use * @param handler the handler that will be called with a result containing the buffer or a failure. */ @GenIgnore(GenIgnore.PERMITTED_TYPE) void render(Map context, String templateFileName, Handler> handler); /** * @see TemplateEngine#render(Map, String, Handler) * @param context the routing context * @param templateFileName the template file name to use */ @GenIgnore(GenIgnore.PERMITTED_TYPE) default Future render(Map context, String templateFileName) { Promise promise = Promise.promise(); render(context, templateFileName, promise); return promise.future(); } /** * Returns the underlying engine, so further configurations or customizations may be applied. * @param the engine object type. * @return the engine instance. * @throws ClassCastException when the expected type does not match the internal type. */ @GenIgnore(GenIgnore.PERMITTED_TYPE) default T unwrap() throws ClassCastException { return null; } /** * Clears any internal caches used by this engine. For most engines this means clearing the * vert.x cache, implementations that do not use vert.x as a cache should clear their own cache. */ void clearCache(); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy