Search in sources :

Example 1 with Perl5Matcher

use of org.apache.oro.text.regex.Perl5Matcher in project canal by alibaba.

the class SimpleDdlParser method parseTableName.

private static DdlResult parseTableName(String matchString, String schmeaName) {
    Perl5Matcher tableMatcher = new Perl5Matcher();
    matchString = matchString + " ";
    if (tableMatcher.matches(matchString, PatternUtils.getPattern(TABLE_PATTERN))) {
        String tableString = tableMatcher.getMatch().group(3);
        if (StringUtils.isEmpty(tableString)) {
            return null;
        }
        tableString = StringUtils.removeEnd(tableString, ";");
        tableString = StringUtils.removeEnd(tableString, "(");
        tableString = StringUtils.trim(tableString);
        // 特殊处理引号`
        tableString = removeEscape(tableString);
        // 处理schema.table的写法
        String[] names = StringUtils.split(tableString, ".");
        if (names.length == 0) {
            return null;
        }
        if (names != null && names.length > 1) {
            return new DdlResult(removeEscape(names[0]), removeEscape(names[1]));
        } else {
            return new DdlResult(schmeaName, removeEscape(names[0]));
        }
    }
    return null;
}
Also used : Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher)

Example 2 with Perl5Matcher

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

the class DataStringConnection method getAnalyse.

/**
     * Method getAnalyse extact serveur, port, sid of stringConnection and check the dbType.
     * 
     * @param stringConnection
     * @return string[] { selectionIndex, serveur, port, sid }
     */
public String[] getAnalyse(final String stringConnection) {
    Integer selectionIndex = getSelectionIndex();
    //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
    String[] s = { selectionIndex.toString(), "", "", "", "", "" };
    String regex = getRegex();
    if (stringConnection == "") {
        //$NON-NLS-1$
        return s;
    }
    Perl5Compiler compiler = new Perl5Compiler();
    Perl5Matcher matcher = new Perl5Matcher();
    Pattern pattern = null;
    try {
        pattern = compiler.compile(regex);
        if (matcher.contains(stringConnection, pattern)) {
            matcher.matches(stringConnection, pattern);
            MatchResult matchResult = matcher.getMatch();
            s[0] = selectionIndex.toString();
            if (matchResult != null) {
                for (int i = 1; i < matchResult.groups(); i++) {
                    s[i] = matchResult.group(i);
                }
            }
        } else {
            // search if another regex corresponding at the string of connection
            int i = searchGoodRegex(stringConnection);
            if (i != getSelectionIndex()) {
                setSelectionIndex(i);
                s = getAnalyse(stringConnection);
            }
        }
    } catch (MalformedPatternException e) {
        // e.printStackTrace();
        ExceptionHandler.process(e);
    }
    return s;
}
Also used : Perl5Compiler(org.apache.oro.text.regex.Perl5Compiler) Pattern(org.apache.oro.text.regex.Pattern) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException) MatchResult(org.apache.oro.text.regex.MatchResult)

Example 3 with Perl5Matcher

use of org.apache.oro.text.regex.Perl5Matcher 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 Perl5Matcher

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

the class VarsTable method checkValidColumnName.

/**
     * Check if the given name will be unique in the process. If another link already exists with that name, false will
     * be returned.
     * 
     * @param uniqueName
     * @return true if the name is unique
     */
public boolean checkValidColumnName(String connectionName) {
    for (ITableEntry entry : dataMapTableEntries) {
        if (entry.getName().equals(connectionName)) {
            return false;
        }
    }
    Perl5Matcher matcher = new Perl5Matcher();
    Perl5Compiler compiler = new Perl5Compiler();
    Pattern pattern;
    try {
        //$NON-NLS-1$
        pattern = compiler.compile("^[A-Za-z_][A-Za-z0-9_]*$");
        if (!matcher.matches(connectionName, pattern)) {
            return false;
        }
    } catch (MalformedPatternException e) {
        throw new RuntimeException(e);
    }
    return true;
}
Also used : Perl5Compiler(org.apache.oro.text.regex.Perl5Compiler) Pattern(org.apache.oro.text.regex.Pattern) ITableEntry(org.talend.designer.abstractmap.model.tableentry.ITableEntry) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException)

Example 5 with Perl5Matcher

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

the class VirtualRowGeneratorNode method valueContains.

// add for bug 9471
private boolean valueContains(String value, String toTest) {
    if (value.contains(toTest)) {
        Perl5Matcher matcher = new Perl5Matcher();
        Perl5Compiler compiler = new Perl5Compiler();
        Pattern pattern;
        try {
            //$NON-NLS-1$ //$NON-NLS-2$
            pattern = compiler.compile("\\b(" + UpdateContextVariablesHelper.replaceSpecialChar(toTest) + ")(\\b|\\_)");
            if (matcher.contains(value, pattern)) {
                return true;
            }
        } catch (MalformedPatternException e) {
            throw new RuntimeException(e);
        }
    }
    return false;
}
Also used : Perl5Compiler(org.apache.oro.text.regex.Perl5Compiler) Pattern(org.apache.oro.text.regex.Pattern) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException)

Aggregations

Perl5Matcher (org.apache.oro.text.regex.Perl5Matcher)72 Pattern (org.apache.oro.text.regex.Pattern)50 Perl5Compiler (org.apache.oro.text.regex.Perl5Compiler)23 MalformedPatternException (org.apache.oro.text.regex.MalformedPatternException)22 MatchResult (org.apache.oro.text.regex.MatchResult)21 PatternMatcher (org.apache.oro.text.regex.PatternMatcher)17 PatternMatcherInput (org.apache.oro.text.regex.PatternMatcherInput)14 ArrayList (java.util.ArrayList)12 PatternCompiler (org.apache.oro.text.regex.PatternCompiler)8 IOException (java.io.IOException)6 MalformedURLException (java.net.MalformedURLException)6 MalformedCachePatternException (org.apache.oro.text.MalformedCachePatternException)5 Perl5Substitution (org.apache.oro.text.regex.Perl5Substitution)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 SampleResult (org.apache.jmeter.samplers.SampleResult)3 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)3 PatternCacheLRU (org.apache.oro.text.PatternCacheLRU)3 BufferedReader (java.io.BufferedReader)2 EOFException (java.io.EOFException)2 File (java.io.File)2