Search in sources :

Example 6 with MalformedCachePatternException

use of org.apache.oro.text.MalformedCachePatternException in project jmeter by apache.

the class RenderAsRegexp method process.

private String process(String textToParse) {
    Perl5Matcher matcher = new Perl5Matcher();
    PatternMatcherInput input = new PatternMatcherInput(textToParse);
    PatternCacheLRU pcLRU = new PatternCacheLRU();
    Pattern pattern;
    try {
        pattern = pcLRU.getPattern(regexpField.getText(), Perl5Compiler.READ_ONLY_MASK);
    } catch (MalformedCachePatternException e) {
        return e.toString();
    }
    List<MatchResult> matches = new LinkedList<>();
    while (matcher.contains(input, pattern)) {
        matches.add(matcher.getMatch());
    }
    // Construct a multi-line string with all matches
    StringBuilder sb = new StringBuilder();
    final int size = matches.size();
    sb.append("Match count: ").append(size).append("\n");
    for (int j = 0; j < size; j++) {
        MatchResult mr = matches.get(j);
        final int groups = mr.groups();
        for (int i = 0; i < groups; i++) {
            sb.append("Match[").append(j + 1).append("][").append(i).append("]=").append(mr.group(i)).append("\n");
        }
    }
    return sb.toString();
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) PatternMatcherInput(org.apache.oro.text.regex.PatternMatcherInput) MalformedCachePatternException(org.apache.oro.text.MalformedCachePatternException) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) MatchResult(org.apache.oro.text.regex.MatchResult) LinkedList(java.util.LinkedList) PatternCacheLRU(org.apache.oro.text.PatternCacheLRU)

Aggregations

MalformedCachePatternException (org.apache.oro.text.MalformedCachePatternException)6 Pattern (org.apache.oro.text.regex.Pattern)6 Perl5Matcher (org.apache.oro.text.regex.Perl5Matcher)5 MatchResult (org.apache.oro.text.regex.MatchResult)4 ArrayList (java.util.ArrayList)3 PatternMatcherInput (org.apache.oro.text.regex.PatternMatcherInput)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)2 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 LinkedList (java.util.LinkedList)1 Callable (java.util.concurrent.Callable)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 CompoundVariable (org.apache.jmeter.engine.util.CompoundVariable)1 Cookie (org.apache.jmeter.protocol.http.control.Cookie)1