Search in sources :

Example 6 with Perl5Substitution

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

the class AbstractMapComponent method getRenameSubstitution.

protected final Perl5Substitution getRenameSubstitution(String newName) {
    if (substitutionsCache.containsKey(newName)) {
        return substitutionsCache.get(newName);
    }
    //$NON-NLS-1$
    Perl5Substitution ps = new Perl5Substitution(newName + "$2", Perl5Substitution.INTERPOLATE_ALL);
    substitutionsCache.put(newName, ps);
    return ps;
}
Also used : Perl5Substitution(org.apache.oro.text.regex.Perl5Substitution)

Example 7 with Perl5Substitution

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

the class AbstractMapComponent method hasOrRenameEntry.

/**
     * 
     * ggu Comment method "hasOrRenameEntry".
     * 
     */
protected boolean hasOrRenameEntry(IExternalMapEntry entry, String oldName, String newName, boolean renameAction) {
    if (entry == null || oldName == null || newName == null && renameAction) {
        throw new NullPointerException();
    }
    if (entry.getExpression() != null) {
        Pattern pattern = getRenamePattern(oldName);
        if (pattern != null) {
            PatternMatcher matcher = new Perl5Matcher();
            ((Perl5Matcher) matcher).setMultiline(true);
            if (renameAction) {
                Perl5Substitution substitution = getRenameSubstitution(newName);
                String expression = renameDataIntoExpression(pattern, matcher, substitution, entry.getExpression());
                entry.setExpression(expression);
            } else {
                if (hasDataIntoExpression(pattern, matcher, entry.getExpression())) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) Perl5Substitution(org.apache.oro.text.regex.Perl5Substitution) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) PatternMatcher(org.apache.oro.text.regex.PatternMatcher)

Example 8 with Perl5Substitution

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

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

the class DataMapExpressionParser method replaceLocation.

public String replaceLocation(String expression, TableEntryLocation oldLocation, TableEntryLocation newLocation) {
    String returnedExpression = expression;
    String tempPattern = StringHelper.replacePrms(language.getSubstPatternForReplaceLocation(), new Object[] { oldLocation.tableName, oldLocation.columnName });
    recompilePatternIfNecessary(tempPattern);
    if (returnedExpression != null) {
        matcher.setMultiline(true);
        Perl5Substitution substitution = new Perl5Substitution(language.getPrefixTableRegexp() + "$1" + newLocation.tableName + //$NON-NLS-1$ //$NON-NLS-2$
        "$2" + language.getSuffixTableRegexp() + "$3" + language.getPrefixFieldRegexp() + "$4" + newLocation.columnName + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "$5" + language.getSuffixFieldRegexp(), Perl5Substitution.INTERPOLATE_ALL);
        returnedExpression = substitute(matcher, pattern, substitution, returnedExpression, Util.SUBSTITUTE_ALL);
    }
    return returnedExpression;
}
Also used : Perl5Substitution(org.apache.oro.text.regex.Perl5Substitution)

Example 10 with Perl5Substitution

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

the class DataMapExpressionParser method replaceLocation.

public String replaceLocation(String expression, TableEntryLocation oldLocation, TableEntryLocation newLocation) {
    String returnedExpression = expression;
    String tempPattern = StringHelper.replacePrms(language.getSubstPatternForReplaceLocation(), new Object[] { oldLocation.tableName, oldLocation.columnName });
    recompilePatternIfNecessary(tempPattern);
    if (returnedExpression != null) {
        matcher.setMultiline(true);
        Perl5Substitution substitution = new Perl5Substitution(language.getPrefixTableRegexp() + "$1" + newLocation.tableName + //$NON-NLS-1$ //$NON-NLS-2$
        "$2" + language.getSuffixTableRegexp() + "$3" + language.getPrefixFieldRegexp() + "$4" + newLocation.columnName + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "$5" + language.getSuffixFieldRegexp(), Perl5Substitution.INTERPOLATE_ALL);
        returnedExpression = Util.substitute(matcher, pattern, substitution, returnedExpression, Util.SUBSTITUTE_ALL);
    }
    return returnedExpression;
}
Also used : Perl5Substitution(org.apache.oro.text.regex.Perl5Substitution)

Aggregations

Perl5Substitution (org.apache.oro.text.regex.Perl5Substitution)13 Perl5Matcher (org.apache.oro.text.regex.Perl5Matcher)5 Pattern (org.apache.oro.text.regex.Pattern)4 MalformedPatternException (org.apache.oro.text.regex.MalformedPatternException)3 Perl5Compiler (org.apache.oro.text.regex.Perl5Compiler)3 PatternCompiler (org.apache.oro.text.regex.PatternCompiler)2 PatternMatcher (org.apache.oro.text.regex.PatternMatcher)2 TableEntryLocation (org.talend.designer.mapper.model.tableentry.TableEntryLocation)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 PatternMatcherInput (org.apache.oro.text.regex.PatternMatcherInput)1 CoreException (org.eclipse.core.runtime.CoreException)1 SystemException (org.talend.commons.exception.SystemException)1 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)1 TableEntryLocation (org.talend.designer.dbmap.model.tableentry.TableEntryLocation)1 ExternalMapperTable (org.talend.designer.mapper.external.data.ExternalMapperTable)1 ExternalMapperTableEntry (org.talend.designer.mapper.external.data.ExternalMapperTableEntry)1 PerlLanguage (org.talend.designer.mapper.language.perl.PerlLanguage)1