Search in sources :

Example 1 with Pattern

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

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

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

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

Example 5 with Pattern

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

the class ConnectionAddUniqueNameMigrationTask method checkValidConnectionName.

public boolean checkValidConnectionName(String connectionName) {
    if (checkIgnoreCase(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 !KeywordsValidator.isKeyword(connectionName);
}
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

Pattern (org.apache.oro.text.regex.Pattern)70 Perl5Matcher (org.apache.oro.text.regex.Perl5Matcher)48 MalformedPatternException (org.apache.oro.text.regex.MalformedPatternException)27 Perl5Compiler (org.apache.oro.text.regex.Perl5Compiler)24 MatchResult (org.apache.oro.text.regex.MatchResult)17 PatternMatcherInput (org.apache.oro.text.regex.PatternMatcherInput)14 ArrayList (java.util.ArrayList)12 PatternMatcher (org.apache.oro.text.regex.PatternMatcher)9 PatternCompiler (org.apache.oro.text.regex.PatternCompiler)7 IOException (java.io.IOException)6 MalformedCachePatternException (org.apache.oro.text.MalformedCachePatternException)6 MalformedURLException (java.net.MalformedURLException)4 BufferedReader (java.io.BufferedReader)3 FileInputStream (java.io.FileInputStream)3 InputStreamReader (java.io.InputStreamReader)3 Perl5Substitution (org.apache.oro.text.regex.Perl5Substitution)3 EOFException (java.io.EOFException)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2