|
|
@ -45,7 +45,8 @@ public class Criteria implements Predicate { |
|
|
|
CriteriaType.LTE.toString(), |
|
|
|
CriteriaType.LTE.toString(), |
|
|
|
CriteriaType.NE.toString(), |
|
|
|
CriteriaType.NE.toString(), |
|
|
|
CriteriaType.LT.toString(), |
|
|
|
CriteriaType.LT.toString(), |
|
|
|
CriteriaType.GT.toString() |
|
|
|
CriteriaType.GT.toString(), |
|
|
|
|
|
|
|
CriteriaType.REGEX.toString() |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
private Object left; |
|
|
|
private Object left; |
|
|
@ -232,13 +233,27 @@ public class Criteria implements Predicate { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
boolean eval(Object left, Object right, PredicateContext ctx) { |
|
|
|
boolean eval(Object left, Object right, PredicateContext ctx) { |
|
|
|
boolean res = false; |
|
|
|
boolean res = false; |
|
|
|
final Pattern pattern = (Pattern) left; |
|
|
|
Pattern pattern; |
|
|
|
if (right != null && right instanceof String) { |
|
|
|
Object target; |
|
|
|
res = pattern.matcher(right.toString()).matches(); |
|
|
|
|
|
|
|
|
|
|
|
if(right instanceof Pattern){ |
|
|
|
|
|
|
|
pattern = (Pattern) right; |
|
|
|
|
|
|
|
target = left; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
pattern = (Pattern) left; |
|
|
|
|
|
|
|
target = right; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(target != null){ |
|
|
|
|
|
|
|
res = pattern.matcher(target.toString()).matches(); |
|
|
|
} |
|
|
|
} |
|
|
|
if(logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", right, name(), left.toString(), res); |
|
|
|
if(logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", right.toString(), name(), left.toString(), res); |
|
|
|
return res; |
|
|
|
return res; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public String toString() { |
|
|
|
|
|
|
|
return "=~"; |
|
|
|
|
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
MATCHES { |
|
|
|
MATCHES { |
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -282,6 +297,8 @@ public class Criteria implements Predicate { |
|
|
|
return LTE; |
|
|
|
return LTE; |
|
|
|
} else if ("!=".equals(str)) { |
|
|
|
} else if ("!=".equals(str)) { |
|
|
|
return NE; |
|
|
|
return NE; |
|
|
|
|
|
|
|
} else if ("=~".equals(str)) { |
|
|
|
|
|
|
|
return REGEX; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
throw new UnsupportedOperationException("CriteriaType " + str + " can not be parsed"); |
|
|
|
throw new UnsupportedOperationException("CriteriaType " + str + " can not be parsed"); |
|
|
|
} |
|
|
|
} |
|
|
@ -639,9 +656,27 @@ public class Criteria implements Predicate { |
|
|
|
private static boolean isPath(String string){ |
|
|
|
private static boolean isPath(String string){ |
|
|
|
return (string != null && (string.startsWith("$") || string.startsWith("@"))); |
|
|
|
return (string != null && (string.startsWith("$") || string.startsWith("@"))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static boolean isString(String string){ |
|
|
|
private static boolean isString(String string){ |
|
|
|
return (string != null && !string.isEmpty() && string.charAt(0) == '\'' && string.charAt(string.length() - 1) == '\''); |
|
|
|
return (string != null && !string.isEmpty() && string.charAt(0) == '\'' && string.charAt(string.length() - 1) == '\''); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private static boolean isPattern(String string){ |
|
|
|
|
|
|
|
return (string != null |
|
|
|
|
|
|
|
&& !string.isEmpty() |
|
|
|
|
|
|
|
&& string.charAt(0) == '/' |
|
|
|
|
|
|
|
&& (string.charAt(string.length() - 1) == '/' || (string.charAt(string.length() - 2) == '/' && string.charAt(string.length() - 1) == 'i')) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static Pattern compilePattern(String string) { |
|
|
|
|
|
|
|
int lastIndex = string.lastIndexOf('/'); |
|
|
|
|
|
|
|
boolean ignoreCase = string.endsWith("i"); |
|
|
|
|
|
|
|
String regex = string.substring(1, lastIndex); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int flags = ignoreCase ? Pattern.CASE_INSENSITIVE : 0; |
|
|
|
|
|
|
|
return Pattern.compile(regex, flags); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -691,6 +726,8 @@ public class Criteria implements Predicate { |
|
|
|
leftPrepared = leftPath; |
|
|
|
leftPrepared = leftPath; |
|
|
|
} else if(isString(left)) { |
|
|
|
} else if(isString(left)) { |
|
|
|
leftPrepared = left.substring(1, left.length() - 1); |
|
|
|
leftPrepared = left.substring(1, left.length() - 1); |
|
|
|
|
|
|
|
} else if(isPattern(left)){ |
|
|
|
|
|
|
|
leftPrepared = compilePattern(left); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(isPath(right)){ |
|
|
|
if(isPath(right)){ |
|
|
@ -701,6 +738,8 @@ public class Criteria implements Predicate { |
|
|
|
rightPrepared = rightPath; |
|
|
|
rightPrepared = rightPath; |
|
|
|
} else if(isString(right)) { |
|
|
|
} else if(isString(right)) { |
|
|
|
rightPrepared = right.substring(1, right.length() - 1); |
|
|
|
rightPrepared = right.substring(1, right.length() - 1); |
|
|
|
|
|
|
|
} else if(isPattern(right)){ |
|
|
|
|
|
|
|
rightPrepared = compilePattern(right); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(leftPath != null && operator.isEmpty()){ |
|
|
|
if(leftPath != null && operator.isEmpty()){ |
|
|
|