use of java.util.regex.PatternSyntaxException in project tdi-studio-se by Talend.
the class FunctionManagerExt method getAvailableFunFromValue.
/**
* qzhang Comment method "isAvailableSubValue".
*
* @param value
* @return
*/
private Function getAvailableFunFromValue(MetadataColumnExt bean, String value, List<Function> funs) {
Function currentFun = null;
if (("id_Date").equals(bean.getTalendType()) && value != null && value.split("\\.").length > 3 && value.split("\\(").length > 3) {
int index = -1;
int k = 0;
for (int i = 0; i < funs.size(); i++) {
// && !isExsit
Function function = funs.get(i);
int indexOf = value.indexOf(function.getName());
if (index == -1 || (indexOf > -1 && index > indexOf)) {
index = indexOf;
k = i;
}
}
int firstIndex = value.indexOf("(");
int lastIndex = value.lastIndexOf(")");
if (firstIndex < lastIndex && lastIndex < value.length()) {
String str = value.substring(firstIndex + 1, lastIndex);
String[] split = str.split(" ,");
if (funs.get(k).getParameters().size() == split.length) {
currentFun = funs.get(k).clone(split);
if (currentFun != null) {
return currentFun;
}
}
}
}
boolean isExsit = false;
for (int i = 0; i < funs.size() && !isExsit; i++) {
Function function = funs.get(i);
if (value != null && value.indexOf(function.getName()) != -1) {
isExsit = true;
}
}
if (value != null) {
boolean isPure = true;
int paramLength = value.length() - 2;
if (UIManager.isJavaProject()) {
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
isPure = value.indexOf(".") != -1 && value.indexOf("(") > value.indexOf(".") && value.endsWith(")");
paramLength = value.length() - 1;
} else {
isPure = value.startsWith(PERL_FUN_PREFIX) && value.endsWith(PERL_FUN_SUFFIX);
}
if (isPure && isExsit) {
for (Function function : funs) {
int indexOf = value.indexOf(function.getName());
if (indexOf != -1) {
String para = value.substring(indexOf + function.getName().length() + 1, paramLength);
if ("".equals(para)) {
//$NON-NLS-1$
if (function.getParameters().size() == 0) {
currentFun = (Function) function.clone();
}
} else {
// add by wzhang to fix bug 8732.
try {
// Pattern regex = Pattern.compile("(\\.|\\w)+\\(([^()]|\\(([^()])*\\))*\\)|\".*?\"|\\w+", //$NON-NLS-1$
// Pattern.CANON_EQ);
Pattern regex = //$NON-NLS-1$
Pattern.compile(//$NON-NLS-1$
"[^,]+", Pattern.CANON_EQ);
Matcher m = regex.matcher(para);
List<String> strs = new ArrayList<String>();
while (m.find()) {
strs.add(m.group());
}
String[] ps = strs.toArray(new String[strs.size()]);
if (ps.length == function.getParameters().size()) {
currentFun = function.clone(ps);
}
} catch (PatternSyntaxException ex) {
// Syntax error in the regular expression
}
}
}
}
} else {
currentFun = createPureFunctions(value, funs, currentFun);
}
}
return currentFun;
}
use of java.util.regex.PatternSyntaxException in project tdi-studio-se by Talend.
the class TreeSettingDirectEditCommand method execute.
@Override
public void execute() {
try {
if (model instanceof InputXmlTree) {
InputXmlTree inputTree = (InputXmlTree) model;
if (type != null) {
switch(type) {
case LOOKUP_MODEL:
inputTree.setLookupMode(getLookupModelByLabel((String) newValue));
break;
case MATCH_MODEL:
inputTree.setMatchingMode(getMatchModelByLabel((String) newValue));
break;
case JOIN_MODEL:
if (TreeSettingsConstant.INNER_JOIN.equals(newValue)) {
inputTree.setInnerJoin(true);
} else {
inputTree.setInnerJoin(false);
}
break;
case PERSISTENT_MODEL:
inputTree.setPersistent(Boolean.valueOf((String) newValue));
break;
case EXPRESSION_FILTER:
calculateFilterConnections(inputTree, (String) newValue);
inputTree.setExpressionFilter((String) newValue);
break;
default:
break;
}
}
} else if (model instanceof OutputXmlTree) {
OutputXmlTree outputTree = (OutputXmlTree) model;
if (type != null) {
switch(type) {
case OUTPUT_REJECT:
outputTree.setReject(Boolean.valueOf((String) newValue));
break;
case LOOK_UP_INNER_JOIN_REJECT:
outputTree.setRejectInnerJoin(Boolean.valueOf((String) newValue));
break;
case EXPRESSION_FILTER:
calculateFilterConnections(outputTree, (String) newValue);
outputTree.setExpressionFilter((String) newValue);
break;
case ALL_IN_ONE:
outputTree.setAllInOne(Boolean.valueOf((String) newValue));
break;
case ENABLE_EMPTY_ELEMENT:
outputTree.setEnableEmptyElement(Boolean.valueOf((String) newValue));
}
}
}
} catch (PatternSyntaxException ex) {
// Syntax error in the regular expression
}
}
use of java.util.regex.PatternSyntaxException in project tdi-studio-se by Talend.
the class DbGenerationManager method containWith.
public static boolean containWith(String expression, String pattern, boolean start) {
if (expression != null) {
expression = expression.trim();
try {
if (start) {
pattern = DbMapSqlConstants.EMPTY + '^' + pattern;
}
Pattern regex = Pattern.compile(pattern, Pattern.CANON_EQ | Pattern.CASE_INSENSITIVE);
Matcher regexMatcher = regex.matcher(expression);
return regexMatcher.find();
} catch (PatternSyntaxException ex) {
//
}
}
return false;
}
use of java.util.regex.PatternSyntaxException in project ACS by ACS-Community.
the class RegExpFilter method applyTo.
protected boolean applyTo(Object obj) {
if (obj == null) {
return false;
}
// Temporary: Used to remember if the test passes
// and apply the not policy (if requested)
boolean res = false;
try {
Matcher m = pattern.matcher((String) obj);
res = m.matches();
} catch (PatternSyntaxException exception) {
// This is a problem! Ignore the filter returning true
return true;
}
if (notFilter)
return !res;
else
return res;
}
use of java.util.regex.PatternSyntaxException in project ACS by ACS-Community.
the class ACSAlarmDAOImpl method processRef.
static Pattern processRef(String abase, String ref) throws PatternSyntaxException {
Stack stack;
String[] tmp;
if (ref.startsWith("/") || abase == null) {
if (ref.startsWith("/")) {
tmp = ref.substring(1).split("/");
} else {
tmp = ref.split("/");
}
stack = new Stack();
} else {
tmp = ref.split("/");
stack = new Stack();
String[] orig = abase.substring(1).split("/");
for (int a = 0; a < orig.length; a++) stack.push(orig[a]);
}
for (int a = 0; a < tmp.length; a++) {
String t = tmp[a];
if (".".equals(t)) {
// ignore
} else if ("..".equals(t)) {
if (stack.size() > 0) {
String removed = (String) stack.pop();
if ("**".equals(removed))
throw new PatternSyntaxException(".. can't follow **", ref, -1);
}
} else {
stack.push(t);
}
}
StringBuffer sb = new StringBuffer();
sb.append('^');
int s = stack.size();
for (int a = 0; a < s; a++) {
if (a > 0)
sb.append("/");
String t = (String) stack.get(a);
if (t.indexOf("**") >= 0) {
if ("**".equals(t)) {
sb.append(".*");
} else {
throw new PatternSyntaxException("** can't appear as a substring", t, -1);
}
} else {
int l = t.length();
for (int b = 0; b < l; b++) {
char c = t.charAt(b);
if (c == '*') {
sb.append("[^/]*");
} else {
regexEncodeChar(sb, c);
}
}
}
}
sb.append('$');
return Pattern.compile(sb.toString());
}
Aggregations