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

lv.ctco.cukesrest.internal.templating.TemplatingEngine Maven / Gradle / Ivy

The newest version!
package lv.ctco.cukesrest.internal.templating;

import com.google.common.base.Optional;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import lv.ctco.cukesrest.CukesOptions;
import lv.ctco.cukesrest.internal.context.GlobalWorldFacade;
import lv.ctco.cukesrest.internal.context.InflateContext;
import org.rythmengine.Rythm;

import java.util.HashMap;
import java.util.Map;

@Singleton
@InflateContext
public class TemplatingEngine {

    @Inject
    GlobalWorldFacade world;

    private Boolean isBodyTemplatesEnabled() {
        return world.getBoolean(CukesOptions.REQUEST_BODY_TEMPLATES_ENABLED);
    }

    public String processBody(String body) {
        if (isBodyTemplatesEnabled()) {
            final Map rythmParams = new HashMap();
            for (String key : world.keys()) {
                Optional value = world.get(key);
                if (value.isPresent() && body.contains("@" + key)) rythmParams.put(key, value.get());
            }
            return Rythm.render(body, rythmParams);
        }
        return body;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy