Search in sources :

Example 16 with MatchResult

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

the class TestHTTPSamplersAgainstHttpMirrorServer method getBoundaryStringFromContentType.

private String getBoundaryStringFromContentType(String requestHeaders) {
    Perl5Matcher localMatcher = JMeterUtils.getMatcher();
    String regularExpression = "^" + HTTPConstants.HEADER_CONTENT_TYPE + ": multipart/form-data; boundary=(.+)$";
    Pattern pattern = JMeterUtils.getPattern(regularExpression, Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.MULTILINE_MASK);
    if (localMatcher.contains(requestHeaders, pattern)) {
        MatchResult match = localMatcher.getMatch();
        String matchString = match.group(1);
        // Header may contain ;charset= , regexp extracts it so computed boundary is wrong
        int indexOf = matchString.indexOf(';');
        if (indexOf >= 0) {
            return matchString.substring(0, indexOf);
        } else {
            return matchString;
        }
    } else {
        return null;
    }
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) MatchResult(org.apache.oro.text.regex.MatchResult)

Example 17 with MatchResult

use of org.apache.oro.text.regex.MatchResult in project intellij-plugins by JetBrains.

the class GherkinPsiUtil method buildParameterRanges.

@Nullable
public static List<TextRange> buildParameterRanges(@NotNull GherkinStep step, @NotNull AbstractStepDefinition definition, final int shiftOffset) {
    final List<TextRange> parameterRanges = new ArrayList<>();
    final Pattern pattern = definition.getPattern();
    if (pattern == null)
        return null;
    final Perl5Matcher matcher = new Perl5Matcher();
    if (matcher.contains(step.getStepName(), pattern)) {
        final MatchResult match = matcher.getMatch();
        final int groupCount = match.groups();
        for (int i = 1; i < groupCount; i++) {
            final int start = match.beginOffset(i);
            final int end = match.endOffset(i);
            if (start >= 0 && end >= 0) {
                parameterRanges.add(new TextRange(start, end).shiftRight(shiftOffset));
            }
        }
    }
    int k = step.getText().indexOf(step.getStepName());
    k += step.getStepName().length();
    if (k < step.getText().length() - 1) {
        String text = step.getText().substring(k + 1);
        boolean inParam = false;
        int paramStart = 0;
        int i = 0;
        while (i < text.length()) {
            if (text.charAt(i) == '<') {
                paramStart = i;
                inParam = true;
            }
            if (text.charAt(i) == '>' && inParam) {
                parameterRanges.add(new TextRange(paramStart, i + 1).shiftRight(shiftOffset + step.getStepName().length() + 1));
                inParam = false;
            }
            i++;
        }
    }
    return parameterRanges;
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) ArrayList(java.util.ArrayList) TextRange(com.intellij.openapi.util.TextRange) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) MatchResult(org.apache.oro.text.regex.MatchResult) Nullable(org.jetbrains.annotations.Nullable)

Example 18 with MatchResult

use of org.apache.oro.text.regex.MatchResult in project tdi-studio-se by Talend.

the class MapExpressionParser method parseInTableEntryLocations.

public List<Map<String, String>> parseInTableEntryLocations(String expression) {
    List<Map<String, String>> result = new ArrayList<Map<String, String>>();
    if (expression != null) {
        matcher.setMultiline(true);
        if (patternMatcherInput == null) {
            patternMatcherInput = new PatternMatcherInput(expression);
        } else {
            patternMatcherInput.setInput(expression);
        }
        recompilePatternIfNecessary(locationPattern);
        while (matcher.contains(patternMatcherInput, pattern)) {
            MatchResult matchResult = matcher.getMatch();
            Map<String, String> map = new HashMap<String, String>();
            if (matchResult.group(3) != null && !"".equals(matchResult.group(3))) {
                map.put(matchResult.group(3), matchResult.group(1) + "." + matchResult.group(2));
            } else {
                map.put(matchResult.group(2), matchResult.group(1));
            }
            result.add(map);
        }
    }
    // .toArray(new TableEntryLocation[0]);
    return result;
}
Also used : PatternMatcherInput(org.apache.oro.text.regex.PatternMatcherInput) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) MatchResult(org.apache.oro.text.regex.MatchResult)

Example 19 with MatchResult

use of org.apache.oro.text.regex.MatchResult in project tdi-studio-se by Talend.

the class DataMapExpressionParser method parseTableEntryLocations.

public TableEntryLocation[] parseTableEntryLocations(String expression) {
    resultList.clear();
    if (expression != null) {
        matcher.setMultiline(true);
        if (patternMatcherInput == null) {
            patternMatcherInput = new PatternMatcherInput(expression);
        } else {
            patternMatcherInput.setInput(expression);
        }
        recompilePatternIfNecessary(EXPRESSION_PATTERN);
        while (matcher.contains(patternMatcherInput, pattern)) {
            MatchResult matchResult = matcher.getMatch();
            TableEntryLocation location = null;
            if (matchResult.group(1) != null) {
                // context.schema.context.table.comlumn
                location = new TableEntryLocation(matchResult.group(2) + DOT_STR + matchResult.group(3) + DOT_STR + matchResult.group(4) + DOT_STR + matchResult.group(5), matchResult.group(6));
            } else if (matchResult.group(7) != null) {
                // context.schema.table.comlumn | schema.context.table.comlumn
                location = new TableEntryLocation(matchResult.group(8) + DOT_STR + matchResult.group(9) + DOT_STR + matchResult.group(10), matchResult.group(11));
            } else if (matchResult.group(12) != null) {
                // schema.table.column
                location = new TableEntryLocation(matchResult.group(13) + DOT_STR + matchResult.group(14), matchResult.group(15));
            } else if (matchResult.group(16) != null) {
                // table.column
                location = new TableEntryLocation(matchResult.group(17), matchResult.group(18));
            }
            if (location != null) {
                resultList.add(location);
            }
        }
    }
    return resultList.toArray(new TableEntryLocation[resultList.size()]);
}
Also used : PatternMatcherInput(org.apache.oro.text.regex.PatternMatcherInput) TableEntryLocation(org.talend.designer.dbmap.model.tableentry.TableEntryLocation) MatchResult(org.apache.oro.text.regex.MatchResult)

Example 20 with MatchResult

use of org.apache.oro.text.regex.MatchResult in project tdi-studio-se by Talend.

the class XmlMapExpressionManager method getMatchedExpression.

public List<String> getMatchedExpression(String expression) {
    List<String> matched = new ArrayList<String>();
    if (expression == null) {
        return matched;
    }
    recompilePatternIfNecessary(EXPRESSION_PATTERN);
    patternMatcherInput = new PatternMatcherInput(expression);
    while (matcher.contains(patternMatcherInput, pattern)) {
        MatchResult matchResult = matcher.getMatch();
        if (matchResult.group(0) != null) {
            matched.add(matchResult.group(0).trim());
        }
    }
    return matched;
}
Also used : PatternMatcherInput(org.apache.oro.text.regex.PatternMatcherInput) ArrayList(java.util.ArrayList) MatchResult(org.apache.oro.text.regex.MatchResult)

Aggregations

MatchResult (org.apache.oro.text.regex.MatchResult)25 PatternMatcherInput (org.apache.oro.text.regex.PatternMatcherInput)16 Perl5Matcher (org.apache.oro.text.regex.Perl5Matcher)15 Pattern (org.apache.oro.text.regex.Pattern)14 ArrayList (java.util.ArrayList)10 MalformedCachePatternException (org.apache.oro.text.MalformedCachePatternException)4 Perl5Compiler (org.apache.oro.text.regex.Perl5Compiler)4 MalformedURLException (java.net.MalformedURLException)3 HashMap (java.util.HashMap)3 SampleResult (org.apache.jmeter.samplers.SampleResult)3 MalformedPatternException (org.apache.oro.text.regex.MalformedPatternException)3 PatternMatcher (org.apache.oro.text.regex.PatternMatcher)3 BufferedReader (java.io.BufferedReader)2 EOFException (java.io.EOFException)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 Charset (java.nio.charset.Charset)2