Search in sources :

Example 1 with PatternMatcherInput

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

the class DataMapExpressionParser method substitute.

private String substitute(PatternMatcher matcher, Pattern pattern, Substitution sub, String input, int numSubs) {
    StringBuffer buffer = new StringBuffer(input.length());
    PatternMatcherInput pinput = new PatternMatcherInput(input);
    // are performed,
    if (substitute(buffer, matcher, pattern, sub, pinput, numSubs) != 0)
        return buffer.toString();
    return input;
}
Also used : PatternMatcherInput(org.apache.oro.text.regex.PatternMatcherInput)

Example 2 with PatternMatcherInput

use of org.apache.oro.text.regex.PatternMatcherInput 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(locationPattern);
        while (matcher.contains(patternMatcherInput, pattern)) {
            MatchResult matchResult = matcher.getMatch();
            resultList.add(new TableEntryLocation(matchResult.group(1), matchResult.group(2)));
        }
    }
    return resultList.toArray(new TableEntryLocation[0]);
}
Also used : PatternMatcherInput(org.apache.oro.text.regex.PatternMatcherInput) TableEntryLocation(org.talend.designer.mapper.model.tableentry.TableEntryLocation) MatchResult(org.apache.oro.text.regex.MatchResult)

Example 3 with PatternMatcherInput

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

the class DataMapExpressionParserTest method main.

public static void main(String[] args) throws Exception {
    Perl5Matcher matcher = new Perl5Matcher();
    Perl5Compiler compiler = new Perl5Compiler();
    // String PATTERN_STR = "\\s*(\\w+)\\s*(\\.\\s*(\\w+)\\s*)+"; // can't get correct group count.
    String PATTERN_STR = "(\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*)" + "|(\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*)" + "|(\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*)" + "|(\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*)";
    String expression = "context. schema.  context  .table.column";
    // String expression = "context.schema.table.column";
    // String expression = "schema.table.column";
    // String expression = "table.column";
    matcher.setMultiline(true);
    PatternMatcherInput patternMatcherInput = new PatternMatcherInput(expression);
    Pattern pattern = compiler.compile(PATTERN_STR);
    while (matcher.contains(patternMatcherInput, pattern)) {
        MatchResult matchResult = matcher.getMatch();
        System.out.println("group count:" + matchResult.groups());
        for (int i = 1; i <= matchResult.groups(); i++) {
            System.out.println("group[" + i + "] content:" + matchResult.group(i));
        }
    }
}
Also used : Perl5Compiler(org.apache.oro.text.regex.Perl5Compiler) Pattern(org.apache.oro.text.regex.Pattern) PatternMatcherInput(org.apache.oro.text.regex.PatternMatcherInput) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) MatchResult(org.apache.oro.text.regex.MatchResult)

Example 4 with PatternMatcherInput

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

the class WebServiceExpressionParser method parseOutTableEntryLocations.

public Set<String> parseOutTableEntryLocations(String expression) {
    Set<String> set = new HashSet<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();
            String columnName = matchResult.group(0);
            set.add(columnName);
        }
    }
    return set;
}
Also used : PatternMatcherInput(org.apache.oro.text.regex.PatternMatcherInput) MatchResult(org.apache.oro.text.regex.MatchResult) HashSet(java.util.HashSet)

Example 5 with PatternMatcherInput

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

the class XmlMapExpressionManager method parseTableEntryLocation.

public List<TableEntryLocation> parseTableEntryLocation(String expression) {
    List<TableEntryLocation> locations = new ArrayList<TableEntryLocation>();
    recompilePatternIfNecessary(EXPRESSION_PATTERN);
    patternMatcherInput = new PatternMatcherInput(expression);
    while (matcher.contains(patternMatcherInput, pattern)) {
        MatchResult matchResult = matcher.getMatch();
        if (matchResult.group(1) != null) {
            TableEntryLocation location = new TableEntryLocation(matchResult.group(1), matchResult.group(2), matchResult.group(3), matchResult.group(6));
            locations.add(location);
        } else if (matchResult.group(matchResult.groups() - 1) != null) {
            TableEntryLocation location = new TableEntryLocation(matchResult.group(matchResult.groups() - 2), matchResult.group(matchResult.groups() - 1));
            locations.add(location);
        }
    }
    return locations;
}
Also used : PatternMatcherInput(org.apache.oro.text.regex.PatternMatcherInput) ArrayList(java.util.ArrayList) MatchResult(org.apache.oro.text.regex.MatchResult)

Aggregations

PatternMatcherInput (org.apache.oro.text.regex.PatternMatcherInput)27 MatchResult (org.apache.oro.text.regex.MatchResult)19 Pattern (org.apache.oro.text.regex.Pattern)14 Perl5Matcher (org.apache.oro.text.regex.Perl5Matcher)12 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)3 MalformedCachePatternException (org.apache.oro.text.MalformedCachePatternException)3 PatternMatcher (org.apache.oro.text.regex.PatternMatcher)3 Perl5Compiler (org.apache.oro.text.regex.Perl5Compiler)3 Map (java.util.Map)2 Array (lucee.runtime.type.Array)2 ArrayImpl (lucee.runtime.type.ArrayImpl)2 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 HashSet (java.util.HashSet)1 Struct (lucee.runtime.type.Struct)1 StructImpl (lucee.runtime.type.StructImpl)1 CompoundVariable (org.apache.jmeter.engine.util.CompoundVariable)1 SampleSaveConfiguration (org.apache.jmeter.samplers.SampleSaveConfiguration)1