use of com.zimbra.cs.account.EntrySearchFilter.Operator 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);
}