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

io.vertx.rxjava.ext.web.templ.TemplateEngine Maven / Gradle / Ivy

There is a newer version: 4.5.10
Show newest version
/*
 * Copyright 2014 Red Hat, Inc.
 *
 * Red Hat licenses this file to you under the Apache License, version 2.0
 * (the "License"); you may not use this file except in compliance with the
 * License.  You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package io.vertx.rxjava.ext.web.templ;

import java.util.Map;
import io.vertx.lang.rxjava.InternalHelper;
import rx.Observable;
import io.vertx.rxjava.core.buffer.Buffer;
import io.vertx.rxjava.ext.web.RoutingContext;
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;

/**
 * A template engine 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. * *

* NOTE: This class has been automatically generated from the {@link io.vertx.ext.web.templ.TemplateEngine original} non RX-ified interface using Vert.x codegen. */ public class TemplateEngine { final io.vertx.ext.web.templ.TemplateEngine delegate; public TemplateEngine(io.vertx.ext.web.templ.TemplateEngine delegate) { this.delegate = delegate; } public Object getDelegate() { return delegate; } /** * Render * @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. */ public void render(RoutingContext context, String templateFileName, Handler> handler) { this.delegate.render((io.vertx.ext.web.RoutingContext) context.getDelegate(), templateFileName, new Handler>() { public void handle(AsyncResult event) { AsyncResult f; if (event.succeeded()) { f = InternalHelper.result(new Buffer(event.result())); } else { f = InternalHelper.failure(event.cause()); } handler.handle(f); } }); } /** * Render * @param context the routing context * @param templateFileName the template file name to use * @return */ public Observable renderObservable(RoutingContext context, String templateFileName) { io.vertx.rx.java.ObservableFuture handler = io.vertx.rx.java.RxHelper.observableFuture(); render(context, templateFileName, handler.toHandler()); return handler; } public static TemplateEngine newInstance(io.vertx.ext.web.templ.TemplateEngine arg) { return arg != null ? new TemplateEngine(arg) : null; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy