use of org.apache.oro.text.regex.Perl5Compiler in project tdi-studio-se by Talend.
the class DataStringConnection method getAnalyse.
/**
* Method getAnalyse extact serveur, port, sid of stringConnection and check the dbType.
*
* @param stringConnection
* @return string[] { selectionIndex, serveur, port, sid }
*/
public String[] getAnalyse(final String stringConnection) {
Integer selectionIndex = getSelectionIndex();
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
String[] s = { selectionIndex.toString(), "", "", "", "", "" };
String regex = getRegex();
if (stringConnection == "") {
//$NON-NLS-1$
return s;
}
Perl5Compiler compiler = new Perl5Compiler();
Perl5Matcher matcher = new Perl5Matcher();
Pattern pattern = null;
try {
pattern = compiler.compile(regex);
if (matcher.contains(stringConnection, pattern)) {
matcher.matches(stringConnection, pattern);
MatchResult matchResult = matcher.getMatch();
s[0] = selectionIndex.toString();
if (matchResult != null) {
for (int i = 1; i < matchResult.groups(); i++) {
s[i] = matchResult.group(i);
}
}
} else {
// search if another regex corresponding at the string of connection
int i = searchGoodRegex(stringConnection);
if (i != getSelectionIndex()) {
setSelectionIndex(i);
s = getAnalyse(stringConnection);
}
}
} catch (MalformedPatternException e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
return s;
}
use of org.apache.oro.text.regex.Perl5Compiler in project tdi-studio-se by Talend.
the class DataMapExpressionParserTest method main.
public static void main(String[] args) throws Exception {
Perl5Matcher matcher = new Perl5Matcher();
Perl5Compiler compiler = new Perl5Compiler();
// String PATTERN_STR = "\\s*(\\w+)\\s*(\\.\\s*(\\w+)\\s*)+"; // can't get correct group count.
String PATTERN_STR = "(\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*)" + "|(\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*)" + "|(\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*)" + "|(\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*)";
String expression = "context. schema. context .table.column";
// String expression = "context.schema.table.column";
// String expression = "schema.table.column";
// String expression = "table.column";
matcher.setMultiline(true);
PatternMatcherInput patternMatcherInput = new PatternMatcherInput(expression);
Pattern pattern = compiler.compile(PATTERN_STR);
while (matcher.contains(patternMatcherInput, pattern)) {
MatchResult matchResult = matcher.getMatch();
System.out.println("group count:" + matchResult.groups());
for (int i = 1; i <= matchResult.groups(); i++) {
System.out.println("group[" + i + "] content:" + matchResult.group(i));
}
}
}
use of org.apache.oro.text.regex.Perl5Compiler in project tdi-studio-se by Talend.
the class VarsTable method checkValidColumnName.
/**
* Check if the given name will be unique in the process. If another link already exists with that name, false will
* be returned.
*
* @param uniqueName
* @return true if the name is unique
*/
public boolean checkValidColumnName(String connectionName) {
for (ITableEntry entry : dataMapTableEntries) {
if (entry.getName().equals(connectionName)) {
return false;
}
}
Perl5Matcher matcher = new Perl5Matcher();
Perl5Compiler compiler = new Perl5Compiler();
Pattern pattern;
try {
//$NON-NLS-1$
pattern = compiler.compile("^[A-Za-z_][A-Za-z0-9_]*$");
if (!matcher.matches(connectionName, pattern)) {
return false;
}
} catch (MalformedPatternException e) {
throw new RuntimeException(e);
}
return true;
}
use of org.apache.oro.text.regex.Perl5Compiler in project tdi-studio-se by Talend.
the class VirtualRowGeneratorNode method valueContains.
// add for bug 9471
private boolean valueContains(String value, String toTest) {
if (value.contains(toTest)) {
Perl5Matcher matcher = new Perl5Matcher();
Perl5Compiler compiler = new Perl5Compiler();
Pattern pattern;
try {
//$NON-NLS-1$ //$NON-NLS-2$
pattern = compiler.compile("\\b(" + UpdateContextVariablesHelper.replaceSpecialChar(toTest) + ")(\\b|\\_)");
if (matcher.contains(value, pattern)) {
return true;
}
} catch (MalformedPatternException e) {
throw new RuntimeException(e);
}
}
return false;
}
use of org.apache.oro.text.regex.Perl5Compiler in project tdi-studio-se by Talend.
the class ConnectionAddUniqueNameMigrationTask method checkValidConnectionName.
public boolean checkValidConnectionName(String connectionName) {
if (checkIgnoreCase(connectionName)) {
return false;
}
Perl5Matcher matcher = new Perl5Matcher();
Perl5Compiler compiler = new Perl5Compiler();
Pattern pattern;
try {
//$NON-NLS-1$
pattern = compiler.compile("^[A-Za-z_][A-Za-z0-9_]*$");
if (!matcher.matches(connectionName, pattern)) {
return false;
}
} catch (MalformedPatternException e) {
throw new RuntimeException(e);
}
return !KeywordsValidator.isKeyword(connectionName);
}
Aggregations