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

lv.ctco.cukesrest.internal.context.ContextInflater Maven / Gradle / Ivy

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

import com.google.common.base.Optional;
import com.google.inject.*;
import lv.ctco.cukesrest.*;

import java.util.*;

public class ContextInflater extends BaseContextHandler {

    @Inject
    GlobalWorldFacade world;

    public String inflate(String input) {
        Set groups = new HashSet(extractGroups(input));
        boolean inflatingEnabled = world.getBoolean(CukesOptions.CONTEXT_INFLATING_ENABLED, true);
        if (inflatingEnabled) {
            return inflateGroups(input, groups);
        }
        return inflateGroupsWithPlaceholders(input, groups);
    }

    String inflateGroups(String input, Set groups) {
        String result = input;
        for (String key : groups) {
            Optional $value = world.get(key);
            if ($value.isPresent()) {
                result = result.replaceAll("\\{\\(" + key + "\\)\\}", $value.get());
            }
        }
        return result;
    }

    String inflateGroupsWithPlaceholders(String input, Set groups) {
        String result = input;
        for (String key : groups) {
            result = result.replaceAll("\\{\\(" + key + "\\)\\}", "{" + key + "}");
        }
        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy