use of org.apache.oro.text.regex.MalformedPatternException 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.MalformedPatternException 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.MalformedPatternException in project tdi-studio-se by Talend.
the class UpgradeParameterHelper method hasParent.
/*
* check the parent form name
*/
private static boolean hasParent(final String name, final String parent) {
if (name == null) {
return false;
}
if (parent != null) {
final String parentExp = parent + COLON;
if (name.contains(parentExp)) {
Perl5Matcher matcher = new Perl5Matcher();
Perl5Compiler compiler = new Perl5Compiler();
Pattern pattern;
try {
//$NON-NLS-1$ //$NON-NLS-2$
pattern = compiler.compile("\\b(" + parentExp + ")\\b");
if (matcher.contains(name, pattern)) {
return true;
}
} catch (MalformedPatternException e) {
//
}
}
}
return false;
}
use of org.apache.oro.text.regex.MalformedPatternException in project tdi-studio-se by Talend.
the class VarsTable method validateColumnName.
/**
*
* DOC amaumont Comment method "validateColumnName".
*
* @param columnName
* @return true if columnName has a valid value
*/
public String validateColumnName(String columnName, int beanPosition) {
if (columnName == null) {
//$NON-NLS-1$
return Messages.getString("VarsTable.columnNameIsNull");
}
Pattern validPatternColumnNameRegexp = null;
if (validPatternColumnNameRegexp == null) {
try {
validPatternColumnNameRegexp = COMPILER.compile(VALID_PATTERN_COLUMN_NAME);
} catch (MalformedPatternException e) {
throw new RuntimeException(e);
}
}
Perl5Matcher matcher = new Perl5Matcher();
boolean match = matcher.matches(columnName, validPatternColumnNameRegexp);
// System.out.println(columnName + " -> "+ match);
if (!match) {
//$NON-NLS-1$ //$NON-NLS-2$
return Messages.getString("VarsTable.columnNameTip") + columnName + Messages.getString("VarsTable.invalidTip");
}
int lstSize = dataMapTableEntries.size();
for (int i = 0; i < lstSize; i++) {
if (columnName.equals(dataMapTableEntries.get(i).getName()) && i != beanPosition) {
//$NON-NLS-1$ //$NON-NLS-2$
return Messages.getString("VarsTable.columnNameTip") + columnName + Messages.getString("VarsTable.existTip");
}
}
return null;
}
Aggregations