Search in sources :

Example 11 with Perl5Substitution

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

the class DataMapExpressionParser method addTablePrefixToColumnName.

public String addTablePrefixToColumnName(String expression, TableEntryLocation[] locations) {
    String returnedExpression = expression;
    for (TableEntryLocation location : locations) {
        recompilePatternIfNecessary(StringHelper.replacePrms(language.getSubstPatternForPrefixColumnName(), new Object[] { location.tableName, location.columnName }));
        if (returnedExpression != null) {
            matcher.setMultiline(true);
            Perl5Substitution substitution = new Perl5Substitution(//$NON-NLS-1$
            language.getPrefixTableRegexp() + "$1" + language.getPrefixFieldRegexp() + "$1__$2" + language.getSuffixFieldRegexp(), //$NON-NLS-1$
            Perl5Substitution.INTERPOLATE_ALL);
            returnedExpression = Util.substitute(matcher, pattern, substitution, returnedExpression, Util.SUBSTITUTE_ALL);
        }
    }
    return returnedExpression;
}
Also used : Perl5Substitution(org.apache.oro.text.regex.Perl5Substitution) TableEntryLocation(org.talend.designer.dbmap.model.tableentry.TableEntryLocation)

Example 12 with Perl5Substitution

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

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

the class MapExpressionParser method replaceLocation.

public String replaceLocation(String expression, String tempPattern, String sub) {
    String returnedExpression = expression;
    recompilePatternIfNecessary(tempPattern);
    if (returnedExpression != null) {
        matcher.setMultiline(true);
        Perl5Substitution substitution = new Perl5Substitution(sub);
        returnedExpression = 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