Search in sources :

Example 21 with MalformedPatternException

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

the class NodeQueryCheckUtil method compareNodeTableColumnsWithFunc.

/**
     * 
     * DOC wzhang Comment method "compareNodeTableColumnsWithFunc".
     * 
     * @param node
     * @param columns
     * @return
     */
private static boolean compareNodeTableColumnsWithFunc(Node node, String columns) {
    String originalColumns = columns;
    if (node.getMetadataList().size() == 0) {
        return true;
    }
    IMetadataTable metaTable = node.getMetadataList().get(0);
    if (metaTable == null || metaTable.getListColumns() == null) {
        return true;
    }
    int originColumnSize = metaTable.getListColumns().size();
    // modified by wzhang. replace the field to one String if it contains function
    //$NON-NLS-1$  
    columns = columns.replaceAll(FUNC_SPLIT, "column");
    //$NON-NLS-1$
    String[] columnArray = columns.split(",");
    // columns not match
    if (columnArray.length != originColumnSize) {
        // if can not match , we should match the columns with function
        try {
            PatternCompiler pc = new Perl5Compiler();
            org.apache.oro.text.regex.Pattern pattern = null;
            pattern = pc.compile(SQL_FUNC_REGX, REGX_FLAG);
            PatternMatcher columnMatcher = new Perl5Matcher();
            if (columnMatcher.matches(originalColumns, pattern)) {
                String columnWithFunc = columnMatcher.getMatch().group(4).trim();
                if (columnWithFunc != null) {
                    //$NON-NLS-1$
                    String[] columnWithFuncArray = columnWithFunc.split(",");
                    if (columnWithFuncArray.length > 1) {
                        //$NON-NLS-1$
                        originalColumns = originalColumns.replace(columnWithFunc, "columnWithFunction");
                        return compareNodeTableColumnsWithFunc(node, originalColumns);
                    }
                }
            }
        } catch (MalformedPatternException e) {
            return false;
        }
        return false;
    }
    return true;
}
Also used : Perl5Compiler(org.apache.oro.text.regex.Perl5Compiler) PatternCompiler(org.apache.oro.text.regex.PatternCompiler) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException) PatternMatcher(org.apache.oro.text.regex.PatternMatcher)

Example 22 with MalformedPatternException

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

the class ReplaceRunJobLabelVariableMigrationTask method replaceValue.

private boolean replaceValue(NodeType node, boolean replace) {
    if (node == null) {
        return false;
    }
    //$NON-NLS-1$
    ElementParameterType param = ComponentUtilities.getNodeProperty(node, "LABEL");
    if (param != null && param.getField().equals(EParameterFieldType.TEXT.getName())) {
        String value = param.getValue();
        if (value != null) {
            PatternCompiler compiler = new Perl5Compiler();
            Perl5Matcher matcher = new Perl5Matcher();
            try {
                Pattern pattern = compiler.compile(//$NON-NLS-1$
                "\\b(" + "__PROCESS_TYPE_PROCESS__" + //$NON-NLS-1$ //$NON-NLS-2$
                ")(\\b)");
                if (matcher.contains(value, pattern)) {
                    if (replace) {
                        // replace
                        Perl5Substitution substitution = new //$NON-NLS-1$ //$NON-NLS-2$
                        Perl5Substitution(//$NON-NLS-1$ //$NON-NLS-2$
                        "__PROCESS__" + "$2", Perl5Substitution.INTERPOLATE_ALL);
                        String newValue = Util.substitute(matcher, pattern, substitution, value, Util.SUBSTITUTE_ALL);
                        param.setValue(newValue);
                    }
                    return true;
                }
            } catch (MalformedPatternException e) {
            //
            }
        }
    }
    return false;
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) Perl5Compiler(org.apache.oro.text.regex.Perl5Compiler) Pattern(org.apache.oro.text.regex.Pattern) PatternCompiler(org.apache.oro.text.regex.PatternCompiler) Perl5Substitution(org.apache.oro.text.regex.Perl5Substitution) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException)

Example 23 with MalformedPatternException

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

the class UpgradeParameterHelper 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 24 with MalformedPatternException

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

MalformedPatternException (org.apache.oro.text.regex.MalformedPatternException)24 Perl5Compiler (org.apache.oro.text.regex.Perl5Compiler)22 Pattern (org.apache.oro.text.regex.Pattern)20 Perl5Matcher (org.apache.oro.text.regex.Perl5Matcher)19 PatternCompiler (org.apache.oro.text.regex.PatternCompiler)8 PatternMatcher (org.apache.oro.text.regex.PatternMatcher)5 IOException (java.io.IOException)3 MatchResult (org.apache.oro.text.regex.MatchResult)3 Perl5Substitution (org.apache.oro.text.regex.Perl5Substitution)3 ITableEntry (org.talend.designer.abstractmap.model.tableentry.ITableEntry)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 InputStreamReader (java.io.InputStreamReader)2 MalformedURLException (java.net.MalformedURLException)2 Charset (java.nio.charset.Charset)2 ModifyEvent (org.eclipse.swt.events.ModifyEvent)2 ModifyListener (org.eclipse.swt.events.ModifyListener)2