Search in sources :

Example 21 with Perl5Compiler

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

the class VirtualRowGeneratorNode method renameValues.

// add for bug 9471
private String renameValues(final String value, final String oldName, final String newName) {
    if (value == null || oldName == null || newName == null) {
        // keep original value
        return value;
    }
    PatternCompiler compiler = new Perl5Compiler();
    Perl5Matcher matcher = new Perl5Matcher();
    matcher.setMultiline(true);
    Perl5Substitution substitution = new //$NON-NLS-1$
    Perl5Substitution(//$NON-NLS-1$
    newName + "$2", Perl5Substitution.INTERPOLATE_ALL);
    Pattern pattern;
    try {
        pattern = compiler.compile(//$NON-NLS-1$
        "\\b(" + UpdateContextVariablesHelper.replaceSpecialChar(oldName) + //$NON-NLS-1$
        ")(\\b|\\_)");
    } catch (MalformedPatternException e) {
        // keep original value
        return value;
    }
    if (matcher.contains(value, pattern)) {
        // replace
        String returnValue = Util.substitute(matcher, pattern, substitution, value, Util.SUBSTITUTE_ALL);
        return returnValue;
    }
    // keep original value
    return value;
}
Also used : 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 22 with Perl5Compiler

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

the class InputDataMapTableView method checkValidName.

/**
     * Check if the given name will be unique in the process. If already exists with that name, false will be returned.
     * 
     * @param uniqueName
     * @return true if the name is unique
     */
public boolean checkValidName(String name) {
    for (ITableEntry entry : getInputTable().getGlobalMapEntries()) {
        if (TalendQuoteUtils.removeQuotesIfExist(entry.getName()).equals(name)) {
            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(name, 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 23 with Perl5Compiler

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

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

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

Aggregations

Perl5Compiler (org.apache.oro.text.regex.Perl5Compiler)30 Pattern (org.apache.oro.text.regex.Pattern)26 MalformedPatternException (org.apache.oro.text.regex.MalformedPatternException)23 Perl5Matcher (org.apache.oro.text.regex.Perl5Matcher)23 PatternCompiler (org.apache.oro.text.regex.PatternCompiler)10 PatternMatcher (org.apache.oro.text.regex.PatternMatcher)7 MatchResult (org.apache.oro.text.regex.MatchResult)6 PatternMatcherInput (org.apache.oro.text.regex.PatternMatcherInput)5 MalformedURLException (java.net.MalformedURLException)4 ArrayList (java.util.ArrayList)4 IOException (java.io.IOException)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 Charset (java.nio.charset.Charset)2