use of org.apache.oro.text.regex.PatternCompiler 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;
}
use of org.apache.oro.text.regex.PatternCompiler 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;
}
use of org.apache.oro.text.regex.PatternCompiler 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;
}
Aggregations