use of com.zimbra.cs.account.EntrySearchFilter.AndOr in project zm-mailbox by Zimbra.
the class LdapFilterParser method parseCompound.
private static Multi parseCompound(FilterType filterType, String filterStr, int startPos, int endPos) throws ServiceException {
String dbgInfo = "filter=" + filterStr + ", startPos=" + startPos + ", endPos=" + endPos;
if (startPos == endPos)
throw ServiceException.PARSE_ERROR(dbgInfo, null);
// the first and last characters must be parentheses
if ((filterStr.charAt(startPos) != '(') || (filterStr.charAt(endPos - 1) != ')'))
throw ServiceException.PARSE_ERROR("mising parentheses: " + dbgInfo, null);
// create the Term
AndOr andOr = (filterType == FilterType.OR) ? AndOr.or : AndOr.and;
boolean negation = (filterType == FilterType.NOT) ? true : false;
Multi multi = new Multi(negation, andOr);
// iterate through the characters in the value. Whenever an open
// parenthesis is found, locate the corresponding close parenthesis by
// counting the number of intermediate open/close parentheses.
int pendingOpens = 0;
int openPos = -1;
for (int i = startPos; i < endPos; i++) {
char c = filterStr.charAt(i);
if (c == '(') {
if (openPos < 0) {
openPos = i;
}
pendingOpens++;
} else if (c == ')') {
pendingOpens--;
if (pendingOpens == 0) {
Term subTerm = parse(filterStr, openPos, i + 1);
multi.add(subTerm);
openPos = -1;
} else if (pendingOpens < 0) {
throw ServiceException.PARSE_ERROR("mising open parentheses: " + dbgInfo, null);
}
} else if (pendingOpens <= 0) {
throw ServiceException.PARSE_ERROR("mising parentheses: " + dbgInfo, null);
}
}
if (pendingOpens != 0)
throw ServiceException.PARSE_ERROR("mising parentheses: " + dbgInfo, null);
return multi;
}