Search in sources :

Example 6 with Perl5Matcher

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

Example 7 with Perl5Matcher

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

the class NodeQueryCheckUtil method apacheRegexMatch.

/**
     * See bug 5836. java.util.regex works too slow here. Use apache oro regex library instead.
     * <p>
     * DOC xye Comment method "apacheRegexMatch".
     * 
     * @param patternString
     * @param flag
     * @param input
     * @return
     */
private static boolean apacheRegexMatch(final String patternString, final int flag, final String input) {
    PatternCompiler pc = new Perl5Compiler();
    org.apache.oro.text.regex.Pattern pattern = null;
    try {
        pattern = pc.compile(patternString, flag);
        PatternMatcher columnMatcher = new Perl5Matcher();
        return columnMatcher.matches(input, pattern);
    } catch (MalformedPatternException e) {
        return false;
    }
}
Also used : Perl5Compiler(org.apache.oro.text.regex.Perl5Compiler) PatternCompiler(org.apache.oro.text.regex.PatternCompiler) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException) PatternMatcher(org.apache.oro.text.regex.PatternMatcher)

Example 8 with Perl5Matcher

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

the class DowngradeParameterHelper method hasParent.

/*
     * check the parent form name
     */
private static boolean hasParent(final String name, final String parent) {
    if (name == null) {
        return false;
    }
    if (parent != null) {
        final String parentExp = parent + COLON;
        if (name.contains(parentExp)) {
            Perl5Matcher matcher = new Perl5Matcher();
            Perl5Compiler compiler = new Perl5Compiler();
            Pattern pattern;
            try {
                //$NON-NLS-1$ //$NON-NLS-2$
                pattern = compiler.compile("\\b(" + parentExp + ")\\b");
                if (matcher.contains(name, pattern)) {
                    return true;
                }
            } catch (MalformedPatternException 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 9 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 10 with Perl5Matcher

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

the class VarsTable method validateColumnName.

/**
     * 
     * DOC amaumont Comment method "validateColumnName".
     * 
     * @param columnName
     * @return true if columnName has a valid value
     */
public String validateColumnName(String columnName, int beanPosition) {
    if (columnName == null) {
        //$NON-NLS-1$
        return Messages.getString("VarsTable.columnNameIsNull");
    }
    Pattern validPatternColumnNameRegexp = null;
    if (validPatternColumnNameRegexp == null) {
        try {
            validPatternColumnNameRegexp = COMPILER.compile(VALID_PATTERN_COLUMN_NAME);
        } catch (MalformedPatternException e) {
            throw new RuntimeException(e);
        }
    }
    Perl5Matcher matcher = new Perl5Matcher();
    boolean match = matcher.matches(columnName, validPatternColumnNameRegexp);
    // System.out.println(columnName + " -> "+ match);
    if (!match) {
        //$NON-NLS-1$ //$NON-NLS-2$
        return Messages.getString("VarsTable.columnNameTip") + columnName + Messages.getString("VarsTable.invalidTip");
    }
    int lstSize = dataMapTableEntries.size();
    for (int i = 0; i < lstSize; i++) {
        if (columnName.equals(dataMapTableEntries.get(i).getName()) && i != beanPosition) {
            //$NON-NLS-1$ //$NON-NLS-2$
            return Messages.getString("VarsTable.columnNameTip") + columnName + Messages.getString("VarsTable.existTip");
        }
    }
    return null;
}
Also used : 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