use of com.zimbra.cs.account.EntrySearchFilter.Term 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.Term 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;
}
use of com.zimbra.cs.account.EntrySearchFilter.Term in project zm-mailbox by Zimbra.
the class LdapEntrySearchFilter method toLdapIDNFilter.
/**
* Takes a RFC 2254 filter and converts assertions value from unicode to ACE
* for IDN attributes. IDN attributes are those storing the ACE representation
* of the unicode. For non-IDN attributes, assertion values are just passed through.
*
* e.g.
* (zimbraMailDeliveryAddress=*@test.中文.com) will be converted to
* (zimbraMailDeliveryAddress=*@test.xn--fiq228c.com)
* because zimbraMailDeliveryAddress is an IDN attribute.
*
* (zimbraDomainName=*中文*) will remain the same because zimbraDomainName
* is not an IDN attribute.
*
* @param filterStr a RFC 2254 filter (assertion values must be already RFC 2254 escaped)
* @return
*/
public static String toLdapIDNFilter(String filterStr) {
String asciiQuery;
try {
Term term = LdapFilterParser.parse(filterStr);
EntrySearchFilter filter = new EntrySearchFilter(term);
asciiQuery = toLdapIDNFilter(filter);
ZimbraLog.account.debug("original query=[" + filterStr + "], converted ascii query=[" + asciiQuery + "]");
} catch (ServiceException e) {
ZimbraLog.account.warn("unable to convert query to ascii, using original query: " + filterStr, e);
asciiQuery = filterStr;
}
return asciiQuery;
}
use of com.zimbra.cs.account.EntrySearchFilter.Term in project zm-mailbox by Zimbra.
the class GalExtraSearchFilter method parseSearchFilter.
public static EntrySearchFilter parseSearchFilter(Element request) throws ServiceException {
Element filterElem = request.getOptionalElement(AccountConstants.E_ENTRY_SEARCH_FILTER);
if (filterElem == null) {
return null;
}
Element termElem = filterElem.getOptionalElement(AccountConstants.E_ENTRY_SEARCH_FILTER_MULTICOND);
if (termElem == null)
termElem = filterElem.getElement(AccountConstants.E_ENTRY_SEARCH_FILTER_SINGLECOND);
Term term = GalExtraSearchFilter.parseFilterTermElem(termElem);
EntrySearchFilter filter = new EntrySearchFilter(term);
return filter;
}
Aggregations