Search in sources :

Example 1 with StringSubstitution

use of org.apache.oro.text.regex.StringSubstitution in project jmeter by apache.

the class ReplaceFunctionsWithStrings method transformValue.

@Override
public JMeterProperty transformValue(JMeterProperty prop) throws InvalidVariableException {
    PatternMatcher pm = JMeterUtils.getMatcher();
    PatternCompiler compiler = new Perl5Compiler();
    String input = prop.getStringValue();
    if (input == null) {
        return prop;
    }
    for (Map.Entry<String, String> entry : getVariables().entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();
        if (regexMatch) {
            try {
                Pattern pattern = compiler.compile(constructPattern(value));
                input = Util.substitute(pm, pattern, new StringSubstitution(FUNCTION_REF_PREFIX + key + FUNCTION_REF_SUFFIX), input, Util.SUBSTITUTE_ALL);
            } catch (MalformedPatternException e) {
                log.warn("Malformed pattern: {}", value);
            }
        } else {
            input = StringUtilities.substitute(input, value, FUNCTION_REF_PREFIX + key + FUNCTION_REF_SUFFIX);
        }
    }
    return new StringProperty(prop.getName(), input);
}
Also used : Perl5Compiler(org.apache.oro.text.regex.Perl5Compiler) Pattern(org.apache.oro.text.regex.Pattern) PatternCompiler(org.apache.oro.text.regex.PatternCompiler) StringProperty(org.apache.jmeter.testelement.property.StringProperty) StringSubstitution(org.apache.oro.text.regex.StringSubstitution) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException) PatternMatcher(org.apache.oro.text.regex.PatternMatcher) Map(java.util.Map)

Aggregations

Map (java.util.Map)1 StringProperty (org.apache.jmeter.testelement.property.StringProperty)1 MalformedPatternException (org.apache.oro.text.regex.MalformedPatternException)1 Pattern (org.apache.oro.text.regex.Pattern)1 PatternCompiler (org.apache.oro.text.regex.PatternCompiler)1 PatternMatcher (org.apache.oro.text.regex.PatternMatcher)1 Perl5Compiler (org.apache.oro.text.regex.Perl5Compiler)1 StringSubstitution (org.apache.oro.text.regex.StringSubstitution)1