Example usage for org.apache.commons.lang3.text StrSubstitutor replace

List of usage examples for org.apache.commons.lang3.text StrSubstitutor replace

Introduction

In this page you can find the example usage for org.apache.commons.lang3.text StrSubstitutor replace.

Prototype

public static String replace(final Object source, final Properties valueProperties) 

Source Link

Document

Replaces all the occurrences of variables in the given source object with their matching values from the properties.

Usage

From source file:com.google.mr4c.config.ConfigUtils.java

public static String applyProperties(String template, Properties props, boolean checkAll) {
    Properties trimmed = CollectionUtils.toTrimmedProperties(props);
    String result = StrSubstitutor.replace(template, trimmed);
    if (checkAll) {
        Set<String> missing = extractVariables(result);
        if (!missing.isEmpty()) {
            throw new IllegalStateException("No values found for parameters [" + missing + "]");
        }/*from   ww w  . j a  v  a2s.  c  om*/
    }
    return result;
}

From source file:com.google.mr4c.util.CustomFormat.java

/**
  * Create a CustomFormat with custom regular expressions for some variables
*///from www  . j a  v  a  2 s .  co m
public static CustomFormat createInstance(String pattern, Map<String, String> regexMap) {
    CustomFormat format = new CustomFormat();
    format.m_nameList = extractNames(pattern);
    format.m_nameSet = new HashSet<String>(format.m_nameList);
    format.m_pattern = pattern;
    Map<String, String> varMap = new HashMap<String, String>();
    for (String name : format.m_nameSet) {
        String regex = String.format("(%s)", regexMap.containsKey(name) ? regexMap.get(name) : VALUE_REGEX);
        varMap.put(name, regex);
    }
    format.m_regex = StrSubstitutor.replace(pattern, varMap);
    return format;
}

From source file:io.apiman.cli.util.BeanUtil.java

/**
 * Replace the placeholders in the given input String.
 *
 * @param original     the input String, containing placeholders in the form <code>Example ${placeholder} text.</code>
 * @param replacements the Map of placeholders and their values
 * @return the {@code original} string with {@code replacements}
 *//*w w  w .j av a  2s.c om*/
public static String resolvePlaceholders(String original, Map<String, String> replacements) {
    return StrSubstitutor.replace(original, replacements);
}

From source file:com.young.util.jni.generator.template.FileTemplate.java

public String create() {
    return StrSubstitutor.replace(mTemplate, mTemplateParams);
}

From source file:com.github.rozidan.springboot.logger.LoggerMsgFormatter.java

public String enter(ProceedingJoinPoint joinPoint, Loggable loggable) {
    Map<String, Object> values = new HashMap<>();
    values.put(METHDO_VALUE, methodName(joinPoint));
    values.put(ARGS_VALUE, methodArgs(joinPoint, loggable));
    return StrSubstitutor.replace(formats.getEnter(), values);
}

From source file:io.apiman.test.integration.runner.PolicyLoader.java

private void storeBean(String definitionId, String config, List<NewPolicyBean> policies) {
    config = StrSubstitutor.replace(config, System.getProperties());
    config = StrSubstitutor.replace(config, SuiteProperties.getProperties());
    config = StrSubstitutor.replace(config, params);

    NewPolicyBean bean = new NewPolicyBean();
    bean.setDefinitionId(definitionId);/*from w  w  w.  j a  v a  2 s  . c  om*/
    bean.setConfiguration(config);

    policies.add(bean);
}

From source file:com.github.rozidan.springboot.logger.LoggerMsgFormatter.java

public String warnBefore(ProceedingJoinPoint joinPoint, Loggable loggable, long nano) {
    Map<String, Object> values = new HashMap<>();
    values.put(METHDO_VALUE, methodName(joinPoint));
    values.put(ARGS_VALUE, methodArgs(joinPoint, loggable));
    values.put(DURATION_VALUE, durationString(nano));
    values.put(WARN_DURATION_VALUE, warnDuration(loggable));
    return StrSubstitutor.replace(formats.getWarnBefore(), values);
}

From source file:com.github.rozidan.springboot.logger.LoggerMsgFormatter.java

public String warnAfter(ProceedingJoinPoint joinPoint, Loggable loggable, Object result, long nano) {
    Map<String, Object> values = new HashMap<>();
    values.put(METHDO_VALUE, methodName(joinPoint));
    values.put(ARGS_VALUE, methodArgs(joinPoint, loggable));
    values.put(DURATION_VALUE, durationString(nano));
    values.put(WARN_DURATION_VALUE, warnDuration(loggable));
    values.put(RESULT_VALUE, methodResults(result, loggable));
    return StrSubstitutor.replace(formats.getWarnAfter(), values);
}

From source file:io.sledge.core.impl.installer.SledgePackageConfigurer.java

@Override
public Properties mergeProperties(String envFileContent, Properties propsForMerge) {
    Properties mergedProps = new Properties();
    try {//from  ww w .j  a  va  2 s  .  c o  m

        // Support internal property references for application package provided properties
        Properties origProps = new Properties();
        origProps.load(new StringReader(envFileContent));
        String configuredEnvironmentFileContent = StrSubstitutor.replace(envFileContent, origProps);

        mergedProps.load(new StringReader(configuredEnvironmentFileContent));

        // Support internal property references for overwrite properties
        StringWriter propsForMergeWriter = new StringWriter();
        propsForMerge.store(propsForMergeWriter, "");
        String propsForMergeAsString = propsForMergeWriter.getBuffer().toString();
        String configuredPropsForMerge = StrSubstitutor.replace(propsForMergeAsString, propsForMerge);
        Properties reconfiguredPropsForMerge = new Properties();
        reconfiguredPropsForMerge.load(new StringReader(configuredPropsForMerge));

        mergedProps.putAll(reconfiguredPropsForMerge);

    } catch (IOException e) {
        throw new InstallationException("Could not load environment properties.", e);
    }

    return mergedProps;
}

From source file:com.github.rozidan.springboot.logger.LoggerMsgFormatter.java

public String after(ProceedingJoinPoint joinPoint, Loggable loggable, Object result, long nano) {
    Map<String, Object> values = new HashMap<>();
    values.put(METHDO_VALUE, methodName(joinPoint));
    values.put(ARGS_VALUE, methodArgs(joinPoint, loggable));
    values.put(DURATION_VALUE, durationString(nano));
    values.put(RESULT_VALUE, methodResults(result, loggable));
    return StrSubstitutor.replace(formats.getAfter(), values);
}