use of com.zimbra.cs.account.EntrySearchFilter.Single in project zm-mailbox by Zimbra.
the class LdapFilterParser method parseSimple.
private static Single parseSimple(String filterStr, int startPos, int endPos) throws ServiceException {
String dbgInfo = "filter=" + filterStr + ", startPos=" + startPos + ", endPos=" + endPos;
// it must have an equal sign somewhere
int equalPos = -1;
for (int i = startPos; i < endPos; i++) {
if (filterStr.charAt(i) == '=') {
equalPos = i;
break;
}
}
if (equalPos == -1 || equalPos == startPos)
throw ServiceException.PARSE_ERROR(dbgInfo, null);
// determine the filter type by looking at the character immediately before the equal sign
int attrEndPos;
Operator op;
switch(filterStr.charAt(equalPos - 1)) {
case '>':
op = Operator.ge;
attrEndPos = equalPos - 1;
break;
case '<':
op = Operator.le;
attrEndPos = equalPos - 1;
break;
case '~':
throw ServiceException.PARSE_ERROR("approx match not supported " + dbgInfo, null);
case ':':
throw ServiceException.PARSE_ERROR("extensible match not supported " + dbgInfo, null);
default:
op = Operator.eq;
attrEndPos = equalPos;
break;
}
// get the attribute type(name)
String attrName = filterStr.substring(startPos, attrEndPos);
if (attrName.length() == 0)
throw ServiceException.PARSE_ERROR("missing attr name" + dbgInfo, null);
// get the attribute value.
String attrValue = filterStr.substring(equalPos + 1, endPos);
if (attrValue.length() == 0)
throw ServiceException.PARSE_ERROR("missing attr value" + dbgInfo, null);
if (op == Operator.eq) {
if (attrValue.equals("*")) {
// treat it as eq and pass thru, we currently don't have a present operator
} else if (attrValue.startsWith("*") && attrValue.endsWith("*")) {
if (attrValue.length() > 2) {
op = Operator.has;
attrValue = attrValue.substring(1, attrValue.length() - 1);
}
// otherwise treat it as eq and pass thru
} else if (attrValue.startsWith("*")) {
op = Operator.endswith;
attrValue = attrValue.substring(1, attrValue.length());
} else if (attrValue.endsWith("*")) {
op = Operator.startswith;
attrValue = attrValue.substring(0, attrValue.length() - 1);
}
}
return new Single(false, attrName, op, attrValue);
}
use of com.zimbra.cs.account.EntrySearchFilter.Single 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;
}