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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations