use of com.zimbra.cs.account.EntrySearchFilter.Multi 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;
}
use of com.zimbra.cs.account.EntrySearchFilter.Multi in project zm-mailbox by Zimbra.
the class GalExtraSearchFilter method parseFilterTermElem.
private static Term parseFilterTermElem(Element termElem) throws ServiceException {
Term term;
String elemName = termElem.getName();
boolean negation = termElem.getAttributeBool(AccountConstants.A_ENTRY_SEARCH_FILTER_NEGATION, false);
if (elemName.equals(AccountConstants.E_ENTRY_SEARCH_FILTER_MULTICOND)) {
boolean or = termElem.getAttributeBool(AccountConstants.A_ENTRY_SEARCH_FILTER_OR, false);
Multi multiTerm = new Multi(negation, or ? AndOr.or : AndOr.and);
for (Iterator<Element> iter = termElem.elementIterator(); iter.hasNext(); ) {
Term child = parseFilterTermElem(iter.next());
multiTerm.add(child);
}
term = multiTerm;
} else if (elemName.equals(AccountConstants.E_ENTRY_SEARCH_FILTER_SINGLECOND)) {
String attr = termElem.getAttribute(AccountConstants.A_ENTRY_SEARCH_FILTER_ATTR);
if (attr == null)
throw ServiceException.INVALID_REQUEST("Missing search term attr", null);
String op = termElem.getAttribute(AccountConstants.A_ENTRY_SEARCH_FILTER_OP);
if (op == null)
throw ServiceException.INVALID_REQUEST("Missing search term op", null);
String value = termElem.getAttribute(AccountConstants.A_ENTRY_SEARCH_FILTER_VALUE);
if (value == null)
throw ServiceException.INVALID_REQUEST("Missing search term value", null);
term = new Single(negation, attr, op, value);
} else {
throw ServiceException.INVALID_REQUEST("Unknown element <" + elemName + "> in search filter", null);
}
return term;
}