public static GranteeType fromString(String s) throws ServiceException { try { return GranteeType.valueOf(s); } catch (IllegalArgumentException e) { throw ZClientException.CLIENT_ERROR( "invalid grantee: " + s + ", valid values: " + Arrays.asList(GranteeType.values()), e); } }
public static HeaderOp fromString(String s) throws ServiceException { try { return HeaderOp.valueOf(s.toUpperCase()); } catch (IllegalArgumentException e) { throw ZClientException.CLIENT_ERROR( "invalid op: " + s + ", value values: " + Arrays.asList(HeaderOp.values()), null); } }
public ZDateCondition(DateOp op, String dateStr) throws ServiceException { mDateOp = op; try { mDate = new SimpleDateFormat("yyyyMMdd").parse(dateStr); } catch (ParseException e) { throw ZClientException.CLIENT_ERROR( "invalid date: " + dateStr + ", should be: YYYYMMDD", e); } }
public static ZAce.GranteeType getGranteeTypeFromDisplay(String name) throws ServiceException { if (name.equalsIgnoreCase("account")) return GranteeType.usr; else if (name.equalsIgnoreCase("group")) return GranteeType.grp; else if (name.equalsIgnoreCase("domain")) return GranteeType.dom; else if (name.equalsIgnoreCase("public")) return GranteeType.pub; else if (name.equalsIgnoreCase("all")) return GranteeType.all; else if (name.equalsIgnoreCase("guest")) return GranteeType.gst; else if (name.equalsIgnoreCase("key")) return GranteeType.key; else throw ZClientException.CLIENT_ERROR("unknown grantee type: " + name, null); }
public static ZFilterCondition getCondition(Element condEl) throws ServiceException { String name = condEl.getName(); boolean isNegative = condEl.getAttributeBool(MailConstants.A_NEGATIVE, false); if (name.equals(MailConstants.E_HEADER_TEST)) { String header = condEl.getAttribute(MailConstants.A_HEADER); String s = condEl.getAttribute(MailConstants.A_STRING_COMPARISON); s = s.toLowerCase(); StringComparison comparison = StringComparison.fromString(s); boolean caseSensitive = condEl.getAttributeBool(MailConstants.A_CASE_SENSITIVE, false); String value = condEl.getAttribute(MailConstants.A_VALUE); return new ZHeaderCondition( header, HeaderOp.fromStringComparison(comparison, isNegative), caseSensitive, value); } else if (name.equals(MailConstants.E_MIME_HEADER_TEST)) { String header = condEl.getAttribute(MailConstants.A_HEADER); String s = condEl.getAttribute(MailConstants.A_STRING_COMPARISON); s = s.toLowerCase(); StringComparison comparison = StringComparison.fromString(s); boolean caseSensitive = condEl.getAttributeBool(MailConstants.A_CASE_SENSITIVE, false); String value = condEl.getAttribute(MailConstants.A_VALUE); return new ZMimeHeaderCondition( header, HeaderOp.fromStringComparison(comparison, isNegative), caseSensitive, value); } else if (name.equals(MailConstants.E_HEADER_EXISTS_TEST)) { String header = condEl.getAttribute(MailConstants.A_HEADER); return new ZHeaderExistsCondition(header, !isNegative); } else if (name.equals(MailConstants.E_SIZE_TEST)) { String s = condEl.getAttribute(MailConstants.A_NUMBER_COMPARISON); s = s.toLowerCase(); NumberComparison comparison = NumberComparison.fromString(s); String size = condEl.getAttribute(MailConstants.A_SIZE); return new ZSizeCondition(SizeOp.fromNumberComparison(comparison, isNegative), size); } else if (name.equals(MailConstants.E_DATE_TEST)) { String s = condEl.getAttribute(MailConstants.A_DATE_COMPARISON); s = s.toLowerCase(); DateComparison comparison = DateComparison.fromString(s); Date date = new Date(condEl.getAttributeLong(MailConstants.A_DATE) * 1000); return new ZDateCondition(DateOp.fromDateComparison(comparison, isNegative), date); } else if (name.equals(MailConstants.E_CURRENT_TIME_TEST)) { String s = condEl.getAttribute(MailConstants.A_DATE_COMPARISON); s = s.toLowerCase(); DateComparison comparison = DateComparison.fromString(s); String timeStr = condEl.getAttribute(MailConstants.A_TIME); return new ZCurrentTimeCondition(DateOp.fromDateComparison(comparison, isNegative), timeStr); } else if (name.equals(MailConstants.E_BODY_TEST)) { String value = condEl.getAttribute(MailConstants.A_VALUE); BodyOp op = (isNegative ? BodyOp.NOT_CONTAINS : BodyOp.CONTAINS); boolean caseSensitive = condEl.getAttributeBool(MailConstants.A_CASE_SENSITIVE, false); return new ZBodyCondition(op, caseSensitive, value); } else if (name.equals(MailConstants.E_CURRENT_DAY_OF_WEEK_TEST)) { String value = condEl.getAttribute(MailConstants.A_VALUE); SimpleOp op = (isNegative ? SimpleOp.NOT_IS : SimpleOp.IS); return new ZCurrentDayOfWeekCondition(op, value); } else if (name.equals(MailConstants.E_ADDRESS_BOOK_TEST)) { String header = condEl.getAttribute(MailConstants.A_HEADER); // String folderPath = condEl.getAttribute(MailConstants.A_FOLDER_PATH); // TODO: support path to contacts folder AddressBookOp op = (isNegative ? AddressBookOp.NOT_IN : AddressBookOp.IN); return new ZAddressBookCondition(op, header); } else if (name.equals(MailConstants.E_ATTACHMENT_TEST)) { return new ZAttachmentExistsCondition(!isNegative); } else if (name.equals(MailConstants.E_INVITE_TEST)) { List<Element> eMethods = condEl.listElements(MailConstants.E_METHOD); if (eMethods.isEmpty()) { return new ZInviteCondition(!isNegative); } else { List<String> methods = new ArrayList<String>(); for (Element eMethod : eMethods) { methods.add(eMethod.getText()); } return new ZInviteCondition(!isNegative, methods); } } else if (name.equals(MailConstants.E_TRUE_TEST)) { return new ZTrueCondition(); } else { throw ZClientException.CLIENT_ERROR("unknown filter condition: " + name, null); } }