use of org.apache.oro.text.regex.Perl5Substitution in project tdi-studio-se by Talend.
the class JavaRoutineSynchronizer method renamePigudfClass.
/*
* (non-Javadoc)
*
* @see org.talend.designer.codegen.AbstractRoutineSynchronizer#renamePigudfClass(org.talend.core.model.properties.
* RoutineItem)
*/
@Override
public void renamePigudfClass(PigudfItem pigudfItem, String oldLabel) {
if (pigudfItem == null) {
return;
}
String routineContent = new String(pigudfItem.getContent().getInnerContent());
String label = pigudfItem.getProperty().getLabel();
//
Perl5Matcher matcher = new Perl5Matcher();
Perl5Compiler compiler = new Perl5Compiler();
PatternMatcherInput patternMatcherInput = new PatternMatcherInput(routineContent);
//$NON-NLS-1$//$NON-NLS-2$
String regx = "public(\\s)+class(\\s)+" + oldLabel + "(\\s)(.+)\\{";
String extendsText = "";
try {
org.apache.oro.text.regex.Pattern pattern = compiler.compile(regx);
boolean contains = matcher.contains(patternMatcherInput, pattern);
if (contains) {
org.apache.oro.text.regex.MatchResult matchResult = matcher.getMatch();
extendsText = matchResult.group(matchResult.groups() - 1);
}
//$NON-NLS-1$
String regexp = "public(\\s)+class(\\s)+\\w+(\\s)\\{";
if (extendsText != null) {
extendsText = extendsText.trim();
//$NON-NLS-1$//$NON-NLS-2$
regexp = "public(\\s)+class(\\s)+\\w+(\\s)+" + extendsText + "(\\s)*\\{";
}
// rename class name
//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
routineContent = routineContent.replaceFirst(regexp, "public class " + label + " " + extendsText + " {");
// rename constructor
String constructorRegx = "(\\s+)" + oldLabel + "(\\((.*)\\))";
String toReplace = "$1" + label + "$1$2";
pattern = compiler.compile(constructorRegx);
Perl5Substitution substitution = new Perl5Substitution(toReplace, Perl5Substitution.INTERPOLATE_ALL);
routineContent = Util.substitute(matcher, pattern, substitution, routineContent, Util.SUBSTITUTE_ALL);
} catch (MalformedPatternException e) {
ExceptionHandler.process(new Exception("Rename pigudf failed"));
}
pigudfItem.getContent().setInnerContent(routineContent.getBytes());
}
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 MapperComponent method hasOrRenameData.
/**
*
* DOC amaumont Comment method "hasOrRenameData".
*
* @param oldName
* @param newName can be null if <code>renameAction</code> is false
* @param renameAction true to rename in all expressions, false to get boolean if present in one of the expressions
* @return
*/
@Override
protected boolean hasOrRenameData(String oldName, String newName, boolean renameAction) {
if (oldName == null || newName == null && renameAction) {
throw new NullPointerException();
}
if (externalData != null) {
List<ExternalMapperTable> tables = new ArrayList<ExternalMapperTable>(externalData.getInputTables());
tables.addAll(externalData.getOutputTables());
if (externalData.getVarsTables() != null) {
tables.addAll(externalData.getVarsTables());
}
for (ExternalMapperTable table : tables) {
if (table.getExpressionFilter() != 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, table.getExpressionFilter());
table.setExpressionFilter(expression);
} else {
if (hasDataIntoExpression(pattern, matcher, table.getExpressionFilter())) {
return true;
}
}
}
}
List<ExternalMapperTableEntry> metadataTableEntries = table.getMetadataTableEntries();
if (metadataTableEntries != null) {
// loop on all entries of current table
for (ExternalMapperTableEntry entry : metadataTableEntries) {
if (hasOrRenameEntry(entry, oldName, newName, renameAction)) {
// existed
return true;
}
}
// for (ExternalMapperTableEntry entry : metadataTableEntries) {
}
if (table.getConstraintTableEntries() != null) {
for (ExternalMapperTableEntry entry : table.getConstraintTableEntries()) {
if (hasOrRenameEntry(entry, oldName, newName, renameAction)) {
// existed
return true;
}
}
}
}
}
return false;
}
use of org.apache.oro.text.regex.Perl5Substitution in project tdi-studio-se by Talend.
the class XmlMapExpressionManager method replaceExpression.
public String replaceExpression(String expression, TableEntryLocation oldLocation, TableEntryLocation newLocation) {
String returnedExpression = expression;
boolean needPrefixAndSuffix = oldLocation.prefix != null && !"".equals(oldLocation.prefix) && oldLocation.sufix != null && !"".equals(oldLocation.sufix);
String tempPattern = StringHelper.replacePrms(SUBS_PATTERN_FOR_REPLACE_LOCATION, new Object[] { needPrefixAndSuffix ? (XmlMapUtil.DOUBLE_ESCAPE + oldLocation.prefix) : "", oldLocation.tableName, oldLocation.columnValue, needPrefixAndSuffix ? (XmlMapUtil.DOUBLE_ESCAPE + oldLocation.sufix) : "" });
recompilePatternIfNecessary(tempPattern);
if (returnedExpression != null) {
matcher.setMultiline(true);
Perl5Substitution substitution = new Perl5Substitution(oldLocation.prefix + "$1" + newLocation.tableName + "$2" + XmlMapUtil.EXPRESSION_SEPARATOR_SPLIT + "$3" + newLocation.columnValue + "$4" + oldLocation.sufix, Perl5Substitution.INTERPOLATE_ALL);
returnedExpression = Util.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 addRefArrayPointer.
public String addRefArrayPointer(String expression, TableEntryLocation[] locations) {
String returnedExpression = expression;
PerlLanguage perlLanguage = (PerlLanguage) language;
for (TableEntryLocation location : locations) {
recompilePatternIfNecessary(StringHelper.replacePrms(perlLanguage.getSubstPatternToAddRefArrayPointer(), new Object[] { location.tableName }));
if (returnedExpression != null) {
matcher.setMultiline(true);
Perl5Substitution substitution = new Perl5Substitution(//$NON-NLS-1$
language.getPrefixTableRegexp() + "$1->" + perlLanguage.getPrefixFieldRegexp() + "$2" + perlLanguage.getSuffixFieldRegexp(), //$NON-NLS-1$
Perl5Substitution.INTERPOLATE_ALL);
returnedExpression = substitute(matcher, pattern, substitution, returnedExpression, Util.SUBSTITUTE_ALL);
}
}
return returnedExpression;
}
Aggregations